Skip to main content

Engine

Struct Engine 

Source
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

Source

pub fn new() -> Self

Create a new engine with an empty World and Schedule.

Source

pub fn world(&self) -> &World

Immutable reference to the world.

Source

pub fn world_mut(&mut self) -> &mut World

Mutable reference to the world.

Source

pub fn schedule(&self) -> &Schedule

Immutable reference to the schedule.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn pause(&mut self)

Pause the simulation. Ticks will produce zero simulation steps.

Lazily inserts a default VirtualTime if not already present.

Source

pub fn resume(&mut self)

Resume the simulation after a pause.

Lazily inserts a default VirtualTime if not already present.

Source

pub fn set_speed(&mut self, scale: f64)

Set the simulation speed multiplier (clamped to [0.0, 8.0] at tick time).

  • 1.0 = normal speed
  • 2.0 = double speed (RTS fast-forward)
  • 0.5 = half speed (slow-mo)

Lazily inserts a default VirtualTime if not already present.

Source

pub fn is_paused(&self) -> bool

Returns true if the simulation is paused.

Trait Implementations§

Source§

impl Default for Engine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Engine

§

impl !Send for Engine

§

impl !Sync for Engine

§

impl !UnwindSafe for Engine

§

impl Freeze for Engine

§

impl Unpin for Engine

§

impl UnsafeUnpin for Engine

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.