Add design persistence, world rendering, metrics overlay and logs
M3: STL/OBJ import with mesh validation, mass/COM/inertia, material database, RON scene with content-addressed blobs and v0->v1 migration. M4: deterministic heightmap terrain, trimesh colliders, wgpu renderer with instancing and depth, winit app with 1 kHz physics, fly camera, on-screen metrics overlay and per-frame CSV/dev logs. Docs: UI, logging, network and headless CLI plans.
This commit is contained in:
parent
79928b645b
commit
93075ab1fd
107 changed files with 14785 additions and 46 deletions
35
crates/sensors/src/delay.rs
Normal file
35
crates/sensors/src/delay.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//! A fixed-length FIFO that models the transport delay of a sensor bus.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
|
||||
/// A FIFO of `steps` samples.
|
||||
///
|
||||
/// The queue starts filled with `initial`, so the first `steps` calls to
|
||||
/// [`Delay::push`] report that value while the queue drains.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Delay<T> {
|
||||
initial: T,
|
||||
queue: VecDeque<T>,
|
||||
}
|
||||
|
||||
impl<T: Clone> Delay<T> {
|
||||
/// A delay of `steps` samples, reporting `initial` until the queue fills.
|
||||
pub fn new(steps: usize, initial: T) -> Self {
|
||||
Self {
|
||||
initial: initial.clone(),
|
||||
queue: core::iter::repeat_n(initial, steps).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Pushes a new sample and returns the one measured `steps` samples ago, or the
|
||||
/// new sample itself when the delay is zero.
|
||||
pub fn push(&mut self, value: T) -> T {
|
||||
if self.queue.is_empty() {
|
||||
return value;
|
||||
}
|
||||
self.queue.push_back(value);
|
||||
self.queue
|
||||
.pop_front()
|
||||
.unwrap_or_else(|| self.initial.clone())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue