-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSession_local.h
382 lines (289 loc) · 11.3 KB
/
Session_local.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*****************************************************************************
The Dark Mod GPL Source Code
This file is part of the The Dark Mod Source Code, originally based
on the Doom 3 GPL Source Code as published in 2011.
The Dark Mod Source Code is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version. For details, see LICENSE.TXT.
Project: The Dark Mod (http://www.thedarkmod.com/)
******************************************************************************/
#ifndef __SESSIONLOCAL_H__
#define __SESSIONLOCAL_H__
#include <thread>
#include <condition_variable>
#include <memory>
/*
IsConnectedToServer();
IsGameLoaded();
IsGuiActive();
IsPlayingRenderDemo();
if connected to a server
if handshaking
if map loading
if in game
else if a game loaded
if in load game menu
if main menu up
else if playing render demo
else
if error dialog
full console
*/
typedef struct {
usercmd_t cmd;
int consistencyHash;
} logCmd_t;
struct fileTIME_T {
int index;
ID_TIME_T timeStamp;
operator int() const { return timeStamp; }
};
#define MAX_ASYNC_CLIENTS 1
typedef struct {
idDict serverInfo;
idDict syncedCVars;
idDict userInfo[MAX_ASYNC_CLIENTS];
idDict persistentPlayerInfo[MAX_ASYNC_CLIENTS];
usercmd_t mapSpawnUsercmd[MAX_ASYNC_CLIENTS]; // needed for tracking delta angles
} mapSpawnData_t;
typedef enum {
TD_NO,
TD_YES,
TD_YES_THEN_QUIT
} timeDemo_t;
typedef enum {
MMSS_MAINMENU,
MMSS_SUCCESS,
MMSS_FAILURE,
MMSS_BRIEFING,
} mainMenuStartState_t;
const int USERCMD_PER_DEMO_FRAME = 2;
const int CONNECT_TRANSMIT_TIME = 1000;
const int MAX_LOGGED_USERCMDS = 60*60*60; // one hour of single player, 15 minutes of four player
class idSessionLocal : public idSession {
public:
idSessionLocal();
virtual ~idSessionLocal();
virtual void Init();
virtual void Shutdown();
virtual void Stop();
virtual void TerminateFrontendThread();
virtual void UpdateScreen( bool outOfSequence = true );
virtual void PacifierUpdate(loadkey_t key, int count); // grayman #3763
virtual void Frame();
virtual bool ProcessEvent( const sysEvent_t *event );
virtual void StartMenu( bool playIntro = false );
virtual void ExitMenu();
virtual void GuiFrameEvents();
virtual void SetGUI( idUserInterface *gui, HandleGuiCommand_t handle );
virtual idUserInterface* GetGui(GuiType type) const;
virtual bool RunGuiScript(const char *windowName, int scriptNum);
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 );
virtual void StopBox( void );
virtual void DownloadProgressBox( backgroundDownload_t *bgl, const char *title, int progress_start = 0, int progress_end = 100 );
virtual void SetPlayingSoundWorld();
virtual void TimeHitch( int msec );
virtual int GetSaveGameVersion( void );
virtual void RunGameTic(int timestepMs);
virtual void ActivateFrontend();
virtual void WaitForFrontendCompletion();
virtual void StartFrontendThread();
virtual void ExecuteFrameCommand(const char *command, bool delayed);
virtual void ExecuteDelayedFrameCommands();
virtual const char *GetCurrentMapName();
//=====================================
int GetLocalClientNum();
void MoveToNewMap( const char *mapName );
// loads a map and starts a new game on it
void StartNewGame( const char *mapName, bool devmap = false );
void PlayIntroGui();
void LoadSession( const char *name );
void SaveSession( const char *name );
// called by Draw when the scene to scene wipe is still running
void DrawWipeModel();
void StartWipe( const char *materialName, bool hold = false);
void CompleteWipe();
void ClearWipe();
void ShowLoadingGui();
void ScrubSaveGameFileName( idStr &saveFileName ) const;
idStr GetAutoSaveName( const char *mapName ) const;
enum eSaveConflictHandling
{
eSaveConflictHandling_QueryUser,
eSaveConflictHandling_Ignore,
eSaveConflictHandling_LoadMapStart,
};
bool LoadGame(const char *saveName, eSaveConflictHandling conflictHandling = eSaveConflictHandling_QueryUser);
private: // Helper methods for LoadGame
bool ParseSavegamePreamble(const char * saveName, idFile** savegameFile, idStr* saveMap);
enum SavegameValidity
{
savegame_valid,
savegame_invalid,
savegame_versionMismatch,
};
SavegameValidity IsSavegameValid(const char *saveName, int* savegameRevision = NULL);
bool DoLoadGame(const char *saveName, const bool initialializedLoad);
public:
bool SaveGame(const char *saveName, bool autosave = false, bool skipCheck = false);
//=====================================
static idCVar com_showAngles;
static idCVar com_showTics;
static idCVar com_minTics;
static idCVar com_fixedTic;
static idCVar com_maxFPS;
static idCVar com_maxTicTimestep;
static idCVar com_maxTicsPerFrame;
static idCVar com_showDemo;
static idCVar com_skipGameDraw;
static idCVar com_aviDemoWidth;
static idCVar com_aviDemoHeight;
static idCVar com_aviDemoSamples;
static idCVar com_aviDemoTics;
static idCVar com_wipeSeconds;
static idCVar com_guid;
static idCVar gui_configServerRate;
//Obsttorte: cvar for disabling manual saves
static idCVar saveGameName;
// SteveL #4161: Support > 1 quicksave
static idCVar com_numQuickSaves;
int timeHitch;
bool menuActive;
idSoundWorld * menuSoundWorld; // so the game soundWorld can be muted
bool insideExecuteMapChange; // draw loading screen and update
// screen on prints
//int bytesNeededForMapLoad; // grayman #3763 - no longer used
float pct; // grayman #3763 - used by PacifierUpdate()
float pct_delta; // grayman #3763 - used by PacifierUpdate()
// we don't want to redraw the loading screen for every single
// console print that happens
int lastPacifierTime;
// this is the information required to be set before ExecuteMapChange() is called,
// which can be saved off at any time with the following commands so it can all be played back
mapSpawnData_t mapSpawnData;
idStr currentMapName; // for checking reload on same level
bool mapSpawned; // cleared on Stop()
mainMenuStartState_t mainMenuStartState; // stgatilov: which state of main menu to start with when it activates?
int numClients; // from serverInfo
int logIndex;
logCmd_t loggedUsercmds[MAX_LOGGED_USERCMDS];
int statIndex;
logStats_t loggedStats[MAX_LOGGED_STATS];
int lastSaveIndex;
// each game tic, numClients usercmds will be added, until full
bool insideUpdateScreen; // true while inside ::UpdateScreen()
idStr lastSaveName;
int savegameVersion;
idFile * cmdDemoFile; // if non-zero, we are reading commands from a file
int latchedTicNumber; // set to com_ticNumber each frame
int lastGameTic; // while latchedTicNumber > lastGameTic, run game frames
int lastDemoTic;
bool syncNextGameFrame;
bool aviCaptureMode; // if true, screenshots will be taken and sound captured
idStr aviDemoShortName; //
float aviDemoFrameCount;
int aviTicStart;
timeDemo_t timeDemo;
int timeDemoStartTime;
int numDemoFrames; // for timeDemo and demoShot
int demoTimeOffset;
renderView_t currentDemoRenderView;
// the next one will be read when
// com_frameTime + demoTimeOffset > currentDemoRenderView.
// TODO: make this private (after sync networking removal and idnet tweaks)
idUserInterface * guiActive;
HandleGuiCommand_t guiHandle;
idUserInterface * guiInGame;
idUserInterface * guiMainMenu;
idListGUI * guiMainMenu_MapList; // easy map list handling
idUserInterface * guiLoading;
idUserInterface * guiTest;
idUserInterface * guiMsg;
idUserInterface * guiMsgRestore; // store the calling GUI for restore
idStr msgFireBack[ 2 ];
bool msgRunning;
int msgRetIndex;
bool msgIgnoreButtons;
bool waitingOnBind;
const idMaterial * whiteMaterial;
const idMaterial * wipeMaterial;
int wipeStartTic;
int wipeStopTic;
bool wipeHold;
#if ID_CONSOLE_LOCK
int emptyDrawCount; // watchdog to force the main menu to restart
#endif
int gameTicsToRun; // how many game ticks to run this frame
int gameTimestepTotal; // total timestep for all game tics to be run this frame (in milliseconds)
uintptr_t frontendThread;
std::condition_variable signalFrontendThread;
std::condition_variable signalMainThread;
std::mutex signalMutex;
volatile bool frontendActive;
volatile bool shutdownFrontend;
std::shared_ptr<ErrorReportedException> frontendException;
void FrontendThreadFunction();
bool IsFrontend() const;
//=====================================
void Clear();
void DrawCmdGraph();
void Draw();
void WriteCmdDemo( const char *name, bool save = false);
void StartPlayingCmdDemo( const char *demoName);
void TimeCmdDemo( const char *demoName);
void SaveCmdDemoToFile(idFile *file);
void LoadCmdDemoFromFile(idFile *file);
void StartRecordingRenderDemo( const char *name );
void StopRecordingRenderDemo();
void StartPlayingRenderDemo( idStr name );
void StopPlayingRenderDemo();
void CompressDemoFile( const char *scheme, const char *name );
void TimeRenderDemo( const char *name, bool twice = false );
void AVIRenderDemo( const char *name );
void AVICmdDemo( const char *name );
void AVIGame( const char *name );
void BeginAVICapture( const char *name );
void EndAVICapture();
void AdvanceRenderDemo( bool singleFrameOnly );
void RunGameTics();
void DrawFrame();
void FinishCmdLoad();
void LoadLoadingGui(const char *mapName);
void DemoShot( const char *name );
void TestGUI( const char *name );
// int GetBytesNeededForMapLoad( const char *mapName ); // #3763 debug - no longer used
void SetBytesNeededForMapLoad( const char *mapName, int bytesNeeded );
bool ExecuteMapChange( idFile* savegameFile = NULL, bool noFadeWipe = false );
void UnloadMap();
//------------------
// Session_menu.cpp
idStrList loadGameList;
idStrList modsList;
idUserInterface * GetActiveMenu();
void DispatchCommand( idUserInterface *gui, const char *menuCommand, bool doIngame = true );
void MenuEvent( const sysEvent_t *event );
bool HandleSaveGameMenuCommand( idCmdArgs &args, int &icmd );
void HandleInGameCommands( const char *menuCommand );
void HandleMainMenuCommands( const char *menuCommand );
void HandleChatMenuCommands( const char *menuCommand );
void HandleRestartMenuCommands( const char *menuCommand );
void HandleMsgCommands( const char *menuCommand );
void GetSaveGameList( idStrList &fileList, idList<fileTIME_T> &fileTimes );
void UpdateMPLevelShot( void );
void ResetMainMenu() override;
void CreateMainMenu();
void SetMainMenuStartAtBriefing() override;
void SetSaveGameGuiVars( void );
void SetMainMenuGuiVars( void );
void SetModsMenuGuiVars( void );
void SetMainMenuSkin( void );
void SetPbMenuGuiVars( void );
void ToggleMenu( void );
private:
bool BoxDialogSanityCheck( void );
idStr authMsg;
idStrList delayedFrameCommands;
};
extern idSessionLocal sessLocal;
#endif /* !__SESSIONLOCAL_H__ */