HoverRace  2.0
GameApp.h
Go to the documentation of this file.
1 #ifdef HR_LEGACY_BUILD
2 // GameApp.h
3 //
4 //
5 // Copyright (c) 1995-1998 - Richard Langlois and Grokksoft Inc.
6 //
7 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
8 // you may not use this file except in compliance with the License.
9 //
10 // A copy of the license should have been attached to the package from which
11 // you have taken this file. If you can not find the license you can not use
12 // this file.
13 //
14 //
15 // The author makes no representations about the suitability of
16 // this software for any purpose. It is provided "as is" "AS IS",
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
18 // implied.
19 //
20 // See the License for the specific language governing permissions
21 // and limitations under the License.
22 //
23 
24 #pragma once
25 
26 #include "../../engine/Util/Config.h"
27 
28 #include "GameDirector.h"
29 #include "Observer.h"
30 #include "ClientSession.h"
31 
32 #ifndef WITH_SDL
33 
34 namespace HoverRace {
35  namespace Client {
36  namespace Control {
37  class Controller;
38  class UiHandler;
39  typedef std::shared_ptr<UiHandler> UiHandlerPtr;
40  }
41  namespace HoverScript {
42  class GamePeer;
43  class HighConsole;
44  class SessionPeer;
45  typedef std::shared_ptr<SessionPeer> SessionPeerPtr;
46  class SysEnv;
47  }
48  class FullscreenTest;
49  class GameApp;
50  class HighObserver;
51  class IntroMovie;
52  class Rulebook;
53  typedef std::shared_ptr<Rulebook> RulebookPtr;
54  }
55  namespace Script {
56  class Core;
57  }
58 }
59 
60 namespace HoverRace {
61 namespace Client {
62 
63 class GameThread
64 {
65  private:
66  GameApp *mGameApp;
67  CRITICAL_SECTION mMutex;
68  HANDLE mThread;
69  BOOL mTerminate;
70  int mPauseLevel;
71 
72  static unsigned long __stdcall Loop(LPVOID pThread);
73 
74  GameThread(GameApp * pApp);
75  ~GameThread();
76 
77  public:
78  static GameThread *New(GameApp * pApp);
79  void Kill();
80  void Pause();
81  void Restart();
82 };
83 
84 class GameApp : public GameDirector
85 {
86  typedef GameDirector SUPER;
87  friend GameThread;
88 
89  private:
90  enum eViewMode { e3DView, eDebugView };
91 
92  static GameApp *This; // unique instance pointer
93 
94  HINSTANCE mInstance;
95  HWND mMainWindow;
96  HWND mBadVideoModeDlg;
97  HACCEL mAccelerators;
98  VideoServices::VideoBuffer *mVideoBuffer;
99  static const int MAX_OBSERVERS = HoverRace::Util::Config::MAX_PLAYERS;
100  Observer *observers[MAX_OBSERVERS];
101  bool nonInteractiveShutdown;
102  HighObserver *highObserver;
103  HoverScript::HighConsole *highConsole;
104  IntroMovie *introMovie;
105  FullscreenTest *fullscreenTest;
106  Script::Core *scripting;
107  HoverScript::GamePeer *gamePeer;
108  HoverScript::SysEnv *sysEnv;
109  ClientSession *mCurrentSession;
110  HoverScript::SessionPeerPtr sessionPeer;
111  GameThread *mGameThread;
112  RulebookPtr requestedNewSession;
113  class UiInput;
114  std::shared_ptr<UiInput> uiInput;
115 
116  eViewMode mCurrentMode;
117 
118  int mClrScrTodo;
119 
120  BOOL mPaletteChangeAllowed;
121 
122  BOOL mServerHasChanged;
123 
124  // Debug data
125  time_t mNbFramesStartingTime;
126  int mNbFrames;
127 
128  // we only want to check for updates once an instance so we have to keep track
129  bool mustCheckUpdates;
130 
131  static LRESULT CALLBACK DispatchFunc(HWND pWindow, UINT pMsgId, WPARAM pWParam, LPARAM pLParam);
132  static BOOL CALLBACK BadModeDialogFunc(HWND pWindow, UINT pMsgId, WPARAM pWParam, LPARAM pLParam);
133 
134  BOOL CreateMainWindow();
135  bool CreateMainMenu();
136 
137  void RefreshView();
138  bool SetVideoMode(int pX, int pY, const std::string *monitor=NULL,
139  bool testing=false);
140  void RefreshTitleBar();
141 
142  void PollController();
143  int ReadAsyncInputControllerPlayer(int playerIdx);
144  void ReadAsyncInputController(); // Get the state of the input controler (KDB, joystick, mouse)
145 
146  // Message handlers
147  public:
148  void NewLocalSession(RulebookPtr rules=RulebookPtr());
149  void NewSplitSession(int pSplitPlayers);
150  void NewNetworkSession(BOOL pIsServer);
151  void NewInternetSession();
152 
153  virtual void RequestShutdown();
154 
155  private:
156  void LoadRegistry();
157 
158  void Clean();
159 
160  void OnDisplayChange();
161 
162  private:
163  void PauseGameThread();
164  void RestartGameThread();
165 
166  void DeleteMovieWnd();
167 
168  void DrawBackground();
169 
170  void UpdateMenuItems();
171 
172  void DisplayHelp();
173  void DisplaySite();
174  void DisplayAbout();
175  void DisplayPrefs();
176 
177  BOOL IsGameRunning(); // return TRUE if a not terminated game is running
178  int AskUserToAbortGame(); // Return IDOK if OK
179 
180  static void TrackOpenFailMessageBox(HWND parent, const std::string &name, const std::string &details);
181 
182  Control::InputEventController* controller;
183 
184  public:
185  GameApp(HINSTANCE pInstance, bool safeMode);
186  virtual ~GameApp();
187 
188  BOOL IsFirstInstance() const;
189 
190  BOOL InitApplication();
191  BOOL InitGame();
192 
193  int MainLoop();
194 
195  virtual void SignalServerHasChanged() { mServerHasChanged = TRUE; }
196  virtual void ChangeAutoUpdates(bool newSetting) { mustCheckUpdates = newSetting; }
197  virtual void AssignPalette();
198 
199  virtual VideoServices::VideoBuffer *GetVideoBuffer() const { return mVideoBuffer; }
200 
201  virtual Control::InputEventController *GetController() const { return controller; }
202  virtual Control::InputEventController *ReloadController();
203 
204  virtual HWND GetWindowHandle() const { return mMainWindow; }
205 
206  // Helper stuff
207  static void NewInternetSessionCall();
208 };
209 
210 } // namespace Client
211 } // namespace HoverRace
212 
213 #endif // ifndef WITH_SDL
214 #endif
MR_DllDeclare void Clean() noexcept
Must be called at the end of the program.
Definition: DllObjectFactory.cpp:63
Definition: Announcement.h:24
static const int MAX_PLAYERS
Definition: Config.h:289