Game initialization: Difference between revisions
TomEdwards (talk | contribs) (Game loop) |
Islandstone (talk | contribs) m (clarified) |
||
Line 1: | Line 1: | ||
{{stub}} | {{stub}} | ||
The 'ignition circuit' of every Source game and mod is the file traditonally named '''<code><game>_client.cpp</code>'''. It contains several scopeless functions (i.e. not in a [[class]]) that are called when server.dll is loaded, when the world spawns, when a player connects, and so on. For obvious reasons there can only be one game_client.cpp in a project! | The 'ignition circuit' of every Source game and mod is the file traditonally named '''<code><game>_client.cpp</code>'''. It contains several scopeless functions (i.e. not in a [[class]]) that are called when server.dll is loaded, when the world spawns, when a player connects, and so on. One of its main purposes is to create a player entity for all connecting clients. For obvious reasons there can only be one game_client.cpp in a project! | ||
== Client.cpp functions == | == Client.cpp functions == |
Revision as of 04:31, 29 June 2009
The 'ignition circuit' of every Source game and mod is the file traditonally named <game>_client.cpp
. It contains several scopeless functions (i.e. not in a class) that are called when server.dll is loaded, when the world spawns, when a player connects, and so on. One of its main purposes is to create a player entity for all connecting clients. For obvious reasons there can only be one game_client.cpp in a project!
Client.cpp functions
Various console commands etc. that are processed on the server but only affect one player. Changing player model, saying things, god mode...
The code is shared between all games and mods, so don't put anything game-specific in here!
Game_client.cpp functions
The functions in _client.cpp are apparently called from within the engine, and as such must always be the same.
void ClientPutInServer()
void ClientActive()
- Called when a player connects and activates respectively. These functions define the C++ class used for players.
void respawn()
- Called by
ClientKill()
andDeadThink()
whenever a player dies. Spawns ragdolls in multiplayer, reloads the last saved game in singleplayer. const char* GetGameDescription()
- Returns the descriptive name of the .dll (e.g. Half-Life or Team Fortress 2).
CBaseEntity* FindEntity()
- Called when the !picker targetname is invoked.
void ClientGamePrecache()
- Precache function for the player. Todo: Why not use
CBasePlayer::Precache()
? void GameStartFrame()
- Entry point for game-specific code that needs to run once per frame. Use with caution.
void InstallGameRules()
- Decides which GameRules to use. Use
CreateGameRulesObject( string ClassName )
to do this.
Game loop
(Adapted from this report by James Gadbury)
CServerGameDLL::GameFrame()
GameStartFrame()
Physics_RunThinkFunctions()
- Runs the main physics simulation loop against all entities except playersPhysics_SimulateEntity(player)
CBasePlayer::PhysicsSimulate()
CBasePlayer::PlayerRunCommand()
-Todo: This appears to actually be called from somewhere within the engine.CPlayerMove::RunCommand()
CPlayerMove::StartCommand()
CBasePlayer::PreThink()
CBasePlayer::Think()
CPlayerMove::SetupMove()
- applies a usercmdCGameMovement::PlayerMove()
CGameMovement::FullWalkMove()
CPlayerMove::FinishMove()
CBasePlayer::PostThink()
CPlayerMove::FinishCommand()
IGameSystem::FrameUpdatePostEntityThinkAllSystems()
-Todo: call Think() on all non-player entities?g_pGameRules->EndGameFrame()