Game.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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_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. typedef struct {
  32. char sessionCommand[MAX_STRING_CHARS]; // "map", "disconnect", "victory", etc
  33. int consistencyHash; // used to check for network game divergence
  34. int health;
  35. int heartRate;
  36. int stamina;
  37. int combat;
  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. } gameReturn_t;
  41. typedef enum {
  42. ALLOW_YES = 0,
  43. ALLOW_BADPASS, // core will prompt for password and connect again
  44. ALLOW_NOTYET, // core will wait with transmitted message
  45. ALLOW_NO // core will abort with transmitted message
  46. } allowReply_t;
  47. typedef enum {
  48. ESC_IGNORE = 0, // do nothing
  49. ESC_MAIN, // start main menu GUI
  50. ESC_GUI // set an explicit GUI
  51. } escReply_t;
  52. #define TIME_GROUP1 0
  53. #define TIME_GROUP2 1
  54. class idGame {
  55. public:
  56. virtual ~idGame() {}
  57. // Initialize the game for the first time.
  58. virtual void Init( void ) = 0;
  59. // Shut down the entire game.
  60. virtual void Shutdown( void ) = 0;
  61. // Set the local client number. Distinguishes listen ( == 0 ) / dedicated ( == -1 )
  62. virtual void SetLocalClient( int clientNum ) = 0;
  63. // Sets the user info for a client.
  64. // if canModify is true, the game can modify the user info in the returned dictionary pointer, server will forward the change back
  65. // canModify is never true on network client
  66. virtual const idDict * SetUserInfo( int clientNum, const idDict &userInfo, bool isClient, bool canModify ) = 0;
  67. // Retrieve the game's userInfo dict for a client.
  68. virtual const idDict * GetUserInfo( int clientNum ) = 0;
  69. // The game gets a chance to alter userinfo before they are emitted to server.
  70. virtual void ThrottleUserInfo( void ) = 0;
  71. // Sets the serverinfo at map loads and when it changes.
  72. virtual void SetServerInfo( const idDict &serverInfo ) = 0;
  73. // The session calls this before moving the single player game to a new level.
  74. virtual const idDict & GetPersistentPlayerInfo( int clientNum ) = 0;
  75. // The session calls this right before a new level is loaded.
  76. virtual void SetPersistentPlayerInfo( int clientNum, const idDict &playerInfo ) = 0;
  77. // Loads a map and spawns all the entities.
  78. virtual void InitFromNewMap( const char *mapName, idRenderWorld *renderWorld, idSoundWorld *soundWorld, bool isServer, bool isClient, int randseed ) = 0;
  79. // Loads a map from a savegame file.
  80. virtual bool InitFromSaveGame( const char *mapName, idRenderWorld *renderWorld, idSoundWorld *soundWorld, idFile *saveGameFile ) = 0;
  81. // Saves the current game state, the session may have written some data to the file already.
  82. virtual void SaveGame( idFile *saveGameFile ) = 0;
  83. // Shut down the current map.
  84. virtual void MapShutdown( void ) = 0;
  85. // Caches media referenced from in key/value pairs in the given dictionary.
  86. virtual void CacheDictionaryMedia( const idDict *dict ) = 0;
  87. // Spawns the player entity to be used by the client.
  88. virtual void SpawnPlayer( int clientNum ) = 0;
  89. // Runs a game frame, may return a session command for level changing, etc
  90. virtual gameReturn_t RunFrame( const usercmd_t *clientCmds ) = 0;
  91. // Makes rendering and sound system calls to display for a given clientNum.
  92. virtual bool Draw( int clientNum ) = 0;
  93. // Let the game do it's own UI when ESCAPE is used
  94. virtual escReply_t HandleESC( idUserInterface **gui ) = 0;
  95. // get the games menu if appropriate ( multiplayer )
  96. virtual idUserInterface * StartMenu() = 0;
  97. // When the game is running it's own UI fullscreen, GUI commands are passed through here
  98. // return NULL once the fullscreen UI mode should stop, or "main" to go to main menu
  99. virtual const char * HandleGuiCommands( const char *menuCommand ) = 0;
  100. // main menu commands not caught in the engine are passed here
  101. virtual void HandleMainMenuCommands( const char *menuCommand, idUserInterface *gui ) = 0;
  102. // Early check to deny connect.
  103. virtual allowReply_t ServerAllowClient( int numClients, const char *IP, const char *guid, const char *password, char reason[MAX_STRING_CHARS] ) = 0;
  104. // Connects a client.
  105. virtual void ServerClientConnect( int clientNum, const char *guid ) = 0;
  106. // Spawns the player entity to be used by the client.
  107. virtual void ServerClientBegin( int clientNum ) = 0;
  108. // Disconnects a client and removes the player entity from the game.
  109. virtual void ServerClientDisconnect( int clientNum ) = 0;
  110. // Writes initial reliable messages a client needs to recieve when first joining the game.
  111. virtual void ServerWriteInitialReliableMessages( int clientNum ) = 0;
  112. // Writes a snapshot of the server game state for the given client.
  113. virtual void ServerWriteSnapshot( int clientNum, int sequence, idBitMsg &msg, byte *clientInPVS, int numPVSClients ) = 0;
  114. // Patches the network entity states at the server with a snapshot for the given client.
  115. virtual bool ServerApplySnapshot( int clientNum, int sequence ) = 0;
  116. // Processes a reliable message from a client.
  117. virtual void ServerProcessReliableMessage( int clientNum, const idBitMsg &msg ) = 0;
  118. // Reads a snapshot and updates the client game state.
  119. virtual void ClientReadSnapshot( int clientNum, int sequence, const int gameFrame, const int gameTime, const int dupeUsercmds, const int aheadOfServer, const idBitMsg &msg ) = 0;
  120. // Patches the network entity states at the client with a snapshot.
  121. virtual bool ClientApplySnapshot( int clientNum, int sequence ) = 0;
  122. // Processes a reliable message from the server.
  123. virtual void ClientProcessReliableMessage( int clientNum, const idBitMsg &msg ) = 0;
  124. // Runs prediction on entities at the client.
  125. virtual gameReturn_t ClientPrediction( int clientNum, const usercmd_t *clientCmds, bool lastPredictFrame ) = 0;
  126. // Used to manage divergent time-lines
  127. virtual void SelectTimeGroup( int timeGroup ) = 0;
  128. virtual int GetTimeGroupTime( int timeGroup ) = 0;
  129. virtual void GetBestGameType( const char* map, const char* gametype, char buf[ MAX_STRING_CHARS ] ) = 0;
  130. // Returns a summary of stats for a given client
  131. virtual void GetClientStats( int clientNum, char *data, const int len ) = 0;
  132. // Switch a player to a particular team
  133. virtual void SwitchTeam( int clientNum, int team ) = 0;
  134. virtual bool DownloadRequest( const char *IP, const char *guid, const char *paks, char urls[ MAX_STRING_CHARS ] ) = 0;
  135. virtual void GetMapLoadingGUI( char gui[ MAX_STRING_CHARS ] ) = 0;
  136. };
  137. extern idGame * game;
  138. /*
  139. ===============================================================================
  140. Public game interface with methods for in-game editing.
  141. ===============================================================================
  142. */
  143. typedef struct {
  144. idSoundEmitter * referenceSound; // this is the interface to the sound system, created
  145. // with idSoundWorld::AllocSoundEmitter() when needed
  146. idVec3 origin;
  147. int listenerId; // SSF_PRIVATE_SOUND only plays if == listenerId from PlaceListener
  148. // no spatialization will be performed if == listenerID
  149. const idSoundShader * shader; // this really shouldn't be here, it is a holdover from single channel behavior
  150. float diversity; // 0.0 to 1.0 value used to select which
  151. // samples in a multi-sample list from the shader are used
  152. bool waitfortrigger; // don't start it at spawn time
  153. soundShaderParms_t parms; // override volume, flags, etc
  154. } refSound_t;
  155. enum {
  156. TEST_PARTICLE_MODEL = 0,
  157. TEST_PARTICLE_IMPACT,
  158. TEST_PARTICLE_MUZZLE,
  159. TEST_PARTICLE_FLIGHT,
  160. TEST_PARTICLE_SELECTED
  161. };
  162. class idEntity;
  163. class idMD5Anim;
  164. // FIXME: this interface needs to be reworked but it properly separates code for the time being
  165. class idGameEdit {
  166. public:
  167. virtual ~idGameEdit( void ) {}
  168. // These are the canonical idDict to parameter parsing routines used by both the game and tools.
  169. virtual void ParseSpawnArgsToRenderLight( const idDict *args, renderLight_t *renderLight );
  170. virtual void ParseSpawnArgsToRenderEntity( const idDict *args, renderEntity_t *renderEntity );
  171. virtual void ParseSpawnArgsToRefSound( const idDict *args, refSound_t *refSound );
  172. // Animation system calls for non-game based skeletal rendering.
  173. virtual idRenderModel * ANIM_GetModelFromEntityDef( const char *classname );
  174. virtual const idVec3 &ANIM_GetModelOffsetFromEntityDef( const char *classname );
  175. virtual idRenderModel * ANIM_GetModelFromEntityDef( const idDict *args );
  176. virtual idRenderModel * ANIM_GetModelFromName( const char *modelName );
  177. virtual const idMD5Anim * ANIM_GetAnimFromEntityDef( const char *classname, const char *animname );
  178. virtual int ANIM_GetNumAnimsFromEntityDef( const idDict *args );
  179. virtual const char * ANIM_GetAnimNameFromEntityDef( const idDict *args, int animNum );
  180. virtual const idMD5Anim * ANIM_GetAnim( const char *fileName );
  181. virtual int ANIM_GetLength( const idMD5Anim *anim );
  182. virtual int ANIM_GetNumFrames( const idMD5Anim *anim );
  183. virtual void ANIM_CreateAnimFrame( const idRenderModel *model, const idMD5Anim *anim, int numJoints, idJointMat *frame, int time, const idVec3 &offset, bool remove_origin_offset );
  184. virtual idRenderModel * ANIM_CreateMeshForAnim( idRenderModel *model, const char *classname, const char *animname, int frame, bool remove_origin_offset );
  185. // Articulated Figure calls for AF editor and Radiant.
  186. virtual bool AF_SpawnEntity( const char *fileName );
  187. virtual void AF_UpdateEntities( const char *fileName );
  188. virtual void AF_UndoChanges( void );
  189. virtual idRenderModel * AF_CreateMesh( const idDict &args, idVec3 &meshOrigin, idMat3 &meshAxis, bool &poseIsSet );
  190. // Entity selection.
  191. virtual void ClearEntitySelection( void );
  192. virtual int GetSelectedEntities( idEntity *list[], int max );
  193. virtual void AddSelectedEntity( idEntity *ent );
  194. // Selection methods
  195. virtual void TriggerSelected();
  196. // Entity defs and spawning.
  197. virtual const idDict * FindEntityDefDict( const char *name, bool makeDefault = true ) const;
  198. virtual void SpawnEntityDef( const idDict &args, idEntity **ent );
  199. virtual idEntity * FindEntity( const char *name ) const;
  200. virtual const char * GetUniqueEntityName( const char *classname ) const;
  201. // Entity methods.
  202. virtual void EntityGetOrigin( idEntity *ent, idVec3 &org ) const;
  203. virtual void EntityGetAxis( idEntity *ent, idMat3 &axis ) const;
  204. virtual void EntitySetOrigin( idEntity *ent, const idVec3 &org );
  205. virtual void EntitySetAxis( idEntity *ent, const idMat3 &axis );
  206. virtual void EntityTranslate( idEntity *ent, const idVec3 &org );
  207. virtual const idDict * EntityGetSpawnArgs( idEntity *ent ) const;
  208. virtual void EntityUpdateChangeableSpawnArgs( idEntity *ent, const idDict *dict );
  209. virtual void EntityChangeSpawnArgs( idEntity *ent, const idDict *newArgs );
  210. virtual void EntityUpdateVisuals( idEntity *ent );
  211. virtual void EntitySetModel( idEntity *ent, const char *val );
  212. virtual void EntityStopSound( idEntity *ent );
  213. virtual void EntityDelete( idEntity *ent );
  214. virtual void EntitySetColor( idEntity *ent, const idVec3 color );
  215. // Player methods.
  216. virtual bool PlayerIsValid() const;
  217. virtual void PlayerGetOrigin( idVec3 &org ) const;
  218. virtual void PlayerGetAxis( idMat3 &axis ) const;
  219. virtual void PlayerGetViewAngles( idAngles &angles ) const;
  220. virtual void PlayerGetEyePosition( idVec3 &org ) const;
  221. // In game map editing support.
  222. virtual const idDict * MapGetEntityDict( const char *name ) const;
  223. virtual void MapSave( const char *path = NULL ) const;
  224. virtual void MapSetEntityKeyVal( const char *name, const char *key, const char *val ) const ;
  225. virtual void MapCopyDictToEntity( const char *name, const idDict *dict ) const;
  226. virtual int MapGetUniqueMatchingKeyVals( const char *key, const char *list[], const int max ) const;
  227. virtual void MapAddEntity( const idDict *dict ) const;
  228. virtual int MapGetEntitiesMatchingClassWithString( const char *classname, const char *match, const char *list[], const int max ) const;
  229. virtual void MapRemoveEntity( const char *name ) const;
  230. virtual void MapEntityTranslate( const char *name, const idVec3 &v ) const;
  231. };
  232. extern idGameEdit * gameEdit;
  233. /*
  234. ===============================================================================
  235. Game API.
  236. ===============================================================================
  237. */
  238. const int GAME_API_VERSION = 8;
  239. typedef struct {
  240. int version; // API version
  241. idSys * sys; // non-portable system services
  242. idCommon * common; // common
  243. idCmdSystem * cmdSystem; // console command system
  244. idCVarSystem * cvarSystem; // console variable system
  245. idFileSystem * fileSystem; // file system
  246. idNetworkSystem * networkSystem; // network system
  247. idRenderSystem * renderSystem; // render system
  248. idSoundSystem * soundSystem; // sound system
  249. idRenderModelManager * renderModelManager; // render model manager
  250. idUserInterfaceManager * uiManager; // user interface manager
  251. idDeclManager * declManager; // declaration manager
  252. idAASFileManager * AASFileManager; // AAS file manager
  253. idCollisionModelManager * collisionModelManager; // collision model manager
  254. } gameImport_t;
  255. typedef struct {
  256. int version; // API version
  257. idGame * game; // interface to run the game
  258. idGameEdit * gameEdit; // interface for in-game editing
  259. } gameExport_t;
  260. extern "C" {
  261. typedef gameExport_t * (*GetGameAPI_t)( gameImport_t *import );
  262. }
  263. #endif /* !__GAME_H__ */