Zh/Game initialization
< Zh
Jump to navigation
Jump to search
译者注:因个人翻译水平有限以及涉入SDK领域未深,大部分的翻译都尽量在通畅的前提下进行直译,部分内容保留不译是为了文章的连贯性,也希望能有人帮忙完善,我在此感谢你们!
每个Source游戏和mods的The 'ignition circuit'是一般命名为 <game>_client.cpp
的文件。 它包括一些当sever.dll被加载,当世界生成或是一个玩家连接等情况调用的scopeless函数 (i.e. not in a class) 它的一个主要目的是为所有连接的客户端创建一个玩家实体。很明显,一个项目里只能有一个 game_client.cpp 文件!
自定义 <game>_client.cpp
建议自己创建一个 <game>_client.cpp文件而不是修改hl2_client.cpp或者hl2mp_client.cpp。定义在该文件的函数是全局函数,所以为了创建你自己的 <game>_client.cpp文件,你只需复制上述两个文件中的一个并重命名,然后把旧的那个文件exclude for the build. (右击->属性->Exclude from build -- 确定),
Client.cpp 函数
许多在sever中处理的控制台命令等只能作用于一个玩家。 Changing player model, saying things, god mode...
代码为所有游戏以及mods所共享,所以不要把任何game-specific放在这里!
Game_client.cpp 函数
_client.cpp里的函数实际上是在引擎内被调用, and as such must always be the same.
void ClientPutInServer()
void ClientActive()
- 当一个玩家连接并且分别激活的时候调用。这些函数定义用于玩家的c++类
void respawn()
- 当一个玩家死亡的时候由
ClientKill()
和DeadThink()
调用。Spawns ragdolls in multiplayer, reloads the last saved game in singleplayer. const char* GetGameDescription()
- 返回.dll文件的the descriptive name (比如说半条命或者军团要塞2)。
CBaseEntity* FindEntity()
- Called when the !picker targetname is invoked.
void ClientGamePrecache()
- 预缓存玩家的函数 待完善: 为什么不使用
CBasePlayer::Precache() 呢?
? void GameStartFrame()
- Entry point for game-specific code that needs to run once per frame. Use with caution.
void InstallGameRules()
- 决定使用哪条游戏规则。使用
CreateGameRulesObject( string ClassName )
命令来达到这种目的。
Game loop
(Adapted from this report by James Gadbury)
CServerGameDLL::GameFrame()
GameStartFrame()
Physics_RunThinkFunctions()
- Runs the main physics simulation loop against所有实体,除了玩家实体。Physics_SimulateEntity(player)
CBasePlayer::PhysicsSimulate()
CBasePlayer::PlayerRunCommand()
-待完善: 它实际上是在引擎内的某处被调用CPlayerMove::RunCommand()
CPlayerMove::StartCommand()
CBasePlayer::PreThink()
CBasePlayer::Think()
CPlayerMove::SetupMove()
- applies a usercmdCGameMovement::PlayerMove()
CGameMovement::FullWalkMove()
CPlayerMove::FinishMove()
CBasePlayer::PostThink()
CPlayerMove::FinishCommand()
IGameSystem::FrameUpdatePostEntityThinkAllSystems()
-待完善: call Think() on all non-player entities?g_pGameRules->EndGameFrame()