Game_local.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition 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 BFG Edition 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 __GAME_LOCAL_H__
  21. #define __GAME_LOCAL_H__
  22. /*
  23. ===============================================================================
  24. Local implementation of the public game interface.
  25. ===============================================================================
  26. */
  27. #ifdef ID_DEBUG_UNINITIALIZED_MEMORY
  28. // This is real evil but allows the code to inspect arbitrary class variables.
  29. #define private public
  30. #define protected public
  31. #endif
  32. extern idRenderWorld * gameRenderWorld;
  33. extern idSoundWorld * gameSoundWorld;
  34. // the "gameversion" client command will print this plus compile date
  35. #define GAME_VERSION "baseDOOM-1"
  36. // classes used by idGameLocal
  37. class idEntity;
  38. class idActor;
  39. class idPlayer;
  40. class idCamera;
  41. class idWorldspawn;
  42. class idTestModel;
  43. class idAAS;
  44. class idAI;
  45. class idSmokeParticles;
  46. class idEntityFx;
  47. class idTypeInfo;
  48. class idProgram;
  49. class idThread;
  50. class idEditEntities;
  51. class idLocationEntity;
  52. class idMenuHandler_Shell;
  53. const int MAX_CLIENTS = MAX_PLAYERS;
  54. const int MAX_CLIENTS_IN_PVS = MAX_CLIENTS >> 3;
  55. const int GENTITYNUM_BITS = 12;
  56. const int MAX_GENTITIES = 1 << GENTITYNUM_BITS;
  57. const int ENTITYNUM_NONE = MAX_GENTITIES - 1;
  58. const int ENTITYNUM_WORLD = MAX_GENTITIES - 2;
  59. const int ENTITYNUM_MAX_NORMAL = MAX_GENTITIES - 2;
  60. const int ENTITYNUM_FIRST_NON_REPLICATED = ENTITYNUM_MAX_NORMAL - 256;
  61. //============================================================================
  62. void gameError( const char *fmt, ... );
  63. #include "gamesys/Event.h"
  64. #include "gamesys/Class.h"
  65. #include "gamesys/SysCvar.h"
  66. #include "gamesys/SysCmds.h"
  67. #include "gamesys/SaveGame.h"
  68. #include "script/Script_Program.h"
  69. #include "anim/Anim.h"
  70. #include "ai/AAS.h"
  71. #include "physics/Clip.h"
  72. #include "physics/Push.h"
  73. #include "Pvs.h"
  74. #include "Leaderboards.h"
  75. #include "MultiplayerGame.h"
  76. class idWeapon;
  77. //============================================================================
  78. const int MAX_GAME_MESSAGE_SIZE = 8192;
  79. const int MAX_ENTITY_STATE_SIZE = 512;
  80. const int ENTITY_PVS_SIZE = ((MAX_GENTITIES+31)>>5);
  81. const int NUM_RENDER_PORTAL_BITS = idMath::BitsForInteger( PS_BLOCK_ALL );
  82. const int MAX_EVENT_PARAM_SIZE = 128;
  83. typedef struct entityNetEvent_s {
  84. int spawnId;
  85. int event;
  86. int time;
  87. int paramsSize;
  88. byte paramsBuf[MAX_EVENT_PARAM_SIZE];
  89. struct entityNetEvent_s *next;
  90. struct entityNetEvent_s *prev;
  91. } entityNetEvent_t;
  92. enum {
  93. GAME_RELIABLE_MESSAGE_SYNCEDCVARS,
  94. GAME_RELIABLE_MESSAGE_SPAWN_PLAYER,
  95. GAME_RELIABLE_MESSAGE_CHAT,
  96. GAME_RELIABLE_MESSAGE_TCHAT,
  97. GAME_RELIABLE_MESSAGE_SOUND_EVENT,
  98. GAME_RELIABLE_MESSAGE_SOUND_INDEX,
  99. GAME_RELIABLE_MESSAGE_DB,
  100. GAME_RELIABLE_MESSAGE_DROPWEAPON,
  101. GAME_RELIABLE_MESSAGE_RESTART,
  102. GAME_RELIABLE_MESSAGE_TOURNEYLINE,
  103. GAME_RELIABLE_MESSAGE_VCHAT,
  104. GAME_RELIABLE_MESSAGE_STARTSTATE,
  105. GAME_RELIABLE_MESSAGE_WARMUPTIME,
  106. GAME_RELIABLE_MESSAGE_SPECTATE,
  107. GAME_RELIABLE_MESSAGE_EVENT,
  108. GAME_RELIABLE_MESSAGE_LOBBY_COUNTDOWN,
  109. GAME_RELIABLE_MESSAGE_RESPAWN_AVAILABLE, // Used just to show clients the respawn text on the hud.
  110. GAME_RELIABLE_MESSAGE_MATCH_STARTED_TIME,
  111. GAME_RELIABLE_MESSAGE_ACHIEVEMENT_UNLOCK,
  112. GAME_RELIABLE_MESSAGE_CLIENT_HITSCAN_HIT
  113. };
  114. typedef enum {
  115. GAMESTATE_UNINITIALIZED, // prior to Init being called
  116. GAMESTATE_NOMAP, // no map loaded
  117. GAMESTATE_STARTUP, // inside InitFromNewMap(). spawning map entities.
  118. GAMESTATE_ACTIVE, // normal gameplay
  119. GAMESTATE_SHUTDOWN // inside MapShutdown(). clearing memory.
  120. } gameState_t;
  121. typedef struct {
  122. idEntity *ent;
  123. int dist;
  124. int team;
  125. } spawnSpot_t;
  126. //============================================================================
  127. class idEventQueue {
  128. public:
  129. typedef enum {
  130. OUTOFORDER_IGNORE,
  131. OUTOFORDER_DROP,
  132. OUTOFORDER_SORT
  133. } outOfOrderBehaviour_t;
  134. idEventQueue() : start( NULL ), end( NULL ) {}
  135. entityNetEvent_t * Alloc();
  136. void Free( entityNetEvent_t *event );
  137. void Shutdown();
  138. void Init();
  139. void Enqueue( entityNetEvent_t* event, outOfOrderBehaviour_t oooBehaviour );
  140. entityNetEvent_t * Dequeue();
  141. entityNetEvent_t * RemoveLast();
  142. entityNetEvent_t * Start() { return start; }
  143. private:
  144. entityNetEvent_t * start;
  145. entityNetEvent_t * end;
  146. idBlockAlloc<entityNetEvent_t,32> eventAllocator;
  147. };
  148. //============================================================================
  149. template< class type >
  150. class idEntityPtr {
  151. public:
  152. idEntityPtr();
  153. // save games
  154. void Save( idSaveGame *savefile ) const; // archives object for save game file
  155. void Restore( idRestoreGame *savefile ); // unarchives object from save game file
  156. idEntityPtr & operator=( const type * ent );
  157. idEntityPtr & operator=( const idEntityPtr & ep );
  158. bool operator==( const idEntityPtr & ep ) { return spawnId == ep.spawnId; }
  159. type * operator->() const { return GetEntity(); }
  160. operator type * () const { return GetEntity(); }
  161. // synchronize entity pointers over the network
  162. int GetSpawnId() const { return spawnId; }
  163. bool SetSpawnId( int id );
  164. bool UpdateSpawnId();
  165. bool IsValid() const;
  166. type * GetEntity() const;
  167. int GetEntityNum() const;
  168. private:
  169. int spawnId;
  170. };
  171. struct timeState_t {
  172. int time;
  173. int previousTime;
  174. int realClientTime;
  175. void Set( int t, int pt, int rct ) { time = t; previousTime = pt; realClientTime = rct; };
  176. void Get( int & t, int & pt, int & rct ) { t = time; pt = previousTime; rct = realClientTime; };
  177. void Save( idSaveGame *savefile ) const { savefile->WriteInt( time ); savefile->WriteInt( previousTime ); savefile->WriteInt( realClientTime ); }
  178. void Restore( idRestoreGame *savefile ) { savefile->ReadInt( time ); savefile->ReadInt( previousTime ); savefile->ReadInt( realClientTime ); }
  179. };
  180. enum slowmoState_t {
  181. SLOWMO_STATE_OFF,
  182. SLOWMO_STATE_RAMPUP,
  183. SLOWMO_STATE_ON,
  184. SLOWMO_STATE_RAMPDOWN
  185. };
  186. //============================================================================
  187. class idGameLocal : public idGame {
  188. public:
  189. int previousServerTime; // time in msec of last frame on the server
  190. int serverTime; // in msec. ( on the client ) the server time. ( on the server ) the actual game time.
  191. idDict serverInfo; // all the tunable parameters, like numclients, etc
  192. int numClients; // pulled from serverInfo and verified
  193. idArray< lobbyUserID_t, MAX_CLIENTS > lobbyUserIDs; // Maps from a client (player) number to a lobby user
  194. idDict persistentPlayerInfo[MAX_CLIENTS];
  195. idEntity * entities[MAX_GENTITIES];// index to entities
  196. int spawnIds[MAX_GENTITIES];// for use in idEntityPtr
  197. idArray< int, 2 > firstFreeEntityIndex; // first free index in the entities array. [0] for replicated entities, [1] for non-replicated
  198. int num_entities; // current number <= MAX_GENTITIES
  199. idHashIndex entityHash; // hash table to quickly find entities by name
  200. idWorldspawn * world; // world entity
  201. idLinkList<idEntity> spawnedEntities; // all spawned entities
  202. idLinkList<idEntity> activeEntities; // all thinking entities (idEntity::thinkFlags != 0)
  203. idLinkList<idEntity> aimAssistEntities; // all aim Assist entities
  204. int numEntitiesToDeactivate;// number of entities that became inactive in current frame
  205. bool sortPushers; // true if active lists needs to be reordered to place pushers at the front
  206. bool sortTeamMasters; // true if active lists needs to be reordered to place physics team masters before their slaves
  207. idDict persistentLevelInfo; // contains args that are kept around between levels
  208. // can be used to automatically effect every material in the world that references globalParms
  209. float globalShaderParms[ MAX_GLOBAL_SHADER_PARMS ];
  210. idRandom random; // random number generator used throughout the game
  211. idProgram program; // currently loaded script and data space
  212. idThread * frameCommandThread;
  213. idClip clip; // collision detection
  214. idPush push; // geometric pushing
  215. idPVS pvs; // potential visible set
  216. idTestModel * testmodel; // for development testing of models
  217. idEntityFx * testFx; // for development testing of fx
  218. idStr sessionCommand; // a target_sessionCommand can set this to return something to the session
  219. idMultiplayerGame mpGame; // handles rules for standard dm
  220. idSmokeParticles * smokeParticles; // global smoke trails
  221. idEditEntities * editEntities; // in game editing
  222. bool inCinematic; // game is playing cinematic (player controls frozen)
  223. int framenum;
  224. int time; // in msec
  225. int previousTime; // time in msec of last frame
  226. int vacuumAreaNum; // -1 if level doesn't have any outside areas
  227. gameType_t gameType;
  228. idLinkList<idEntity> snapshotEntities; // entities from the last snapshot
  229. int realClientTime; // real client time
  230. bool isNewFrame; // true if this is a new game frame, not a rerun due to prediction
  231. float clientSmoothing; // smoothing of other clients in the view
  232. int entityDefBits; // bits required to store an entity def number
  233. static const char * sufaceTypeNames[ MAX_SURFACE_TYPES ]; // text names for surface types
  234. idEntityPtr<idEntity> lastGUIEnt; // last entity with a GUI, used by Cmd_NextGUI_f
  235. int lastGUI; // last GUI on the lastGUIEnt
  236. idEntityPtr<idPlayer> playerActivateFragChamber; // The player that activated the frag chamber
  237. idEntityPtr<idEntity> portalSkyEnt;
  238. bool portalSkyActive;
  239. void SetPortalSkyEnt( idEntity *ent );
  240. bool IsPortalSkyAcive();
  241. timeState_t fast;
  242. timeState_t slow;
  243. int selectedGroup;
  244. slowmoState_t slowmoState;
  245. float slowmoScale;
  246. bool quickSlowmoReset;
  247. virtual void SelectTimeGroup( int timeGroup );
  248. virtual int GetTimeGroupTime( int timeGroup );
  249. void ComputeSlowScale();
  250. void RunTimeGroup2( idUserCmdMgr & userCmdMgr );
  251. void ResetSlowTimeVars();
  252. void QuickSlowmoReset();
  253. void Tokenize( idStrList &out, const char *in );
  254. // ---------------------- Public idGame Interface -------------------
  255. idGameLocal();
  256. virtual void Init();
  257. virtual void Shutdown();
  258. virtual void SetServerInfo( const idDict &serverInfo );
  259. virtual const idDict & GetServerInfo();
  260. virtual const idDict & GetPersistentPlayerInfo( int clientNum );
  261. virtual void SetPersistentPlayerInfo( int clientNum, const idDict &playerInfo );
  262. virtual void InitFromNewMap( const char *mapName, idRenderWorld *renderWorld, idSoundWorld *soundWorld, int gameType, int randSeed );
  263. virtual bool InitFromSaveGame( const char *mapName, idRenderWorld *renderWorld, idSoundWorld *soundWorld, idFile * saveGameFile, idFile * stringTableFile, int saveGameVersion );
  264. virtual void SaveGame( idFile *saveGameFile, idFile *stringTableFile );
  265. virtual void GetSaveGameDetails( idSaveGameDetails & gameDetails );
  266. virtual void MapShutdown();
  267. virtual void CacheDictionaryMedia( const idDict *dict );
  268. virtual void Preload( const idPreloadManifest &manifest );
  269. virtual void RunFrame( idUserCmdMgr & cmdMgr, gameReturn_t & gameReturn );
  270. void RunAllUserCmdsForPlayer( idUserCmdMgr & cmdMgr, const int playerNumber );
  271. void RunSingleUserCmd( usercmd_t & cmd, idPlayer & player );
  272. void RunEntityThink( idEntity & ent, idUserCmdMgr & userCmdMgr );
  273. virtual bool Draw( int clientNum );
  274. virtual bool HandlePlayerGuiEvent( const sysEvent_t * ev );
  275. virtual void ServerWriteSnapshot( idSnapShot & ss );
  276. virtual void ProcessReliableMessage( int clientNum, int type, const idBitMsg &msg );
  277. virtual void ClientReadSnapshot( const idSnapShot & ss );
  278. virtual void ClientRunFrame( idUserCmdMgr & cmdMgr, bool lastPredictFrame, gameReturn_t & ret );
  279. void BuildReturnValue( gameReturn_t & ret );
  280. virtual int GetMPGameModes( const char *** gameModes, const char *** gameModesDisplay );
  281. virtual void GetClientStats( int clientNum, char *data, const int len );
  282. virtual bool IsInGame() const { return GameState() == GAMESTATE_ACTIVE; }
  283. virtual int MapPeerToClient( int peer ) const;
  284. virtual int GetLocalClientNum() const;
  285. virtual void GetAimAssistAngles( idAngles & angles );
  286. virtual float GetAimAssistSensitivity();
  287. // ---------------------- Public idGameLocal Interface -------------------
  288. void Printf( VERIFY_FORMAT_STRING const char *fmt, ... ) const;
  289. void DPrintf( VERIFY_FORMAT_STRING const char *fmt, ... ) const;
  290. void Warning( VERIFY_FORMAT_STRING const char *fmt, ... ) const;
  291. void DWarning( VERIFY_FORMAT_STRING const char *fmt, ... ) const;
  292. void Error( VERIFY_FORMAT_STRING const char *fmt, ... ) const;
  293. // Initializes all map variables common to both save games and spawned games
  294. void LoadMap( const char *mapName, int randseed );
  295. void LocalMapRestart();
  296. void MapRestart();
  297. static void MapRestart_f( const idCmdArgs &args );
  298. idMapFile * GetLevelMap();
  299. const char * GetMapName() const;
  300. int NumAAS() const;
  301. idAAS * GetAAS( int num ) const;
  302. idAAS * GetAAS( const char *name ) const;
  303. void SetAASAreaState( const idBounds &bounds, const int areaContents, bool closed );
  304. aasHandle_t AddAASObstacle( const idBounds &bounds );
  305. void RemoveAASObstacle( const aasHandle_t handle );
  306. void RemoveAllAASObstacles();
  307. bool CheatsOk( bool requirePlayer = true );
  308. gameState_t GameState() const;
  309. idEntity * SpawnEntityType( const idTypeInfo &classdef, const idDict *args = NULL, bool bIsClientReadSnapshot = false );
  310. bool SpawnEntityDef( const idDict &args, idEntity **ent = NULL, bool setDefaults = true );
  311. int GetSpawnId( const idEntity *ent ) const;
  312. const idDeclEntityDef * FindEntityDef( const char *name, bool makeDefault = true ) const;
  313. const idDict * FindEntityDefDict( const char *name, bool makeDefault = true ) const;
  314. void RegisterEntity( idEntity *ent, int forceSpawnId, const idDict & spawnArgsToCopy );
  315. void UnregisterEntity( idEntity *ent );
  316. const idDict & GetSpawnArgs() const { return spawnArgs; }
  317. bool RequirementMet( idEntity *activator, const idStr &requires, int removeItem );
  318. void AlertAI( idEntity *ent );
  319. idActor * GetAlertEntity();
  320. bool InPlayerPVS( idEntity *ent ) const;
  321. bool InPlayerConnectedArea( idEntity *ent ) const;
  322. pvsHandle_t GetPlayerPVS() { return playerPVS; };
  323. void SetCamera( idCamera *cam );
  324. idCamera * GetCamera() const;
  325. void CalcFov( float base_fov, float &fov_x, float &fov_y ) const;
  326. void AddEntityToHash( const char *name, idEntity *ent );
  327. bool RemoveEntityFromHash( const char *name, idEntity *ent );
  328. int GetTargets( const idDict &args, idList< idEntityPtr<idEntity> > &list, const char *ref ) const;
  329. // returns the master entity of a trace. for example, if the trace entity is the player's head, it will return the player.
  330. idEntity * GetTraceEntity( const trace_t &trace ) const;
  331. static void ArgCompletion_EntityName( const idCmdArgs &args, void(*callback)( const char *s ) );
  332. idEntity * FindTraceEntity( idVec3 start, idVec3 end, const idTypeInfo &c, const idEntity *skip ) const;
  333. idEntity * FindEntity( const char *name ) const;
  334. idEntity * FindEntityUsingDef( idEntity *from, const char *match ) const;
  335. int EntitiesWithinRadius( const idVec3 org, float radius, idEntity **entityList, int maxCount ) const;
  336. void KillBox( idEntity *ent, bool catch_teleport = false );
  337. void RadiusDamage( const idVec3 &origin, idEntity *inflictor, idEntity *attacker, idEntity *ignoreDamage, idEntity *ignorePush, const char *damageDefName, float dmgPower = 1.0f );
  338. void RadiusPush( const idVec3 &origin, const float radius, const float push, const idEntity *inflictor, const idEntity *ignore, float inflictorScale, const bool quake );
  339. void RadiusPushClipModel( const idVec3 &origin, const float push, const idClipModel *clipModel );
  340. void ProjectDecal( const idVec3 &origin, const idVec3 &dir, float depth, bool parallel, float size, const char *material, float angle = 0 );
  341. void BloodSplat( const idVec3 &origin, const idVec3 &dir, float size, const char *material );
  342. void CallFrameCommand( idEntity *ent, const function_t *frameCommand );
  343. void CallObjectFrameCommand( idEntity *ent, const char *frameCommand );
  344. const idVec3 & GetGravity() const;
  345. // added the following to assist licensees with merge issues
  346. int GetFrameNum() const { return framenum; };
  347. int GetTime() const { return time; };
  348. int GetNextClientNum( int current ) const;
  349. idPlayer * GetClientByNum( int current ) const;
  350. idPlayer * GetLocalPlayer() const;
  351. void SpreadLocations();
  352. idLocationEntity * LocationForPoint( const idVec3 &point ); // May return NULL
  353. idEntity * SelectInitialSpawnPoint( idPlayer *player );
  354. void SetPortalState( qhandle_t portal, int blockingBits );
  355. void SaveEntityNetworkEvent( const idEntity *ent, int event, const idBitMsg *msg );
  356. int ServerRemapDecl( int clientNum, declType_t type, int index );
  357. int ClientRemapDecl( declType_t type, int index );
  358. void SyncPlayersWithLobbyUsers( bool initial );
  359. void ServerWriteInitialReliableMessages( int clientNum, lobbyUserID_t lobbyUserID );
  360. void ServerSendNetworkSyncCvars();
  361. virtual void SetInterpolation( const float fraction, const int serverGameMS, const int ssStartTime, const int ssEndTime );
  362. void ServerProcessReliableMessage( int clientNum, int type, const idBitMsg &msg );
  363. void ClientProcessReliableMessage( int type, const idBitMsg &msg );
  364. // Snapshot times - track exactly what times we are interpolating from and to
  365. int GetSSEndTime() const { return netInterpolationInfo.ssEndTime; }
  366. int GetSSStartTime() const { return netInterpolationInfo.ssStartTime; }
  367. virtual void SetServerGameTimeMs( const int time );
  368. virtual int GetServerGameTimeMs() const;
  369. idEntity * FindPredictedEntity( uint32 predictedKey, idTypeInfo * type );
  370. uint32 GeneratePredictionKey( idWeapon * weapon, idPlayer * playerAttacker, int overrideKey );
  371. int GetLastClientUsercmdMilliseconds( int playerIndex ) const { return usercmdLastClientMilliseconds[ playerIndex ]; }
  372. void SetGlobalMaterial( const idMaterial *mat );
  373. const idMaterial * GetGlobalMaterial();
  374. void SetGibTime( int _time ) { nextGibTime = _time; };
  375. int GetGibTime() { return nextGibTime; };
  376. virtual bool InhibitControls();
  377. virtual bool IsPDAOpen() const;
  378. virtual bool IsPlayerChatting() const;
  379. // Creates leaderboards for each map/mode defined.
  380. virtual void Leaderboards_Init();
  381. virtual void Leaderboards_Shutdown();
  382. // MAIN MENU FUNCTIONS
  383. virtual void Shell_Init( const char * filename, idSoundWorld * sw );
  384. virtual void Shell_Cleanup();
  385. virtual void Shell_Show( bool show );
  386. virtual void Shell_ClosePause();
  387. virtual void Shell_CreateMenu( bool inGame );
  388. virtual bool Shell_IsActive() const;
  389. virtual bool Shell_HandleGuiEvent( const sysEvent_t * sev );
  390. virtual void Shell_Render();
  391. virtual void Shell_ResetMenu();
  392. virtual void Shell_SyncWithSession() ;
  393. virtual void Shell_SetCanContinue( bool valid );
  394. virtual void Shell_UpdateSavedGames();
  395. virtual void Shell_UpdateClientCountdown( int countdown );
  396. virtual void Shell_UpdateLeaderboard( const idLeaderboardCallback * callback );
  397. virtual void Shell_SetGameComplete();
  398. void Shell_ClearRepeater();
  399. const char * GetMapFileName() { return mapFileName.c_str(); }
  400. const char * GetMPPlayerDefName() const;
  401. private:
  402. const static int INITIAL_SPAWN_COUNT = 1;
  403. idStr mapFileName; // name of the map, empty string if no map loaded
  404. idMapFile * mapFile; // will be NULL during the game unless in-game editing is used
  405. bool mapCycleLoaded;
  406. int spawnCount;
  407. int mapSpawnCount; // it's handy to know which entities are part of the map
  408. idLocationEntity ** locationEntities; // for location names, etc
  409. idCamera * camera;
  410. const idMaterial * globalMaterial; // for overriding everything
  411. idList<idAAS *> aasList; // area system
  412. idMenuHandler_Shell * shellHandler;
  413. idStrList aasNames;
  414. idEntityPtr<idActor> lastAIAlertEntity;
  415. int lastAIAlertTime;
  416. idDict spawnArgs; // spawn args used during entity spawning FIXME: shouldn't be necessary anymore
  417. pvsHandle_t playerPVS; // merged pvs of all players
  418. pvsHandle_t playerConnectedAreas; // all areas connected to any player area
  419. idVec3 gravity; // global gravity vector
  420. gameState_t gamestate; // keeps track of whether we're spawning, shutting down, or normal gameplay
  421. bool influenceActive; // true when a phantasm is happening
  422. int nextGibTime;
  423. idEventQueue eventQueue;
  424. idEventQueue savedEventQueue;
  425. idStaticList<spawnSpot_t, MAX_GENTITIES> spawnSpots;
  426. idStaticList<idEntity *, MAX_GENTITIES> initialSpots;
  427. int currentInitialSpot;
  428. idStaticList<spawnSpot_t, MAX_GENTITIES> teamSpawnSpots[2];
  429. idStaticList<idEntity *, MAX_GENTITIES> teamInitialSpots[2];
  430. int teamCurrentInitialSpot[2];
  431. struct netInterpolationInfo_t { // Was in GameTimeManager.h in id5, needed common place to put this.
  432. netInterpolationInfo_t()
  433. : pct( 0.0f )
  434. , serverGameMs( 0 )
  435. , previousServerGameMs( 0 )
  436. , ssStartTime( 0 )
  437. , ssEndTime( 0 )
  438. {}
  439. float pct; // % of current interpolation
  440. int serverGameMs; // Interpolated server game time
  441. int previousServerGameMs; // last frame's interpolated server game time
  442. int ssStartTime; // Server time of old snapshot
  443. int ssEndTime; // Server time of next snapshot
  444. };
  445. netInterpolationInfo_t netInterpolationInfo;
  446. idDict newInfo;
  447. idArray< int, MAX_PLAYERS > usercmdLastClientMilliseconds; // The latest client time the server has run.
  448. idArray< int, MAX_PLAYERS > lastCmdRunTimeOnClient;
  449. idArray< int, MAX_PLAYERS > lastCmdRunTimeOnServer;
  450. void Clear();
  451. // returns true if the entity shouldn't be spawned at all in this game type or difficulty level
  452. bool InhibitEntitySpawn( idDict &spawnArgs );
  453. // spawn entities from the map file
  454. void SpawnMapEntities();
  455. // commons used by init, shutdown, and restart
  456. void MapPopulate();
  457. void MapClear( bool clearClients );
  458. pvsHandle_t GetClientPVS( idPlayer *player, pvsType_t type );
  459. void SetupPlayerPVS();
  460. void FreePlayerPVS();
  461. void UpdateGravity();
  462. void SortActiveEntityList();
  463. void ShowTargets();
  464. void RunDebugInfo();
  465. void InitScriptForMap();
  466. void SetScriptFPS( const float com_engineHz );
  467. void SpawnPlayer( int clientNum );
  468. void InitConsoleCommands();
  469. void ShutdownConsoleCommands();
  470. void InitAsyncNetwork();
  471. void ShutdownAsyncNetwork();
  472. void NetworkEventWarning( const entityNetEvent_t *event, VERIFY_FORMAT_STRING const char *fmt, ... );
  473. void ServerProcessEntityNetworkEventQueue();
  474. void ClientProcessEntityNetworkEventQueue();
  475. // call after any change to serverInfo. Will update various quick-access flags
  476. void UpdateServerInfoFlags();
  477. void RandomizeInitialSpawns();
  478. static int sortSpawnPoints( const void *ptr1, const void *ptr2 );
  479. bool SimulateProjectiles();
  480. };
  481. //============================================================================
  482. extern idGameLocal gameLocal;
  483. extern idAnimManager animationLib;
  484. //============================================================================
  485. class idGameError : public idException {
  486. public:
  487. idGameError( const char *text ) : idException( text ) {}
  488. };
  489. //============================================================================
  490. template< class type >
  491. ID_INLINE idEntityPtr<type>::idEntityPtr() {
  492. spawnId = 0;
  493. }
  494. template< class type >
  495. ID_INLINE void idEntityPtr<type>::Save( idSaveGame *savefile ) const {
  496. savefile->WriteInt( spawnId );
  497. }
  498. template< class type >
  499. ID_INLINE void idEntityPtr<type>::Restore( idRestoreGame *savefile ) {
  500. savefile->ReadInt( spawnId );
  501. }
  502. template< class type >
  503. ID_INLINE idEntityPtr<type> &idEntityPtr<type>::operator=( const type *ent ) {
  504. if ( ent == NULL ) {
  505. spawnId = 0;
  506. } else {
  507. spawnId = ( gameLocal.spawnIds[ent->entityNumber] << GENTITYNUM_BITS ) | ent->entityNumber;
  508. }
  509. return *this;
  510. }
  511. template< class type >
  512. ID_INLINE idEntityPtr< type > &idEntityPtr<type>::operator=( const idEntityPtr & ep ) {
  513. spawnId = ep.spawnId;
  514. return *this;
  515. }
  516. template< class type >
  517. ID_INLINE bool idEntityPtr<type>::SetSpawnId( int id ) {
  518. // the reason for this first check is unclear:
  519. // the function returning false may mean the spawnId is already set right, or the entity is missing
  520. if ( id == spawnId ) {
  521. return false;
  522. }
  523. if ( ( id >> GENTITYNUM_BITS ) == gameLocal.spawnIds[ id & ( ( 1 << GENTITYNUM_BITS ) - 1 ) ] ) {
  524. spawnId = id;
  525. return true;
  526. }
  527. return false;
  528. }
  529. template< class type >
  530. ID_INLINE bool idEntityPtr<type>::IsValid() const {
  531. return ( gameLocal.spawnIds[ spawnId & ( ( 1 << GENTITYNUM_BITS ) - 1 ) ] == ( spawnId >> GENTITYNUM_BITS ) );
  532. }
  533. template< class type >
  534. ID_INLINE type *idEntityPtr<type>::GetEntity() const {
  535. int entityNum = spawnId & ( ( 1 << GENTITYNUM_BITS ) - 1 );
  536. if ( ( gameLocal.spawnIds[ entityNum ] == ( spawnId >> GENTITYNUM_BITS ) ) ) {
  537. return static_cast<type *>( gameLocal.entities[ entityNum ] );
  538. }
  539. return NULL;
  540. }
  541. template< class type >
  542. ID_INLINE int idEntityPtr<type>::GetEntityNum() const {
  543. return ( spawnId & ( ( 1 << GENTITYNUM_BITS ) - 1 ) );
  544. }
  545. // ===========================================================================
  546. //
  547. // these defines work for all startsounds from all entity types
  548. // make sure to change script/doom_defs.script if you add any channels, or change their order
  549. //
  550. typedef enum {
  551. SND_CHANNEL_ANY = SCHANNEL_ANY,
  552. SND_CHANNEL_VOICE = SCHANNEL_ONE,
  553. SND_CHANNEL_VOICE2,
  554. SND_CHANNEL_BODY,
  555. SND_CHANNEL_BODY2,
  556. SND_CHANNEL_BODY3,
  557. SND_CHANNEL_WEAPON,
  558. SND_CHANNEL_ITEM,
  559. SND_CHANNEL_HEART,
  560. SND_CHANNEL_PDA_AUDIO,
  561. SND_CHANNEL_PDA_VIDEO,
  562. SND_CHANNEL_DEMONIC,
  563. SND_CHANNEL_RADIO,
  564. // internal use only. not exposed to script or framecommands.
  565. SND_CHANNEL_AMBIENT,
  566. SND_CHANNEL_DAMAGE
  567. } gameSoundChannel_t;
  568. // content masks
  569. #define MASK_ALL (-1)
  570. #define MASK_SOLID (CONTENTS_SOLID)
  571. #define MASK_MONSTERSOLID (CONTENTS_SOLID|CONTENTS_MONSTERCLIP|CONTENTS_BODY)
  572. #define MASK_PLAYERSOLID (CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_BODY)
  573. #define MASK_DEADSOLID (CONTENTS_SOLID|CONTENTS_PLAYERCLIP)
  574. #define MASK_WATER (CONTENTS_WATER)
  575. #define MASK_OPAQUE (CONTENTS_OPAQUE)
  576. #define MASK_SHOT_RENDERMODEL (CONTENTS_SOLID|CONTENTS_RENDERMODEL)
  577. #define MASK_SHOT_BOUNDINGBOX (CONTENTS_SOLID|CONTENTS_BODY)
  578. const float DEFAULT_GRAVITY = 1066.0f;
  579. #define DEFAULT_GRAVITY_STRING "1066"
  580. const idVec3 DEFAULT_GRAVITY_VEC3( 0, 0, -DEFAULT_GRAVITY );
  581. const int CINEMATIC_SKIP_DELAY = SEC2MS( 2.0f );
  582. //============================================================================
  583. #include "physics/Force.h"
  584. #include "physics/Force_Constant.h"
  585. #include "physics/Force_Drag.h"
  586. #include "physics/Force_Grab.h"
  587. #include "physics/Force_Field.h"
  588. #include "physics/Force_Spring.h"
  589. #include "physics/Physics.h"
  590. #include "physics/Physics_Static.h"
  591. #include "physics/Physics_StaticMulti.h"
  592. #include "physics/Physics_Base.h"
  593. #include "physics/Physics_Actor.h"
  594. #include "physics/Physics_Monster.h"
  595. #include "physics/Physics_Player.h"
  596. #include "physics/Physics_Parametric.h"
  597. #include "physics/Physics_RigidBody.h"
  598. #include "physics/Physics_AF.h"
  599. #include "SmokeParticles.h"
  600. #include "Entity.h"
  601. #include "GameEdit.h"
  602. #include "Grabber.h"
  603. #include "AF.h"
  604. #include "IK.h"
  605. #include "AFEntity.h"
  606. #include "Misc.h"
  607. #include "Actor.h"
  608. #include "Projectile.h"
  609. #include "Weapon.h"
  610. #include "Light.h"
  611. #include "WorldSpawn.h"
  612. #include "Item.h"
  613. #include "PlayerView.h"
  614. #include "PlayerIcon.h"
  615. #include "Achievements.h"
  616. #include "AimAssist.h"
  617. #include "Player.h"
  618. #include "Mover.h"
  619. #include "Camera.h"
  620. #include "Moveable.h"
  621. #include "Target.h"
  622. #include "Trigger.h"
  623. #include "Sound.h"
  624. #include "Fx.h"
  625. #include "SecurityCamera.h"
  626. #include "BrittleFracture.h"
  627. #include "ai/AI.h"
  628. #include "anim/Anim_Testmodel.h"
  629. // menus
  630. #include "menus/MenuWidget.h"
  631. #include "menus/MenuScreen.h"
  632. #include "menus/MenuHandler.h"
  633. #include "script/Script_Compiler.h"
  634. #include "script/Script_Interpreter.h"
  635. #include "script/Script_Thread.h"
  636. #endif /* !__GAME_LOCAL_H__ */