pub struct Engine { /* private fields */ }Expand description
The central game engine object.
Engine owns the World and Schedule and exposes a builder API for
wiring up systems and plugins before (or during) the game loop.
§Example
use galeon_engine::{Engine, Plugin, QueryMut, Component};
#[derive(Component)]
struct Score(u32);
fn add_score(mut scores: QueryMut<'_, Score>) {
for (_, s) in scores.iter_mut() { s.0 += 1; }
}
struct MyPlugin;
impl Plugin for MyPlugin {
fn build(&self, engine: &mut Engine) {
engine.add_system::<(QueryMut<'_, Score>,)>("update", "add_score", add_score);
}
}
let mut engine = Engine::new();
engine.add_plugin(MyPlugin);
engine.run_once();Implementations§
Source§impl Engine
impl Engine
Sourcepub fn add_system<P>(
&mut self,
stage: &'static str,
name: &'static str,
func: impl IntoSystem<P>,
) -> &mut Self
pub fn add_system<P>( &mut self, stage: &'static str, name: &'static str, func: impl IntoSystem<P>, ) -> &mut Self
Add a system to the schedule.
Accepts any parameterized function like fn(Res<T>, QueryMut<U>).
Delegates to Schedule::add_system. Returns &mut Self for chaining.
Sourcepub fn add_plugin(&mut self, plugin: impl Plugin) -> &mut Self
pub fn add_plugin(&mut self, plugin: impl Plugin) -> &mut Self
Apply a plugin to this engine.
Calls Plugin::build with self. Returns &mut Self for chaining.
Sourcepub fn set_tick_rate(&mut self, hz: f64) -> &mut Self
pub fn set_tick_rate(&mut self, hz: f64) -> &mut Self
Set the fixed-timestep tick rate in Hz.
Common values: 10 Hz (RTS/tycoon), 20 Hz (strategy), 30 Hz (action), 60 Hz (platformer/FPS). If not called, defaults to 10 Hz on first tick.
Sourcepub fn insert_resource<T: Send + 'static>(&mut self, value: T) -> &mut Self
pub fn insert_resource<T: Send + 'static>(&mut self, value: T) -> &mut Self
Insert a resource into the world.
Delegates to World::insert_resource. Returns &mut Self for
chaining.
Sourcepub fn register_render_channel<T: ExtractToFloats>(
&mut self,
name: &str,
) -> &mut Self
pub fn register_render_channel<T: ExtractToFloats>( &mut self, name: &str, ) -> &mut Self
Register a named render data channel.
The component type must implement ExtractToFloats. During frame
extraction, this channel will produce a flat Vec<f32> with
T::STRIDE floats per entity.
Lazily inserts a RenderChannelRegistry resource if not already
present. Returns &mut Self for chaining.
Sourcepub fn tick(&mut self, elapsed: f64) -> u32
pub fn tick(&mut self, elapsed: f64) -> u32
Advance the simulation by elapsed seconds using a fixed timestep.
If a FixedTimestep resource has not been inserted yet this method
inserts the default RTS timestep (10 Hz) automatically. Returns the
number of ticks executed.
Sourcepub fn run_once(&mut self)
pub fn run_once(&mut self)
Run the schedule exactly once without any fixed-timestep logic.
Useful for integration tests or non-game-loop scenarios.
Sourcepub fn pause(&mut self)
pub fn pause(&mut self)
Pause the simulation. Ticks will produce zero simulation steps.
Lazily inserts a default VirtualTime if not already present.
Sourcepub fn resume(&mut self)
pub fn resume(&mut self)
Resume the simulation after a pause.
Lazily inserts a default VirtualTime if not already present.