Debian Codegraph @

src/game/scene.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2011 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 SCENE_HPP
17 #define SCENE_HPP
18
19 #include "ai.hpp"
20 #include "car.hpp"
21 #include "crashoverlay.hpp"
22 #include "minimap.hpp"
23 #include "timingoverlay.hpp"
24
25 #include <MCCamera>
26 #include <QObject>
27 #include <memory>
28 #include <vector>
29
30 #include <MenuManager>
31
32 class CheckeredFlag;
33 class FadeAnimation;
34 class Game;
35 class InputHandler;
36 class Intro;
37 class MCCamera;
38 class MCObject;
39 class MCSurface;
40 class MCWorld;
41 class MessageOverlay;
42 class ParticleFactory;
43 class Race;
44 class Renderer;
45 class Startlights;
46 class StartlightsOverlay;
47 class StateMachine;
48 class Track;
49 class TrackSelectionMenu;
50
51 namespace MTFH {
52 class Menu;
53 }
54
55 //! The game scene.
56 class Scene : public QObject
57 {
58 Q_OBJECT
59
60 public:
61 Scene(Game & game, StateMachine & stateMachine, Renderer & renderer, MCWorld & world);
62 ~Scene() override;
63
64 static int width();
65 static int height();
66
67 static void setSize(int width, int height);
68
69 static size_t carCount();
70
71 //! Update physics and objects by the given time step in ms.
72 void updateFrame(InputHandler & handler, std::chrono::milliseconds timeStep);
73 void updateOverlays();
74
75 void setActiveTrack(std::shared_ptr<Track> activeTrack);
76 std::shared_ptr<Track> activeTrack() const;
77
78 //! Return track selection menu.
79 MTFH::MenuPtr trackSelectionMenu() const;
80
81 void renderCommonHUD();
82 void renderHUD();
83 void renderMenu();
84 void renderTrack();
85 void renderWorld(MCRenderGroup renderGroup, bool prepareRendering = false);
86
87 signals:
88
89 void listenerLocationChanged(float x, float y);
90
91 private:
92 void addCarsToWorld();
93 void addTrackObjectsToWorld();
94
95 void connectComponents();
96
97 void createBridgeObjects();
98 void createCars();
99 void createMenus();
100 void createNormalObjects();
101
102 void initializeComponents();
103 void initializeRace();
104
105 void processUserInput(InputHandler & handler);
106
107 void renderPlayerScene(MCCamera & camera);
108 void renderPlayerSceneShadows(MCCamera & camera);
109
110 void resizeOverlays();
111
112 void setupAudio(Car & car, size_t index);
113 void setupAI(std::shared_ptr<Track> activeTrack);
114 void setupCameras(Track & activeTrack);
115 void setupMinimaps();
116
117 void getSplitPositions(MCGLScene::SplitType & p0, MCGLScene::SplitType & p1);
118
119 void setWorldDimensions();
120
121 void updateAi();
122 void updateCameraLocation(MCCamera & camera, float & offset, MCObject & object);
123 void updateRace(std::chrono::milliseconds timeStep);
124 void updateWorld(std::chrono::milliseconds timeStep);
125
126 static int m_width;
127 static int m_height;
128
129 Game & m_game;
130
131 StateMachine & m_stateMachine;
132
133 Renderer & m_renderer;
134
135 std::unique_ptr<MessageOverlay> m_messageOverlay;
136
137 std::shared_ptr<Race> m_race;
138 std::shared_ptr<Track> m_activeTrack;
139
140 MCWorld & m_world;
141
142 std::array<CrashOverlay, 2> m_crashOverlay;
143 std::array<TimingOverlay, 2> m_timingOverlay;
144 std::unique_ptr<Startlights> m_startlights;
145 std::unique_ptr<StartlightsOverlay> m_startlightsOverlay;
146 std::unique_ptr<CheckeredFlag> m_checkeredFlag;
147
148 std::array<MCCamera, 2> m_camera;
149 std::array<float, 2> m_cameraOffset;
150
151 MTFH::MenuPtr m_mainMenu;
152 std::unique_ptr<MTFH::MenuManager> m_menuManager;
153 std::unique_ptr<Intro> m_intro;
154 std::unique_ptr<ParticleFactory> m_particleFactory;
155 std::unique_ptr<FadeAnimation> m_fadeAnimation;
156
157 std::array<Minimap, 2> m_minimap;
158
159 using CarVector = std::vector<CarS>;
160 CarVector m_cars;
161
162 using AIVector = std::vector<AIPtr>;
163 AIVector m_ai;
164
165 std::vector<MCObjectPtr> m_bridges;
166 };
167
168 #endif // SCENE_HPP