Trait lf_gfx::Game

source ·
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§

source

type InitData

Data processed before the window exists. This should be minimal and kept to mpsc message reception from initialiser threads.

source

type LinearInputType

source

type VectorInputType

Required Methods§

source

fn default_inputs() -> InputMap<Self::LinearInputType, Self::VectorInputType>

source

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,

source

fn window_resize(&mut self, data: &GameData, new_size: PhysicalSize<u32>)

source

fn handle_linear_input( &mut self, data: &GameData, input: &Self::LinearInputType, activation: LinearInputActivation )

source

fn handle_vector_input( &mut self, data: &GameData, input: &Self::VectorInputType, activation: VectorInputActivation )

source

fn render_to(&mut self, data: &GameData, view: TextureView)

Requests that the next frame is drawn into the view, pretty please :)

Provided Methods§

source

fn target_limits() -> Limits

source

fn on_init_failure(error: GameInitialisationFailure) -> !

source

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.

source

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

source

fn finished(self, _: GameData)

Invoked right at the end of the program life, after the final frame is rendered.

Object Safety§

This trait is not object safe.

Implementors§