Game.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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_H__
  21. #define __GAME_H__
  22. /*
  23. ===============================================================================
  24. Public game interface with methods to run the game.
  25. ===============================================================================
  26. */
  27. // default scripts
  28. #define SCRIPT_DEFAULTDEFS "script/doom_defs.script"
  29. #define SCRIPT_DEFAULT "script/doom_main.script"
  30. #define SCRIPT_DEFAULTFUNC "doom_main"
  31. struct gameReturn_t {
  32. gameReturn_t() :
  33. syncNextGameFrame( false ),
  34. vibrationLow( 0 ),
  35. vibrationHigh( 0 ) {
  36. }
  37. char sessionCommand[MAX_STRING_CHARS]; // "map", "disconnect", "victory", etc
  38. bool syncNextGameFrame; // used when cinematics are skipped to prevent session from simulating several game frames to
  39. // keep the game time in sync with real time
  40. int vibrationLow;
  41. int vibrationHigh;
  42. };
  43. #define TIME_GROUP1 0
  44. #define TIME_GROUP2 1
  45. class idGame {
  46. public:
  47. virtual ~idGame() {}
  48. // Initialize the game for the first time.
  49. virtual void Init() = 0;
  50. // Shut down the entire game.
  51. virtual void Shutdown() = 0;
  52. // Sets the serverinfo at map loads and when it changes.
  53. virtual void SetServerInfo( const idDict &serverInfo ) = 0;
  54. // Gets the serverinfo, common calls this before saving the game
  55. virtual const idDict & GetServerInfo() = 0;
  56. // Interpolated server time
  57. virtual void SetServerGameTimeMs( const int time ) = 0;
  58. // Interpolated server time
  59. virtual int GetServerGameTimeMs() const = 0;
  60. virtual int GetSSEndTime() const = 0;
  61. virtual int GetSSStartTime() const = 0;
  62. // common calls this before moving the single player game to a new level.
  63. virtual const idDict & GetPersistentPlayerInfo( int clientNum ) = 0;
  64. // common calls this right before a new level is loaded.
  65. virtual void SetPersistentPlayerInfo( int clientNum, const idDict &playerInfo ) = 0;
  66. // Loads a map and spawns all the entities.
  67. virtual void InitFromNewMap( const char *mapName, idRenderWorld *renderWorld, idSoundWorld *soundWorld, int gameMode, int randseed ) = 0;
  68. // Loads a map from a savegame file.
  69. virtual bool InitFromSaveGame( const char *mapName, idRenderWorld *renderWorld, idSoundWorld *soundWorld, idFile *saveGameFile, idFile *stringTableFile, int saveGameVersion ) = 0;
  70. // Saves the current game state, common may have written some data to the file already.
  71. virtual void SaveGame( idFile *saveGameFile, idFile *stringTableFile ) = 0;
  72. // Pulls the current player location from the game information
  73. virtual void GetSaveGameDetails( idSaveGameDetails & gameDetails ) = 0;
  74. // Shut down the current map.
  75. virtual void MapShutdown() = 0;
  76. // Caches media referenced from in key/value pairs in the given dictionary.
  77. virtual void CacheDictionaryMedia( const idDict *dict ) = 0;
  78. virtual void Preload( const idPreloadManifest &manifest ) = 0;
  79. // Runs a game frame, may return a session command for level changing, etc
  80. virtual void RunFrame( idUserCmdMgr & cmdMgr, gameReturn_t & gameReturn ) = 0;
  81. // Makes rendering and sound system calls to display for a given clientNum.
  82. virtual bool Draw( int clientNum ) = 0;
  83. virtual bool HandlePlayerGuiEvent( const sysEvent_t * ev ) = 0;
  84. // Writes a snapshot of the server game state.
  85. virtual void ServerWriteSnapshot( idSnapShot & ss ) = 0;
  86. // Processes a reliable message
  87. virtual void ProcessReliableMessage( int clientNum, int type, const idBitMsg &msg ) = 0;
  88. virtual void SetInterpolation( const float fraction, const int serverGameMS, const int ssStartTime, const int ssEndTime ) = 0;
  89. // Reads a snapshot and updates the client game state.
  90. virtual void ClientReadSnapshot( const idSnapShot & ss ) = 0;
  91. // Runs prediction on entities at the client.
  92. virtual void ClientRunFrame( idUserCmdMgr & cmdMgr, bool lastPredictFrame, gameReturn_t & ret ) = 0;
  93. // Used to manage divergent time-lines
  94. virtual int GetTimeGroupTime( int timeGroup ) = 0;
  95. // Returns a list of available multiplayer game modes
  96. virtual int GetMPGameModes( const char *** gameModes, const char *** gameModesDisplay ) = 0;
  97. // Returns a summary of stats for a given client
  98. virtual void GetClientStats( int clientNum, char *data, const int len ) = 0;
  99. virtual bool IsInGame() const = 0;
  100. // Get the player entity number for a network peer.
  101. virtual int MapPeerToClient( int peer ) const = 0;
  102. // Get the player entity number of the local player.
  103. virtual int GetLocalClientNum() const = 0;
  104. // compute an angle offset to be applied to the given client's aim
  105. virtual void GetAimAssistAngles( idAngles & angles ) = 0;
  106. virtual float GetAimAssistSensitivity() = 0;
  107. // Release the mouse when the PDA is open
  108. virtual bool IsPDAOpen() const = 0;
  109. virtual bool IsPlayerChatting() const = 0;
  110. // Creates leaderboards for each map/mode defined.
  111. virtual void Leaderboards_Init() = 0;
  112. virtual void Leaderboards_Shutdown() = 0;
  113. // MAIN MENU FUNCTIONS
  114. virtual bool InhibitControls() = 0;
  115. virtual void Shell_Init( const char * filename, idSoundWorld * sw ) = 0;
  116. virtual void Shell_Cleanup() = 0;
  117. virtual void Shell_CreateMenu( bool inGame ) = 0;
  118. virtual void Shell_ClosePause() = 0;
  119. virtual void Shell_Show( bool show ) = 0;
  120. virtual bool Shell_IsActive() const = 0;
  121. virtual bool Shell_HandleGuiEvent( const sysEvent_t * sev ) = 0;
  122. virtual void Shell_Render() = 0;
  123. virtual void Shell_ResetMenu() = 0;
  124. virtual void Shell_SyncWithSession() = 0;
  125. virtual void Shell_UpdateSavedGames() = 0;
  126. virtual void Shell_SetCanContinue( bool valid ) = 0;
  127. virtual void Shell_UpdateClientCountdown( int countdown ) = 0;
  128. virtual void Shell_UpdateLeaderboard( const idLeaderboardCallback * callback ) = 0;
  129. virtual void Shell_SetGameComplete() = 0;
  130. };
  131. extern idGame * game;
  132. /*
  133. ===============================================================================
  134. Public game interface with methods for in-game editing.
  135. ===============================================================================
  136. */
  137. typedef struct {
  138. idSoundEmitter * referenceSound; // this is the interface to the sound system, created
  139. // with idSoundWorld::AllocSoundEmitter() when needed
  140. idVec3 origin;
  141. int listenerId; // SSF_PRIVATE_SOUND only plays if == listenerId from PlaceListener
  142. // no spatialization will be performed if == listenerID
  143. const idSoundShader * shader; // this really shouldn't be here, it is a holdover from single channel behavior
  144. float diversity; // 0.0 to 1.0 value used to select which
  145. // samples in a multi-sample list from the shader are used
  146. bool waitfortrigger; // don't start it at spawn time
  147. soundShaderParms_t parms; // override volume, flags, etc
  148. } refSound_t;
  149. enum {
  150. TEST_PARTICLE_MODEL = 0,
  151. TEST_PARTICLE_IMPACT,
  152. TEST_PARTICLE_MUZZLE,
  153. TEST_PARTICLE_FLIGHT,
  154. TEST_PARTICLE_SELECTED
  155. };
  156. class idEntity;
  157. class idMD5Anim;
  158. // FIXME: this interface needs to be reworked but it properly separates code for the time being
  159. class idGameEdit {
  160. public:
  161. virtual ~idGameEdit() {}
  162. // These are the canonical idDict to parameter parsing routines used by both the game and tools.
  163. virtual void ParseSpawnArgsToRenderLight( const idDict *args, renderLight_t *renderLight );
  164. virtual void ParseSpawnArgsToRenderEntity( const idDict *args, renderEntity_t *renderEntity );
  165. virtual void ParseSpawnArgsToRefSound( const idDict *args, refSound_t *refSound );
  166. // Animation system calls for non-game based skeletal rendering.
  167. virtual idRenderModel * ANIM_GetModelFromEntityDef( const char *classname );
  168. virtual const idVec3 &ANIM_GetModelOffsetFromEntityDef( const char *classname );
  169. virtual idRenderModel * ANIM_GetModelFromEntityDef( const idDict *args );
  170. virtual idRenderModel * ANIM_GetModelFromName( const char *modelName );
  171. virtual const idMD5Anim * ANIM_GetAnimFromEntityDef( const char *classname, const char *animname );
  172. virtual int ANIM_GetNumAnimsFromEntityDef( const idDict *args );
  173. virtual const char * ANIM_GetAnimNameFromEntityDef( const idDict *args, int animNum );
  174. virtual const idMD5Anim * ANIM_GetAnim( const char *fileName );
  175. virtual int ANIM_GetLength( const idMD5Anim *anim );
  176. virtual int ANIM_GetNumFrames( const idMD5Anim *anim );
  177. virtual void ANIM_CreateAnimFrame( const idRenderModel *model, const idMD5Anim *anim, int numJoints, idJointMat *frame, int time, const idVec3 &offset, bool remove_origin_offset );
  178. virtual idRenderModel * ANIM_CreateMeshForAnim( idRenderModel *model, const char *classname, const char *animname, int frame, bool remove_origin_offset );
  179. // Articulated Figure calls for AF editor and Radiant.
  180. virtual bool AF_SpawnEntity( const char *fileName );
  181. virtual void AF_UpdateEntities( const char *fileName );
  182. virtual void AF_UndoChanges();
  183. virtual idRenderModel * AF_CreateMesh( const idDict &args, idVec3 &meshOrigin, idMat3 &meshAxis, bool &poseIsSet );
  184. // Entity selection.
  185. virtual void ClearEntitySelection();
  186. virtual int GetSelectedEntities( idEntity *list[], int max );
  187. virtual void AddSelectedEntity( idEntity *ent );
  188. // Selection methods
  189. virtual void TriggerSelected();
  190. // Entity defs and spawning.
  191. virtual const idDict * FindEntityDefDict( const char *name, bool makeDefault = true ) const;
  192. virtual void SpawnEntityDef( const idDict &args, idEntity **ent );
  193. virtual idEntity * FindEntity( const char *name ) const;
  194. virtual const char * GetUniqueEntityName( const char *classname ) const;
  195. // Entity methods.
  196. virtual void EntityGetOrigin( idEntity *ent, idVec3 &org ) const;
  197. virtual void EntityGetAxis( idEntity *ent, idMat3 &axis ) const;
  198. virtual void EntitySetOrigin( idEntity *ent, const idVec3 &org );
  199. virtual void EntitySetAxis( idEntity *ent, const idMat3 &axis );
  200. virtual void EntityTranslate( idEntity *ent, const idVec3 &org );
  201. virtual const idDict * EntityGetSpawnArgs( idEntity *ent ) const;
  202. virtual void EntityUpdateChangeableSpawnArgs( idEntity *ent, const idDict *dict );
  203. virtual void EntityChangeSpawnArgs( idEntity *ent, const idDict *newArgs );
  204. virtual void EntityUpdateVisuals( idEntity *ent );
  205. virtual void EntitySetModel( idEntity *ent, const char *val );
  206. virtual void EntityStopSound( idEntity *ent );
  207. virtual void EntityDelete( idEntity *ent );
  208. virtual void EntitySetColor( idEntity *ent, const idVec3 color );
  209. // Player methods.
  210. virtual bool PlayerIsValid() const;
  211. virtual void PlayerGetOrigin( idVec3 &org ) const;
  212. virtual void PlayerGetAxis( idMat3 &axis ) const;
  213. virtual void PlayerGetViewAngles( idAngles &angles ) const;
  214. virtual void PlayerGetEyePosition( idVec3 &org ) const;
  215. // In game map editing support.
  216. virtual const idDict * MapGetEntityDict( const char *name ) const;
  217. virtual void MapSave( const char *path = NULL ) const;
  218. virtual void MapSetEntityKeyVal( const char *name, const char *key, const char *val ) const ;
  219. virtual void MapCopyDictToEntity( const char *name, const idDict *dict ) const;
  220. virtual int MapGetUniqueMatchingKeyVals( const char *key, const char *list[], const int max ) const;
  221. virtual void MapAddEntity( const idDict *dict ) const;
  222. virtual int MapGetEntitiesMatchingClassWithString( const char *classname, const char *match, const char *list[], const int max ) const;
  223. virtual void MapRemoveEntity( const char *name ) const;
  224. virtual void MapEntityTranslate( const char *name, const idVec3 &v ) const;
  225. };
  226. extern idGameEdit * gameEdit;
  227. /*
  228. ===============================================================================
  229. Game API.
  230. ===============================================================================
  231. */
  232. const int GAME_API_VERSION = 8;
  233. typedef struct {
  234. int version; // API version
  235. idSys * sys; // non-portable system services
  236. idCommon * common; // common
  237. idCmdSystem * cmdSystem; // console command system
  238. idCVarSystem * cvarSystem; // console variable system
  239. idFileSystem * fileSystem; // file system
  240. idRenderSystem * renderSystem; // render system
  241. idSoundSystem * soundSystem; // sound system
  242. idRenderModelManager * renderModelManager; // render model manager
  243. idUserInterfaceManager * uiManager; // user interface manager
  244. idDeclManager * declManager; // declaration manager
  245. idAASFileManager * AASFileManager; // AAS file manager
  246. idCollisionModelManager * collisionModelManager; // collision model manager
  247. } gameImport_t;
  248. typedef struct {
  249. int version; // API version
  250. idGame * game; // interface to run the game
  251. idGameEdit * gameEdit; // interface for in-game editing
  252. } gameExport_t;
  253. extern "C" {
  254. typedef gameExport_t * (*GetGameAPI_t)( gameImport_t *import );
  255. }
  256. #endif /* !__GAME_H__ */