pub trait EngineApp:
AgentProvider
+ PhaseProvider
+ Send
+ Sync {
// Required methods
fn window_config() -> WindowConfig
where Self: Sized;
fn new() -> Self
where Self: Sized;
fn setup(&mut self, world: &mut GameWorld, runtime: &Runtime);
fn update(&mut self, world: &mut GameWorld, inputs: &[InputEvent]);
// Provided methods
fn on_shutdown(&mut self) { ... }
fn intercept_window_event(
&mut self,
_event: &dyn Any,
_window: &dyn KhoraWindow,
) -> bool { ... }
fn before_frame(
&mut self,
_world: &mut GameWorld,
_runtime: &Runtime,
_window: &dyn KhoraWindow,
) { ... }
fn before_agents(&mut self, _world: &mut GameWorld, _runtime: &Runtime) { ... }
fn after_agents(&mut self, _world: &mut GameWorld, _runtime: &Runtime) { ... }
}Expand description
The single generic bound for the engine’s application type.
An application must implement AgentProvider and PhaseProvider.
AgentProvider::register_agents is where the app registers its custom agents
with the DCC — game logic belongs in custom agents using ExecutionTiming
and ExecutionPhase, not in a free-form update() method.
The engine also requires these inherent methods on the app type:
window_config() -> WindowConfignew() -> Selfsetup(&mut self, world: &mut GameWorld)update(&mut self, world: &mut GameWorld, inputs: &[InputEvent])on_shutdown(&mut self)
§Examples
A minimal application. setup populates the world once; update runs every
frame. The optional hooks (on_shutdown, before_frame, …) keep their
no-op defaults.
use khora_sdk::prelude::*;
use khora_sdk::{
AgentProvider, DccService, EngineApp, GameWorld, PhaseProvider, Runtime,
WindowConfig,
};
struct MyGame {
frame: u64,
}
impl EngineApp for MyGame {
fn window_config() -> WindowConfig {
WindowConfig::default()
}
fn new() -> Self {
MyGame { frame: 0 }
}
fn setup(&mut self, world: &mut GameWorld, _runtime: &Runtime) {
world.spawn_camera(ecs::Camera::new_perspective(
std::f32::consts::FRAC_PI_4,
16.0 / 9.0,
0.1,
1000.0,
));
}
fn update(&mut self, _world: &mut GameWorld, _inputs: &[InputEvent]) {
self.frame += 1;
}
}
impl AgentProvider for MyGame {
fn register_agents(&self, _dcc: &DccService, _runtime: &mut Runtime) {}
}
impl PhaseProvider for MyGame {}Required Methods§
Sourcefn window_config() -> WindowConfigwhere
Self: Sized,
fn window_config() -> WindowConfigwhere
Self: Sized,
Returns the window configuration for the application.
Sourcefn setup(&mut self, world: &mut GameWorld, runtime: &Runtime)
fn setup(&mut self, world: &mut GameWorld, runtime: &Runtime)
Called once during engine initialization to set up the game world.
Sourcefn update(&mut self, world: &mut GameWorld, inputs: &[InputEvent])
fn update(&mut self, world: &mut GameWorld, inputs: &[InputEvent])
Called every frame to update game logic.
Provided Methods§
Sourcefn on_shutdown(&mut self)
fn on_shutdown(&mut self)
Called during shutdown to clean up application resources.
Sourcefn intercept_window_event(
&mut self,
_event: &dyn Any,
_window: &dyn KhoraWindow,
) -> bool
fn intercept_window_event( &mut self, _event: &dyn Any, _window: &dyn KhoraWindow, ) -> bool
Optional: intercept a raw window event before the engine translates it into
an InputEvent. Return true if the event was consumed (e.g., by an
egui overlay) and should NOT be forwarded to game logic.
Default: do not intercept.
Sourcefn before_frame(
&mut self,
_world: &mut GameWorld,
_runtime: &Runtime,
_window: &dyn KhoraWindow,
)
fn before_frame( &mut self, _world: &mut GameWorld, _runtime: &Runtime, _window: &dyn KhoraWindow, )
Optional: called once per frame BEFORE update.
Use to begin a UI overlay frame (e.g., egui::Context::begin_frame) and
render shell chrome (menus, docks, panels) that produces UI commands.
Sourcefn before_agents(&mut self, _world: &mut GameWorld, _runtime: &Runtime)
fn before_agents(&mut self, _world: &mut GameWorld, _runtime: &Runtime)
Optional: called after the renderer’s begin_frame and before the
scheduler dispatches agents. Use to switch the renderer to an offscreen
viewport target (e.g., set_render_to_viewport(true)).
Sourcefn after_agents(&mut self, _world: &mut GameWorld, _runtime: &Runtime)
fn after_agents(&mut self, _world: &mut GameWorld, _runtime: &Runtime)
Optional: called after agent execution and submit_frame_graph, but
BEFORE the renderer’s end_frame. Use to render gizmos to the offscreen
viewport, switch back to the swapchain (set_render_to_viewport(false)),
and present a UI overlay (render_overlay).