Core Game Loop

The worldserver executable has three primary phases: initialization, game loop, shutdown and then additionally a crash handler procedure. The execution flow of the primary phases are relatively straightforward, while the crash handler is a special procedure that is only called when something goes wrong.

Initialization

The initialization is handled through primarily two functions, main and World::SetInitialWorldSettings, which themselves call tons of other smaller functions for initializing specific subsystems.

Game Loop

The main game loop is the phase that handles what happens to the world as players enter it, reacting to network packets, moving entities around, executing combat and so on.

The game loop is itself divided into three primary phases:

  • Early Updates: Various global things like cleanup, who lists etc.
  • Map Updates: Updates individual maps (Kalimdor, Eastern Kingdoms, Outland, Instances, Battlegrounds etc)
    • Primary Map Updates: Multithreaded, where almost all game logic happens
    • Delayed Map Updates: Single-threaded, handles minor things like moving transports and cross-map spells
  • Late Updates: Handles various things like groups, guilds and channels.

Callstack outline

This is an outline of some of the most important functions involved in the game loop. The call stack is not exact, but is mostly meant to allow easily visualize roughly in what orders things happen in the server.

Multithreading

The primary use of multithreading that is relevant to most developers is the worker threads handling map updates, but these are not the only instances of threading in the core.

Threads are also used to handle various other things in parallel to the primary game loop such as:

  • Network connections / Packet handlers
  • Database queries and utility
  • Freeze detection
  • Crash handling

Developers usually do not need to worry about these the way they need to worry about threaded map updates unless they stumble into them, primarily relating to database connections.