OpenEnroth 73e68f7
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
EngineController Class Reference

#include <EngineController.h>

Public Types

using GameRoutine = std::function< void()>
 

Public Member Functions

 EngineController (EngineControlStateHandle state)
 
 ~EngineController ()
 
void tick (int count=1)
 
void postEvent (std::unique_ptr< PlatformEvent > event)
 
void pressKey (PlatformKey key)
 
void pressAutoRepeatedKey (PlatformKey key)
 
void releaseKey (PlatformKey key)
 
void pressButton (PlatformMouseButton button, int x, int y)
 
void releaseButton (PlatformMouseButton button, int x, int y)
 
void moveMouse (int x, int y)
 
void pressAndReleaseKey (PlatformKey key)
 
void pressAndReleaseButton (PlatformMouseButton button, int x, int y)
 
void pressGuiButton (std::string_view buttonId)
 
void goToMainMenu ()
 
void startNewGame ()
 
void skipLoadingScreen ()
 
Blob saveGame ()
 
void loadGame (const Blob &savedGame)
 
void runGameRoutine (GameRoutine routine)
 
void resizeWindow (int w, int h)
 

Private Member Functions

GUIButtonexistingButton (std::string_view buttonId)
 

Private Attributes

EngineControlStateHandle _state
 

Detailed Description

This is the interface to be used from a control routine to control the game thread.

Most errors are reported as exceptions (derived from std::runtime_error) because the main way to use this class is from unit tests.

Member Typedef Documentation

◆ GameRoutine

using EngineController::GameRoutine = std::function<void()>

Constructor & Destructor Documentation

◆ EngineController()

EngineController::EngineController ( EngineControlStateHandle  state)
explicit

◆ ~EngineController()

EngineController::~EngineController ( )
default

Member Function Documentation

◆ existingButton()

GUIButton * EngineController::existingButton ( std::string_view  buttonId)
private

◆ goToMainMenu()

void EngineController::goToMainMenu ( )

Opens main menu no matter the current game state.

◆ loadGame()

void EngineController::loadGame ( const Blob savedGame)

Loads the game by opening up the load game menu and actually clicking all the buttons.

Parameters
savedGameBlob containing saved game data.

◆ moveMouse()

void EngineController::moveMouse ( int  x,
int  y 
)

◆ postEvent()

void EngineController::postEvent ( std::unique_ptr< PlatformEvent event)

◆ pressAndReleaseButton()

void EngineController::pressAndReleaseButton ( PlatformMouseButton  button,
int  x,
int  y 
)

◆ pressAndReleaseKey()

void EngineController::pressAndReleaseKey ( PlatformKey  key)

◆ pressAutoRepeatedKey()

void EngineController::pressAutoRepeatedKey ( PlatformKey  key)

◆ pressButton()

void EngineController::pressButton ( PlatformMouseButton  button,
int  x,
int  y 
)

◆ pressGuiButton()

void EngineController::pressGuiButton ( std::string_view  buttonId)

Presses a GUI button identified by the provided id by sending a mouse press and release event.

Parameters
buttonIdButton id.
Exceptions
ExceptionIf the button with the provided id doesn't exist.

◆ pressKey()

void EngineController::pressKey ( PlatformKey  key)

◆ releaseButton()

void EngineController::releaseButton ( PlatformMouseButton  button,
int  x,
int  y 
)

◆ releaseKey()

void EngineController::releaseKey ( PlatformKey  key)

◆ resizeWindow()

void EngineController::resizeWindow ( int  w,
int  h 
)

◆ runGameRoutine()

void EngineController::runGameRoutine ( GameRoutine  routine)

Runs the provided routine in game thread and returns once it's finished. This is mainly for running OpenGL code as the corresponding context is bound in the main thread.

Parameters
routineRoutine to run.

◆ saveGame()

Blob EngineController::saveGame ( )

Saves the game.

Returns
Blob containing saved game data.

◆ skipLoadingScreen()

void EngineController::skipLoadingScreen ( )

Waits for the loading screen to complete.

Exceptions
ExceptionIf there is no loading screen.

◆ startNewGame()

void EngineController::startNewGame ( )

Start new game no matter the current game state.

◆ tick()

void EngineController::tick ( int  count = 1)

Passes execution to the game thread for the provided number of frames. This function provides a coroutine-like interface for control routines as calling tick basically suspends the control routine until the next frame.

Parameters
countNumber of frames to suspend the control routine for.

Member Data Documentation

◆ _state

EngineControlStateHandle EngineController::_state
private

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