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-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.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 #include "common/event.h"
28 #include "common/language.h"
29 #include "common/singleton.h"
30 
31 #include "graphics/core/device.h"
32 
33 #include "level/level_category.h"
34 
35 
36 #include <string>
37 #include <vector>
38 
39 
40 class CEventQueue;
41 class CController;
42 class CSoundInterface;
43 class CInput;
44 class CPathManager;
45 class CConfigFile;
46 class CSystemUtils;
47 struct SystemTimeStamp;
48 
49 namespace Gfx
50 {
51 class CEngine;
52 struct DeviceConfig;
53 }
54 
60 {
62  int index;
64  std::string name;
66  int axisCount;
69 
71  : index(-1), axisCount(0), buttonCount(0) {}
72 };
73 
79 {
80  PARSE_ARGS_OK = 1,
83 };
84 
90 {
91  MOUSE_SYSTEM,
95 };
96 
102 {
103  PCNT_EVENT_PROCESSING,
104 
109 
117 
119 
121 
123 };
124 
125 enum DebugMode
126 {
127  DEBUG_SYS_EVENTS = 1 << 0,
128  DEBUG_UPDATE_EVENTS = 1 << 1,
129  DEBUG_APP_EVENTS = 1 << 2,
130  DEBUG_EVENTS = DEBUG_SYS_EVENTS | DEBUG_UPDATE_EVENTS | DEBUG_APP_EVENTS,
131  DEBUG_MODELS = 1 << 3,
132  DEBUG_ALL = DEBUG_SYS_EVENTS | DEBUG_APP_EVENTS | DEBUG_MODELS
133 };
134 
135 struct ApplicationPrivate;
136 
180 class CApplication : public CSingleton<CApplication>
181 {
182 public:
184  CApplication(CSystemUtils* systemUtils);
186  ~CApplication();
187 
189  CEventQueue* GetEventQueue();
191  CSoundInterface* GetSound();
192 
193 public:
195  ParseArgsStatus ParseArguments(int argc, char *argv[]);
197  bool Create();
199  int Run();
201  int GetExitCode() const;
202 
204  const std::string& GetErrorMessage() const;
205 
207  void GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions, int display = 0) const;
208 
210  Gfx::DeviceConfig GetVideoConfig() const;
211 
213  bool ChangeVideoConfig(const Gfx::DeviceConfig &newConfig);
214 
216  void SuspendSimulation();
218  void ResumeSimulation();
220  bool GetSimulationSuspended() const;
221 
223  void ResetTimeAfterLoading();
224 
226  void SetSimulationSpeed(float speed);
228  float GetSimulationSpeed() const;
230 
232  float GetAbsTime() const;
234  long long GetExactAbsTime() const;
235 
237  long long GetRealAbsTime() const;
238 
240  float GetRelTime() const;
242  long long GetExactRelTime() const;
243 
245  long long GetRealRelTime() const;
246 
248  std::vector<JoystickDevice> GetJoystickList() const;
249 
251  JoystickDevice GetJoystick() const;
252 
254  bool ChangeJoystick(const JoystickDevice &newJoystick);
255 
257 
258  void SetJoystickEnabled(bool enable);
259  bool GetJoystickEnabled() const;
261 
263  void UpdateJoystick();
264 
266  void UpdateMouse();
267 
269 
270  void SetMouseMode(MouseMode mode);
271  MouseMode GetMouseMode() const;
273 
275 
276  void SetTextInput(bool textInputEnabled);
277 
279  void MoveMouse(Math::Point pos);
280 
282 
283  void SetDebugModeActive(DebugMode mode, bool active);
284  bool IsDebugModeActive(DebugMode mode) const;
285  static bool ParseDebugModes(const std::string& str, int& debugModes);
287 
289 
290  Language GetLanguage() const;
291  char GetLanguageChar() const;
292  void SetLanguage(Language language);
294 
296 
297  void StartPerformanceCounter(PerformanceCounter counter);
298  void StopPerformanceCounter(PerformanceCounter counter);
299  float GetPerformanceCounterData(PerformanceCounter counter) const;
301 
302  bool GetSceneTestMode();
303 
305  void Render();
306 
308  void RenderIfNeeded(int updateRate);
309 
311  void PlayForceFeedbackEffect(float strength = 1.0f, int length = 999999);
313  void StopForceFeedbackEffect();
314 
315 protected:
317  bool CreateVideoSurface();
318 
320  Event ProcessSystemEvent();
322  Event CreateVirtualEvent(const Event& sourceEvent);
324  TEST_VIRTUAL Event CreateUpdateEvent();
326  void LogEvent(const Event& event);
327 
329  bool OpenJoystick();
331  void CloseJoystick();
332 
334  void InternalResumeSimulation();
335 
337  void ResetPerformanceCounters();
339  void UpdatePerformanceCountersData();
340 
341 protected:
345  std::unique_ptr<ApplicationPrivate> m_private;
347  std::unique_ptr<CEventQueue> m_eventQueue;
349  std::unique_ptr<Gfx::CEngine> m_engine;
351  std::unique_ptr<Gfx::CDevice> m_device;
353  std::unique_ptr<CSoundInterface> m_sound;
355  std::unique_ptr<CController> m_controller;
357  std::unique_ptr<CConfigFile> m_configFile;
359  std::unique_ptr<CInput> m_input;
361  std::unique_ptr<CPathManager> m_pathManager;
362 
366  bool m_active;
369 
371  std::string m_errorMessage;
372 
375 
377  std::string m_windowTitle;
378 
380 
382  SystemTimeStamp* m_lastTimeStamp;
383  SystemTimeStamp* m_curTimeStamp;
384 
385  SystemTimeStamp* m_performanceCounters[PCNT_MAX][2];
386  float m_performanceCountersData[PCNT_MAX];
387 
388  long long m_realAbsTimeBase;
389  long long m_realAbsTime;
390  long long m_realRelTime;
391 
392  long long m_absTimeBase;
393  long long m_exactAbsTime;
394  long long m_exactRelTime;
395 
396  float m_absTime;
397  float m_relTime;
398 
399  float m_simulationSpeed;
400  bool m_simulationSuspended;
402 
403  SystemTimeStamp* m_manualFrameLast;
404  SystemTimeStamp* m_manualFrameTime;
405 
407  bool m_graphicsOverride = false;
408  std::string m_graphics = "default";
410  bool m_glVersionOverride = false;
411  int m_glMajor = -1;
412  int m_glMinor = -1;
414  bool m_glProfileOverride = false;
415  int m_glProfile = 0;
416 
419 
425  std::vector<int> m_joyAxeState;
427  std::vector<bool> m_joyButtonState;
428 
430  LevelCategory m_runSceneCategory;
432  int m_runSceneRank;
434 
437 
439  Language m_language;
440 
443 
446 
448  static char m_languageLocale[50];
449 };
CSingleton base class for singletons.
< frame update in CParticle
Definition: app.h:108
std::unique_ptr< CInput > m_input
Input manager.
Definition: app.h:359
std::string m_windowTitle
Text set as window title.
Definition: app.h:377
ParseArgsStatus
State of parsing commandline arguments.
Definition: app.h:78
< swapping buffers and vsync
Definition: app.h:120
Class for managing data/lang/save paths.
Definition: pathman.h:37
bool m_sceneTest
Scene test mode.
Definition: app.h:436
< rendering shadow map
Definition: app.h:118
bool m_resolutionOverride
Screen resoultion overriden by commandline.
Definition: app.h:442
< rendering the water
Definition: app.h:113
std::vector< bool > m_joyButtonState
Current state of joystick buttons; may be updated from another thread.
Definition: app.h:427
< all ok
Definition: app.h:81
< all counters together
Definition: app.h:122
CSystemUtils * m_systemUtils
System utils instance.
Definition: app.h:343
std::vector< int > m_joyAxeState
Current state of joystick axes; may be updated from another thread.
Definition: app.h:425
< invalid syntax
Definition: app.h:82
< the whole frame update process
Definition: app.h:106
Gfx::DeviceConfig m_deviceConfig
Current configuration of OpenGL display device.
Definition: app.h:374
< in-game cursor visible; system cursor hidden
Definition: app.h:93
Definition: singleton.h:30
int index
Device index (-1 = invalid device)
Definition: app.h:62
std::string name
Device name.
Definition: app.h:64
std::unique_ptr< ApplicationPrivate > m_private
Private (SDL-dependent data)
Definition: app.h:345
Global event queue.
Definition: event.h:866
int axisCount
Number of axes (only available after joystick opened)
Definition: app.h:66
SystemTimeStamp * m_baseTimeStamp
Animation time stamps, etc.
Definition: app.h:381
Class for loading config file.
Definition: config_file.h:40
PerformanceCounter
Type of counter testing performance.
Definition: app.h:101
std::unique_ptr< CSoundInterface > m_sound
Sound subsystem.
Definition: app.h:353
General config for graphics device.
Definition: device.h:64
std::unique_ptr< Gfx::CDevice > m_device
Graphics device.
Definition: app.h:351
< rendering 2D interface
Definition: app.h:116
long m_debugModes
Bit array of active debug modes.
Definition: app.h:368
std::unique_ptr< Gfx::CEngine > m_engine
Graphics engine.
Definition: app.h:349
< rendering the particles in 3D
Definition: app.h:112
< rendering the terrain
Definition: app.h:114
< frame update in CEngine
Definition: app.h:107
2D point
Definition: point.h:50
< both cursors visible (only for debug)
Definition: app.h:94
< the whole rendering process
Definition: app.h:111
Main application.
Definition: app.h:180
std::unique_ptr< CEventQueue > m_eventQueue
Global event queue.
Definition: app.h:347
Language m_language
Application language.
Definition: app.h:439
std::unique_ptr< CPathManager > m_pathManager
Path manager.
Definition: app.h:361
int m_exitCode
Code to return at exit.
Definition: app.h:364
Entry point into CRobotMain.
Definition: controller.h:39
JoystickDevice m_joystick
Info about current joystick device.
Definition: app.h:421
bool m_joystickEnabled
Whether joystick is enabled.
Definition: app.h:423
std::unique_ptr< CConfigFile > m_configFile
Profile (INI) reader/writer.
Definition: app.h:357
Namespace for (new) graphics code.
Definition: app.h:49
< rendering the 3D objects
Definition: app.h:115
bool m_headless
Headles mode.
Definition: app.h:445
The graphics engine.
Definition: engine.h:585
Event types, structs and event queue.
MouseMode m_mouseMode
Current mode of mouse.
Definition: app.h:418
bool m_active
Whether application window is active.
Definition: app.h:366
< event processing (except update events)
Definition: app.h:105
std::unique_ptr< CController > m_controller
Game controller - game engine and UI.
Definition: app.h:355
MouseMode
Mode of mouse cursor.
Definition: app.h:89
Platform-specific utils.
Definition: system.h:91
Definition: system_linux.h:31
Abstract graphics device - CDevice class and related structs/enums.
std::string m_errorMessage
Message to be displayed as error to the user.
Definition: app.h:371
< system cursor visible; in-game cursor hidden
Definition: app.h:92
< frame update in CRobotMain
Definition: app.h:110
Event sent by system, interface or game.
Definition: event.h:735
int buttonCount
Number of buttons (only available after joystick opened)
Definition: app.h:68
Private data of CApplication class.
Definition: app.cpp:79
Information about a joystick device.
Definition: app.h:59
Sound plugin interface.
Definition: sound.h:60
Management of mouse, keyboard and joystick.
Definition: input.h:71