Basic Control Flow


Because different platforms can have different main() entry points for applications, the Torque Engine main() function resides in the target OS platform library. In the case of Windows, this is in file engine/platformWin32/, where both main() (for console apps) and WinMain() are defined. These in turn call run() which calls Game->main(int argc, const char **argv). Game is a global object pointer referencing an instance of the GameInterface class that can be overridden for specific game behavior.

The Torque example program's main initialization occurs in engine/game/ in DemoGame::main(). This function initializes libraries, initializes game functions and then cycles in the main game loop until the program is terminated. The main loop basically calls platform library functions (engine/platform/platform.h) to produce platform events, which then drive the main simulation.

The file also has DemoGame function overrides for some of the basic event procession functions: processMouseMoveEvent (which dispatches Windows mouse movements to the GUI), processInputEvent (which processes other input related events), and processTimeEvent which computes an elapsed time value based on the time scale setting of the simulation and then:

  1. Processes time for server objects (serverProcess() in engine/game/
  2. Checks for server network packet sends (serverNetProcess() in engine/game/
  3. Advances simulation event time (Sim::advanceTime() in engine/console/
  4. Processes time for client objects (clientProcess() in engine/game/
  5. Checks for client network packet sends (clientNetProcess() in engine/game/
  6. Renders the current frame (GuiCanvas::render() in engine/gui/
  7. Checks for network timeouts (dispatchCheckTimeouts() in engine/game/

Incoming UDP network packets are processed in DemoGame::processPacketReceiveEvent (defined in engine/game/, and incoming TCP connection data or information is processed in DemoGame::processConnected*Event (defined in engine/game/