Difference between revisions of "Game initialization:zn"

From Valve Developer Community
Jump to: navigation, search
(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...")
 
Line 3: Line 3:
 
}}
 
}}
 
{{stub}}
 
{{stub}}
 +
译者注:因个人翻译水平有限以及涉入SDK领域未深,大部分的翻译都尽量在通畅的前提下进行直译,部分内容保留不译是为了文章的连贯性,也希望能有人帮忙完善,我在此感谢你们!
  
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!
+
每个Source游戏和mods的The 'ignition circuit'是一般命名为 '''<code><game>_client.cpp</code>'''的文件。 它包括一些当sever.dll被加载,当世界生成或是一个玩家连接等情况调用的scopeless函数 (i.e. not in a [[class]]) 它的一个主要目的是为所有连接的客户端创建一个玩家实体。很明显,一个项目里只能有一个 game_client.cpp 文件!
  
== Custom <game>_client.cpp ==
+
== 自定义 <game>_client.cpp ==
Rather than modify hl2_client.cpp or hl2mp_client.cpp it is advised to create your own. The functions defined in this file are global functions so to create your own ''<game>_client.cpp'' simply copy the existing one and rename it and then exclude the old one for the build. (right click->properties->Exclude from build -- yes),
+
建议自己创建一个 <game>_client.cpp文件而不是修改hl2_client.cpp或者hl2mp_client.cpp。定义在该文件的函数是全局函数,所以为了创建你自己的 <game>_client.cpp文件,你只需复制上述两个文件中的一个并重命名,然后把旧的那个文件exclude for the build. (右击->属性->Exclude from build -- 确定),
  
== Client.cpp functions ==
+
== Client.cpp 函数 ==
  
Various console commands etc. that are processed on the server but only affect one player. Changing player model, [[say]]ing things, [[god]] mode...
+
许多在sever中处理的控制台命令等只能作用于一个玩家。 Changing player model, [[say]]ing things, [[god]] mode...
  
The code is shared between all games and mods, so don't put anything game-specific in here!
+
代码为所有游戏以及mods所共享,所以不要把任何game-specific放在这里!
  
== Game_client.cpp functions ==
+
== Game_client.cpp 函数 ==
  
The functions in _client.cpp are apparently called from within the engine, and as such must always be the same.
+
_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>
: Called when a player connects and [[Activate()|activates]] respectively. ''These functions define the C++ class used for players.''
+
: 当一个玩家连接并且分别激活的时候调用。''这些函数定义用于玩家的c++''
 
; <code>void respawn()</code>
 
; <code>void respawn()</code>
: Called by <code>ClientKill()</code> and <code>DeadThink()</code> whenever a player dies. Spawns ragdolls in multiplayer, reloads the last saved game in singleplayer.
+
: 当一个玩家死亡的时候由<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>
: Returns the descriptive name of the .dll (e.g. Half-Life or Team Fortress 2).
+
: 返回.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>
: Precache function for the player. {{todo|Why not use <code>CBasePlayer::Precache()</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>
: Decides which [[GameRules]] to use. Use <code>CreateGameRulesObject( [[string]] ClassName )</code> to do this.
+
: 决定使用哪条游戏规则。使用<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 against all entities except players
+
** <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|This appears to actually be called from somewhere within the engine.}}
+
**** <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:Programming]]
+
[[Category:编程]]

Revision as of 03:44, 14 September 2016

Deutsch

译者注:因个人翻译水平有限以及涉入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()
预缓存玩家的函数 To do: 为什么不使用 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() - To do: 它实际上是在引擎内的某处被调用
          • CPlayerMove::RunCommand()
            • CPlayerMove::StartCommand()
            • CBasePlayer::PreThink()
            • CBasePlayer::Think()
            • CPlayerMove::SetupMove() - applies a usercmd
              • CGameMovement::PlayerMove()
              • CGameMovement::FullWalkMove()
            • CPlayerMove::FinishMove()
            • CBasePlayer::PostThink()
            • CPlayerMove::FinishCommand()
    • IGameSystem::FrameUpdatePostEntityThinkAllSystems() - To do: call Think() on all non-player entities?
    • g_pGameRules->EndGameFrame()