summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-16 17:29:42 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-16 17:29:42 -0700
commitf177cc716c5f2aa5b50b14ccbb421de89e3a7854 (patch)
treedb06f9f44251d6d90e5e9709d47e6cc4397b9443 /src/main.rs
parent40e9d818195824749293dff3afcfdd5c1432adbe (diff)
wip
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index bb4cb27..a01dbbd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,9 +19,13 @@ use winit::{
use crate::{
camera::Camera,
- config::{PHYSICS_DELTA_TIME, PHYSICS_FPS, SIM_DELTA_TIME, SIM_FPS, WINDOW_TITLE},
+ config::{PHYSICS_DELTA_TIME, PHYSICS_FPS, SIM_FPS, WINDOW_TITLE},
renderer::RendererState,
- sim::{cell::Cell, materials::MaterialId, sim::sim_tick, world::World},
+ sim::{
+ cell::{cell::Cell, materials::MaterialId},
+ cell_sim::{sim::sim_tick, world::World},
+ rb_sim::{PhysicsManager, RbSimManager},
+ },
};
pub type Error = Box<dyn std::error::Error>;
@@ -58,8 +62,12 @@ struct App {
camera: Option<Camera>,
+ // grid
world: Option<World>,
+ // physics
+ rb_sim_manager: Option<RbSimManager>,
+
// sim state
// the last/current (not yet completed) seqno
sim_seqno: u64,
@@ -122,8 +130,7 @@ impl App {
// called SIM_FPS times per second
// will be called before the render and before the physics update(s)
// may be called multiple times if the sim time is behind
- // sim_delta_time is statically 1/SIM_FPS
- fn sim_update(&mut self, _sim_delta_time: f32) {
+ fn sim_update(&mut self) {
if let Some(world) = &mut self.world {
sim_tick(world, self.sim_seqno, self.config.use_threading);
self.sim_seqno += 1;
@@ -133,7 +140,11 @@ impl App {
// will be called before the render
// may be called multiple times if the physics time is behind
// physics_delta_time is statically 1/PHYSICS_FPS
- fn physics_update(&mut self, _physics_delta_time: f32) {}
+ fn physics_update(&mut self, physics_delta_time: f32) {
+ if let Some(physics_manager) = &mut self.rb_sim_manager {
+ physics_manager.rb_tick(physics_delta_time);
+ }
+ }
}
impl Default for App {
@@ -157,6 +168,8 @@ impl Default for App {
world: Some(World::from_default_size()),
+ rb_sim_manager: Some(RbSimManager::new()),
+
sim_seqno: 0,
sim_paused: false,
ignore_pause_next_tick: false,
@@ -191,6 +204,9 @@ impl ApplicationHandler for App {
self.window = Some(window.clone());
self.renderer_state = Some(executor::block_on(RendererState::new(window.clone())));
+ if let Some(rbsm) = &mut self.rb_sim_manager {
+ rbsm.test();
+ }
let size = window.inner_size();
self.camera = Some(Camera::new((size.width as i32, size.height as i32)));
@@ -300,7 +316,7 @@ impl ApplicationHandler for App {
self.last_sim_update = now;
if self.sim_paused && self.ignore_pause_next_tick {
- self.sim_update(SIM_DELTA_TIME);
+ self.sim_update();
self.ignore_pause_next_tick = false;
} else if !self.sim_paused {
self.sim_updates_due +=
@@ -308,7 +324,7 @@ impl ApplicationHandler for App {
let mut updates_done = 0;
// don't ever update more than 3 times per frame, or else we can get a pseudo deadlock
while self.sim_updates_due >= 1.0 && updates_done < 3 {
- self.sim_update(SIM_DELTA_TIME);
+ self.sim_update();
updates_done += 1;
}
self.sim_updates_due -= updates_done as f32;
@@ -333,10 +349,12 @@ impl ApplicationHandler for App {
if let Some(renderer_state) = &mut self.renderer_state
&& let Some(world) = &mut self.world
+ && let Some(rb_sim_manager) = &mut self.rb_sim_manager
&& let Some(camera) = &mut self.camera
{
renderer_state.render(
world,
+ rb_sim_manager,
camera,
&mut self.config,
&self.diagnostics,