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.
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.
void UpdateMouse ()
 Updates the mouse position explicitly.
int GetKmods () const
 Returns the current key modifiers.
bool GetKmodState (int kmod) const
 Returns whether the given kmod is active.
bool GetTrackedKeyState (TrackedKey key) const
 Returns whether the tracked key is pressed.
bool GetMouseButtonState (int index) const
 Returns whether the mouse button is pressed.
void ResetKeyStates ()
 Resets tracked key states and modifiers.
Math::Point GetMousePos () const
 Returns the position of mouse cursor (in interface coords)
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.
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.
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.
CRobotMainm_robotMain
 Main class of the proper game engine.
CProfilem_profile
 Profile (INI) reader/writer.
CGameDatam_gameData
 Game data.
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::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.
unsigned int m_kmodState
 Current state of key modifiers (bitmask of SDLMod)
unsigned int m_trackedKeys
 Current state of some tracked keys (bitmask of TrackedKey enum values)
MouseMode m_mouseMode
 Current mode of mouse.
Math::Point m_mousePos
 Current position of mouse cursor.
unsigned int m_mouseButtonsState
 Current state of mouse buttons (bitmask of MouseButton enum values)
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.
std::string m_dataPath
 Path to directory with data files.
bool m_customDataPath
 True if datadir was passed in command line.
std::string m_langPath
 Path to directory with language files.
bool m_sceneTest
 Scene test mode.
Language m_language
 Application language.
bool m_lowCPU
 Low cpu mode.
bool m_protoMode
 Show prototype levels.
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: