Usercmd: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
'''Usercmd''' (user command) is the player's input, for example the current keys pressed and current viewangle, which is sent to the server. By default it's sent 30 times per second ([[cl_cmdrate]]). It uses booleans to tell the server whether or not a specific variable has changed; if there has been no change, it doesn't send the new data.
'''CUserCmd''' ("user command") is the networkable representation of the player's input, including keys pressed and viewangle. By default, updates are sent from client to server at a rate of 30 per second ([[cl_cmdrate]]) in the form of delta-compressed usercmds. Delta compression and and decompression are handled in <code>WriteUsercmd</code> and <code>ReadUsercmd</code>.


== Code locations ==
== Production ==
Usercmds are created when the engine invokes <code>IInput::CreateMove</code>, and are stored in a circular buffer (<code>CInput::PerUserInput_t::m_pCommands</code>) until the engine invokes <code>IBaseClientDLL::WriteUsercmdDeltaToBuffer</code> to compress and serialize them to the server.


These need confirming.
During <code>CInput::CreateMove</code>, the current client mode is also given a chance to manipulate the newly created usercmd via <code>IClientMode::CreateMove</code>. The default implementation (<code>ClientModeShared::CreateMove</code>) delegates to the local player via <code>C_BasePlayer::CreateMove</code>, which in turn passes the usercmd to <code>CBaseCombatWeapon::CreateMove</code> on the active weapon.


#Input packaged in <code>client/c_baseplayer.cpp</code> and <code>client/c_basehlplayer.cpp</code> - look for <code>[[CreateMove()]]</code>.
== Consumption ==
#Class definition and data serialisation in <code>shared/usercmd.cpp</code>.
The incoming usercmds are consumed on the server when the engine invokes <code>IGameServerClients::ProcessUsercmds</code>. This method handles decompressing the delta usercmds, and then dispatches them to <code>CBasePlayer::ProcessUsercmds</code>. The player caches each such batch of commands together in a <code>CCommandContext</code> object to be processed later.
#Server execution performed from the various <code>[[RunCommand()]]</code> and <code>[[PlayerRunCommand()]]</code> functions.
 
Once <code>IServerGameDLL::GameFrame</code> is called, the player's <code>PhysicsSimulate</code> method executes the cached usercmds via <code>CBasePlayer::PlayerRunCommand</code>. From here, the active CPlayerMove-derived class executes (Pre/Post)Think for the player, as well as populating g_pMoveData and executing <code>IGameMovement::ProcessMovement</code> for the player.


== See also ==
== See also ==
* [[Client to Server Messages]]
* [[UserCmd strings]]


[[Category:Networking]]
[[Category:Networking]]
[[Category:Glossary]]
[[Category:Glossary]]

Revision as of 14:08, 7 October 2012

CUserCmd ("user command") is the networkable representation of the player's input, including keys pressed and viewangle. By default, updates are sent from client to server at a rate of 30 per second (cl_cmdrate) in the form of delta-compressed usercmds. Delta compression and and decompression are handled in WriteUsercmd and ReadUsercmd.

Production

Usercmds are created when the engine invokes IInput::CreateMove, and are stored in a circular buffer (CInput::PerUserInput_t::m_pCommands) until the engine invokes IBaseClientDLL::WriteUsercmdDeltaToBuffer to compress and serialize them to the server.

During CInput::CreateMove, the current client mode is also given a chance to manipulate the newly created usercmd via IClientMode::CreateMove. The default implementation (ClientModeShared::CreateMove) delegates to the local player via C_BasePlayer::CreateMove, which in turn passes the usercmd to CBaseCombatWeapon::CreateMove on the active weapon.

Consumption

The incoming usercmds are consumed on the server when the engine invokes IGameServerClients::ProcessUsercmds. This method handles decompressing the delta usercmds, and then dispatches them to CBasePlayer::ProcessUsercmds. The player caches each such batch of commands together in a CCommandContext object to be processed later.

Once IServerGameDLL::GameFrame is called, the player's PhysicsSimulate method executes the cached usercmds via CBasePlayer::PlayerRunCommand. From here, the active CPlayerMove-derived class executes (Pre/Post)Think for the player, as well as populating g_pMoveData and executing IGameMovement::ProcessMovement for the player.

See also