Zh/Game initialization: Difference between revisions
< Zh
Jump to navigation
Jump to search
Kalenclark (talk | contribs) (Created page with "{{otherlang2 |de=Game_initialization:de }} {{stub}} The 'ignition circuit' of every Source game and mod is the file traditonally named '''<code><game>_client.cpp</code>'''. I...") |
Kalenclark (talk | contribs) No edit summary |
||
| Line 3: | Line 3: | ||
}} | }} | ||
{{stub}} | {{stub}} | ||
译者注:因个人翻译水平有限以及涉入SDK领域未深,大部分的翻译都尽量在通畅的前提下进行直译,部分内容保留不译是为了文章的连贯性,也希望能有人帮忙完善,我在此感谢你们! | |||
每个Source游戏和mods的The 'ignition circuit'是一般命名为 '''<code><game>_client.cpp</code>'''的文件。 它包括一些当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 | == Client.cpp 函数 == | ||
许多在sever中处理的控制台命令等只能作用于一个玩家。 Changing player model, [[say]]ing things, [[god]] mode... | |||
代码为所有游戏以及mods所共享,所以不要把任何game-specific放在这里! | |||
== Game_client.cpp | == Game_client.cpp 函数 == | ||
_client.cpp里的函数实际上是在引擎内被调用, and as such must always be the same. | |||
; <code>void ClientPutInServer()</code> | ; <code>void ClientPutInServer()</code> | ||
; <code>void ClientActive()</code> | ; <code>void ClientActive()</code> | ||
: | : 当一个玩家连接并且分别激活的时候调用。''这些函数定义用于玩家的c++类'' | ||
; <code>void respawn()</code> | ; <code>void respawn()</code> | ||
: | : 当一个玩家死亡的时候由<code>ClientKill()</code>和<code>DeadThink()</code>调用。Spawns ragdolls in multiplayer, reloads the last saved game in singleplayer. | ||
; <code>[[const]] [[char]]* GetGameDescription()</code> | ; <code>[[const]] [[char]]* GetGameDescription()</code> | ||
: | : 返回.dll文件的the descriptive name (比如说半条命或者军团要塞2)。 | ||
; <code>[[CBaseEntity]]* FindEntity()</code> | ; <code>[[CBaseEntity]]* FindEntity()</code> | ||
: Called when the [[!picker]] targetname is invoked. | : Called when the [[!picker]] targetname is invoked. | ||
; <code>void ClientGamePrecache()</code> | ; <code>void ClientGamePrecache()</code> | ||
: | : 预缓存玩家的函数 {{todo|为什么不使用 <code>CBasePlayer::Precache() 呢?</code>?}} | ||
; <code>void GameStartFrame()</code> | ; <code>void GameStartFrame()</code> | ||
: Entry point for game-specific code that needs to run once per frame. Use with caution. | : Entry point for game-specific code that needs to run once per frame. Use with caution. | ||
; <code>void InstallGameRules()</code> | ; <code>void InstallGameRules()</code> | ||
: | : 决定使用哪条游戏规则。使用<code>CreateGameRulesObject( [[string]] ClassName )</code>命令来达到这种目的。 | ||
== Game loop == | == Game loop == | ||
| Line 41: | Line 42: | ||
* <code>CServerGameDLL::'''GameFrame()'''</code> | * <code>CServerGameDLL::'''GameFrame()'''</code> | ||
** <code>'''GameStartFrame()'''</code> | ** <code>'''GameStartFrame()'''</code> | ||
** <code>'''Physics_RunThinkFunctions()'''</code> - Runs the main physics simulation loop | ** <code>'''Physics_RunThinkFunctions()'''</code> - Runs the main physics simulation loop against所有实体,除了玩家实体。 | ||
*** <code>'''Physics_SimulateEntity(player)'''</code> | *** <code>'''Physics_SimulateEntity(player)'''</code> | ||
**** <code>CBasePlayer::'''PhysicsSimulate()'''</code> | **** <code>CBasePlayer::'''PhysicsSimulate()'''</code> | ||
**** <code>CBasePlayer::'''PlayerRunCommand()'''</code> - {{todo| | **** <code>CBasePlayer::'''PlayerRunCommand()'''</code> - {{todo|它实际上是在引擎内的某处被调用}} | ||
***** <code>CPlayerMove::'''RunCommand()'''</code> | ***** <code>CPlayerMove::'''RunCommand()'''</code> | ||
****** <code>CPlayerMove::'''StartCommand()'''</code> | ****** <code>CPlayerMove::'''StartCommand()'''</code> | ||
| Line 58: | Line 59: | ||
** <code>g_pGameRules->'''EndGameFrame()'''</code> | ** <code>g_pGameRules->'''EndGameFrame()'''</code> | ||
[[Category: | [[Category:编程]] | ||
Revision as of 20:44, 13 September 2016
译者注:因个人翻译水平有限以及涉入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()