HoverRace  2.0
ClientApp.h
Go to the documentation of this file.
1 
2 // ClientApp.h
3 //
4 // Copyright (c) 2010, 2014-2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include "../../engine/Util/OS.h"
25 
26 #include "Observer.h"
27 
28 #include "GameDirector.h"
29 
30 namespace HoverRace {
31  namespace Client {
32  namespace HoverScript {
33  class ConsoleScene;
34  class DebugPeer;
35  class GamePeer;
36  class HighConsole;
37  class InputPeer;
38  class SessionPeer;
39  class SysConsole;
40  class SysEnv;
41  }
42  class Announcement;
43  class DebugScene;
44  class HighObserver;
45  class LoadingScene;
46  class Rulebook;
47  class RulebookLibrary;
48  class Scene;
49  class StatusOverlayScene;
50  }
51  namespace Control {
53  }
54  namespace Display {
55  class ActiveText;
56  class Display;
57  }
58  namespace Player {
59  class AvatarGallery;
60  }
61  namespace Script {
62  class Core;
63  }
64  namespace Util {
65  class Profiler;
66  }
67 }
68 
69 namespace HoverRace {
70 namespace Client {
71 
76 class ClientApp : public GameDirector
77 {
79 
80 public:
81  ClientApp();
82  virtual ~ClientApp();
83 
84 private:
85  void LoadInitialProfile();
86 
87 private:
88  std::string GetWindowTitle();
89  void OnWindowResize(int w, int h);
90  void IncFrameCount();
91  void AdvanceScenes(Util::OS::timestamp_t tick);
92  void PrepareScenes();
93  void RenderScenes();
94  void RenderFrame();
95 
96 public:
97  enum class ExitMode
98  {
99  QUITTING,
100  SOFT_RESTART,
101  };
102  ExitMode MainLoop();
103 
104 private:
105  void OnConsoleToggle();
106 
107 private:
108  using sceneStack_t = std::list<std::shared_ptr<Scene>>;
109  void SetForegroundScene();
110  void SetForegroundScene(const std::shared_ptr<Scene> &iter);
111  void PushScene(const std::shared_ptr<Scene> &scene);
112  void PopScene();
113  void ReplaceScene(const std::shared_ptr<Scene> &scene);
114  void TerminateAllScenes();
115 
116 public:
117  // GameDirector
118  Scene *GetForegroundScene() const override { return sceneStack.empty() ? nullptr : sceneStack.back().get(); }
119  void RequestPushScene(const std::shared_ptr<Scene> &scene) override;
120  void RequestPopScene() override;
121  void RequestReplaceScene(const std::shared_ptr<Scene> &scene) override;
122  void RequestMainMenu(
123  std::shared_ptr<LoadingScene> loadingScene =
124  std::shared_ptr<LoadingScene>()) override;
125  void RequestStatusPresentation() override;
126  void RequestNewPracticeSession(
127  std::shared_ptr<Rules> rules,
128  std::shared_ptr<LoadingScene> loadingScene =
129  std::shared_ptr<LoadingScene>()) override;
130  void RequestAnnouncement(std::shared_ptr<Announcement> ann) override;
131  void RequestShutdown() override;
132  void RequestSoftRestart() override;
133  Display::Display *GetDisplay() const override { return display.get(); }
134  VideoServices::VideoBuffer *GetVideoBuffer() const override;
135  Control::InputEventController *GetController() const override { return controller.get(); }
136  Control::InputEventController *ReloadController() override;
137  std::shared_ptr<Player::AvatarGallery> ShareAvatarGallery() const override { return avatarGallery; }
138  Roster *GetParty() const override { return party.get(); }
139  std::shared_ptr<Player::Player> ShareUiPilot() const override;
140  sessionChangedSignal_t &GetSessionChangedSignal() override { return sessionChangedSignal; }
141 
142 private:
146 
147  std::unique_ptr<Display::Display> display;
148 
149  std::unique_ptr<Control::InputEventController> controller;
150  std::shared_ptr<Player::AvatarGallery> avatarGallery;
151  std::unique_ptr<Roster> party;
152 
153  std::unique_ptr<Script::Core> scripting;
154  std::unique_ptr<RulebookLibrary> rulebookLibrary;
155  std::unique_ptr<HoverScript::DebugPeer> debugPeer;
156  std::unique_ptr<HoverScript::GamePeer> gamePeer;
157  std::unique_ptr<HoverScript::InputPeer> inputPeer;
158  std::unique_ptr<HoverScript::SysEnv> sysEnv;
159  std::unique_ptr<HoverScript::SysConsole> sysConsole;
160 
161  // Stats counters.
162  std::unique_ptr<Display::ActiveText> fpsLbl;
163  unsigned int frameCount;
165  double fps;
166  const bool &showFps;
167 
169  std::shared_ptr<Scene> fgScene;
170  std::unique_ptr<StatusOverlayScene> statusOverlayScene;
172  std::unique_ptr<DebugScene> debugScene;
173  const bool &showDebug;
174  std::list<std::shared_ptr<Announcement>> announcements;
175 
176  std::weak_ptr<HoverScript::ConsoleScene> consoleScene;
177 
179 
180  boost::signals2::connection consoleToggleConn;
181 
182  std::shared_ptr<Util::Profiler> rootProfiler;
183  std::shared_ptr<Util::Profiler> advanceProfiler;
184  std::shared_ptr<Util::Profiler> prepareProfiler;
185  std::shared_ptr<Util::Profiler> renderProfiler;
186 };
187 
188 } // namespace HoverScript
189 } // namespace Client
std::unique_ptr< DebugScene > debugScene
Definition: ClientApp.h:172
Scene * GetForegroundScene() const override
Gets foreground scene, if available.
Definition: ClientApp.h:118
std::unique_ptr< HoverScript::SysConsole > sysConsole
Definition: ClientApp.h:159
Scripting peer for system-level control of the game.
Definition: GamePeer.h:56
UI for the system console.
Definition: ConsoleScene.h:48
std::shared_ptr< Util::Profiler > prepareProfiler
Definition: ClientApp.h:184
std::unique_ptr< Control::InputEventController > controller
Definition: ClientApp.h:149
std::shared_ptr< Util::Profiler > renderProfiler
Definition: ClientApp.h:185
Interface for game client shells.
Definition: GameDirector.h:57
Scripting peer for a game session.
Definition: SessionPeer.h:55
std::unique_ptr< HoverScript::InputPeer > inputPeer
Definition: ClientApp.h:157
bool needsLocaleCheck
Check locale and warn on next menu.
Definition: ClientApp.h:144
sceneStack_t sceneStack
Definition: ClientApp.h:168
std::shared_ptr< Scene > fgScene
The scene that currently has input focus.
Definition: ClientApp.h:169
unsigned int frameCount
Definition: ClientApp.h:163
std::shared_ptr< Util::Profiler > advanceProfiler
Definition: ClientApp.h:183
Overlay for displaying debug information.
Definition: DebugScene.h:46
double fps
Definition: ClientApp.h:165
bool showOverlay
Definition: ClientApp.h:171
std::weak_ptr< HoverScript::ConsoleScene > consoleScene
Definition: ClientApp.h:176
MR_UInt32 userEventId
Definition: ClientApp.h:145
Display::Display * GetDisplay() const override
Definition: ClientApp.h:133
A list of players.
Definition: Roster.h:37
std::shared_ptr< Player::AvatarGallery > avatarGallery
Definition: ClientApp.h:150
Base class for display managers.
Definition: Display.h:73
std::list< std::shared_ptr< Scene >> sceneStack_t
Definition: ClientApp.h:108
Video framebuffer for legacy (8-bit, palettized) rendering.
Definition: VideoBuffer.h:54
const bool & showFps
Definition: ClientApp.h:166
std::shared_ptr< Player::AvatarGallery > ShareAvatarGallery() const override
Retrieve the global avatar gallery.
Definition: ClientApp.h:137
std::shared_ptr< Util::Profiler > rootProfiler
Definition: ClientApp.h:182
Simple profiler.
Definition: Profiler.h:43
std::shared_ptr< Scene > scene
Definition: ClientApp.cpp:100
Scenes are analogous to fullscreen windows that are layered on top of each other. ...
Definition: Scene.h:43
The global system environment.
Definition: SysEnv.h:47
Provides access to debugging tools.
Definition: DebugPeer.h:50
std::unique_ptr< Display::ActiveText > fpsLbl
Definition: ClientApp.h:162
The collection of all registered rulebooks.
Definition: RulebookLibrary.h:40
std::unique_ptr< HoverScript::GamePeer > gamePeer
Definition: ClientApp.h:156
Main game shell.
Definition: ClientApp.h:76
boost::signals2::signal< void(std::shared_ptr< HoverScript::MetaSession >)> sessionChangedSignal_t
Definition: GameDirector.h:165
Scripting peer for input.
Definition: InputPeer.h:45
std::unique_ptr< RulebookLibrary > rulebookLibrary
Definition: ClientApp.h:154
std::list< std::shared_ptr< Announcement > > announcements
Definition: ClientApp.h:174
Roster * GetParty() const override
Retrieve the list of players connected to this game instance.
Definition: ClientApp.h:138
std::unique_ptr< Script::Core > scripting
Definition: ClientApp.h:153
const bool & showDebug
Definition: ClientApp.h:173
Overlay for showing connected players, pop-up messages, etc.
Definition: StatusOverlayScene.h:49
std::unique_ptr< Display::Display > display
Definition: ClientApp.h:147
bool needsDevWarning
Display dev release warning on next menu.
Definition: ClientApp.h:143
Definition: Announcement.h:24
uint32_t MR_UInt32
Definition: MR_Types.h:44
sessionChangedSignal_t & GetSessionChangedSignal() override
Access the signal that indicates that the gameplay session started or stopped.
Definition: ClientApp.h:140
Base class for "Please Wait" loading scenes.
Definition: LoadingScene.h:52
Util::OS::timestamp_t lastTimestamp
Definition: ClientApp.h:164
std::unique_ptr< HoverScript::SysEnv > sysEnv
Definition: ClientApp.h:158
Defines the rules for a particular game session.
Definition: Rulebook.h:57
ExitMode
Definition: ClientApp.h:97
std::shared_ptr< Announcement > ann
Definition: ClientApp.cpp:110
std::unique_ptr< HoverScript::DebugPeer > debugPeer
Definition: ClientApp.h:155
Base class for announcements.
Definition: Announcement.h:43
std::unique_ptr< StatusOverlayScene > statusOverlayScene
Definition: ClientApp.h:170
boost::signals2::connection consoleToggleConn
Definition: ClientApp.h:180
Translates input events into actions.
Definition: Controller.h:106
std::unique_ptr< Roster > party
Definition: ClientApp.h:151
Global always-on console.
Definition: SysConsole.h:60
MR_Int64 timestamp_t
Definition: OS.h:55
Control::InputEventController * GetController() const override
Definition: ClientApp.h:135
sessionChangedSignal_t sessionChangedSignal
Definition: ClientApp.h:178
A script environment.
Definition: Core.h:66