ASGE  3.2.0
Simple Game Framework in GL
ASGE::Game Class Referenceabstract

#include <Game.hpp>

Inheritance diagram for ASGE::Game:
[legend]

Public Member Functions

 Game (const GameSettings &game_settings)
 
 Game (const Game &rhs)=delete
 
Gameoperator= (const Game &rhs)=delete
 
virtual ~Game ()
 
virtual void fixedUpdate (const GameTime &us)
 
virtual void update (const GameTime &us)=0
 
virtual void beginFrame ()=0
 
virtual void render (const GameTime &us)=0
 
virtual void endFrame ()=0
 
virtual bool initAPI (const ASGE::GameSettings &)=0
 
virtual bool exitAPI () noexcept=0
 
int run ()
 
void signalExit () noexcept
 

Protected Member Functions

void toggleFPS () noexcept
 
int updateFPS ()
 
void initFileIO (const ASGE::GameSettings &settings)
 
const std::string & title () const
 
uint32_t fpsLimit () const
 
uint32_t fixedTimeStep () const
 

Protected Attributes

std::unique_ptr< Rendererrenderer
 
std::unique_ptr< Inputinputs
 
std::atomic< bool > show_fps { false }
 
std::atomic< bool > exit { false }
 

Detailed Description

The core of the engine.

A skeleton structure and interface for running an instance of a Game. It stores access to the renderer and the input system. The input system is intrinsically linked to the renderer subsystem due to needing access to the window for polling events. To help speed up development, a typical update and render function is provided, along with GameTime. The initialisation code is not created by the Game, but by its derived classes as the setup of the renderer is platform specific.

See also
Input
GameTime
Renderer

Usage:

#pragma once
#include <Engine/OGLGame.h>
class MyASGEGame : public ASGE::OGLGame
{
public:
explicit MyASGEGame(ASGE::GameSettings settings);
~MyASGEGame();
private:
void update(const ASGE::GameTime& us) override;
void render() override;
};
virtual void update(const GameTime &us)=0
Function used to update the game using variable time-steps instead of relying on the deterministic fi...
virtual void render(const GameTime &us)=0
Pure virtual function used to render the game world. The render pattern is common usage within engine...
an OpenGL implementation of the Game engine.
Definition: OGLGame.hpp:30
GameSettings allows you to configure the game window and its initial state upon construction of the g...
Stores both frame and game deltas.
Definition: GameTime.hpp:31

Definition at line 61 of file Game.hpp.

Constructor & Destructor Documentation

◆ Game()

ASGE::Game::Game ( const GameSettings game_settings)
explicit

Default constructor.

◆ ~Game()

virtual ASGE::Game::~Game ( )
virtual

Default destructor.

Member Function Documentation

◆ beginFrame()

virtual void ASGE::Game::beginFrame ( )
pure virtual

Pure virtual function that sets up the renderer before rendering a frame.

Can include flushing of buffers, clearing screens etc. This is handled inside the platform's specific implementation.

Implemented in ASGE::OGLGame.

◆ endFrame()

virtual void ASGE::Game::endFrame ( )
pure virtual

Pure virtual function that completes the render frame.

Typically, flushes the render queue, instructs any batched calls to complete and swaps the video buffers. This is handled inside the platform's specific implementation.

Implemented in ASGE::OGLGame.

◆ exitAPI()

virtual bool ASGE::Game::exitAPI ( )
pure virtualnoexcept

Pure virtual function for terminating the API.

This is handled inside the platform's specific implementation.

Returns
The result of the initialisation operation.

Implemented in ASGE::OGLGame.

◆ fixedTimeStep()

uint32_t ASGE::Game::fixedTimeStep ( ) const
protected

Retrieves the fixed time step. The game has two updates, one is variable and the other fixed. The fixed time step controls how much time should be simulated everytime it's called.

Returns
The fixed time step used by the game.

◆ fixedUpdate()

virtual void ASGE::Game::fixedUpdate ( const GameTime us)
virtual

Function used to update the game using fixed time-steps instead of the regular frame update.

This is useful when you only want to progress the game world by a known amount i.e. physics calculations which should act deterministically or network simulations where clients need syncing. It is best to use fixed updates as a divisible or multiple of the FPS count. This allows a smoother delivery of frame data. For example: 60/120 would deliver one fixed update per two renders.

Note
It's important to remember that the amount of time being simulated does not directly correlate with the wall clock. It will always pass the same delta in to the fixedUpdate function. So six fixed updates will always simulate the same amount of time irrespective of the game's speed.
Parameters
[in]usGame and fixed delta information.
See also
GameTime

◆ fpsLimit()

uint32_t ASGE::Game::fpsLimit ( ) const
protected

Retrieves the FPS limit. Each game can manually throttle the maximum FPS, this value can easily be retrieved using this function.

Returns
The FPS limit applied to the game.

◆ initAPI()

virtual bool ASGE::Game::initAPI ( const ASGE::GameSettings )
pure virtual

Pure virtual function for setup and initialisation of API.

This is handled inside the platform's specific implementation.

Parameters
[in]settingsThe window mode to start the game with.
Returns
The result of the initialisation operation.
See also
WindowMode

Implemented in ASGE::OGLGame.

◆ initFileIO()

void ASGE::Game::initFileIO ( const ASGE::GameSettings settings)
protected

Initialises the file system.

◆ render()

virtual void ASGE::Game::render ( const GameTime us)
pure virtual

Pure virtual function used to render the game world. The render pattern is common usage within engines and will be automatically called every frame. All game objects to be visualised need to be drawn at this stage using the Game's renderer.

Parameters
[in]usGame and Frame delta information.
See also
GameTime

◆ run()

int ASGE::Game::run ( )

The main game loop.

Will keep looping until a request to exit is received either from the renderer or via the signal exit function.

Returns
The exit code for the game.
See also
signalExit

◆ signalExit()

void ASGE::Game::signalExit ( )
noexcept

Signals the game should exit.

Will flag the game to stop processing updates and abort the main game loop, thus exiting the game.

◆ title()

const std::string& ASGE::Game::title ( ) const
protected

Retrieves the game title. The title is used to name the window but also to control the default write directory to use.

Returns
The game title.

◆ toggleFPS()

void ASGE::Game::toggleFPS ( )
protectednoexcept

Toggles the FPS on-screen.

Will cause the game to draw and update the FPS on the screen every tick along with additional debug information.

◆ update()

virtual void ASGE::Game::update ( const GameTime us)
pure virtual

Function used to update the game using variable time-steps instead of relying on the deterministic fixedUpdate function calls.

If the fixed update lags too aggressively, a forced render and update call will be performed. This is to prevent the window from hanging, as it is possible that the loop will never recover otherwise.

Note
You can think of the update function as the render update. It gets called once per each frame rendered. If too much time passes between updates, the delta will be capped and will result in the amount of game time being progressed to be slowed down.
Parameters
[in]usGame and frame delta information.
See also
GameTime

◆ updateFPS()

int ASGE::Game::updateFPS ( )
protected

Updates the FPS counter.

Update the FPS calculation every tick. Uses the average number of frames over a single second.

Member Data Documentation

◆ exit

std::atomic<bool> ASGE::Game::exit { false }
protected

Exit boolean. If true the game loop will exit.

Definition at line 254 of file Game.hpp.

◆ inputs

std::unique_ptr<Input> ASGE::Game::inputs
protected

Unique pointer to the Input handler. A smart pointer managing the input handler. Use inputs.get() to retrieve the raw pointer.

Definition at line 246 of file Game.hpp.

◆ renderer

std::unique_ptr<Renderer> ASGE::Game::renderer
protected

Unique pointer to the Renderer subsystem. //NOLINT A smart pointer managing the renderer. Use renderer.get() to retrieve the raw pointer.

Definition at line 241 of file Game.hpp.

◆ show_fps

std::atomic<bool> ASGE::Game::show_fps { false }
protected

FPS counter. Shows the FPS on screen if set to true.

Definition at line 251 of file Game.hpp.


The documentation for this class was generated from the following file: