Trait mage_core::app::App

source ·
pub trait App {
    // Required methods
    fn tick(&mut self, tick_input: TickInput) -> TickResult;
    fn present(&mut self, present_input: PresentInput<'_>) -> PresentResult;
}
Expand description

The App trait is the main interface for the game. It is called by the framework to update the game state and render the game.

Mage manages a window and GPU state to render ASCII characters to the screen. The App trait is used by the host to hook into the engine’s main loop.

The tick method is called once per frame to update the game state. The present method is called once per frame to render the game.

Tick method

The tick_input parameter contains information about the current frame to be helpful with updating the game state. This includes the time since the last frame, the size of the window (in characters), and the current state of the keyboard and mouse.

It returns a TickResult to indicate whether the game should continue or quit.

Present method

The present_input parameter contains information about the current frame to be helpful with rendering the game. This includes the size of the window (in characters), and the current state of the screen.

The screen is represented as 3 32-bit RGBA buffers, one for the foreground color of each character, one for the background color of each character, and one for each character.

For the foreground and background colors, each 32-bit RGBA value represents a single character. The least significant 8 bits are the red value, the next 8 bits are the green value, the next 8 bits are the blue value, and the most significant 8 bits are the alpha value. The alpha value is unused by the engine but is available for use by the game.

For the character buffer, each 32-bit RGBA value represents a single character. The least significant 8 bits are the character value, the most significant 24 bits are unused by the engine but are available for use by the game.

It returns a PresentResult to indicate whether the screen has changed since the last frame.

Required Methods§

source

fn tick(&mut self, tick_input: TickInput) -> TickResult

Called once per frame to update the game state.

Parameters
  • tick_input - Information about the current frame.
Returns

A TickResult to indicate whether the game should continue or quit.

source

fn present(&mut self, present_input: PresentInput<'_>) -> PresentResult

Called once per frame to render the game.

Parameters
  • present_input - Information about the current frame.
Returns

A PresentResult to indicate whether the screen has changed since the last frame.

Implementors§