Colobot
|
Main application. More...
#include <app.h>
Public Member Functions | |
CApplication (CSystemUtils *systemUtils) | |
Constructor (can only be called once!) More... | |
~CApplication () | |
Destructor. More... | |
CEventQueue * | GetEventQueue () |
Returns the application's event queue. More... | |
CSoundInterface * | GetSound () |
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< JoystickDevice > | GetJoystickList () 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 | |
CSystemUtils * | m_systemUtils |
System utils instance. More... | |
std::unique_ptr< ApplicationPrivate > | m_private |
Private (SDL-dependent data) More... | |
std::unique_ptr< CEventQueue > | m_eventQueue |
Global event queue. More... | |
std::unique_ptr< Gfx::CEngine > | m_engine |
Graphics engine. More... | |
std::unique_ptr< Gfx::CDevice > | m_device |
Graphics device. More... | |
std::unique_ptr< CSoundInterface > | m_sound |
Sound subsystem. More... | |
std::unique_ptr< CController > | m_controller |
Game controller - game engine and UI. More... | |
std::unique_ptr< CConfigFile > | m_configFile |
Profile (INI) reader/writer. More... | |
std::unique_ptr< CInput > | m_input |
Input manager. More... | |
std::unique_ptr< CPathManager > | m_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... | |
SystemTimeStamp * | m_manualFrameLast |
SystemTimeStamp * | m_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... | |
SystemTimeStamp * | m_baseTimeStamp |
Animation time stamps, etc. More... | |
SystemTimeStamp * | m_lastTimeStamp |
SystemTimeStamp * | m_curTimeStamp |
SystemTimeStamp * | m_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 CApplication * | m_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 CApplication & | GetInstance () |
static CApplication * | GetInstancePointer () |
static bool | IsCreated () |
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.
The class creates the only instance of CEventQueue, CEngine, CRobotMain and CSoundInterface classes.
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 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.
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.
CApplication::CApplication | ( | CSystemUtils * | systemUtils | ) |
Constructor (can only be called once!)
CApplication::~CApplication | ( | ) |
Destructor.
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.
|
protected |
Creates the window's SDL_Surface.
|
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.
If applicable, creates a virtual event to match the changed state as of new event.
|
protected |
Prepares a simulation update event.
|
protected |
Logs debug data for event.
|
protected |
Opens the joystick device.
|
protected |
Closes the joystick device.
|
protected |
Internal procedure to reset time counters.
|
protected |
Resets all performance counters to zero.
|
protected |
Updates performance counters from gathered timer data.
|
protected |
System utils instance.
|
protected |
Private (SDL-dependent data)
|
protected |
Global event queue.
|
protected |
Graphics engine.
|
protected |
Graphics device.
|
protected |
Sound subsystem.
|
protected |
Game controller - game engine and UI.
|
protected |
Profile (INI) reader/writer.
|
protected |
Input manager.
|
protected |
Path manager.
|
protected |
Code to return at exit.
|
protected |
Whether application window is active.
|
protected |
Bit array of active debug modes.
|
protected |
Message to be displayed as error to the user.
|
protected |
Current configuration of OpenGL display device.
|
protected |
Text set as window title.
|
protected |
Animation time stamps, etc.
|
protected |
Graphics device to use.
|
protected |
OpenGL version to use.
|
protected |
OpenGL profile.
|
protected |
Current mode of mouse.
|
protected |
Info about current joystick device.
|
protected |
Whether joystick is enabled.
|
protected |
Current state of joystick axes; may be updated from another thread.
|
protected |
Current state of joystick buttons; may be updated from another thread.
|
protected |
Scene to run on startup.
|
protected |
Scene test mode.
|
protected |
Application language.
|
protected |
Screen resoultion overriden by commandline.
|
protected |
Headles mode.
|
staticprotected |
Static buffer for putenv locale.