Colobot
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CApplication Class Reference

Main application. More...

#include <app.h>

Inheritance diagram for CApplication:
Inheritance graph
[legend]

Public Member Functions

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

Protected Member Functions

bool CreateVideoSurface ()
 Creates the window's SDL_Surface. More...
 
Event ProcessSystemEvent ()
 Processes the captured SDL event to Event struct. More...
 
Event CreateVirtualEvent (const Event &sourceEvent)
 If applicable, creates a virtual event to match the changed state as of new event. More...
 
TEST_VIRTUAL Event CreateUpdateEvent ()
 Prepares a simulation update event. More...
 
void LogEvent (const Event &event)
 Logs debug data for event. More...
 
bool OpenJoystick ()
 Opens the joystick device. More...
 
void CloseJoystick ()
 Closes the joystick device. More...
 
void InternalResumeSimulation ()
 Internal procedure to reset time counters. More...
 
void ResetPerformanceCounters ()
 Resets all performance counters to zero. More...
 
void UpdatePerformanceCountersData ()
 Updates performance counters from gathered timer data. More...
 

Protected Attributes

CSystemUtilsm_systemUtils
 System utils instance. More...
 
std::unique_ptr< ApplicationPrivatem_private
 Private (SDL-dependent data) More...
 
std::unique_ptr< CEventQueuem_eventQueue
 Global event queue. More...
 
std::unique_ptr< Gfx::CEnginem_engine
 Graphics engine. More...
 
std::unique_ptr< Gfx::CDevicem_device
 Graphics device. More...
 
std::unique_ptr< CSoundInterfacem_sound
 Sound subsystem. More...
 
std::unique_ptr< CControllerm_controller
 Game controller - game engine and UI. More...
 
std::unique_ptr< CConfigFilem_configFile
 Profile (INI) reader/writer. More...
 
std::unique_ptr< CInputm_input
 Input manager. More...
 
std::unique_ptr< CPathManagerm_pathManager
 Path manager. More...
 
int m_exitCode
 Code to return at exit. More...
 
bool m_active
 Whether application window is active. More...
 
long m_debugModes
 Bit array of active debug modes. More...
 
std::string m_errorMessage
 Message to be displayed as error to the user. More...
 
Gfx::DeviceConfig m_deviceConfig
 Current configuration of OpenGL display device. More...
 
std::string m_windowTitle
 Text set as window title. More...
 
SystemTimeStampm_manualFrameLast
 
SystemTimeStampm_manualFrameTime
 
bool m_graphicsOverride = false
 Graphics device to use. More...
 
std::string m_graphics = "default"
 
bool m_glVersionOverride = false
 OpenGL version to use. More...
 
int m_glMajor = -1
 
int m_glMinor = -1
 
bool m_glProfileOverride = false
 OpenGL profile. More...
 
int m_glProfile = 0
 
MouseMode m_mouseMode
 Current mode of mouse. More...
 
JoystickDevice m_joystick
 Info about current joystick device. More...
 
bool m_joystickEnabled
 Whether joystick is enabled. More...
 
std::vector< int > m_joyAxeState
 Current state of joystick axes; may be updated from another thread. More...
 
std::vector< bool > m_joyButtonState
 Current state of joystick buttons; may be updated from another thread. More...
 
bool m_sceneTest
 Scene test mode. More...
 
Language m_language
 Application language. More...
 
bool m_resolutionOverride
 Screen resoultion overriden by commandline. More...
 
bool m_headless
 Headles mode. More...
 
SystemTimeStampm_baseTimeStamp
 Animation time stamps, etc. More...
 
SystemTimeStampm_lastTimeStamp
 
SystemTimeStampm_curTimeStamp
 
SystemTimeStampm_performanceCounters [PCNT_MAX][2]
 
float m_performanceCountersData [PCNT_MAX]
 
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
 
LevelCategory m_runSceneCategory
 Scene to run on startup. More...
 
int m_runSceneRank
 

Static Protected Attributes

static char m_languageLocale [50] = { 0 }
 Static buffer for putenv locale. More...
 
- Static Protected Attributes inherited from CSingleton< CApplication >
static CApplicationm_instance = nullptr
 
void SetDebugModeActive (DebugMode mode, bool active)
 Management of debug modes (printing more info in logger) More...
 
bool IsDebugModeActive (DebugMode mode) const
 
static bool ParseDebugModes (const std::string &str, int &debugModes)
 

Additional Inherited Members

- Static Public Member Functions inherited from CSingleton< CApplication >
static CApplicationGetInstance ()
 
static CApplicationGetInstancePointer ()
 
static bool IsCreated ()
 

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 ( CSystemUtils systemUtils)

Constructor (can only be called once!)

CApplication::~CApplication ( )

Destructor.

Member Function Documentation

CEventQueue * CApplication::GetEventQueue ( )

Returns the application's event queue.

CSoundInterface * CApplication::GetSound ( )

Returns the sound subsystem.

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

Parses commandline arguments.

bool CApplication::Create ( )

Initializes the application.

int CApplication::Run ( )

Main event loop.

int CApplication::GetExitCode ( ) const

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

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

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

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

Returns a list of possible video modes.

Gfx::DeviceConfig CApplication::GetVideoConfig ( ) const

Returns the current video mode.

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

Change the video mode to given mode.

void CApplication::SuspendSimulation ( )

Suspends animation (time will not be updated)

void CApplication::ResumeSimulation ( )

Resumes animation.

bool CApplication::GetSimulationSuspended ( ) const

Returns whether simulation is suspended.

void CApplication::ResetTimeAfterLoading ( )

Resets time counters to account for time spent loading game.

void CApplication::SetSimulationSpeed ( float  speed)

Management of simulation speed.

float CApplication::GetAbsTime ( ) const

Returns the absolute time counter [seconds].

long long CApplication::GetExactAbsTime ( ) const

Returns the exact absolute time counter [nanoseconds].

long long CApplication::GetRealAbsTime ( ) const

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

float CApplication::GetRelTime ( ) const

Returns the relative time since last update [seconds].

long long CApplication::GetExactRelTime ( ) const

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

long long CApplication::GetRealRelTime ( ) const

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

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

Returns a list of available joystick devices.

JoystickDevice CApplication::GetJoystick ( ) const

Returns info about the current joystick.

bool CApplication::ChangeJoystick ( const JoystickDevice newJoystick)

Change the current joystick device.

void CApplication::SetJoystickEnabled ( bool  enable)

Management of joystick enable state.

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.

void CApplication::UpdateMouse ( )

Updates the mouse position explicitly.

void CApplication::SetMouseMode ( MouseMode  mode)

Management of mouse mode.

void CApplication::SetTextInput ( bool  textInputEnabled)

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

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

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

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

Management of debug modes (printing more info in logger)

Language CApplication::GetLanguage ( ) const

Management of language.

void CApplication::StartPerformanceCounter ( PerformanceCounter  counter)

Management of performance counters.

void CApplication::Render ( )

Renders the image in window.

Renders the frame and swaps buffers as necessary

void CApplication::RenderIfNeeded ( int  updateRate)

Renders the image in window if needed.

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

Starts a force feedback effect on the joystick.

void CApplication::StopForceFeedbackEffect ( )

Stops a force feedback effect on the joystick.

bool CApplication::CreateVideoSurface ( )
protected

Creates the window's SDL_Surface.

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.

Event CApplication::CreateVirtualEvent ( const Event sourceEvent)
protected

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

Event CApplication::CreateUpdateEvent ( )
protected

Prepares a simulation update event.

void CApplication::LogEvent ( const Event event)
protected

Logs debug data for event.

bool CApplication::OpenJoystick ( )
protected

Opens the joystick device.

void CApplication::CloseJoystick ( )
protected

Closes the joystick device.

void CApplication::InternalResumeSimulation ( )
protected

Internal procedure to reset time counters.

void CApplication::ResetPerformanceCounters ( )
protected

Resets all performance counters to zero.

void CApplication::UpdatePerformanceCountersData ( )
protected

Updates performance counters from gathered timer data.

Member Data Documentation

CSystemUtils* CApplication::m_systemUtils
protected

System utils instance.

std::unique_ptr<ApplicationPrivate> CApplication::m_private
protected

Private (SDL-dependent data)

std::unique_ptr<CEventQueue> CApplication::m_eventQueue
protected

Global event queue.

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

Graphics engine.

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

Graphics device.

std::unique_ptr<CSoundInterface> CApplication::m_sound
protected

Sound subsystem.

std::unique_ptr<CController> CApplication::m_controller
protected

Game controller - game engine and UI.

std::unique_ptr<CConfigFile> CApplication::m_configFile
protected

Profile (INI) reader/writer.

std::unique_ptr<CInput> CApplication::m_input
protected

Input manager.

std::unique_ptr<CPathManager> CApplication::m_pathManager
protected

Path manager.

int CApplication::m_exitCode
protected

Code to return at exit.

bool CApplication::m_active
protected

Whether application window is active.

long CApplication::m_debugModes
protected

Bit array of active debug modes.

std::string CApplication::m_errorMessage
protected

Message to be displayed as error to the user.

Gfx::DeviceConfig CApplication::m_deviceConfig
protected

Current configuration of OpenGL display device.

std::string CApplication::m_windowTitle
protected

Text set as window title.

SystemTimeStamp* CApplication::m_baseTimeStamp
protected

Animation time stamps, etc.

bool CApplication::m_graphicsOverride = false
protected

Graphics device to use.

bool CApplication::m_glVersionOverride = false
protected

OpenGL version to use.

bool CApplication::m_glProfileOverride = false
protected

OpenGL profile.

MouseMode CApplication::m_mouseMode
protected

Current mode of mouse.

JoystickDevice CApplication::m_joystick
protected

Info about current joystick device.

bool CApplication::m_joystickEnabled
protected

Whether joystick is enabled.

std::vector<int> CApplication::m_joyAxeState
protected

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

std::vector<bool> CApplication::m_joyButtonState
protected

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

LevelCategory CApplication::m_runSceneCategory
protected

Scene to run on startup.

bool CApplication::m_sceneTest
protected

Scene test mode.

Language CApplication::m_language
protected

Application language.

bool CApplication::m_resolutionOverride
protected

Screen resoultion overriden by commandline.

bool CApplication::m_headless
protected

Headles mode.

char CApplication::m_languageLocale = { 0 }
staticprotected

Static buffer for putenv locale.


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