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,
impl<G> App<G>where
G: Game,
pub fn new(game: G, session: GameSession) -> App<G>
pub fn new(game: G, session: GameSession) -> App<G>
Take ownership of a game and its configured session without invoking hooks.
pub fn session(&self) -> &GameSession
pub fn session(&self) -> &GameSession
Inspect simulation state and its clock.
pub fn session_mut(&mut self) -> &mut GameSession
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 startup(&mut self) -> Result<AppControl, AppError<<G as Game>::Error>>
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>>
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>>
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>
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);