pub trait Game: Sized {
type InitData;
type LinearInputType;
type VectorInputType;
// Required methods
fn default_inputs(
) -> InputMap<Self::LinearInputType, Self::VectorInputType>;
fn init<'life0, 'async_trait>(
data: &'life0 GameData,
init: Self::InitData
) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn window_resize(&mut self, data: &GameData, new_size: PhysicalSize<u32>);
fn handle_linear_input(
&mut self,
data: &GameData,
input: &Self::LinearInputType,
activation: LinearInputActivation
);
fn handle_vector_input(
&mut self,
data: &GameData,
input: &Self::VectorInputType,
activation: VectorInputActivation
);
fn render_to(&mut self, data: &GameData, view: TextureView);
// Provided methods
fn target_limits() -> Limits { ... }
fn on_init_failure(error: GameInitialisationFailure) -> ! { ... }
fn process_raw_event<'a, T>(
&mut self,
event: Event<'a, T>
) -> Option<Event<'a, T>> { ... }
fn user_exit_requested(&mut self, data: &GameData) { ... }
fn finished(self, _: GameData) { ... }
}Expand description
All of the callbacks required to implement a game. This API is built on top of a message passing event system, and so calls to the below methods may be made concurrently, in any order, and on different threads.
Required Associated Types§
sourcetype InitData
type InitData
Data processed before the window exists. This should be minimal and kept to mpsc message reception from initialiser threads.
type LinearInputType
type VectorInputType
Required Methods§
fn default_inputs() -> InputMap<Self::LinearInputType, Self::VectorInputType>
fn init<'life0, 'async_trait>( data: &'life0 GameData, init: Self::InitData ) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
fn window_resize(&mut self, data: &GameData, new_size: PhysicalSize<u32>)
fn handle_linear_input( &mut self, data: &GameData, input: &Self::LinearInputType, activation: LinearInputActivation )
fn handle_vector_input( &mut self, data: &GameData, input: &Self::VectorInputType, activation: VectorInputActivation )
sourcefn render_to(&mut self, data: &GameData, view: TextureView)
fn render_to(&mut self, data: &GameData, view: TextureView)
Requests that the next frame is drawn into the view, pretty please :)
Provided Methods§
fn target_limits() -> Limits
fn on_init_failure(error: GameInitialisationFailure) -> !
sourcefn process_raw_event<'a, T>(
&mut self,
event: Event<'a, T>
) -> Option<Event<'a, T>>
fn process_raw_event<'a, T>( &mut self, event: Event<'a, T> ) -> Option<Event<'a, T>>
Allows you to intercept and cancel events, before passing them off to the standard event handler, to allow for egui integration, among others.
This method only receives input events if the cursor is not captured, to avoid UI glitches.
sourcefn user_exit_requested(&mut self, data: &GameData)
fn user_exit_requested(&mut self, data: &GameData)
Invoked when the window is told to close (i.e. x pressed, sigint, etc.) but not when
a synthetic exit is triggered by enqueuing GameCommand::Exit. To actually do something with the
user’s request to quit, this method must enqueue GameCommand::Exit