Loading...
Searching...
No Matches
CApplication Class Reference

Main application. More...

`#include <src/app/app.h>`

Inheritance diagram for CApplication:
[legend]

## Public Member Functions

| CApplication (CSystemUtils *systemUtils)
| Constructor (can only be called once!).
| ~CApplication ()
| Destructor.
CEventQueue * | GetEventQueue ()
| Returns the application's event queue.
CSoundInterface * | GetSound ()
| Returns the sound subsystem.
CModManager * | GetModManager ()
| Returns the mod manager.
void | LoadEnvironmentVariables ()
| Loads some data from environment variables.
ParseArgsStatus | ParseArguments (int argc, char *argv[])
| Parses commandline arguments (they take priority).
bool | Create ()
| Initializes the application.
void | ReloadResources ()
| Reloads the application resources, e.g. mods.
int | Run ()
| Main event loop.
int | GetExitCode () const
| Returns the code to be returned at main() exit.
const std::string & | GetErrorMessage () const
| Returns the message of error (set to something if exit code is not 0).
void | GetVideoResolutionList (std::vector< Math::IntPoint > &resolutions, int display=0) const
| Returns a list of possible video modes.
Gfx::DeviceConfig | GetVideoConfig () const
| Returns the current video mode.
bool | ChangeVideoConfig (const Gfx::DeviceConfig &newConfig)
| Change the video mode to given mode.
void | SuspendSimulation ()
| Suspends animation (time will not be updated).
void | ResumeSimulation ()
| Resumes animation.
bool | GetSimulationSuspended () const
| Returns whether simulation is suspended.
void | ResetTimeAfterLoading ()
| Resets time counters to account for time spent loading game.
void | SetSimulationSpeed (float speed)
| Management of simulation speed.
float | GetSimulationSpeed () const
float | GetAbsTime () const
| Returns the absolute time counter [seconds].
long long | GetExactAbsTime () const
| Returns the exact absolute time counter [nanoseconds].
long long | GetRealAbsTime () const
| Returns the exact absolute time counter disregarding speed setting [nanoseconds].
float | GetRelTime () const
| Returns the relative time since last update [seconds].
long long | GetExactRelTime () const
| Returns the exact relative time since last update [nanoseconds].
long long | GetRealRelTime () const
| Returns the exact relative time since last update disregarding speed setting [nanoseconds].
std::vector< JoystickDevice > | GetJoystickList () const
| Returns a list of available joystick devices.
JoystickDevice | GetJoystick () const
| Returns info about the current joystick.
bool | ChangeJoystick (const JoystickDevice &newJoystick)
| Change the current joystick device.
void | SetJoystickEnabled (bool enable)
| Management of joystick enable state.
bool | GetJoystickEnabled () const
void | UpdateJoystick ()
| Polls the state of joystick axes and buttons.
void | UpdateMouse ()
| Updates the mouse position explicitly.
void | SetMouseMode (MouseMode mode)
| Management of mouse mode.
MouseMode | GetMouseMode () const
void | SetTextInput (bool textInputEnabled, int id)
| Enable/disable text input, this toggles the on-screen keyboard on some platforms.
void | MoveMouse (Math::Point pos)
| Moves (warps) the mouse cursor to the specified position (in interface coords).
void | SetDebugModeActive (DebugMode mode, bool active)
| Management of debug modes (printing more info in logger).
bool | IsDebugModeActive (DebugMode mode) const
Language | GetLanguage () const
| Management of language.
char | GetLanguageChar () const
void | SetLanguage (Language language)
bool | GetSceneTestMode ()
void | Render ()
| Renders the image in window.
void | RenderIfNeeded (int updateRate)
| Renders the image in window if needed.
void | PlayForceFeedbackEffect (float strength=1.0f, int length=999999)
| Starts a force feedback effect on the joystick.
void | StopForceFeedbackEffect ()
| Stops a force feedback effect on the joystick.

## Static Public Member Functions

static bool | ParseDebugModes (const std::string &str, int &debugModes)
Static Public Member Functions inherited from CSingleton< CApplication >
static CApplication & | GetInstance ()
static CApplication * | GetInstancePointer ()
static bool | IsCreated ()

## Protected Member Functions

bool | CreateVideoSurface ()
| Creates the window's SDL_Surface.
void | TryToSetVSync ()
Event | ProcessSystemEvent ()
| Processes the captured SDL event to Event struct.
Event | CreateVirtualEvent (const Event &sourceEvent)
| If applicable, creates a virtual event to match the changed state as of new event.
TEST_VIRTUAL Event | CreateUpdateEvent (TimeUtils::TimeStamp newTimeStamp)
| Prepares a simulation update event.
void | LogEvent (const Event &event)
| Logs debug data for event.
bool | OpenJoystick ()
| Opens the joystick device.
void | CloseJoystick ()
| Closes the joystick device.
void | InternalResumeSimulation ()
| Internal procedure to reset time counters.
void | StartLoadingMusic ()
| Loads music in a new thread.

## Protected Attributes

CSystemUtils * | m_systemUtils
| System utils instance.
std::unique_ptr< ApplicationPrivate > | m_private
| Private (SDL-dependent data).
std::unique_ptr< CEventQueue > | m_eventQueue
| Global event queue.
std::unique_ptr< Gfx::CEngine > | m_engine
| Graphics engine.
std::unique_ptr< Gfx::CDevice > | m_device
| Graphics device.
std::unique_ptr< CSoundInterface > | m_sound
| Sound subsystem.
std::unique_ptr< CController > | m_controller
| Game controller - game engine and UI.
std::unique_ptr< CConfigFile > | m_configFile
| Profile (INI) reader/writer.
std::unique_ptr< CInput > | m_input
| Input manager.
std::unique_ptr< CPathManager > | m_pathManager
| Path manager.
std::unique_ptr< CModManager > | m_modManager
| Mod manager.
int | m_exitCode
| Code to return at exit.
bool | m_active
| Whether application window is active.
long | m_debugModes
| Bit array of active debug modes.
std::string | m_errorMessage
| Message to be displayed as error to the user.
Gfx::DeviceConfig | m_deviceConfig
| Current configuration of OpenGL display device.
std::string | m_windowTitle
| Text set as window title.
TimeUtils::TimeStamp | m_baseTimeStamp
| Animation time stamps, etc.
TimeUtils::TimeStamp | m_lastTimeStamp
TimeUtils::TimeStamp | m_curTimeStamp
long long | m_realAbsTimeBase
long long | m_realAbsTime
long long | m_realRelTime
long long | m_absTimeBase
long long | m_exactAbsTime
long long | m_exactRelTime
float | m_absTime
float | m_relTime
float | m_simulationSpeed
bool | m_simulationSuspended
TimeUtils::TimeStamp | m_manualFrameLast
TimeUtils::TimeStamp | m_manualFrameTime
bool | m_graphicsOverride = false
| Graphics device to use.
std::string | m_graphics = "default"
bool | m_glVersionOverride = false
| OpenGL version to use.
int | m_glMajor = -1
int | m_glMinor = -1
bool | m_glProfileOverride = false
| OpenGL profile.
int | m_glProfile = 0
MouseMode | m_mouseMode
| Current mode of mouse.
JoystickDevice | m_joystick
| Info about current joystick device.
bool | m_joystickEnabled
| Whether joystick is enabled.
std::vector< int > | m_joyAxeState
| Current state of joystick axes; may be updated from another thread.
std::vector< bool > | m_joyButtonState
| Current state of joystick buttons; may be updated from another thread.
LevelCategory | m_runSceneCategory
| Scene to run on startup.
int | m_runSceneRank
std::string | m_loadSavePlayerName
| Game to load on startup.
std::string | m_loadSaveDirName
bool | m_sceneTest
| Scene test mode.
Language | m_language
| Application language.
bool | m_resolutionOverride
| Screen resolution overriden by commandline.
bool | m_headless
| Headles mode.
std::map< int, bool > | m_textInputEnabled

## Static Protected Attributes

static char | m_languageLocale [50] = { 0 }
| Static buffer for putenv locale.
Static Protected Attributes inherited from CSingleton< CApplication >
static CApplication * | m_instance

## Detailed Description

Main application.

This class is responsible for main application execution, including creating and handling main application window, receiving events, etc.

It is a singleton class with only one instance that can be created.

# Creation of other main objects

The class creates the only instance of CEventQueue, CEngine, CRobotMain and CSoundInterface classes.

# Window management

The class is responsible for creating app window, setting and changing the video mode, joystick management, grabbing input and changing the system mouse cursor position and visibility. ("System mouse cursor" means the cursor displayed by the OS in constrast to the cursor displayed by CEngine).

# Events

Events are taken from SDL event queue, translated to common events from src/common.h and pushed to global event queue CEventQueue.

Joystick events are generated somewhat differently, by running a separate timer, polling the device for changes and synthesising events on change. It avoids flooding the event queue with too many joystick events and the granularity of the timer can be adjusted.

The events are passed to ProcessEvent() of classes in this order: CApplication, CEngine and CRobotMain. CApplication and CEngine's ProcessEvent() functions return bool, which means whether to pass the event on, or stop the chain. This is to enable handling some events which are internal to CApplication or CEngine.

# Portability

Currently, the class only handles OpenGL devices. SDL can be used with DirectX, but for that to work, video initialization and video setting must be done differently.

## Constructor & Destructor Documentation

## CApplication()

CApplication::CApplication | ( | CSystemUtils * | systemUtils | ) |

Constructor (can only be called once!).

## ~CApplication()

CApplication::~CApplication | ( |  | ) |

Destructor.

## Member Function Documentation

## GetEventQueue()

CEventQueue * CApplication::GetEventQueue | ( |  | ) |

Returns the application's event queue.

## GetSound()

CSoundInterface * CApplication::GetSound | ( |  | ) |

Returns the sound subsystem.

## GetModManager()

CModManager * CApplication::GetModManager | ( |  | ) |

Returns the mod manager.

## LoadEnvironmentVariables()

void CApplication::LoadEnvironmentVariables | ( |  | ) |

Loads some data from environment variables.

## ParseArguments()

ParseArgsStatus CApplication::ParseArguments | ( | int | argc,
|  | char * | argv[] )

Parses commandline arguments (they take priority).

## Create()

bool CApplication::Create | ( |  | ) |

Initializes the application.

## ReloadResources()

void CApplication::ReloadResources | ( |  | ) |

Reloads the application resources, e.g. mods.

## Run()

int CApplication::Run | ( |  | ) |

Main event loop.

## GetExitCode()

int CApplication::GetExitCode | ( |  | ) | const

Returns the code to be returned at main() exit.

## GetErrorMessage()

const std::string & CApplication::GetErrorMessage | ( |  | ) | const

Returns the message of error (set to something if exit code is not 0).

## GetVideoResolutionList()

void CApplication::GetVideoResolutionList | ( | std::vector< Math::IntPoint > & | resolutions,
|  | int | display = 0 ) const

Returns a list of possible video modes.

## GetVideoConfig()

Gfx::DeviceConfig CApplication::GetVideoConfig | ( |  | ) | const

Returns the current video mode.

## ChangeVideoConfig()

bool CApplication::ChangeVideoConfig | ( | const Gfx::DeviceConfig & | newConfig | ) |

Change the video mode to given mode.

## SuspendSimulation()

void CApplication::SuspendSimulation | ( |  | ) |

Suspends animation (time will not be updated).

## ResumeSimulation()

void CApplication::ResumeSimulation | ( |  | ) |

Resumes animation.

## GetSimulationSuspended()

bool CApplication::GetSimulationSuspended | ( |  | ) | const

Returns whether simulation is suspended.

## ResetTimeAfterLoading()

void CApplication::ResetTimeAfterLoading | ( |  | ) |

Resets time counters to account for time spent loading game.

## SetSimulationSpeed()

void CApplication::SetSimulationSpeed | ( | float | speed | ) |

Management of simulation speed.

## GetAbsTime()

float CApplication::GetAbsTime | ( |  | ) | const

Returns the absolute time counter [seconds].

## GetExactAbsTime()

long long CApplication::GetExactAbsTime | ( |  | ) | const

Returns the exact absolute time counter [nanoseconds].

## GetRealAbsTime()

long long CApplication::GetRealAbsTime | ( |  | ) | const

Returns the exact absolute time counter disregarding speed setting [nanoseconds].

## GetRelTime()

float CApplication::GetRelTime | ( |  | ) | const

Returns the relative time since last update [seconds].

## GetExactRelTime()

long long CApplication::GetExactRelTime | ( |  | ) | const

Returns the exact relative time since last update [nanoseconds].

## GetRealRelTime()

long long CApplication::GetRealRelTime | ( |  | ) | const

Returns the exact relative time since last update disregarding speed setting [nanoseconds].

## GetJoystickList()

std::vector< JoystickDevice > CApplication::GetJoystickList | ( |  | ) | const

Returns a list of available joystick devices.

## GetJoystick()

JoystickDevice CApplication::GetJoystick | ( |  | ) | const

Returns info about the current joystick.

## ChangeJoystick()

bool CApplication::ChangeJoystick | ( | const JoystickDevice & | newJoystick | ) |

Change the current joystick device.

## SetJoystickEnabled()

void CApplication::SetJoystickEnabled | ( | bool | enable | ) |

Management of joystick enable state.

## UpdateJoystick()

void CApplication::UpdateJoystick | ( |  | ) |

Polls the state of joystick axes and buttons.

Updates the state info in CApplication and on change, creates SDL events and pushes them to SDL event queue. This way, the events get handled properly in the main event loop and besides, SDL_PushEvent() ensures thread-safety.

## UpdateMouse()

void CApplication::UpdateMouse | ( |  | ) |

Updates the mouse position explicitly.

## SetMouseMode()

void CApplication::SetMouseMode | ( | MouseMode | mode | ) |

Management of mouse mode.

## SetTextInput()

void CApplication::SetTextInput | ( | bool | textInputEnabled,
|  | int | id )

Enable/disable text input, this toggles the on-screen keyboard on some platforms.

This also allows for writing in CJK languages (not tested!), see https://wiki.libsdl.org/Tutorials/TextInput for detailed explanation

## MoveMouse()

void CApplication::MoveMouse | ( | Math::Point | pos | ) |

Moves (warps) the mouse cursor to the specified position (in interface coords).

## SetDebugModeActive()

void CApplication::SetDebugModeActive | ( | DebugMode | mode,
|  | bool | active )

Management of debug modes (printing more info in logger).

## GetLanguage()

Language CApplication::GetLanguage | ( |  | ) | const

Management of language.

## Render()

void CApplication::Render | ( |  | ) |

Renders the image in window.

Renders the frame and swaps buffers as necessary

## RenderIfNeeded()

void CApplication::RenderIfNeeded | ( | int | updateRate | ) |

Renders the image in window if needed.

## PlayForceFeedbackEffect()

void CApplication::PlayForceFeedbackEffect | ( | float | strength = 1.0f,
|  | int | length = 999999 )

Starts a force feedback effect on the joystick.

## StopForceFeedbackEffect()

void CApplication::StopForceFeedbackEffect | ( |  | ) |

Stops a force feedback effect on the joystick.

## CreateVideoSurface()

bool CApplication::CreateVideoSurface | ( |  | ) |

protected

Creates the window's SDL_Surface.

## TryToSetVSync()

void CApplication::TryToSetVSync | ( |  | ) |

protected

Tries to set the SDL vsync state desired by the 3D engine The final state of SDL vsync is set in the 3D engine afterwards

## ProcessSystemEvent()

Event CApplication::ProcessSystemEvent | ( |  | ) |

protected

Processes the captured SDL event to Event struct.

The SDL event parsed is stored internally. If event is not available or is not understood, returned event is of type EVENT_NULL.

## CreateVirtualEvent()

Event CApplication::CreateVirtualEvent | ( | const Event & | sourceEvent | ) |

protected

If applicable, creates a virtual event to match the changed state as of new event.

## CreateUpdateEvent()

Event CApplication::CreateUpdateEvent | ( | TimeUtils::TimeStamp | newTimeStamp | ) |

protected

Prepares a simulation update event.

## LogEvent()

void CApplication::LogEvent | ( | const Event & | event | ) |

protected

Logs debug data for event.

## OpenJoystick()

bool CApplication::OpenJoystick | ( |  | ) |

protected

Opens the joystick device.

## CloseJoystick()

void CApplication::CloseJoystick | ( |  | ) |

protected

Closes the joystick device.

## InternalResumeSimulation()

void CApplication::InternalResumeSimulation | ( |  | ) |

protected

Internal procedure to reset time counters.

## StartLoadingMusic()

void CApplication::StartLoadingMusic | ( |  | ) |

protected

Loads music in a new thread.

## Member Data Documentation

## m_systemUtils

CSystemUtils* CApplication::m_systemUtils

protected

System utils instance.

## m_private

std::unique_ptr<ApplicationPrivate> CApplication::m_private

protected

Private (SDL-dependent data).

## m_eventQueue

std::unique_ptr<CEventQueue> CApplication::m_eventQueue

protected

Global event queue.

## m_engine

std::unique_ptr<Gfx::CEngine> CApplication::m_engine

protected

Graphics engine.

## m_device

std::unique_ptr<Gfx::CDevice> CApplication::m_device

protected

Graphics device.

## m_sound

std::unique_ptr<CSoundInterface> CApplication::m_sound

protected

Sound subsystem.

## m_controller

std::unique_ptr<CController> CApplication::m_controller

protected

Game controller - game engine and UI.

## m_configFile

std::unique_ptr<CConfigFile> CApplication::m_configFile

protected

Profile (INI) reader/writer.

## m_input

std::unique_ptr<CInput> CApplication::m_input

protected

Input manager.

## m_pathManager

std::unique_ptr<CPathManager> CApplication::m_pathManager

protected

Path manager.

## m_modManager

std::unique_ptr<CModManager> CApplication::m_modManager

protected

Mod manager.

## m_exitCode

int CApplication::m_exitCode

protected

Code to return at exit.

## m_active

bool CApplication::m_active

protected

Whether application window is active.

## m_debugModes

long CApplication::m_debugModes

protected

Bit array of active debug modes.

## m_errorMessage

std::string CApplication::m_errorMessage

protected

Message to be displayed as error to the user.

## m_deviceConfig

Gfx::DeviceConfig CApplication::m_deviceConfig

protected

Current configuration of OpenGL display device.

## m_windowTitle

std::string CApplication::m_windowTitle

protected

Text set as window title.

## m_baseTimeStamp

TimeUtils::TimeStamp CApplication::m_baseTimeStamp

protected

Animation time stamps, etc.

## m_graphicsOverride

bool CApplication::m_graphicsOverride = false

protected

Graphics device to use.

## m_glVersionOverride

bool CApplication::m_glVersionOverride = false

protected

OpenGL version to use.

## m_glProfileOverride

bool CApplication::m_glProfileOverride = false

protected

OpenGL profile.

## m_mouseMode

MouseMode CApplication::m_mouseMode

protected

Current mode of mouse.

## m_joystick

JoystickDevice CApplication::m_joystick

protected

Info about current joystick device.

## m_joystickEnabled

bool CApplication::m_joystickEnabled

protected

Whether joystick is enabled.

## m_joyAxeState

std::vector<int> CApplication::m_joyAxeState

protected

Current state of joystick axes; may be updated from another thread.

## m_joyButtonState

std::vector<bool> CApplication::m_joyButtonState

protected

Current state of joystick buttons; may be updated from another thread.

## m_runSceneCategory

LevelCategory CApplication::m_runSceneCategory

protected

Scene to run on startup.

## m_loadSavePlayerName

std::string CApplication::m_loadSavePlayerName

protected

Game to load on startup.

## m_sceneTest

bool CApplication::m_sceneTest

protected

Scene test mode.

## m_language

Language CApplication::m_language

protected

Application language.

## m_resolutionOverride

bool CApplication::m_resolutionOverride

protected

Screen resolution overriden by commandline.

## m_headless

bool CApplication::m_headless

protected

Headles mode.

## m_languageLocale

char CApplication::m_languageLocale = { 0 }

static protected

Static buffer for putenv locale.

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

- src/app/app.h
- src/app/app.cpp