Skip to main content

game_toolkit_core/
lib.rs

1//! Core: app loop, [`Game`] trait, [`Context`], time.
2
3#![forbid(unsafe_code)]
4
5mod app;
6mod context;
7mod time;
8
9pub use app::{AppConfig, run};
10pub use context::{Context, GameEvent};
11pub use time::Time;
12
13pub trait Game: 'static + Sized {
14    fn init(ctx: &mut Context) -> anyhow::Result<Self>;
15    fn update(&mut self, ctx: &mut Context, dt: f32);
16    fn render(&mut self, ctx: &mut Context, frame: &mut game_toolkit_gfx::Frame);
17    fn event(&mut self, _ctx: &mut Context, _event: &GameEvent) {}
18    /// Raw winit window-event hook. Return `true` to mark the event consumed so it is not
19    /// forwarded to the toolkit's [`game_toolkit_input::Input`] state. Use this for egui or other
20    /// overlays that need first crack at events.
21    fn raw_window_event(&mut self, _ctx: &mut Context, _event: &winit::event::WindowEvent) -> bool {
22        false
23    }
24    fn shutdown(&mut self, _ctx: &mut Context) {}
25}