pub struct App { /* private fields */ }Expand description
Main application struct that manages the game loop and plugin lifecycle
The App coordinates:
- Plugin registration and initialization
- System scheduling (startup and per-frame)
- Main loop execution
- Resource cleanup on shutdown
§Example
use kon::prelude::*;
fn main() {
Kon::new()
.add_plugin(DefaultPlugins)
.add_startup_system(setup)
.add_system(update)
.run();Implementations§
Source§impl App
impl App
Sourcepub fn new() -> App
pub fn new() -> App
Creates a new App instance
Initializes logging and installs custom panic handler
Sourcepub fn set_driver<D>(&mut self, driver: D) -> &mut Appwhere
D: Driver + 'static,
pub fn set_driver<D>(&mut self, driver: D) -> &mut Appwhere
D: Driver + 'static,
Sets a custom driver for the game loop
Replaces the default driver with a custom implementation. This allows control over how the application lifecycle executes (e.g., fixed timestep, event-driven loops, or headless simulation).
Must be called before run(). If not set, DefaultDriver is used.
§Returns
Self reference for method chaining
§Example
Kon::new()
.set_driver(CustomDriver)
.run();Sourcepub fn add_plugin<P>(&mut self, plugin: P) -> &mut Appwhere
P: Plugin,
pub fn add_plugin<P>(&mut self, plugin: P) -> &mut Appwhere
P: Plugin,
Adds a plugin to the application
Plugins extend engine functionality. Common examples:
EcsPlugin- Registers the WorldWindowPlugin- Creates the game windowDefaultPlugins- Bundle of core plugins
§Returns
Self reference for method chaining
Sourcepub fn add_startup_system<F>(&mut self, system: F) -> &mut App
pub fn add_startup_system<F>(&mut self, system: F) -> &mut App
Adds a startup system that runs once at application start
§Returns
Self reference for method chaining
Sourcepub fn add_system<F>(&mut self, system: F) -> &mut App
pub fn add_system<F>(&mut self, system: F) -> &mut App
Sourcepub fn add_sync_system<F>(&mut self, system: F) -> &mut App
pub fn add_sync_system<F>(&mut self, system: F) -> &mut App
Sourcepub fn register<R>(&mut self, resource: R) -> &mut App
pub fn register<R>(&mut self, resource: R) -> &mut App
Registers a global resource accessible from all systems
Resources are stored in Context and accessible via ctx.global::<T>().
§Returns
Self reference for method chaining
Sourcepub fn context_mut(&mut self) -> &mut Context
pub fn context_mut(&mut self) -> &mut Context
Returns a mutable reference to the engine context
Sourcepub fn initialize(&mut self)
pub fn initialize(&mut self)
Initializes the application
Called automatically by the driver. This method:
- Calls
ready()on all registered plugins - Executes all startup systems once
Should not be called manually unless implementing a custom driver.
Sourcepub fn tick(&mut self)
pub fn tick(&mut self)
Executes a single frame update
Called automatically by the driver each frame. This method:
- Updates time tracking
- Runs all registered systems
- Clears frame events
Should not be called manually unless implementing a custom driver.
Sourcepub fn cleanup(&mut self)
pub fn cleanup(&mut self)
Cleans up the application
Called automatically by the driver on exit. This method calls cleanup()
on all registered plugins, allowing them to release resources.
Should not be called manually unless implementing a custom driver.
Sourcepub fn run(&mut self)
pub fn run(&mut self)
Starts the application and runs the game loop
This is the entry point for executing the engine. It:
- Transfers ownership of the app to the configured driver
- The driver handles initialization, update loop, and cleanup
- Blocks until the application exits
The driver is consumed during execution. If no custom driver was set
via set_driver(), the DefaultDriver is used.
§Example
Kon::new()
.add_plugin(DefaultPlugins)
.add_system(update_system)
.run(); // Blocks here until exitTrait Implementations§
Auto Trait Implementations§
impl Freeze for App
impl !RefUnwindSafe for App
impl !Send for App
impl !Sync for App
impl Unpin for App
impl !UnwindSafe for App
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.