| 1 | // MR_GameApp.h |
|---|
| 2 | // |
|---|
| 3 | // |
|---|
| 4 | // Copyright (c) 1995-1998 - Richard Langlois and Grokksoft Inc. |
|---|
| 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 | #ifndef GAME_APP_H |
|---|
| 23 | #define GAME_APP_H |
|---|
| 24 | |
|---|
| 25 | #include "Controller.h" |
|---|
| 26 | #include "Observer.h" |
|---|
| 27 | #include "ClientSession.h" |
|---|
| 28 | |
|---|
| 29 | class MR_GameApp; |
|---|
| 30 | class HighObserver; |
|---|
| 31 | namespace HoverRace { |
|---|
| 32 | class HighConsole; |
|---|
| 33 | namespace Client { |
|---|
| 34 | class FullscreenTest; |
|---|
| 35 | class IntroMovie; |
|---|
| 36 | class Rulebook; |
|---|
| 37 | typedef boost::shared_ptr<Rulebook> RulebookPtr; |
|---|
| 38 | } |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | class MR_GameThread |
|---|
| 42 | { |
|---|
| 43 | private: |
|---|
| 44 | MR_GameApp *mGameApp; |
|---|
| 45 | CRITICAL_SECTION mMutex; |
|---|
| 46 | HANDLE mThread; |
|---|
| 47 | BOOL mTerminate; |
|---|
| 48 | int mPauseLevel; |
|---|
| 49 | |
|---|
| 50 | static unsigned long __stdcall Loop(LPVOID pThread); |
|---|
| 51 | |
|---|
| 52 | MR_GameThread(MR_GameApp * pApp); |
|---|
| 53 | ~MR_GameThread(); |
|---|
| 54 | |
|---|
| 55 | public: |
|---|
| 56 | static MR_GameThread *New(MR_GameApp * pApp); |
|---|
| 57 | void Kill(); |
|---|
| 58 | void Pause(); |
|---|
| 59 | void Restart(); |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | class MR_GameApp |
|---|
| 63 | { |
|---|
| 64 | friend MR_GameThread; |
|---|
| 65 | |
|---|
| 66 | private: |
|---|
| 67 | enum eViewMode { e3DView, eDebugView }; |
|---|
| 68 | |
|---|
| 69 | static MR_GameApp *This; // unique instance pointer |
|---|
| 70 | |
|---|
| 71 | HINSTANCE mInstance; |
|---|
| 72 | HWND mMainWindow; |
|---|
| 73 | HWND mBadVideoModeDlg; |
|---|
| 74 | HACCEL mAccelerators; |
|---|
| 75 | MR_VideoBuffer *mVideoBuffer; |
|---|
| 76 | MR_Observer *mObserver1; |
|---|
| 77 | MR_Observer *mObserver2; |
|---|
| 78 | MR_Observer *mObserver3; |
|---|
| 79 | MR_Observer *mObserver4; |
|---|
| 80 | HighObserver *highObserver; |
|---|
| 81 | HoverRace::HighConsole *highConsole; |
|---|
| 82 | HoverRace::Client::IntroMovie *introMovie; |
|---|
| 83 | HoverRace::Client::FullscreenTest *fullscreenTest; |
|---|
| 84 | MR_ClientSession *mCurrentSession; |
|---|
| 85 | MR_GameThread *mGameThread; |
|---|
| 86 | |
|---|
| 87 | eViewMode mCurrentMode; |
|---|
| 88 | |
|---|
| 89 | int mClrScrTodo; |
|---|
| 90 | |
|---|
| 91 | BOOL mPaletteChangeAllowed; |
|---|
| 92 | |
|---|
| 93 | BOOL mServerHasChanged; |
|---|
| 94 | |
|---|
| 95 | // Debug data |
|---|
| 96 | time_t mNbFramesStartingTime; |
|---|
| 97 | int mNbFrames; |
|---|
| 98 | |
|---|
| 99 | // we only want to check for updates once an instance so we have to keep track |
|---|
| 100 | bool mustCheckUpdates; |
|---|
| 101 | |
|---|
| 102 | static LRESULT CALLBACK DispatchFunc(HWND pWindow, UINT pMsgId, WPARAM pWParam, LPARAM pLParam); |
|---|
| 103 | static BOOL CALLBACK BadModeDialogFunc(HWND pWindow, UINT pMsgId, WPARAM pWParam, LPARAM pLParam); |
|---|
| 104 | |
|---|
| 105 | BOOL CreateMainWindow(); |
|---|
| 106 | bool CreateMainMenu(); |
|---|
| 107 | |
|---|
| 108 | void RefreshView(); |
|---|
| 109 | bool SetVideoMode(int pX, int pY, const std::string *monitor=NULL, |
|---|
| 110 | bool testing=false); |
|---|
| 111 | void RefreshTitleBar(); |
|---|
| 112 | |
|---|
| 113 | void OnChar(char c); |
|---|
| 114 | int ReadAsyncInputControllerPlayer(int playerIdx); |
|---|
| 115 | void ReadAsyncInputController(); // Get the state of the input controler (KDB, joystick, mouse) |
|---|
| 116 | |
|---|
| 117 | // Message handlers |
|---|
| 118 | void NewLocalSession(HoverRace::Client::RulebookPtr rules=HoverRace::Client::RulebookPtr()); |
|---|
| 119 | void NewSplitSession(int pSplitPlayers); |
|---|
| 120 | void NewNetworkSession(BOOL pIsServer); |
|---|
| 121 | void NewInternetSession(); |
|---|
| 122 | |
|---|
| 123 | void LoadRegistry(); |
|---|
| 124 | |
|---|
| 125 | void Clean(); |
|---|
| 126 | |
|---|
| 127 | void OnDisplayChange(); |
|---|
| 128 | public: |
|---|
| 129 | void AssignPalette(); |
|---|
| 130 | |
|---|
| 131 | private: |
|---|
| 132 | void PauseGameThread(); |
|---|
| 133 | void RestartGameThread(); |
|---|
| 134 | |
|---|
| 135 | void DeleteMovieWnd(); |
|---|
| 136 | |
|---|
| 137 | void DrawBackground(); |
|---|
| 138 | |
|---|
| 139 | void UpdateMenuItems(); |
|---|
| 140 | |
|---|
| 141 | void DisplayHelp(); |
|---|
| 142 | void DisplaySite(); |
|---|
| 143 | void DisplayAbout(); |
|---|
| 144 | void DisplayPrefs(); |
|---|
| 145 | |
|---|
| 146 | BOOL IsGameRunning(); // return TRUE if a not terminated game is running |
|---|
| 147 | int AskUserToAbortGame(); // Return IDOK if OK |
|---|
| 148 | |
|---|
| 149 | HoverRace::Client::Control::Controller *controller; |
|---|
| 150 | |
|---|
| 151 | public: |
|---|
| 152 | MR_GameApp(HINSTANCE pInstance, bool safeMode); |
|---|
| 153 | ~MR_GameApp(); |
|---|
| 154 | |
|---|
| 155 | BOOL IsFirstInstance() const; |
|---|
| 156 | |
|---|
| 157 | BOOL InitApplication(); |
|---|
| 158 | BOOL InitGame(); |
|---|
| 159 | |
|---|
| 160 | int MainLoop(); |
|---|
| 161 | |
|---|
| 162 | /// Signal that the selected IMR server has (possibly) changed. |
|---|
| 163 | void SignalServerHasChanged() { mServerHasChanged = TRUE; } |
|---|
| 164 | void ChangeAutoUpdates(bool newSetting) { mustCheckUpdates = newSetting; } |
|---|
| 165 | |
|---|
| 166 | MR_VideoBuffer *GetVideoBuffer() const { return mVideoBuffer; } |
|---|
| 167 | |
|---|
| 168 | HoverRace::Client::Control::Controller *GetController() const { return controller; } |
|---|
| 169 | HoverRace::Client::Control::Controller *ReloadController(); |
|---|
| 170 | |
|---|
| 171 | HWND GetWindowHandle() const { return mMainWindow; } |
|---|
| 172 | |
|---|
| 173 | // Helper stuff |
|---|
| 174 | static void NewInternetSessionCall(); |
|---|
| 175 | }; |
|---|
| 176 | |
|---|
| 177 | #undef MR_DllDeclare |
|---|
| 178 | #endif |
|---|