Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
app.h
Go to the documentation of this file.
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
3 // * Copyright (C) 2012, Polish Portal of Colobot (PPC)
4 // *
5 // * This program is free software: you can redistribute it and/or modify
6 // * it under the terms of the GNU General Public License as published by
7 // * the Free Software Foundation, either version 3 of the License, or
8 // * (at your option) any later version.
9 // *
10 // * This program is distributed in the hope that it will be useful,
11 // * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // * GNU General Public License for more details.
14 // *
15 // * You should have received a copy of the GNU General Public License
16 // * along with this program. If not, see http://www.gnu.org/licenses/.
17 
23 #pragma once
24 
25 
26 #include "common/global.h"
27 #include "common/singleton.h"
28 #include "common/profile.h"
29 
30 #include "graphics/core/device.h"
31 #include "graphics/engine/engine.h"
33 
34 #include "object/objman.h"
35 
36 
37 #include <string>
38 #include <vector>
39 
40 
41 class CInstanceManager;
42 class CEventQueue;
43 class CRobotMain;
44 class CSoundInterface;
45 class CGameData;
46 
47 namespace Gfx {
48 class CModelManager;
49 }
50 
56 {
58  int index;
60  std::string name;
62  int axisCount;
65 
67  : index(-1), axisCount(0), buttonCount(0) {}
68 };
69 
75 {
76  VIDEO_QUERY_ERROR,
77  VIDEO_QUERY_NONE,
78  VIDEO_QUERY_ALL,
79  VIDEO_QUERY_OK
80 };
81 
82 
88 {
89  TRKEY_NUM_UP = (1<<0),
90  TRKEY_NUM_DOWN = (1<<1),
91  TRKEY_NUM_LEFT = (1<<2),
92  TRKEY_NUM_RIGHT = (1<<3),
93  TRKEY_NUM_PLUS = (1<<4),
94  TRKEY_NUM_MINUS = (1<<5),
95  TRKEY_PAGE_UP = (1<<6),
96  TRKEY_PAGE_DOWN = (1<<7)
97 };
98 
104 {
105  PARSE_ARGS_OK = 1,
108 };
109 
115 {
116  MOUSE_SYSTEM,
120 };
121 
127 {
128  PCNT_EVENT_PROCESSING,
129 
134 
141 
143 
145 };
146 
147 enum DebugMode
148 {
149  DEBUG_SYS_EVENTS = 1 << 0,
150  DEBUG_APP_EVENTS = 1 << 1,
151  DEBUG_EVENTS = DEBUG_SYS_EVENTS | DEBUG_APP_EVENTS,
152  DEBUG_MODELS = 1 << 2,
153  DEBUG_ALL = DEBUG_SYS_EVENTS | DEBUG_APP_EVENTS | DEBUG_MODELS
154 };
155 
156 struct ApplicationPrivate;
157 
201 class CApplication : public CSingleton<CApplication>
202 {
203 public:
205  CApplication();
207  ~CApplication();
208 
213 
214 public:
216  ParseArgsStatus ParseArguments(int argc, char *argv[]);
218  bool Create();
220  int Run();
222  int GetExitCode() const;
223 
225  const std::string& GetErrorMessage() const;
226 
228  void Destroy();
229 
231  VideoQueryResult GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions,
232  bool fullScreen, bool resizeable) const;
233 
236 
238  bool ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig);
239 
241  void SuspendSimulation();
243  void ResumeSimulation();
245  bool GetSimulationSuspended() const;
246 
248  void ResetTimeAfterLoading();
249 
251  void SetSimulationSpeed(float speed);
253  float GetSimulationSpeed() const;
255 
257  float GetAbsTime() const;
259  long long GetExactAbsTime() const;
260 
262  long long GetRealAbsTime() const;
263 
265  float GetRelTime() const;
267  long long GetExactRelTime() const;
268 
270  long long GetRealRelTime() const;
271 
273  std::vector<JoystickDevice> GetJoystickList() const;
274 
276  JoystickDevice GetJoystick() const;
277 
279  bool ChangeJoystick(const JoystickDevice &newJoystick);
280 
282 
283  void SetJoystickEnabled(bool enable);
284  bool GetJoystickEnabled() const;
286 
288  void UpdateJoystick();
289 
291  void UpdateMouse();
292 
294  int GetKmods() const;
296  bool GetKmodState(int kmod) const;
297 
299  bool GetTrackedKeyState(TrackedKey key) const;
300 
302  bool GetMouseButtonState(int index) const;
303 
305  void ResetKeyStates();
306 
308 
309  void SetGrabInput(bool grab);
310  bool GetGrabInput() const;
312 
314 
315  void SetMouseMode(MouseMode mode);
316  MouseMode GetMouseMode() const;
318 
320  Math::Point GetMousePos() const;
321 
323  void MoveMouse(Math::Point pos);
324 
326 
327  void SetDebugModeActive(DebugMode mode, bool active);
328  bool IsDebugModeActive(DebugMode mode) const;
329  static bool ParseDebugModes(const std::string& str, int& debugModes);
331 
333 
334  Language GetLanguage() const;
335  char GetLanguageChar() const;
336  void SetLanguage(Language language);
337  static bool ParseLanguage(const std::string& str, Language& language);
339 
341 
342  void SetLowCPU(bool low);
343  bool GetLowCPU() const;
345 
347 
349  void StopPerformanceCounter(PerformanceCounter counter);
350  float GetPerformanceCounterData(PerformanceCounter counter) const;
352 
353  bool GetSceneTestMode();
354 
355 protected:
357  bool CreateVideoSurface();
358 
362  Event CreateVirtualEvent(const Event& sourceEvent);
364  TEST_VIRTUAL Event CreateUpdateEvent();
366  void LogEvent(const Event& event);
368  void Render();
369 
371  bool OpenJoystick();
373  void CloseJoystick();
374 
377 
382 
383 protected:
387  // TODO: to be removed
407 
411  bool m_active;
414 
416  std::string m_errorMessage;
417 
422 
424  std::string m_windowTitle;
425 
427 
429  SystemTimeStamp* m_lastTimeStamp;
430  SystemTimeStamp* m_curTimeStamp;
431 
432  SystemTimeStamp* m_performanceCounters[PCNT_MAX][2];
433  float m_performanceCountersData[PCNT_MAX];
434 
435  long long m_realAbsTimeBase;
436  long long m_realAbsTime;
437  long long m_realRelTime;
438 
439  long long m_absTimeBase;
440  long long m_exactAbsTime;
441  long long m_exactRelTime;
442 
443  float m_absTime;
444  float m_relTime;
445 
446  float m_simulationSpeed;
447  bool m_simulationSuspended;
449 
451  unsigned int m_kmodState;
453  unsigned int m_trackedKeys;
454 
460  unsigned int m_mouseButtonsState;
461 
467  std::vector<int> m_joyAxeState;
469  std::vector<bool> m_joyButtonState;
470 
472  std::string m_dataPath;
473 
476 
478  std::string m_langPath;
479 
481  std::string m_runSceneName;
483  int m_runSceneRank;
485 
488 
491 
493  bool m_lowCPU;
494 
497 };
498 
~CApplication()
Destructor.
Definition: app.cpp:167
CSoundInterface * GetSound()
Returns the sound subsystem.
Definition: app.cpp:203
CEventQueue * m_eventQueue
Global event queue.
Definition: app.h:392
Additional config with OpenGL-specific settings.
Definition: gldevice.h:50
CSingleton base class for singletons.
std::string m_runSceneName
Scene to run on startup.
Definition: app.h:482
void Render()
Renders the image in window.
Definition: app.cpp:1241
< frame update in CParticle
Definition: app.h:133
ParseArgsStatus ParseArguments(int argc, char *argv[])
Parses commandline arguments.
Definition: app.cpp:208
std::string m_windowTitle
Text set as window title.
Definition: app.h:424
ParseArgsStatus
State of parsing commandline arguments.
Definition: app.h:103
Main graphics engine - CEngine class.
void CloseJoystick()
Closes the joystick device.
Definition: app.cpp:728
< rendering 2D interface
Definition: app.h:142
bool GetKmodState(int kmod) const
Returns whether the given kmod is active.
Definition: app.cpp:1474
const std::string & GetErrorMessage() const
Returns the message of error (set to something if exit code is not 0)
Definition: app.cpp:976
bool m_sceneTest
Scene test mode.
Definition: app.h:487
void SetJoystickEnabled(bool enable)
Management of joystick enable state.
Definition: app.cpp:1557
long long GetExactAbsTime() const
Returns the exact absolute time counter [nanoseconds].
Definition: app.cpp:1345
void SetSimulationSpeed(float speed)
Management of simulation speed.
Definition: app.cpp:1283
std::string m_langPath
Path to directory with language files.
Definition: app.h:478
< rendering the water
Definition: app.h:138
CEventQueue * GetEventQueue()
Returns the application's event queue.
Definition: app.cpp:198
std::vector< bool > m_joyButtonState
Current state of joystick buttons; may be updated from another thread.
Definition: app.h:469
void SetMouseMode(MouseMode mode)
Management of mouse mode.
Definition: app.cpp:1508
< all ok
Definition: app.h:106
< all counters together
Definition: app.h:144
ApplicationPrivate * m_private
Private (SDL-dependent data)
Definition: app.h:385
std::string m_dataPath
Path to directory with data files.
Definition: app.h:472
std::vector< int > m_joyAxeState
Current state of joystick axes; may be updated from another thread.
Definition: app.h:467
VideoQueryResult GetVideoResolutionList(std::vector< Math::IntPoint > &resolutions, bool fullScreen, bool resizeable) const
Returns a list of possible video modes.
Definition: app.cpp:1375
< invalid syntax
Definition: app.h:107
< the whole frame update process
Definition: app.h:131
< in-game cursor visible; system cursor hidden
Definition: app.h:118
void ResetTimeAfterLoading()
Resets time counters to account for time spent loading game.
Definition: app.cpp:1263
Definition: singleton.h:27
int index
Device index (-1 = invalid device)
Definition: app.h:58
bool GetSimulationSuspended() const
Returns whether simulation is suspended.
Definition: app.cpp:1278
void InternalResumeSimulation()
Internal procedure to reset time counters.
Definition: app.cpp:1270
Some common, global definitions.
void LogEvent(const Event &event)
Logs debug data for event.
Definition: app.cpp:1135
bool ChangeJoystick(const JoystickDevice &newJoystick)
Change the current joystick device.
Definition: app.cpp:736
Gfx::CEngine * m_engine
Graphics engine.
Definition: app.h:394
CProfile * m_profile
Profile (INI) reader/writer.
Definition: app.h:404
long long GetExactRelTime() const
Returns the exact realative time since last update [nanoseconds].
Definition: app.cpp:1360
std::string name
Device name.
Definition: app.h:60
bool CreateVideoSurface()
Creates the window's SDL_Surface.
Definition: app.cpp:546
Global event queue.
Definition: event.h:764
Gfx::CDevice * m_device
Graphics device.
Definition: app.h:396
int axisCount
Number of axes (only available after joystick opened)
Definition: app.h:62
Gfx::CModelManager * m_modelManager
3D models manager
Definition: app.h:398
SystemTimeStamp * m_baseTimeStamp
Animation time stamps, etc.
Definition: app.h:428
Math::Point GetMousePos() const
Returns the position of mouse cursor (in interface coords)
Definition: app.cpp:1522
void SetLowCPU(bool low)
Management of sleep in main loop (lowers CPU usage)
Definition: app.cpp:1737
int GetKmods() const
Returns the current key modifiers.
Definition: app.cpp:1469
TEST_VIRTUAL Event CreateUpdateEvent()
Prepares a simulation update event.
Definition: app.cpp:1294
void UpdateJoystick()
Polls the state of joystick axes and buttons.
Definition: app.cpp:760
CSoundInterface * m_sound
Sound subsystem.
Definition: app.h:400
bool m_lowCPU
Low cpu mode.
Definition: app.h:493
Definition: robotmain.h:196
PerformanceCounter
Type of counter testing performance.
Definition: app.h:126
bool ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig)
Change the video mode to given mode.
Definition: app.cpp:652
long m_debugModes
Bit array of active debug modes.
Definition: app.h:413
void MoveMouse(Math::Point pos)
Moves (warps) the mouse cursor to the specified position (in interface coords)
Definition: app.cpp:1527
Math::Point m_mousePos
Current position of mouse cursor.
Definition: app.h:458
void UpdateMouse()
Updates the mouse position explicitly.
Definition: app.cpp:814
void UpdatePerformanceCountersData()
Updates performance counters from gathered timer data.
Definition: app.cpp:1771
float GetAbsTime() const
Returns the absolute time counter [seconds].
Definition: app.cpp:1340
CApplication()
Constructor (can only be called once!)
Definition: app.cpp:97
< rendering the particles in 3D
Definition: app.h:137
< rendering the terrain
Definition: app.h:139
unsigned int m_kmodState
Current state of key modifiers (bitmask of SDLMod)
Definition: app.h:451
unsigned int m_trackedKeys
Current state of some tracked keys (bitmask of TrackedKey enum values)
Definition: app.h:453
Definition: gamedata.h:48
bool GetTrackedKeyState(TrackedKey key) const
Returns whether the tracked key is pressed.
Definition: app.cpp:1479
CObjectManager * m_objMan
Object manager.
Definition: app.h:390
Gfx::GLDeviceConfig m_lastDeviceConfig
Previous configuration of OpenGL display device.
Definition: app.h:421
< frame update in CEngine
Definition: app.h:132
void ResetKeyStates()
Resets tracked key states and modifiers.
Definition: app.cpp:1489
unsigned int m_mouseButtonsState
Current state of mouse buttons (bitmask of MouseButton enum values)
Definition: app.h:460
2D point
Definition: point.h:46
< both cursors visible (only for debug)
Definition: app.h:119
< the whole rendering process
Definition: app.h:136
bool Create()
Initializes the application.
Definition: app.cpp:382
long long GetRealRelTime() const
Returns the exact relative time since last update disregarding speed setting [nanoseconds].
Definition: app.cpp:1365
Instance manager for objects.
Main application.
Definition: app.h:201
Language m_language
Application language.
Definition: app.h:490
Gfx::GLDeviceConfig GetVideoConfig() const
Returns the current video mode.
Definition: app.cpp:1370
CRobotMain * m_robotMain
Main class of the proper game engine.
Definition: app.h:402
int m_exitCode
Code to return at exit.
Definition: app.h:409
bool m_customDataPath
True if datadir was passed in command line.
Definition: app.h:475
JoystickDevice GetJoystick() const
Returns info about the current joystick.
Definition: app.cpp:1552
OpenGL implementation - CGLDevice class.
float GetRelTime() const
Returns the relative time since last update [seconds].
Definition: app.cpp:1355
JoystickDevice m_joystick
Info about current joystick device.
Definition: app.h:463
Event CreateVirtualEvent(const Event &sourceEvent)
If applicable, creates a virtual event to match the changed state as of new event.
Definition: app.cpp:1200
bool m_joystickEnabled
Whether joystick is enabled.
Definition: app.h:465
Class for loading profile (currently for loading ini config file)
Definition: profile.h:42
void SetDebugModeActive(DebugMode mode, bool active)
Management of debug modes (printing more info in logger)
Definition: app.cpp:1418
VideoQueryResult
Result of querying for available video resolutions.
Definition: app.h:74
< rendering the 3D objects
Definition: app.h:140
std::vector< JoystickDevice > GetJoystickList() const
Returns a list of available joystick devices.
Definition: app.cpp:1535
Manager for static models.
Definition: modelmanager.h:52
The graphics engine.
Definition: engine.h:682
MouseMode m_mouseMode
Current mode of mouse.
Definition: app.h:456
bool m_active
Whether application window is active.
Definition: app.h:411
< event processing (except update events)
Definition: app.h:130
Gfx::GLDeviceConfig m_deviceConfig
Current configuration of OpenGL display device.
Definition: app.h:419
Class for loading profile (currently for loading ini config file)
MouseMode
Mode of mouse cursor.
Definition: app.h:114
void SuspendSimulation()
Suspends animation (time will not be updated)
Definition: app.cpp:1249
Definition: system_linux.h:28
bool m_protoMode
Show prototype levels.
Definition: app.h:496
Abstract graphics device - CDevice class and related structs/enums.
Language GetLanguage() const
Management of language.
Definition: app.cpp:1579
CInstanceManager * m_iMan
Instance manager.
Definition: app.h:388
std::string m_errorMessage
Message to be displayed as error to the user.
Definition: app.h:416
void SetGrabInput(bool grab)
Management of the grab mode for input (keyboard & mouse)
Definition: app.cpp:1497
CGameData * m_gameData
Game data.
Definition: app.h:406
< system cursor visible; in-game cursor hidden
Definition: app.h:117
long long GetRealAbsTime() const
Returns the exact absolute time counter disregarding speed setting [nanoseconds]. ...
Definition: app.cpp:1350
Definition: objman.h:34
< frame update in CRobotMain
Definition: app.h:135
Event sent by system, interface or game.
Definition: event.h:686
void ResumeSimulation()
Resumes animation.
Definition: app.cpp:1255
int GetExitCode() const
Returns the code to be returned at main() exit.
Definition: app.cpp:971
bool OpenJoystick()
Opens the joystick device.
Definition: app.cpp:706
int buttonCount
Number of buttons (only available after joystick opened)
Definition: app.h:64
Language
Application language.
Definition: global.h:171
int Run()
Main event loop.
Definition: app.cpp:821
Manager for instances of certain classes.
Definition: iman.h:71
Event ProcessSystemEvent()
Processes the captured SDL event to Event struct.
Definition: app.cpp:983
Private data of CApplication class.
Definition: app.cpp:72
Information about a joystick device.
Definition: app.h:55
void Destroy()
Cleans up before exit.
Definition: app.cpp:597
Sound plugin interface.
Definition: sound.h:149
Abstract interface of graphics device.
Definition: device.h:235
TrackedKey
Additional keys whose state (pressed/released) is tracked by CApplication.
Definition: app.h:87
void ResetPerformanceCounters()
Resets all performance counters to zero.
Definition: app.cpp:1762
bool GetMouseButtonState(int index) const
Returns whether the mouse button is pressed.
Definition: app.cpp:1484
void StartPerformanceCounter(PerformanceCounter counter)
Management of performance counters.
Definition: app.cpp:1747