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 
252  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 
482  std::string m_runSceneName;
483  int m_runSceneRank;
485 
488 
491 
493  bool m_lowCPU;
494 
497 };
498