Frame Order

From Valve Developer Community
Revision as of 18:31, 1 October 2009 by Vino (talk | contribs)
Jump to navigation Jump to search

This section is currently under construction. Please feel free to add any insights you may have into the structure of the Source engine that you would like to share with the community.

Introduction

This is the order in which systems are invoked for each engine frame.

Engine

The engine has two modes of execution, a threaded path and a non-threaded path. The host_thread_mode cvar determines which path is taken. Dedicated servers will ignore this cvar and always use the non-threaded path. XBox 360 runs in threaded mode by default, while PC runs in non-threaded mode by default. Threaded mode was introduced with the Orange Box version of the Source engine, and does not exist in Episode 1 or previous versions.

Listenservers (ie, singleplayer games, or multiplayer games hosted by one of the players) will run all sections of code, calling both client.dll and server.dll functions from the same thread and in the same engine loop. Clients connected to a remote server will run the italicized sections only, and dedicated servers will run the bold items only. Dedicated server builds (Linux or Windows SrcDs) will run only the underlined sections.

Legend:

  • Bold - Server code, occurs on any server engine, server-only or listenserver
  • Italics - Client code, occurs on any client engine, client-only or listenserver
  • Underline - Code path for a dedicated server (Non underline items do not run on a dedicated server.)


Non-threaded model

Threaded model

Sections

Console commands

This section evaluates and executes commands input into the game console. If the console command is a ConCommand created by the game code, it will execute a callback into the game code through ConCommand::Dispatch( const CCommand &command ) in convar.cpp.

Networking

This section sends and receives network messages. It runs on a localhost server through an internal backdoor loopback device. On server-only or client-only instances it runs over a UDP connection. No game code callbacks are made during this time.

Input

This section reads and processes input devices and messages. It runs only on client or localhost engines.

  • CHLClient::HudProcessInput()
  • Process console commands
  • Process player movement commands
    • CHLClient::CreateMove()
    • Queue movement commands to network to the server

Server game code

This section calls Think functions for each entity and processes game logic.

  • Read network input
  • For each plugin: IServerPluginCallbacks::GameFrame()
  • CServerGameDLL::GameFrame()
    • For each game system: FrameUpdatePreEntityThink()
    • GameRules::Think()
    • Physics simulations
      • For each players: CBasePlayer::PlayerRunCommand()
    • For each game system: FrameUpdatePostEntityThink()