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