Game_local.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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 __GAME_LOCAL_H__
  21. #define __GAME_LOCAL_H__
  22. /*
  23. ===============================================================================
  24. Local implementation of the public game interface.
  25. ===============================================================================
  26. */
  27. #define LAGO_IMG_WIDTH 64
  28. #define LAGO_IMG_HEIGHT 64
  29. #define LAGO_WIDTH 64
  30. #define LAGO_HEIGHT 44
  31. #define LAGO_MATERIAL "textures/sfx/lagometer"
  32. #define LAGO_IMAGE "textures/sfx/lagometer.tga"
  33. // if set to 1 the server sends the client PVS with snapshots and the client compares against what it sees
  34. #ifndef ASYNC_WRITE_PVS
  35. #define ASYNC_WRITE_PVS 0
  36. #endif
  37. #ifdef ID_DEBUG_UNINITIALIZED_MEMORY
  38. // This is real evil but allows the code to inspect arbitrary class variables.
  39. #define private public
  40. #define protected public
  41. #endif
  42. extern idRenderWorld * gameRenderWorld;
  43. extern idSoundWorld * gameSoundWorld;
  44. // the "gameversion" client command will print this plus compile date
  45. #define GAME_VERSION "baseDOOM-1"
  46. // classes used by idGameLocal
  47. class idEntity;
  48. class idActor;
  49. class idPlayer;
  50. class idCamera;
  51. class idWorldspawn;
  52. class idTestModel;
  53. class idAAS;
  54. class idAI;
  55. class idSmokeParticles;
  56. class idEntityFx;
  57. class idTypeInfo;
  58. class idProgram;
  59. class idThread;
  60. class idEditEntities;
  61. class idLocationEntity;
  62. #define MAX_CLIENTS 32
  63. #define GENTITYNUM_BITS 12
  64. #define MAX_GENTITIES (1<<GENTITYNUM_BITS)
  65. #define ENTITYNUM_NONE (MAX_GENTITIES-1)
  66. #define ENTITYNUM_WORLD (MAX_GENTITIES-2)
  67. #define ENTITYNUM_MAX_NORMAL (MAX_GENTITIES-2)
  68. //============================================================================
  69. void gameError( const char *fmt, ... );
  70. #include "gamesys/Event.h"
  71. #include "gamesys/Class.h"
  72. #include "gamesys/SysCvar.h"
  73. #include "gamesys/SysCmds.h"
  74. #include "gamesys/SaveGame.h"
  75. #include "gamesys/DebugGraph.h"
  76. #include "script/Script_Program.h"
  77. #include "anim/Anim.h"
  78. #include "ai/AAS.h"
  79. #include "physics/Clip.h"
  80. #include "physics/Push.h"
  81. #include "Pvs.h"
  82. #include "MultiplayerGame.h"
  83. //============================================================================
  84. const int MAX_GAME_MESSAGE_SIZE = 8192;
  85. const int MAX_ENTITY_STATE_SIZE = 512;
  86. const int ENTITY_PVS_SIZE = ((MAX_GENTITIES+31)>>5);
  87. const int NUM_RENDER_PORTAL_BITS = idMath::BitsForInteger( PS_BLOCK_ALL );
  88. typedef struct entityState_s {
  89. int entityNumber;
  90. idBitMsg state;
  91. byte stateBuf[MAX_ENTITY_STATE_SIZE];
  92. struct entityState_s * next;
  93. } entityState_t;
  94. typedef struct snapshot_s {
  95. int sequence;
  96. entityState_t * firstEntityState;
  97. int pvs[ENTITY_PVS_SIZE];
  98. struct snapshot_s * next;
  99. } snapshot_t;
  100. const int MAX_EVENT_PARAM_SIZE = 128;
  101. typedef struct entityNetEvent_s {
  102. int spawnId;
  103. int event;
  104. int time;
  105. int paramsSize;
  106. byte paramsBuf[MAX_EVENT_PARAM_SIZE];
  107. struct entityNetEvent_s *next;
  108. struct entityNetEvent_s *prev;
  109. } entityNetEvent_t;
  110. enum {
  111. GAME_RELIABLE_MESSAGE_INIT_DECL_REMAP,
  112. GAME_RELIABLE_MESSAGE_REMAP_DECL,
  113. GAME_RELIABLE_MESSAGE_SPAWN_PLAYER,
  114. GAME_RELIABLE_MESSAGE_DELETE_ENT,
  115. GAME_RELIABLE_MESSAGE_CHAT,
  116. GAME_RELIABLE_MESSAGE_TCHAT,
  117. GAME_RELIABLE_MESSAGE_SOUND_EVENT,
  118. GAME_RELIABLE_MESSAGE_SOUND_INDEX,
  119. GAME_RELIABLE_MESSAGE_DB,
  120. GAME_RELIABLE_MESSAGE_KILL,
  121. GAME_RELIABLE_MESSAGE_DROPWEAPON,
  122. GAME_RELIABLE_MESSAGE_RESTART,
  123. GAME_RELIABLE_MESSAGE_SERVERINFO,
  124. GAME_RELIABLE_MESSAGE_TOURNEYLINE,
  125. GAME_RELIABLE_MESSAGE_CALLVOTE,
  126. GAME_RELIABLE_MESSAGE_CASTVOTE,
  127. GAME_RELIABLE_MESSAGE_STARTVOTE,
  128. GAME_RELIABLE_MESSAGE_UPDATEVOTE,
  129. GAME_RELIABLE_MESSAGE_PORTALSTATES,
  130. GAME_RELIABLE_MESSAGE_PORTAL,
  131. GAME_RELIABLE_MESSAGE_VCHAT,
  132. GAME_RELIABLE_MESSAGE_STARTSTATE,
  133. GAME_RELIABLE_MESSAGE_MENU,
  134. GAME_RELIABLE_MESSAGE_WARMUPTIME,
  135. GAME_RELIABLE_MESSAGE_EVENT
  136. };
  137. typedef enum {
  138. GAMESTATE_UNINITIALIZED, // prior to Init being called
  139. GAMESTATE_NOMAP, // no map loaded
  140. GAMESTATE_STARTUP, // inside InitFromNewMap(). spawning map entities.
  141. GAMESTATE_ACTIVE, // normal gameplay
  142. GAMESTATE_SHUTDOWN // inside MapShutdown(). clearing memory.
  143. } gameState_t;
  144. typedef struct {
  145. idEntity *ent;
  146. int dist;
  147. } spawnSpot_t;
  148. //============================================================================
  149. class idEventQueue {
  150. public:
  151. typedef enum {
  152. OUTOFORDER_IGNORE,
  153. OUTOFORDER_DROP,
  154. OUTOFORDER_SORT
  155. } outOfOrderBehaviour_t;
  156. idEventQueue() : start( NULL ), end( NULL ) {}
  157. entityNetEvent_t * Alloc();
  158. void Free( entityNetEvent_t *event );
  159. void Shutdown();
  160. void Init();
  161. void Enqueue( entityNetEvent_t* event, outOfOrderBehaviour_t oooBehaviour );
  162. entityNetEvent_t * Dequeue( void );
  163. entityNetEvent_t * RemoveLast( void );
  164. entityNetEvent_t * Start( void ) { return start; }
  165. private:
  166. entityNetEvent_t * start;
  167. entityNetEvent_t * end;
  168. idBlockAlloc<entityNetEvent_t,32> eventAllocator;
  169. };
  170. //============================================================================
  171. template< class type >
  172. class idEntityPtr {
  173. public:
  174. idEntityPtr();
  175. // save games
  176. void Save( idSaveGame *savefile ) const; // archives object for save game file
  177. void Restore( idRestoreGame *savefile ); // unarchives object from save game file
  178. idEntityPtr<type> & operator=( type *ent );
  179. // synchronize entity pointers over the network
  180. int GetSpawnId( void ) const { return spawnId; }
  181. bool SetSpawnId( int id );
  182. bool UpdateSpawnId( void );
  183. bool IsValid( void ) const;
  184. type * GetEntity( void ) const;
  185. int GetEntityNum( void ) const;
  186. private:
  187. int spawnId;
  188. };
  189. //============================================================================
  190. class idGameLocal : public idGame {
  191. public:
  192. idDict serverInfo; // all the tunable parameters, like numclients, etc
  193. int numClients; // pulled from serverInfo and verified
  194. idDict userInfo[MAX_CLIENTS]; // client specific settings
  195. usercmd_t usercmds[MAX_CLIENTS]; // client input commands
  196. idDict persistentPlayerInfo[MAX_CLIENTS];
  197. idEntity * entities[MAX_GENTITIES];// index to entities
  198. int spawnIds[MAX_GENTITIES];// for use in idEntityPtr
  199. int firstFreeIndex; // first free index in the entities array
  200. int num_entities; // current number <= MAX_GENTITIES
  201. idHashIndex entityHash; // hash table to quickly find entities by name
  202. idWorldspawn * world; // world entity
  203. idLinkList<idEntity> spawnedEntities; // all spawned entities
  204. idLinkList<idEntity> activeEntities; // all thinking entities (idEntity::thinkFlags != 0)
  205. int numEntitiesToDeactivate;// number of entities that became inactive in current frame
  206. bool sortPushers; // true if active lists needs to be reordered to place pushers at the front
  207. bool sortTeamMasters; // true if active lists needs to be reordered to place physics team masters before their slaves
  208. idDict persistentLevelInfo; // contains args that are kept around between levels
  209. // can be used to automatically effect every material in the world that references globalParms
  210. float globalShaderParms[ MAX_GLOBAL_SHADER_PARMS ];
  211. idRandom random; // random number generator used throughout the game
  212. idProgram program; // currently loaded script and data space
  213. idThread * frameCommandThread;
  214. idClip clip; // collision detection
  215. idPush push; // geometric pushing
  216. idPVS pvs; // potential visible set
  217. idTestModel * testmodel; // for development testing of models
  218. idEntityFx * testFx; // for development testing of fx
  219. idStr sessionCommand; // a target_sessionCommand can set this to return something to the session
  220. idMultiplayerGame mpGame; // handles rules for standard dm
  221. idSmokeParticles * smokeParticles; // global smoke trails
  222. idEditEntities * editEntities; // in game editing
  223. int cinematicSkipTime; // don't allow skipping cinemetics until this time has passed so player doesn't skip out accidently from a firefight
  224. int cinematicStopTime; // cinematics have several camera changes, so keep track of when we stop them so that we don't reset cinematicSkipTime unnecessarily
  225. int cinematicMaxSkipTime; // time to end cinematic when skipping. there's a possibility of an infinite loop if the map isn't set up right.
  226. bool inCinematic; // game is playing cinematic (player controls frozen)
  227. bool skipCinematic;
  228. // are kept up to date with changes to serverInfo
  229. int framenum;
  230. int previousTime; // time in msec of last frame
  231. int time; // in msec
  232. static const int msec = USERCMD_MSEC; // time since last update in milliseconds
  233. int vacuumAreaNum; // -1 if level doesn't have any outside areas
  234. gameType_t gameType;
  235. bool isMultiplayer; // set if the game is run in multiplayer mode
  236. bool isServer; // set if the game is run for a dedicated or listen server
  237. bool isClient; // set if the game is run for a client
  238. // discriminates between the RunFrame path and the ClientPrediction path
  239. // NOTE: on a listen server, isClient is false
  240. int localClientNum; // number of the local client. MP: -1 on a dedicated
  241. idLinkList<idEntity> snapshotEntities; // entities from the last snapshot
  242. int realClientTime; // real client time
  243. bool isNewFrame; // true if this is a new game frame, not a rerun due to prediction
  244. float clientSmoothing; // smoothing of other clients in the view
  245. int entityDefBits; // bits required to store an entity def number
  246. static const char * sufaceTypeNames[ MAX_SURFACE_TYPES ]; // text names for surface types
  247. idEntityPtr<idEntity> lastGUIEnt; // last entity with a GUI, used by Cmd_NextGUI_f
  248. int lastGUI; // last GUI on the lastGUIEnt
  249. // ---------------------- Public idGame Interface -------------------
  250. idGameLocal();
  251. virtual void Init( void );
  252. virtual void Shutdown( void );
  253. virtual void SetLocalClient( int clientNum );
  254. virtual void ThrottleUserInfo( void );
  255. virtual const idDict * SetUserInfo( int clientNum, const idDict &userInfo, bool isClient, bool canModify );
  256. virtual const idDict * GetUserInfo( int clientNum );
  257. virtual void SetServerInfo( const idDict &serverInfo );
  258. virtual const idDict & GetPersistentPlayerInfo( int clientNum );
  259. virtual void SetPersistentPlayerInfo( int clientNum, const idDict &playerInfo );
  260. virtual void InitFromNewMap( const char *mapName, idRenderWorld *renderWorld, idSoundWorld *soundWorld, bool isServer, bool isClient, int randSeed );
  261. virtual bool InitFromSaveGame( const char *mapName, idRenderWorld *renderWorld, idSoundWorld *soundWorld, idFile *saveGameFile );
  262. virtual void SaveGame( idFile *saveGameFile );
  263. virtual void MapShutdown( void );
  264. virtual void CacheDictionaryMedia( const idDict *dict );
  265. virtual void SpawnPlayer( int clientNum );
  266. virtual gameReturn_t RunFrame( const usercmd_t *clientCmds );
  267. virtual bool Draw( int clientNum );
  268. virtual escReply_t HandleESC( idUserInterface **gui );
  269. virtual idUserInterface *StartMenu( void );
  270. virtual const char * HandleGuiCommands( const char *menuCommand );
  271. virtual void HandleMainMenuCommands( const char *menuCommand, idUserInterface *gui );
  272. virtual allowReply_t ServerAllowClient( int numClients, const char *IP, const char *guid, const char *password, char reason[MAX_STRING_CHARS] );
  273. virtual void ServerClientConnect( int clientNum, const char *guid );
  274. virtual void ServerClientBegin( int clientNum );
  275. virtual void ServerClientDisconnect( int clientNum );
  276. virtual void ServerWriteInitialReliableMessages( int clientNum );
  277. virtual void ServerWriteSnapshot( int clientNum, int sequence, idBitMsg &msg, byte *clientInPVS, int numPVSClients );
  278. virtual bool ServerApplySnapshot( int clientNum, int sequence );
  279. virtual void ServerProcessReliableMessage( int clientNum, const idBitMsg &msg );
  280. virtual void ClientReadSnapshot( int clientNum, int sequence, const int gameFrame, const int gameTime, const int dupeUsercmds, const int aheadOfServer, const idBitMsg &msg );
  281. virtual bool ClientApplySnapshot( int clientNum, int sequence );
  282. virtual void ClientProcessReliableMessage( int clientNum, const idBitMsg &msg );
  283. virtual gameReturn_t ClientPrediction( int clientNum, const usercmd_t *clientCmds, bool lastPredictFrame );
  284. virtual void GetClientStats( int clientNum, char *data, const int len );
  285. virtual void SwitchTeam( int clientNum, int team );
  286. virtual bool DownloadRequest( const char *IP, const char *guid, const char *paks, char urls[ MAX_STRING_CHARS ] );
  287. // ---------------------- Public idGameLocal Interface -------------------
  288. void Printf( const char *fmt, ... ) const id_attribute((format(printf,2,3)));
  289. void DPrintf( const char *fmt, ... ) const id_attribute((format(printf,2,3)));
  290. void Warning( const char *fmt, ... ) const id_attribute((format(printf,2,3)));
  291. void DWarning( const char *fmt, ... ) const id_attribute((format(printf,2,3)));
  292. void Error( const char *fmt, ... ) const id_attribute((format(printf,2,3)));
  293. // Initializes all map variables common to both save games and spawned games
  294. void LoadMap( const char *mapName, int randseed );
  295. void LocalMapRestart( void );
  296. void MapRestart( void );
  297. static void MapRestart_f( const idCmdArgs &args );
  298. bool NextMap( void ); // returns wether serverinfo settings have been modified
  299. static void NextMap_f( const idCmdArgs &args );
  300. idMapFile * GetLevelMap( void );
  301. const char * GetMapName( void ) const;
  302. int NumAAS( void ) const;
  303. idAAS * GetAAS( int num ) const;
  304. idAAS * GetAAS( const char *name ) const;
  305. void SetAASAreaState( const idBounds &bounds, const int areaContents, bool closed );
  306. aasHandle_t AddAASObstacle( const idBounds &bounds );
  307. void RemoveAASObstacle( const aasHandle_t handle );
  308. void RemoveAllAASObstacles( void );
  309. bool CheatsOk( bool requirePlayer = true );
  310. void SetSkill( int value );
  311. gameState_t GameState( void ) const;
  312. idEntity * SpawnEntityType( const idTypeInfo &classdef, const idDict *args = NULL, bool bIsClientReadSnapshot = false );
  313. bool SpawnEntityDef( const idDict &args, idEntity **ent = NULL, bool setDefaults = true );
  314. int GetSpawnId( const idEntity *ent ) const;
  315. const idDeclEntityDef * FindEntityDef( const char *name, bool makeDefault = true ) const;
  316. const idDict * FindEntityDefDict( const char *name, bool makeDefault = true ) const;
  317. void RegisterEntity( idEntity *ent );
  318. void UnregisterEntity( idEntity *ent );
  319. bool RequirementMet( idEntity *activator, const idStr &requires, int removeItem );
  320. void AlertAI( idEntity *ent );
  321. idActor * GetAlertEntity( void );
  322. bool InPlayerPVS( idEntity *ent ) const;
  323. bool InPlayerConnectedArea( idEntity *ent ) const;
  324. void SetCamera( idCamera *cam );
  325. idCamera * GetCamera( void ) const;
  326. bool SkipCinematic( void );
  327. void CalcFov( float base_fov, float &fov_x, float &fov_y ) const;
  328. void AddEntityToHash( const char *name, idEntity *ent );
  329. bool RemoveEntityFromHash( const char *name, idEntity *ent );
  330. int GetTargets( const idDict &args, idList< idEntityPtr<idEntity> > &list, const char *ref ) const;
  331. // returns the master entity of a trace. for example, if the trace entity is the player's head, it will return the player.
  332. idEntity * GetTraceEntity( const trace_t &trace ) const;
  333. static void ArgCompletion_EntityName( const idCmdArgs &args, void(*callback)( const char *s ) );
  334. idEntity * FindTraceEntity( idVec3 start, idVec3 end, const idTypeInfo &c, const idEntity *skip ) const;
  335. idEntity * FindEntity( const char *name ) const;
  336. idEntity * FindEntityUsingDef( idEntity *from, const char *match ) const;
  337. int EntitiesWithinRadius( const idVec3 org, float radius, idEntity **entityList, int maxCount ) const;
  338. void KillBox( idEntity *ent, bool catch_teleport = false );
  339. void RadiusDamage( const idVec3 &origin, idEntity *inflictor, idEntity *attacker, idEntity *ignoreDamage, idEntity *ignorePush, const char *damageDefName, float dmgPower = 1.0f );
  340. void RadiusPush( const idVec3 &origin, const float radius, const float push, const idEntity *inflictor, const idEntity *ignore, float inflictorScale, const bool quake );
  341. void RadiusPushClipModel( const idVec3 &origin, const float push, const idClipModel *clipModel );
  342. void ProjectDecal( const idVec3 &origin, const idVec3 &dir, float depth, bool parallel, float size, const char *material, float angle = 0 );
  343. void BloodSplat( const idVec3 &origin, const idVec3 &dir, float size, const char *material );
  344. void CallFrameCommand( idEntity *ent, const function_t *frameCommand );
  345. void CallObjectFrameCommand( idEntity *ent, const char *frameCommand );
  346. const idVec3 & GetGravity( void ) const;
  347. // added the following to assist licensees with merge issues
  348. int GetFrameNum() const { return framenum; };
  349. int GetTime() const { return time; };
  350. int GetMSec() const { return msec; };
  351. int GetNextClientNum( int current ) const;
  352. idPlayer * GetClientByNum( int current ) const;
  353. idPlayer * GetClientByName( const char *name ) const;
  354. idPlayer * GetClientByCmdArgs( const idCmdArgs &args ) const;
  355. idPlayer * GetLocalPlayer() const;
  356. void SpreadLocations();
  357. idLocationEntity * LocationForPoint( const idVec3 &point ); // May return NULL
  358. idEntity * SelectInitialSpawnPoint( idPlayer *player );
  359. void SetPortalState( qhandle_t portal, int blockingBits );
  360. void SaveEntityNetworkEvent( const idEntity *ent, int event, const idBitMsg *msg );
  361. void ServerSendChatMessage( int to, const char *name, const char *text );
  362. int ServerRemapDecl( int clientNum, declType_t type, int index );
  363. int ClientRemapDecl( declType_t type, int index );
  364. void SetGlobalMaterial( const idMaterial *mat );
  365. const idMaterial * GetGlobalMaterial();
  366. void SetGibTime( int _time ) { nextGibTime = _time; };
  367. int GetGibTime() { return nextGibTime; };
  368. bool NeedRestart();
  369. private:
  370. const static int INITIAL_SPAWN_COUNT = 1;
  371. idStr mapFileName; // name of the map, empty string if no map loaded
  372. idMapFile * mapFile; // will be NULL during the game unless in-game editing is used
  373. bool mapCycleLoaded;
  374. int spawnCount;
  375. int mapSpawnCount; // it's handy to know which entities are part of the map
  376. idLocationEntity ** locationEntities; // for location names, etc
  377. idCamera * camera;
  378. const idMaterial * globalMaterial; // for overriding everything
  379. idList<idAAS *> aasList; // area system
  380. idStrList aasNames;
  381. idEntityPtr<idActor> lastAIAlertEntity;
  382. int lastAIAlertTime;
  383. idDict spawnArgs; // spawn args used during entity spawning FIXME: shouldn't be necessary anymore
  384. pvsHandle_t playerPVS; // merged pvs of all players
  385. pvsHandle_t playerConnectedAreas; // all areas connected to any player area
  386. idVec3 gravity; // global gravity vector
  387. gameState_t gamestate; // keeps track of whether we're spawning, shutting down, or normal gameplay
  388. bool influenceActive; // true when a phantasm is happening
  389. int nextGibTime;
  390. idList<int> clientDeclRemap[MAX_CLIENTS][DECL_MAX_TYPES];
  391. entityState_t * clientEntityStates[MAX_CLIENTS][MAX_GENTITIES];
  392. int clientPVS[MAX_CLIENTS][ENTITY_PVS_SIZE];
  393. snapshot_t * clientSnapshots[MAX_CLIENTS];
  394. idBlockAlloc<entityState_t,256>entityStateAllocator;
  395. idBlockAlloc<snapshot_t,64>snapshotAllocator;
  396. idEventQueue eventQueue;
  397. idEventQueue savedEventQueue;
  398. idStaticList<spawnSpot_t, MAX_GENTITIES> spawnSpots;
  399. idStaticList<idEntity *, MAX_GENTITIES> initialSpots;
  400. int currentInitialSpot;
  401. idDict newInfo;
  402. idStrList shakeSounds;
  403. byte lagometer[ LAGO_IMG_HEIGHT ][ LAGO_IMG_WIDTH ][ 4 ];
  404. void Clear( void );
  405. // returns true if the entity shouldn't be spawned at all in this game type or difficulty level
  406. bool InhibitEntitySpawn( idDict &spawnArgs );
  407. // spawn entities from the map file
  408. void SpawnMapEntities( void );
  409. // commons used by init, shutdown, and restart
  410. void MapPopulate( void );
  411. void MapClear( bool clearClients );
  412. pvsHandle_t GetClientPVS( idPlayer *player, pvsType_t type );
  413. void SetupPlayerPVS( void );
  414. void FreePlayerPVS( void );
  415. void UpdateGravity( void );
  416. void SortActiveEntityList( void );
  417. void ShowTargets( void );
  418. void RunDebugInfo( void );
  419. void InitScriptForMap( void );
  420. void InitConsoleCommands( void );
  421. void ShutdownConsoleCommands( void );
  422. void InitAsyncNetwork( void );
  423. void ShutdownAsyncNetwork( void );
  424. void InitLocalClient( int clientNum );
  425. void InitClientDeclRemap( int clientNum );
  426. void ServerSendDeclRemapToClient( int clientNum, declType_t type, int index );
  427. void FreeSnapshotsOlderThanSequence( int clientNum, int sequence );
  428. bool ApplySnapshot( int clientNum, int sequence );
  429. void WriteGameStateToSnapshot( idBitMsgDelta &msg ) const;
  430. void ReadGameStateFromSnapshot( const idBitMsgDelta &msg );
  431. void NetworkEventWarning( const entityNetEvent_t *event, const char *fmt, ... ) id_attribute((format(printf,3,4)));
  432. void ServerProcessEntityNetworkEventQueue( void );
  433. void ClientProcessEntityNetworkEventQueue( void );
  434. void ClientShowSnapshot( int clientNum ) const;
  435. // call after any change to serverInfo. Will update various quick-access flags
  436. void UpdateServerInfoFlags( void );
  437. void RandomizeInitialSpawns( void );
  438. static int sortSpawnPoints( const void *ptr1, const void *ptr2 );
  439. void DumpOggSounds( void );
  440. void GetShakeSounds( const idDict *dict );
  441. void SelectTimeGroup( int timeGroup );
  442. int GetTimeGroupTime( int timeGroup );
  443. void GetBestGameType( const char* map, const char* gametype, char buf[ MAX_STRING_CHARS ] );
  444. void Tokenize( idStrList &out, const char *in );
  445. void UpdateLagometer( int aheadOfServer, int dupeUsercmds );
  446. void GetMapLoadingGUI( char gui[ MAX_STRING_CHARS ] );
  447. };
  448. //============================================================================
  449. extern idGameLocal gameLocal;
  450. extern idAnimManager animationLib;
  451. //============================================================================
  452. template< class type >
  453. ID_INLINE idEntityPtr<type>::idEntityPtr() {
  454. spawnId = 0;
  455. }
  456. template< class type >
  457. ID_INLINE void idEntityPtr<type>::Save( idSaveGame *savefile ) const {
  458. savefile->WriteInt( spawnId );
  459. }
  460. template< class type >
  461. ID_INLINE void idEntityPtr<type>::Restore( idRestoreGame *savefile ) {
  462. savefile->ReadInt( spawnId );
  463. }
  464. template< class type >
  465. ID_INLINE idEntityPtr<type> &idEntityPtr<type>::operator=( type *ent ) {
  466. if ( ent == NULL ) {
  467. spawnId = 0;
  468. } else {
  469. spawnId = ( gameLocal.spawnIds[ent->entityNumber] << GENTITYNUM_BITS ) | ent->entityNumber;
  470. }
  471. return *this;
  472. }
  473. template< class type >
  474. ID_INLINE bool idEntityPtr<type>::SetSpawnId( int id ) {
  475. // the reason for this first check is unclear:
  476. // the function returning false may mean the spawnId is already set right, or the entity is missing
  477. if ( id == spawnId ) {
  478. return false;
  479. }
  480. if ( ( id >> GENTITYNUM_BITS ) == gameLocal.spawnIds[ id & ( ( 1 << GENTITYNUM_BITS ) - 1 ) ] ) {
  481. spawnId = id;
  482. return true;
  483. }
  484. return false;
  485. }
  486. template< class type >
  487. ID_INLINE bool idEntityPtr<type>::IsValid( void ) const {
  488. return ( gameLocal.spawnIds[ spawnId & ( ( 1 << GENTITYNUM_BITS ) - 1 ) ] == ( spawnId >> GENTITYNUM_BITS ) );
  489. }
  490. template< class type >
  491. ID_INLINE type *idEntityPtr<type>::GetEntity( void ) const {
  492. int entityNum = spawnId & ( ( 1 << GENTITYNUM_BITS ) - 1 );
  493. if ( ( gameLocal.spawnIds[ entityNum ] == ( spawnId >> GENTITYNUM_BITS ) ) ) {
  494. return static_cast<type *>( gameLocal.entities[ entityNum ] );
  495. }
  496. return NULL;
  497. }
  498. template< class type >
  499. ID_INLINE int idEntityPtr<type>::GetEntityNum( void ) const {
  500. return ( spawnId & ( ( 1 << GENTITYNUM_BITS ) - 1 ) );
  501. }
  502. //============================================================================
  503. class idGameError : public idException {
  504. public:
  505. idGameError( const char *text ) : idException( text ) {}
  506. };
  507. //============================================================================
  508. //
  509. // these defines work for all startsounds from all entity types
  510. // make sure to change script/doom_defs.script if you add any channels, or change their order
  511. //
  512. typedef enum {
  513. SND_CHANNEL_ANY = SCHANNEL_ANY,
  514. SND_CHANNEL_VOICE = SCHANNEL_ONE,
  515. SND_CHANNEL_VOICE2,
  516. SND_CHANNEL_BODY,
  517. SND_CHANNEL_BODY2,
  518. SND_CHANNEL_BODY3,
  519. SND_CHANNEL_WEAPON,
  520. SND_CHANNEL_ITEM,
  521. SND_CHANNEL_HEART,
  522. SND_CHANNEL_PDA,
  523. SND_CHANNEL_DEMONIC,
  524. SND_CHANNEL_RADIO,
  525. // internal use only. not exposed to script or framecommands.
  526. SND_CHANNEL_AMBIENT,
  527. SND_CHANNEL_DAMAGE
  528. } gameSoundChannel_t;
  529. // content masks
  530. #define MASK_ALL (-1)
  531. #define MASK_SOLID (CONTENTS_SOLID)
  532. #define MASK_MONSTERSOLID (CONTENTS_SOLID|CONTENTS_MONSTERCLIP|CONTENTS_BODY)
  533. #define MASK_PLAYERSOLID (CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_BODY)
  534. #define MASK_DEADSOLID (CONTENTS_SOLID|CONTENTS_PLAYERCLIP)
  535. #define MASK_WATER (CONTENTS_WATER)
  536. #define MASK_OPAQUE (CONTENTS_OPAQUE)
  537. #define MASK_SHOT_RENDERMODEL (CONTENTS_SOLID|CONTENTS_RENDERMODEL)
  538. #define MASK_SHOT_BOUNDINGBOX (CONTENTS_SOLID|CONTENTS_BODY)
  539. const float DEFAULT_GRAVITY = 1066.0f;
  540. #define DEFAULT_GRAVITY_STRING "1066"
  541. const idVec3 DEFAULT_GRAVITY_VEC3( 0, 0, -DEFAULT_GRAVITY );
  542. const int CINEMATIC_SKIP_DELAY = SEC2MS( 2.0f );
  543. //============================================================================
  544. #include "physics/Force.h"
  545. #include "physics/Force_Constant.h"
  546. #include "physics/Force_Drag.h"
  547. #include "physics/Force_Field.h"
  548. #include "physics/Force_Spring.h"
  549. #include "physics/Physics.h"
  550. #include "physics/Physics_Static.h"
  551. #include "physics/Physics_StaticMulti.h"
  552. #include "physics/Physics_Base.h"
  553. #include "physics/Physics_Actor.h"
  554. #include "physics/Physics_Monster.h"
  555. #include "physics/Physics_Player.h"
  556. #include "physics/Physics_Parametric.h"
  557. #include "physics/Physics_RigidBody.h"
  558. #include "physics/Physics_AF.h"
  559. #include "SmokeParticles.h"
  560. #include "Entity.h"
  561. #include "GameEdit.h"
  562. #include "AF.h"
  563. #include "IK.h"
  564. #include "AFEntity.h"
  565. #include "Misc.h"
  566. #include "Actor.h"
  567. #include "Projectile.h"
  568. #include "Weapon.h"
  569. #include "Light.h"
  570. #include "WorldSpawn.h"
  571. #include "Item.h"
  572. #include "PlayerView.h"
  573. #include "PlayerIcon.h"
  574. #include "Player.h"
  575. #include "Mover.h"
  576. #include "Camera.h"
  577. #include "Moveable.h"
  578. #include "Target.h"
  579. #include "Trigger.h"
  580. #include "Sound.h"
  581. #include "Fx.h"
  582. #include "SecurityCamera.h"
  583. #include "BrittleFracture.h"
  584. #include "ai/AI.h"
  585. #include "anim/Anim_Testmodel.h"
  586. #include "script/Script_Compiler.h"
  587. #include "script/Script_Interpreter.h"
  588. #include "script/Script_Thread.h"
  589. #endif /* !__GAME_LOCAL_H__ */