From dd5de0107163bc3ea3898c07089d00f82feeec5e Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Sun, 3 May 2026 18:37:35 -0400 Subject: add tick and subtick system for solar system orbit updates --- src/solar_system.rs | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'src/solar_system.rs') diff --git a/src/solar_system.rs b/src/solar_system.rs index df1d246..f4ca9ae 100644 --- a/src/solar_system.rs +++ b/src/solar_system.rs @@ -41,7 +41,15 @@ pub struct SolarSystem id: SystemId, name: String, bodies: Vec, - time: Option +} + +pub fn update_systems( + solar_systems: std::slice::IterMut<'_, SolarSystem>, + time: Second) +{ + for system in solar_systems { + system.update(time); + } } impl SolarSystem @@ -66,6 +74,7 @@ impl SolarSystem } None => {} } + if record.radius == 0.0 { continue; } println!("New body: {:?}", record); bodies.push(OrbitalBody { @@ -78,7 +87,6 @@ impl SolarSystem id: id, name: bodies[0].name().clone(), bodies: bodies, - time: None }) } @@ -103,16 +111,6 @@ impl SolarSystem self.bodies.as_slice() } - fn update_bodies( - &mut self, - time: Second) - { - self.bodies.iter_mut().for_each(|body| { - body.position = Some(body.calculate_orbit_at(time)); - }); - self.time = Some(time); - } - pub fn body_position( &self, body: &OrbitalBody) @@ -132,15 +130,9 @@ impl SolarSystem &mut self, time: Second) { - match self.time { - Some(cache_time) => { - if cache_time == time { return; } - self.update_bodies(time); - } - None => { - self.update_bodies(time); - } - } + self.bodies.iter_mut().for_each(|body| { + body.position = Some(body.calculate_orbit_at(time)); + }); } } -- cgit v1.2.3