diff options
Diffstat (limited to 'src/tacmap/body_render.rs')
| -rw-r--r-- | src/tacmap/body_render.rs | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/src/tacmap/body_render.rs b/src/tacmap/body_render.rs index 92ac13f..23a04c9 100644 --- a/src/tacmap/body_render.rs +++ b/src/tacmap/body_render.rs @@ -1,7 +1,8 @@ use std::error::Error; -use crate::solar_system::Kilometers; -use crate::timeman::{SYSTEM_TICK_INTERVAL, Second}; +use crate::solar_system::{Kilometers}; +use crate::solar_system::body::OrbitalBody; +use crate::timeman::{Second}; use crate::wgpuctx::{WgpuCtx, pipeline::RenderPipelineBuilder}; use super::*; @@ -9,7 +10,7 @@ use super::*; pub struct BodyRenderer { needs_rebuild: bool, - last_time: Option<Second>, + last_tick: Option<i64>, pipeline: wgpu::RenderPipeline, @@ -35,7 +36,7 @@ impl BodyRenderer Self { needs_rebuild: true, - last_time: None, + last_tick: None, pipeline: render_pipeline, body_instance_buffer: None } @@ -75,7 +76,7 @@ impl BodyRenderer } ); - self.last_time = None; + self.last_tick = None; self.body_instance_buffer = Some((bodies.len(), buffer)); } @@ -88,23 +89,12 @@ impl BodyRenderer { //If the last updated time is the same, we don't need to update //the positions of all the bodies. - if self.last_time.is_some_and(|last_time| { last_time == time }) { + let tick = time / OrbitalBody::TICK_DURATION; + if self.last_tick.is_some_and(|last_tick| { last_tick == tick }) { return Ok(()); } - //Round to the nearest tick - let tick_time = match self.last_time { - Some(last_time) => { - let this_tick = time / SYSTEM_TICK_INTERVAL; - let last_tick = last_time / SYSTEM_TICK_INTERVAL; - - if this_tick == last_tick { return Ok(()) } - this_tick * SYSTEM_TICK_INTERVAL - } - None => 0 - }; - - self.last_time = Some(time); + self.last_tick = Some(time); let (_, bodies_buffer) = match &self.body_instance_buffer { Some(tuple) => tuple, @@ -113,11 +103,11 @@ impl BodyRenderer let bodies = solar_system.bodies(); let body_instances = bodies.iter().map(|body| { - let position = body.relative_position(); + let position = body.relative_position(time); let origin = match body.get_orbit() { Some(orbit) => { let origin_body = &bodies[orbit.parent()]; - origin_body.relative_position() + origin_body.relative_position(time) }, None => cgmath::Vector3::new(0.0, 0.0, 0.0) }; |
