euv_engine/scheduler/trait.rs
1/// The trait that game implementations must fulfill to receive
2/// fixed-timestep update and interpolated render callbacks from the scheduler.
3pub trait TickHandler {
4 /// Called at a fixed interval defined by `SchedulerConfig::fixed_timestep`.
5 ///
6 /// All game logic, physics, and state mutations should happen here.
7 ///
8 /// # Arguments
9 ///
10 /// - `f64` - The fixed delta time in seconds.
11 fn on_update(&mut self, delta_time: f64);
12
13 /// Called once per animation frame after all accumulated updates have been processed.
14 ///
15 /// The interpolation factor represents how far between fixed updates the current
16 /// frame is, allowing smooth rendering at variable frame rates.
17 ///
18 /// # Arguments
19 ///
20 /// - `f64` - The interpolation factor in the range 0.0 to 1.0.
21 fn on_render(&mut self, interpolation: f64);
22}
23
24/// A trait for objects that participate in the engine's update step.
25///
26/// All implementors receive the same fixed-timestep delta time; the engine's
27/// scheduler is responsible for dispatching. Provides a single abstraction over
28/// the `update` methods defined on `Entity`, `Animator`, `SceneManager`, and
29/// the `World2D` / `World3D` physics containers, enabling generic iteration
30/// (e.g. `Vec<Box<dyn Updatable>>`).
31///
32/// `SchedulerState::tick` calls into this trait through the `TickHandler`
33/// trait; per-domain implementors (entities, scenes, sprites, physics worlds)
34/// expose their own `update` method that satisfies this contract.
35pub trait Updatable {
36 /// Advance the object's internal state by the given delta time.
37 ///
38 /// # Arguments
39 ///
40 /// - `f64` - The delta time in seconds since the last update.
41 fn update(&mut self, delta_time: f64);
42}