Debian Codegraph @

src/game/game.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2015 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #ifndef GAME_HPP
17 #define GAME_HPP
18
19 #include <QElapsedTimer>
20 #include <QObject>
21 #include <QTime>
22 #include <QTimer>
23 #include <QTranslator>
24
25 #include <MCWorld>
26
27 #include <chrono>
28
29 #include "application.hpp"
30 #include "settings.hpp"
31
32 class AudioWorker;
33 class Database;
34 class EventHandler;
35 class InputHandler;
36 class Renderer;
37 class Scene;
38 class Startlights;
39 class StartlightsOverlay;
40 class StateMachine;
41 class TimingOverlay;
42 class TrackLoader;
43 class QScreen;
44
45 //! The main game class.
46 class Game : public QObject
47 {
48 Q_OBJECT
49
50 public:
51 enum class Mode
52 {
53 OnePlayerRace,
54 TwoPlayerRace,
55 TimeTrial,
56 Duel
57 };
58
59 enum class SplitType
60 {
61 Horizontal,
62 Vertical
63 };
64
65 enum class Fps
66 {
67 Fps30,
68 Fps60
69 };
70
71 Game(int & argc, char ** argv);
72 virtual ~Game() override;
73
74 //! Return the game instance.
75 static Game & instance();
76
77 //! \return The renderer.
78 Renderer & renderer() const;
79
80 int run();
81
82 void setMode(Mode mode);
83 Mode mode() const;
84
85 void setSplitType(SplitType splitType);
86 SplitType splitType() const;
87
88 void setFps(Fps fps);
89 Fps fps() const;
90
91 void setLapCount(int lapCount);
92 int lapCount() const;
93
94 bool hasTwoHumanPlayers() const;
95 bool hasComputerPlayers() const;
96
97 EventHandler & eventHandler();
98 AudioWorker & audioWorker();
99
100 DifficultyProfile & difficultyProfile();
101
102 const std::string & fontName() const;
103
104 QScreen * screen() const;
105
106 public slots:
107
108 void exitGame();
109
110 private slots:
111
112 void init();
113
114 void togglePause();
115
116 private:
117 void addTrackSearchPaths();
118
119 void adjustSceneSize(int hRes, int vRes);
120 void createRenderer();
121
122 void initScene();
123 bool loadTracks();
124
125 void parseArgs(int argc, char ** argv);
126
127 void start();
128 void stop();
129
130 Application m_app;
131
132 QTranslator m_appTranslator;
133
134 std::unique_ptr<Database> m_database;
135
136 bool m_forceNoVSync;
137
138 Settings m_settings;
139
140 DifficultyProfile m_difficultyProfile;
141
142 InputHandler * m_inputHandler;
143 EventHandler * m_eventHandler;
144
145 StateMachine * m_stateMachine;
146
147 Renderer * m_renderer;
148 Scene * m_scene;
149
150 TrackLoader * m_trackLoader;
151
152 QScreen * m_screen = nullptr;
153
154 int m_screenIndex = 0;
155
156 int m_updateFps;
157 int m_updateDelay;
158
159 float m_timeStep;
160
161 int m_lapCount;
162
163 bool m_paused;
164
165 QTimer m_updateTimer;
166 int m_renderElapsed;
167
168 Fps m_fps;
169
170 Mode m_mode;
171
172 SplitType m_splitType;
173
174 AudioWorker * m_audioWorker;
175 QThread * m_audioThread;
176
177 MCWorld * m_world;
178
179 QElapsedTimer m_elapsedTimer;
180 qint64 m_lastUpdateTime = 0;
181 qint64 m_lastDeltaMs = 0;
182
183 static Game * m_instance;
184 };
185
186 #endif // GAME_HPP