Struct App

pub struct App<G>
where G: Game,
{ /* private fields */ }
Expand description

A single application lifecycle driven by host-supplied elapsed time.

No per-frame allocation or platform work is performed by the runner itself. Pause and terminal game states belong to its GameSession; application stop is permanent and also releases resources through Game::shutdown.

Implementations§

§

impl<G> App<G>
where G: Game,

pub fn new(game: G, session: GameSession) -> App<G>

Take ownership of a game and its configured session without invoking hooks.

pub fn game(&self) -> &G

Inspect application data, including after shutdown.

pub fn game_mut(&mut self) -> &mut G

Update host input or application data between frames.

pub fn session(&self) -> &GameSession

Inspect simulation state and its clock.

pub fn session_mut(&mut self) -> &mut GameSession

Control start, pause, finish, or restart between frames.

Let App::frame advance the clock; manually advancing it consumes time without invoking game updates. Session changes never restart a stopped app.

pub fn state(&self) -> AppState

Inspect application state independently of the session’s game state.

pub fn startup(&mut self) -> Result<AppControl, AppError<<G as Game>::Error>>

Attempt startup once, without advancing time or rendering.

Repeated calls return Continue while running and Stop after termination.

pub fn frame( &mut self, elapsed_seconds: f64, ) -> Result<AppControl, AppError<<G as Game>::Error>>

Run startup if needed, bounded fixed updates, and one interpolated render.

The duration is in seconds and is passed directly to GameSession::advance. Negative/non-finite elapsed time follows the core clock’s sanitization policy. Stop or error short-circuits the frame, including during catch-up. Use Self::frame_report for execution counts and timing, or inspect Self::last_frame_report after this call, including on error.

pub fn frame_report( &mut self, elapsed_seconds: f64, ) -> Result<AppFrameReport, AppError<<G as Game>::Error>>

Run a frame with the same hooks and errors as Self::frame, returning details.

Reports distinguish scheduled ticks from executed updates if a hook stops early. On error, the partial report is available through Self::last_frame_report, with control == AppControl::Stop, after exactly-once cleanup has been attempted. Primary and cleanup errors use the unchanged AppError contract. No hooks or elapsed time are retried.

use ferravex_engine::app::{App, AppControl, Game};
use ferravex_core::session::GameSession;
let mut app = App::new(Demo, GameSession::new(64.0, 4, true));
let report = app.frame_report(6.5 / 64.0)?;
assert_eq!(report.scheduled_updates, 4);
assert_eq!(report.executed_updates, 4);
assert_eq!(report.dt, 1.0 / 64.0);
assert_eq!(report.alpha, 0.5);
assert_eq!(report.dropped_seconds, 2.0 / 64.0);
assert!(report.rendered);
assert_eq!(report.control, AppControl::Continue);
app.stop()?;
assert_eq!(app.frame_report(1.0)?.control, AppControl::Stop);

pub fn last_frame_report(&self) -> Option<AppFrameReport>

Snapshot of the most recent completed Self::frame or Self::frame_report.

Returns None before the first frame call. Both successful and failed frames replace this snapshot; a hook panic does not. Direct calls to startup/stop and session changes leave it unchanged, so its control is historical; use Self::state to inspect the current application state.

use ferravex_engine::app::{App, AppControl, AppHook, Game};
use ferravex_core::session::GameSession;
struct FailingGame;
impl Game for FailingGame {
    type Error = &'static str;
    fn fixed_update(&mut self, _: f32) -> Result<AppControl, Self::Error> {
        Err("update failed")
    }
}
let mut app = App::new(FailingGame, GameSession::new(64.0, 4, true));
assert_eq!(app.last_frame_report(), None);
let error = app.frame(3.5 / 64.0).unwrap_err();
assert_eq!(error.hook, AppHook::FixedUpdate);
let report = app.last_frame_report().unwrap();
assert_eq!(report.scheduled_updates, 3);
assert_eq!(report.executed_updates, 1); // Includes the failing hook.
assert_eq!(report.alpha, 0.5);
assert!(!report.rendered);
assert_eq!(report.control, AppControl::Stop);

pub fn stop(&mut self) -> Result<(), AppError<<G as Game>::Error>>

Permanently stop and attempt shutdown once if startup was attempted.

Safe to repeat, including after any hook error. The state becomes Stopped before cleanup, so even a failed shutdown is never retried by Drop.

Trait Implementations§

§

impl<G> Drop for App<G>
where G: Game,

§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<G> Freeze for App<G>
where G: Freeze,

§

impl<G> RefUnwindSafe for App<G>
where G: RefUnwindSafe,

§

impl<G> Send for App<G>
where G: Send,

§

impl<G> Sync for App<G>
where G: Sync,

§

impl<G> Unpin for App<G>
where G: Unpin,

§

impl<G> UnwindSafe for App<G>
where G: UnwindSafe,

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 = 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.