Colobot
|
Main application. More...
#include <app.h>
Public Member Functions | |
CApplication () | |
Constructor (can only be called once!) | |
~CApplication () | |
Destructor. | |
CEventQueue * | GetEventQueue () |
Returns the application's event queue. | |
CSoundInterface * | GetSound () |
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< 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 | 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 | |
ApplicationPrivate * | m_private |
Private (SDL-dependent data) | |
CInstanceManager * | m_iMan |
Instance manager. | |
CObjectManager * | m_objMan |
Object manager. | |
CEventQueue * | m_eventQueue |
Global event queue. | |
Gfx::CEngine * | m_engine |
Graphics engine. | |
Gfx::CDevice * | m_device |
Graphics device. | |
Gfx::CModelManager * | m_modelManager |
3D models manager | |
CSoundInterface * | m_sound |
Sound subsystem. | |
CController * | m_controller |
Game controller - game engine and UI. | |
CProfile * | m_profile |
Profile (INI) reader/writer. | |
CInput * | m_input |
Input manager. | |
CPathManager * | m_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. | |
SystemTimeStamp * | m_baseTimeStamp |
Animation time stamps, etc. | |
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 |
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 CApplication & | GetInstance () |
static CApplication * | GetInstancePointer () |
static bool | IsCreated () |
![]() | |
static CApplication * | m_instance = nullptr |
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 CInstanceManager, 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.
|
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.
|
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.