Game_local.h 30 KB

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