Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Protected Member Functions | 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 ()
 Constructor (can only be called once!)
 
 ~CApplication ()
 Destructor.
 
CEventQueueGetEventQueue ()
 Returns the application's event queue.
 
CSoundInterfaceGetSound ()
 Returns the sound subsystem.
 
ParseArgsStatus ParseArguments (int argc, char *argv[])
 Parses commandline arguments.
 
bool Create ()
 Initializes the application.
 
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 Destroy ()
 Cleans up before exit.
 
void Restart ()
 Restart.
 
bool IsRestarting ()
 Should we restart after app quits?
 
VideoQueryResult GetVideoResolutionList (std::vector< Math::IntPoint > &resolutions, bool fullScreen, bool resizeable) const
 Returns a list of possible video modes.
 
Gfx::GLDeviceConfig GetVideoConfig () const
 Returns the current video mode.
 
bool ChangeVideoConfig (const Gfx::GLDeviceConfig &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.
 
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 realative time since last update [nanoseconds].
 
long long GetRealRelTime () const
 Returns the exact relative time since last update disregarding speed setting [nanoseconds].
 
std::vector< JoystickDeviceGetJoystickList () 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 UpdateJoystick ()
 Polls the state of joystick axes and buttons. More...
 
void UpdateMouse ()
 Updates the mouse position explicitly.
 
void MoveMouse (Math::Point pos)
 Moves (warps) the mouse cursor to the specified position (in interface coords)
 
bool GetSceneTestMode ()
 
void SetSimulationSpeed (float speed)
 Management of simulation speed.
 
float GetSimulationSpeed () const
 
void SetJoystickEnabled (bool enable)
 Management of joystick enable state.
 
bool GetJoystickEnabled () const
 
void SetGrabInput (bool grab)
 Management of the grab mode for input (keyboard & mouse)
 
bool GetGrabInput () const
 
void SetMouseMode (MouseMode mode)
 Management of mouse mode.
 
MouseMode GetMouseMode () const
 
void SetLowCPU (bool low)
 Management of sleep in main loop (lowers CPU usage)
 
bool GetLowCPU () const
 
void StartPerformanceCounter (PerformanceCounter counter)
 Management of performance counters.
 
void StopPerformanceCounter (PerformanceCounter counter)
 
float GetPerformanceCounterData (PerformanceCounter counter) const
 

Protected Member Functions

bool CreateVideoSurface ()
 Creates the window's SDL_Surface.
 
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.
 
TEST_VIRTUAL Event CreateUpdateEvent ()
 Prepares a simulation update event.
 
void LogEvent (const Event &event)
 Logs debug data for event.
 
void Render ()
 Renders the image in window. More...
 
bool OpenJoystick ()
 Opens the joystick device.
 
void CloseJoystick ()
 Closes the joystick device.
 
void InternalResumeSimulation ()
 Internal procedure to reset time counters.
 
void ResetPerformanceCounters ()
 Resets all performance counters to zero.
 
void UpdatePerformanceCountersData ()
 Updates performance counters from gathered timer data.
 

Protected Attributes

ApplicationPrivatem_private
 Private (SDL-dependent data)
 
CInstanceManagerm_iMan
 Instance manager.
 
CObjectManagerm_objMan
 Object manager.
 
CEventQueuem_eventQueue
 Global event queue.
 
Gfx::CEnginem_engine
 Graphics engine.
 
Gfx::CDevicem_device
 Graphics device.
 
Gfx::CModelManagerm_modelManager
 3D models manager
 
CSoundInterfacem_sound
 Sound subsystem.
 
CControllerm_controller
 Game controller - game engine and UI.
 
CProfilem_profile
 Profile (INI) reader/writer.
 
CInputm_input
 Input manager.
 
CPathManagerm_pathManager
 Path 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.
 
bool m_restart
 If we are restarting the app.
 
std::string m_errorMessage
 Message to be displayed as error to the user.
 
Gfx::GLDeviceConfig m_deviceConfig
 Current configuration of OpenGL display device.
 
Gfx::GLDeviceConfig m_lastDeviceConfig
 Previous configuration of OpenGL display device.
 
std::string m_windowTitle
 Text set as window title.
 
std::string m_graphics
 Graphics device to use.
 
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.
 
bool m_sceneTest
 Scene test mode.
 
Language m_language
 Application language.
 
bool m_lowCPU
 Low cpu mode.
 
bool m_resolutionOverride
 Screen resoultion overriden by commandline.
 
bool m_headless
 Headles mode.
 
SystemTimeStampm_baseTimeStamp
 Animation time stamps, etc.
 
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
 
std::string m_runSceneName
 Scene to run on startup.
 
int m_runSceneRank
 
void SetDebugModeActive (DebugMode mode, bool active)
 Management of debug modes (printing more info in logger)
 
bool IsDebugModeActive (DebugMode mode) const
 
static bool ParseDebugModes (const std::string &str, int &debugModes)
 
Language GetLanguage () const
 Management of language.
 
char GetLanguageChar () const
 
void SetLanguage (Language language)
 
static bool ParseLanguage (const std::string &str, Language &language)
 

Additional Inherited Members

- Static Public Member Functions inherited from CSingleton< CApplication >
static CApplicationGetInstance ()
 
static CApplicationGetInstancePointer ()
 
static bool IsCreated ()
 
- Static Protected Attributes inherited from CSingleton< CApplication >
static CApplicationm_instance = nullptr
 

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 CInstanceManager, 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.

Member Function Documentation

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.

void CApplication::Render ( )
protected

Renders the image in window.

Renders the frame and swaps buffers as necessary

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.


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