Session_local.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __SESSIONLOCAL_H__
  21. #define __SESSIONLOCAL_H__
  22. /*
  23. IsConnectedToServer();
  24. IsGameLoaded();
  25. IsGuiActive();
  26. IsPlayingRenderDemo();
  27. if connected to a server
  28. if handshaking
  29. if map loading
  30. if in game
  31. else if a game loaded
  32. if in load game menu
  33. if main menu up
  34. else if playing render demo
  35. else
  36. if error dialog
  37. full console
  38. */
  39. typedef struct {
  40. usercmd_t cmd;
  41. int consistencyHash;
  42. } logCmd_t;
  43. struct fileTIME_T {
  44. int index;
  45. ID_TIME_T timeStamp;
  46. operator int() const { return timeStamp; }
  47. };
  48. typedef struct {
  49. idDict serverInfo;
  50. idDict syncedCVars;
  51. idDict userInfo[MAX_ASYNC_CLIENTS];
  52. idDict persistentPlayerInfo[MAX_ASYNC_CLIENTS];
  53. usercmd_t mapSpawnUsercmd[MAX_ASYNC_CLIENTS]; // needed for tracking delta angles
  54. } mapSpawnData_t;
  55. typedef enum {
  56. TD_NO,
  57. TD_YES,
  58. TD_YES_THEN_QUIT
  59. } timeDemo_t;
  60. const int USERCMD_PER_DEMO_FRAME = 2;
  61. const int CONNECT_TRANSMIT_TIME = 1000;
  62. const int MAX_LOGGED_USERCMDS = 60*60*60; // one hour of single player, 15 minutes of four player
  63. class idSessionLocal : public idSession {
  64. public:
  65. idSessionLocal();
  66. virtual ~idSessionLocal();
  67. virtual void Init();
  68. virtual void Shutdown();
  69. virtual void Stop();
  70. virtual void UpdateScreen( bool outOfSequence = true );
  71. virtual void PacifierUpdate();
  72. virtual void Frame();
  73. virtual bool IsMultiplayer();
  74. virtual bool ProcessEvent( const sysEvent_t *event );
  75. virtual void StartMenu( bool playIntro = false );
  76. virtual void ExitMenu();
  77. virtual void GuiFrameEvents();
  78. virtual void SetGUI( idUserInterface *gui, HandleGuiCommand_t handle );
  79. virtual const char *MessageBox( msgBoxType_t type, const char *message, const char *title = NULL, bool wait = false, const char *fire_yes = NULL, const char *fire_no = NULL, bool network = false );
  80. virtual void StopBox( void );
  81. virtual void DownloadProgressBox( backgroundDownload_t *bgl, const char *title, int progress_start = 0, int progress_end = 100 );
  82. virtual void SetPlayingSoundWorld();
  83. virtual void TimeHitch( int msec );
  84. virtual void ReadCDKey( void );
  85. virtual void WriteCDKey( void );
  86. virtual const char *GetCDKey( bool xp );
  87. virtual bool CheckKey( const char *key, bool netConnect, bool offline_valid[ 2 ] );
  88. virtual bool CDKeysAreValid( bool strict );
  89. virtual void ClearCDKey( bool valid[ 2 ] );
  90. virtual void SetCDKeyGuiVars( void );
  91. virtual bool WaitingForGameAuth( void );
  92. virtual void CDKeysAuthReply( bool valid, const char *auth_msg );
  93. virtual int GetSaveGameVersion( void );
  94. virtual const char *GetCurrentMapName();
  95. //=====================================
  96. int GetLocalClientNum();
  97. void MoveToNewMap( const char *mapName );
  98. // loads a map and starts a new game on it
  99. void StartNewGame( const char *mapName, bool devmap = false );
  100. void PlayIntroGui();
  101. void LoadSession( const char *name );
  102. void SaveSession( const char *name );
  103. // called by Draw when the scene to scene wipe is still running
  104. void DrawWipeModel();
  105. void StartWipe( const char *materialName, bool hold = false);
  106. void CompleteWipe();
  107. void ClearWipe();
  108. void ShowLoadingGui();
  109. void ScrubSaveGameFileName( idStr &saveFileName ) const;
  110. idStr GetAutoSaveName( const char *mapName ) const;
  111. bool LoadGame(const char *saveName);
  112. bool SaveGame(const char *saveName, bool autosave = false);
  113. const char *GetAuthMsg( void );
  114. //=====================================
  115. static idCVar com_showAngles;
  116. static idCVar com_showTics;
  117. static idCVar com_minTics;
  118. static idCVar com_fixedTic;
  119. static idCVar com_showDemo;
  120. static idCVar com_skipGameDraw;
  121. static idCVar com_aviDemoWidth;
  122. static idCVar com_aviDemoHeight;
  123. static idCVar com_aviDemoSamples;
  124. static idCVar com_aviDemoTics;
  125. static idCVar com_wipeSeconds;
  126. static idCVar com_guid;
  127. static idCVar gui_configServerRate;
  128. int timeHitch;
  129. bool menuActive;
  130. idSoundWorld * menuSoundWorld; // so the game soundWorld can be muted
  131. bool insideExecuteMapChange; // draw loading screen and update
  132. // screen on prints
  133. int bytesNeededForMapLoad; //
  134. // we don't want to redraw the loading screen for every single
  135. // console print that happens
  136. int lastPacifierTime;
  137. // this is the information required to be set before ExecuteMapChange() is called,
  138. // which can be saved off at any time with the following commands so it can all be played back
  139. mapSpawnData_t mapSpawnData;
  140. idStr currentMapName; // for checking reload on same level
  141. bool mapSpawned; // cleared on Stop()
  142. int numClients; // from serverInfo
  143. int logIndex;
  144. logCmd_t loggedUsercmds[MAX_LOGGED_USERCMDS];
  145. int statIndex;
  146. logStats_t loggedStats[MAX_LOGGED_STATS];
  147. int lastSaveIndex;
  148. // each game tic, numClients usercmds will be added, until full
  149. bool insideUpdateScreen; // true while inside ::UpdateScreen()
  150. bool loadingSaveGame; // currently loading map from a SaveGame
  151. idFile * savegameFile; // this is the savegame file to load from
  152. int savegameVersion;
  153. idFile * cmdDemoFile; // if non-zero, we are reading commands from a file
  154. int latchedTicNumber; // set to com_ticNumber each frame
  155. int lastGameTic; // while latchedTicNumber > lastGameTic, run game frames
  156. int lastDemoTic;
  157. bool syncNextGameFrame;
  158. bool aviCaptureMode; // if true, screenshots will be taken and sound captured
  159. idStr aviDemoShortName; //
  160. float aviDemoFrameCount;
  161. int aviTicStart;
  162. timeDemo_t timeDemo;
  163. int timeDemoStartTime;
  164. int numDemoFrames; // for timeDemo and demoShot
  165. int demoTimeOffset;
  166. renderView_t currentDemoRenderView;
  167. // the next one will be read when
  168. // com_frameTime + demoTimeOffset > currentDemoRenderView.
  169. // TODO: make this private (after sync networking removal and idnet tweaks)
  170. idUserInterface * guiActive;
  171. HandleGuiCommand_t guiHandle;
  172. idUserInterface * guiInGame;
  173. idUserInterface * guiMainMenu;
  174. idListGUI * guiMainMenu_MapList; // easy map list handling
  175. idUserInterface * guiRestartMenu;
  176. idUserInterface * guiLoading;
  177. idUserInterface * guiIntro;
  178. idUserInterface * guiGameOver;
  179. idUserInterface * guiTest;
  180. idUserInterface * guiTakeNotes;
  181. //bc
  182. idListGUI * guiMainMenu_spMapList; // easy map list handling
  183. idStrList spMapList;
  184. idUserInterface * guiMsg;
  185. idUserInterface * guiMsgRestore; // store the calling GUI for restore
  186. idStr msgFireBack[ 2 ];
  187. bool msgRunning;
  188. int msgRetIndex;
  189. bool msgIgnoreButtons;
  190. bool waitingOnBind;
  191. const idMaterial * whiteMaterial;
  192. const idMaterial * wipeMaterial;
  193. int wipeStartTic;
  194. int wipeStopTic;
  195. bool wipeHold;
  196. #if ID_CONSOLE_LOCK
  197. int emptyDrawCount; // watchdog to force the main menu to restart
  198. #endif
  199. //=====================================
  200. void Clear();
  201. void DrawCmdGraph();
  202. void Draw();
  203. void WriteCmdDemo( const char *name, bool save = false);
  204. void StartPlayingCmdDemo( const char *demoName);
  205. void TimeCmdDemo( const char *demoName);
  206. void SaveCmdDemoToFile(idFile *file);
  207. void LoadCmdDemoFromFile(idFile *file);
  208. void StartRecordingRenderDemo( const char *name );
  209. void StopRecordingRenderDemo();
  210. void StartPlayingRenderDemo( idStr name );
  211. void StopPlayingRenderDemo();
  212. void CompressDemoFile( const char *scheme, const char *name );
  213. void TimeRenderDemo( const char *name, bool twice = false );
  214. void AVIRenderDemo( const char *name );
  215. void AVICmdDemo( const char *name );
  216. void AVIGame( const char *name );
  217. void BeginAVICapture( const char *name );
  218. void EndAVICapture();
  219. void AdvanceRenderDemo( bool singleFrameOnly );
  220. void RunGameTic();
  221. void FinishCmdLoad();
  222. void LoadLoadingGui(const char *mapName);
  223. void DemoShot( const char *name );
  224. void TestGUI( const char *name );
  225. int GetBytesNeededForMapLoad( const char *mapName );
  226. void SetBytesNeededForMapLoad( const char *mapName, int bytesNeeded );
  227. void ExecuteMapChange( bool noFadeWipe = false );
  228. void UnloadMap();
  229. // return true if we actually waiting on an auth reply
  230. bool MaybeWaitOnCDKey( void );
  231. //------------------
  232. // Session_menu.cpp
  233. idStrList loadGameList;
  234. idStrList modsList;
  235. idUserInterface * GetActiveMenu();
  236. void DispatchCommand( idUserInterface *gui, const char *menuCommand, bool doIngame = true );
  237. void MenuEvent( const sysEvent_t *event );
  238. bool HandleSaveGameMenuCommand( idCmdArgs &args, int &icmd );
  239. void HandleInGameCommands( const char *menuCommand );
  240. void HandleMainMenuCommands( const char *menuCommand );
  241. void HandleChatMenuCommands( const char *menuCommand );
  242. void HandleIntroMenuCommands( const char *menuCommand );
  243. void HandleRestartMenuCommands( const char *menuCommand );
  244. void HandleMsgCommands( const char *menuCommand );
  245. void HandleNoteCommands( const char *menuCommand );
  246. void GetSaveGameList( idStrList &fileList, idList<fileTIME_T> &fileTimes );
  247. void TakeNotes( const char * p, bool extended = false );
  248. void UpdateMPLevelShot( void );
  249. void SetSaveGameGuiVars( void );
  250. void SetMainMenuGuiVars( void );
  251. void SetModsMenuGuiVars( void );
  252. void SetMainMenuSkin( void );
  253. void SetPbMenuGuiVars( void );
  254. private:
  255. bool BoxDialogSanityCheck( void );
  256. void EmitGameAuth( void );
  257. typedef enum {
  258. CDKEY_UNKNOWN, // need to perform checks on the key
  259. CDKEY_INVALID, // that key is wrong
  260. CDKEY_OK, // valid
  261. CDKEY_CHECKING, // sent a check request ( gameAuth only )
  262. CDKEY_NA // does not apply, xp key when xp is not present
  263. } cdKeyState_t;
  264. static const int CDKEY_BUF_LEN = 17;
  265. static const int CDKEY_AUTH_TIMEOUT = 5000;
  266. char cdkey[ CDKEY_BUF_LEN ];
  267. cdKeyState_t cdkey_state;
  268. char xpkey[ CDKEY_BUF_LEN ];
  269. cdKeyState_t xpkey_state;
  270. int authEmitTimeout;
  271. bool authWaitBox;
  272. idStr authMsg;
  273. };
  274. extern idSessionLocal sessLocal;
  275. #endif /* !__SESSIONLOCAL_H__ */