summaryrefslogtreecommitdiffstats
path: root/src/solar_system.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/solar_system.rs')
-rw-r--r--src/solar_system.rs34
1 files changed, 13 insertions, 21 deletions
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<OrbitalBody>,
- time: Option<Second>
+}
+
+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));
+ });
}
}