Colobot
app.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 
28 #include "common/global.h"
29 #include "common/singleton.h"
30 #include "common/profile.h"
31 
32 #include "graphics/core/device.h"
33 #include "graphics/engine/engine.h"
35 
36 
37 #include <string>
38 #include <vector>
39 
40 
41 class CInstanceManager;
42 class CEventQueue;
43 class CController;
44 class CSoundInterface;
45 class CInput;
46 class CObjectManager;
47 class CPathManager;
48 
49 namespace Gfx {
50 class CModelManager;
51 }
52 
58 {
60  int index;
62  std::string name;
64  int axisCount;
67 
69  : index(-1), axisCount(0), buttonCount(0) {}
70 };
71 
77 {
78  VIDEO_QUERY_ERROR,
79  VIDEO_QUERY_NONE,
80  VIDEO_QUERY_ALL,
81  VIDEO_QUERY_OK
82 };
83 
89 {
90  PARSE_ARGS_OK = 1,
93 };
94 
100 {
101  MOUSE_SYSTEM,
105 };
106 
112 {
113  PCNT_EVENT_PROCESSING,
114 
119 
127 
129 
131 };
132 
133 enum DebugMode
134 {
135  DEBUG_SYS_EVENTS = 1 << 0,
136  DEBUG_APP_EVENTS = 1 << 1,
137  DEBUG_EVENTS = DEBUG_SYS_EVENTS | DEBUG_APP_EVENTS,
138  DEBUG_MODELS = 1 << 2,
139  DEBUG_ALL = DEBUG_SYS_EVENTS | DEBUG_APP_EVENTS | DEBUG_MODELS
140 };
141 
142 struct ApplicationPrivate;
143 
187 class CApplication : public CSingleton<CApplication>
188 {
189 public:
191  CApplication();
193  ~CApplication();
194 
199 
200 public:
202  ParseArgsStatus ParseArguments(int argc, char *argv[]);
204  bool Create();
206  int Run();
208  int GetExitCode() const;
209 
211  const std::string& GetErrorMessage() const;
212 
214  void Destroy();
215 
217  void Restart();
219  bool IsRestarting();
220 
222  VideoQueryResult GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions,
223  bool fullScreen, bool resizeable) const;
224 
227 
229  bool ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig);
230 
232  void SuspendSimulation();
234  void ResumeSimulation();
236  bool GetSimulationSuspended() const;
237 
239  void ResetTimeAfterLoading();
240 
242  void SetSimulationSpeed(float speed);
244  float GetSimulationSpeed() const;
246 
248  float GetAbsTime() const;
250  long long GetExactAbsTime() const;
251 
253  long long GetRealAbsTime() const;
254 
256  float GetRelTime() const;
258  long long GetExactRelTime() const;
259 
261  long long GetRealRelTime() const;
262 
264  std::vector<JoystickDevice> GetJoystickList() const;
265 
267  JoystickDevice GetJoystick() const;
268 
270  bool ChangeJoystick(const JoystickDevice &newJoystick);
271 
273 
274  void SetJoystickEnabled(bool enable);
275  bool GetJoystickEnabled() const;
277 
279  void UpdateJoystick();
280 
282  void UpdateMouse();
283 
285 
286  void SetGrabInput(bool grab);
287  bool GetGrabInput() const;
289 
291 
292  void SetMouseMode(MouseMode mode);
293  MouseMode GetMouseMode() const;
295 
297  void MoveMouse(Math::Point pos);
298 
300 
301  void SetDebugModeActive(DebugMode mode, bool active);
302  bool IsDebugModeActive(DebugMode mode) const;
303  static bool ParseDebugModes(const std::string& str, int& debugModes);
305 
307 
308  Language GetLanguage() const;
309  char GetLanguageChar() const;
310  void SetLanguage(Language language);
311  static bool ParseLanguage(const std::string& str, Language& language);
313 
315 
316  void SetLowCPU(bool low);
317  bool GetLowCPU() const;
319 
321 
323  void StopPerformanceCounter(PerformanceCounter counter);
324  float GetPerformanceCounterData(PerformanceCounter counter) const;
326 
327  bool GetSceneTestMode();
328 
329 protected:
331  bool CreateVideoSurface();
332 
336  Event CreateVirtualEvent(const Event& sourceEvent);
338  TEST_VIRTUAL Event CreateUpdateEvent();
340  void LogEvent(const Event& event);
342  void Render();
343 
345  bool OpenJoystick();
347  void CloseJoystick();
348 
351 
356 
357 protected:
361  // TODO: to be removed
383 
387  bool m_active;
391  bool m_restart;
392 
394  std::string m_errorMessage;
395 
400 
402  std::string m_windowTitle;
403 
405 
407  SystemTimeStamp* m_lastTimeStamp;
408  SystemTimeStamp* m_curTimeStamp;
409 
410  SystemTimeStamp* m_performanceCounters[PCNT_MAX][2];
411  float m_performanceCountersData[PCNT_MAX];
412 
413  long long m_realAbsTimeBase;
414  long long m_realAbsTime;
415  long long m_realRelTime;
416 
417  long long m_absTimeBase;
418  long long m_exactAbsTime;
419  long long m_exactRelTime;
420 
421  float m_absTime;
422  float m_relTime;
423 
424  float m_simulationSpeed;
425  bool m_simulationSuspended;
427 
429  std::string m_graphics;
430 
433 
439  std::vector<int> m_joyAxeState;
441  std::vector<bool> m_joyButtonState;
442 
444  std::string m_runSceneName;
446  int m_runSceneRank;
448 
451 
454 
456  bool m_lowCPU;
457 
460 
463 };
464 
~CApplication()
Destructor.
Definition: app.cpp:171
bool m_restart
If we are restarting the app.
Definition: app.h:391
CSoundInterface * GetSound()
Returns the sound subsystem.
Definition: app.cpp:210
CEventQueue * m_eventQueue
Global event queue.
Definition: app.h:366
Additional config with OpenGL-specific settings.
Definition: glutil.h:48
CSingleton base class for singletons.
std::string m_runSceneName
Scene to run on startup.
Definition: app.h:445
void Render()
Renders the image in window.
Definition: app.cpp:1268
< frame update in CParticle
Definition: app.h:118
ParseArgsStatus ParseArguments(int argc, char *argv[])
Parses commandline arguments.
Definition: app.cpp:215
std::string m_windowTitle
Text set as window title.
Definition: app.h:402
ParseArgsStatus
State of parsing commandline arguments.
Definition: app.h:88
Main graphics engine - CEngine class.
void CloseJoystick()
Closes the joystick device.
Definition: app.cpp:805
< rendering shadow map
Definition: app.h:128
Class for managing data/lang/save paths, and something% replacements.
Definition: pathman.h:35
const std::string & GetErrorMessage() const
Returns the message of error (set to something if exit code is not 0)
Definition: app.cpp:1053
bool m_sceneTest
Scene test mode.
Definition: app.h:450
void SetJoystickEnabled(bool enable)
Management of joystick enable state.
Definition: app.cpp:1547
long long GetExactAbsTime() const
Returns the exact absolute time counter [nanoseconds].
Definition: app.cpp:1369
void SetSimulationSpeed(float speed)
Management of simulation speed.
Definition: app.cpp:1310
bool m_resolutionOverride
Screen resoultion overriden by commandline.
Definition: app.h:459
< rendering the water
Definition: app.h:123
CEventQueue * GetEventQueue()
Returns the application's event queue.
Definition: app.cpp:205
std::vector< bool > m_joyButtonState
Current state of joystick buttons; may be updated from another thread.
Definition: app.h:441
void SetMouseMode(MouseMode mode)
Management of mouse mode.
Definition: app.cpp:1504
< all ok
Definition: app.h:91
< all counters together
Definition: app.h:130
void Restart()
Restart.
Definition: app.cpp:717
ApplicationPrivate * m_private
Private (SDL-dependent data)
Definition: app.h:359
std::vector< int > m_joyAxeState
Current state of joystick axes; may be updated from another thread.
Definition: app.h:439
VideoQueryResult GetVideoResolutionList(std::vector< Math::IntPoint > &resolutions, bool fullScreen, bool resizeable) const
Returns a list of possible video modes.
Definition: app.cpp:1399
CController * m_controller
Game controller - game engine and UI.
Definition: app.h:376
< invalid syntax
Definition: app.h:92
< the whole frame update process
Definition: app.h:116
< in-game cursor visible; system cursor hidden
Definition: app.h:103
void ResetTimeAfterLoading()
Resets time counters to account for time spent loading game.
Definition: app.cpp:1290
Definition: singleton.h:30
int index
Device index (-1 = invalid device)
Definition: app.h:60
bool GetSimulationSuspended() const
Returns whether simulation is suspended.
Definition: app.cpp:1305
void InternalResumeSimulation()
Internal procedure to reset time counters.
Definition: app.cpp:1297
CInput * m_input
Input manager.
Definition: app.h:380
Some common, global definitions.
std::string m_graphics
Graphics device to use.
Definition: app.h:429
void LogEvent(const Event &event)
Logs debug data for event.
Definition: app.cpp:1168
bool ChangeJoystick(const JoystickDevice &newJoystick)
Change the current joystick device.
Definition: app.cpp:813
Gfx::CEngine * m_engine
Graphics engine.
Definition: app.h:368
CProfile * m_profile
Profile (INI) reader/writer.
Definition: app.h:378
long long GetExactRelTime() const
Returns the exact realative time since last update [nanoseconds].
Definition: app.cpp:1384
std::string name
Device name.
Definition: app.h:62
bool CreateVideoSurface()
Creates the window's SDL_Surface.
Definition: app.cpp:620
Global event queue.
Definition: event.h:751
Gfx::CDevice * m_device
Graphics device.
Definition: app.h:370
int axisCount
Number of axes (only available after joystick opened)
Definition: app.h:64
Gfx::CModelManager * m_modelManager
3D models manager
Definition: app.h:372
SystemTimeStamp * m_baseTimeStamp
Animation time stamps, etc.
Definition: app.h:406
void SetLowCPU(bool low)
Management of sleep in main loop (lowers CPU usage)
Definition: app.cpp:1752
TEST_VIRTUAL Event CreateUpdateEvent()
Prepares a simulation update event.
Definition: app.cpp:1321
void UpdateJoystick()
Polls the state of joystick axes and buttons.
Definition: app.cpp:837
CSoundInterface * m_sound
Sound subsystem.
Definition: app.h:374
bool m_lowCPU
Low cpu mode.
Definition: app.h:456
PerformanceCounter
Type of counter testing performance.
Definition: app.h:111
bool ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig)
Change the video mode to given mode.
Definition: app.cpp:728
< rendering 2D interface
Definition: app.h:126
long m_debugModes
Bit array of active debug modes.
Definition: app.h:389
void MoveMouse(Math::Point pos)
Moves (warps) the mouse cursor to the specified position (in interface coords)
Definition: app.cpp:1518
void UpdateMouse()
Updates the mouse position explicitly.
Definition: app.cpp:891
void UpdatePerformanceCountersData()
Updates performance counters from gathered timer data.
Definition: app.cpp:1786
float GetAbsTime() const
Returns the absolute time counter [seconds].
Definition: app.cpp:1364
CApplication()
Constructor (can only be called once!)
Definition: app.cpp:105
< rendering the particles in 3D
Definition: app.h:122
bool IsRestarting()
Should we restart after app quits?
Definition: app.cpp:723
< rendering the terrain
Definition: app.h:124
CObjectManager * m_objMan
Object manager.
Definition: app.h:364
Gfx::GLDeviceConfig m_lastDeviceConfig
Previous configuration of OpenGL display device.
Definition: app.h:399
< frame update in CEngine
Definition: app.h:117
2D point
Definition: point.h:49
< both cursors visible (only for debug)
Definition: app.h:104
< the whole rendering process
Definition: app.h:121
bool Create()
Initializes the application.
Definition: app.cpp:427
long long GetRealRelTime() const
Returns the exact relative time since last update disregarding speed setting [nanoseconds].
Definition: app.cpp:1389
Main application.
Definition: app.h:187
Language m_language
Application language.
Definition: app.h:453
Gfx::GLDeviceConfig GetVideoConfig() const
Returns the current video mode.
Definition: app.cpp:1394
int m_exitCode
Code to return at exit.
Definition: app.h:385
Entry point into CRobotMain and CMainDialog.
Definition: controller.h:40
JoystickDevice GetJoystick() const
Returns info about the current joystick.
Definition: app.cpp:1542
OpenGL implementation - CGL21Device class.
float GetRelTime() const
Returns the relative time since last update [seconds].
Definition: app.cpp:1379
JoystickDevice m_joystick
Info about current joystick device.
Definition: app.h:435
Event CreateVirtualEvent(const Event &sourceEvent)
If applicable, creates a virtual event to match the changed state as of new event.
Definition: app.cpp:1232
bool m_joystickEnabled
Whether joystick is enabled.
Definition: app.h:437
Namespace for (new) graphics code.
Definition: app.h:49
Class for loading profile (currently for loading ini config file)
Definition: profile.h:45
void SetDebugModeActive(DebugMode mode, bool active)
Management of debug modes (printing more info in logger)
Definition: app.cpp:1442
VideoQueryResult
Result of querying for available video resolutions.
Definition: app.h:76
< rendering the 3D objects
Definition: app.h:125
bool m_headless
Headles mode.
Definition: app.h:462
std::vector< JoystickDevice > GetJoystickList() const
Returns a list of available joystick devices.
Definition: app.cpp:1525
Manager for static models.
Definition: modelmanager.h:54
The graphics engine.
Definition: engine.h:684
MouseMode m_mouseMode
Current mode of mouse.
Definition: app.h:432
bool m_active
Whether application window is active.
Definition: app.h:387
< event processing (except update events)
Definition: app.h:115
CPathManager * m_pathManager
Path manager.
Definition: app.h:382
Gfx::GLDeviceConfig m_deviceConfig
Current configuration of OpenGL display device.
Definition: app.h:397
Class for loading profile (currently for loading ini config file)
MouseMode
Mode of mouse cursor.
Definition: app.h:99
void SuspendSimulation()
Suspends animation (time will not be updated)
Definition: app.cpp:1276
Definition: system_linux.h:30
Abstract graphics device - CDevice class and related structs/enums.
Language GetLanguage() const
Management of language.
Definition: app.cpp:1569
CInstanceManager * m_iMan
Instance manager.
Definition: app.h:362
std::string m_errorMessage
Message to be displayed as error to the user.
Definition: app.h:394
void SetGrabInput(bool grab)
Management of the grab mode for input (keyboard & mouse)
Definition: app.cpp:1493
< system cursor visible; in-game cursor hidden
Definition: app.h:102
long long GetRealAbsTime() const
Returns the exact absolute time counter disregarding speed setting [nanoseconds]. ...
Definition: app.cpp:1374
Definition: objman.h:37
< frame update in CRobotMain
Definition: app.h:120
Event sent by system, interface or game.
Definition: event.h:678
void ResumeSimulation()
Resumes animation.
Definition: app.cpp:1282
int GetExitCode() const
Returns the code to be returned at main() exit.
Definition: app.cpp:1048
bool OpenJoystick()
Opens the joystick device.
Definition: app.cpp:783
int buttonCount
Number of buttons (only available after joystick opened)
Definition: app.h:66
Language
Application language.
Definition: global.h:174
int Run()
Main event loop.
Definition: app.cpp:898
Manager for instances of certain classes.
Definition: iman.h:72
Event ProcessSystemEvent()
Processes the captured SDL event to Event struct.
Definition: app.cpp:1060
Private data of CApplication class.
Definition: app.cpp:80
Information about a joystick device.
Definition: app.h:57
void Destroy()
Cleans up before exit.
Definition: app.cpp:671
Sound plugin interface.
Definition: sound.h:151
Abstract interface of graphics device.
Definition: device.h:251
void ResetPerformanceCounters()
Resets all performance counters to zero.
Definition: app.cpp:1777
void StartPerformanceCounter(PerformanceCounter counter)
Management of performance counters.
Definition: app.cpp:1762
Management of mouse, keyboard and joystick.
Definition: input.h:68