Struct Engine

Source
pub struct Engine {
    pub timeline: Vec<Scene>,
    pub timenow: usize,
}
Expand description

§Engine

The Engine struct represents the core state manager of the RPGX system.
It maintains a timeline of Scenes (like a stack of game states or world instances), enabling dynamic transitions and rewinds across gameplay moments.


§Fields

  • timeline: Vec<Scene>
    A timeline of game scenes, ordered by when they were pushed into the engine.

  • timenow: usize
    The current index in the timeline, representing the active scene.


§Methods

§new(scene: Scene) -> Self

Creates a new engine with the given initial scene.
The engine starts with one scene on its timeline and the pointer set to it.


§get_active_scene(&self) -> Option<&Scene>

Returns an immutable reference to the currently active scene, or None if the timeline is empty.


§get_active_scene_mut(&mut self) -> Option<&mut Scene>

Returns a mutable reference to the currently active scene, allowing modifications like pawn movement.


§push_scene(&mut self, scene: Scene)

Adds a new scene to the end of the timeline and updates the active pointer to it.
Useful when switching maps, progressing story, or entering sub-areas.


§pop_scene(&mut self)

Removes the last scene from the timeline if there is more than one.
Also updates timenow to point to the new last scene.


§rollback_to(&mut self, index: usize)

Rolls back the timeline to a specified earlier index.
All scenes after the index are removed, and the pointer is updated.

No-op if the index is out of bounds.


§rewind_to(&mut self, index: usize) -> Result<(), &str>

Moves the current scene pointer to a past scene in the timeline without removing any entries.
Returns an error string if the index is invalid.


§get_scene_at(&self, index: usize) -> Option<&Scene>

Gets an immutable reference to a scene at a specific point in the timeline, useful for review or replay features.


§Notes

  • The engine timeline is inspired by save-states or undo-redo systems.
  • Scenes can be pushed/popped for forward progression or state rollback.
  • Engine provides centralized control over which scene is currently active.

Fields§

§timeline: Vec<Scene>

Timeline of scene states over time.

§timenow: usize

Current index in the timeline (pointer to active scene).

Implementations§

Source§

impl Engine

Source

pub fn new(scene: Scene) -> Self

Create a new engine starting with an initial scene.

Source

pub fn get_active_scene(&self) -> Option<&Scene>

Get a reference to the currently active scene.

Source

pub fn get_active_scene_mut(&mut self) -> Option<&mut Scene>

Get a mutable reference to the currently active scene.

Source

pub fn push_scene(&mut self, scene: Scene)

Push a new scene to the timeline and move the pointer to it.

Source

pub fn pop_scene(&mut self)

Pop the last scene from the timeline if there’s more than one. Updates timenow to point to the new last scene.

Source

pub fn rollback_to(&mut self, index: usize)

Roll back the timeline to the specified index, truncating all scenes after it. Updates timenow accordingly.

Source

pub fn rewind_to(&mut self, index: usize) -> Result<(), &'static str>

Rewind to a specific point in the timeline without truncating. Returns error if the index is out of range.

Source

pub fn get_scene_at(&self, index: usize) -> Option<&Scene>

Get a reference to the scene at the specified index.

Trait Implementations§

Source§

impl Clone for Engine

Source§

fn clone(&self) -> Engine

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Engine

§

impl RefUnwindSafe for Engine

§

impl Send for Engine

§

impl Sync for Engine

§

impl Unpin for Engine

§

impl UnwindSafe 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.