DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Game.h (14511B)


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