ASGE
3.2.0
Simple Game Framework in GL
|
#include <Game.hpp>
Public Member Functions | |
Game (const GameSettings &game_settings) | |
Game (const Game &rhs)=delete | |
Game & | operator= (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< Renderer > | renderer |
std::unique_ptr< Input > | inputs |
std::atomic< bool > | show_fps { false } |
std::atomic< bool > | exit { false } |
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.
Usage:
|
explicit |
Default constructor.
|
virtual |
Default destructor.
|
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.
|
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.
|
pure virtualnoexcept |
Pure virtual function for terminating the API.
This is handled inside the platform's specific implementation.
Implemented in ASGE::OGLGame.
|
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.
|
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.
[in] | us | Game and fixed delta information. |
|
protected |
Retrieves the FPS limit. Each game can manually throttle the maximum FPS, this value can easily be retrieved using this function.
|
pure virtual |
Pure virtual function for setup and initialisation of API.
This is handled inside the platform's specific implementation.
[in] | settings | The window mode to start the game with. |
Implemented in ASGE::OGLGame.
|
protected |
Initialises the file system.
|
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.
[in] | us | Game and Frame delta information. |
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.
|
noexcept |
Signals the game should exit.
Will flag the game to stop processing updates and abort the main game loop, thus exiting the game.
|
protected |
Retrieves the game title. The title is used to name the window but also to control the default write directory to use.
|
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.
|
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.
[in] | us | Game and frame delta information. |
|
protected |
Updates the FPS counter.
Update the FPS calculation every tick. Uses the average number of frames over a single second.
|
protected |
|
protected |
|
protected |
|
protected |