Basic Control Flow

Introduction

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/winWindow.cc, 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/main.cc 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 main.cc 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/game.cc)
  2. Checks for server network packet sends (serverNetProcess() in engine/game/netDispatch.cc)
  3. Advances simulation event time (Sim::advanceTime() in engine/console/simManager.cc)
  4. Processes time for client objects (clientProcess() in engine/game/game.cc)
  5. Checks for client network packet sends (clientNetProcess() in engine/game/netDispatch.cc)
  6. Renders the current frame (GuiCanvas::render() in engine/gui/guiCanvas.cc)
  7. Checks for network timeouts (dispatchCheckTimeouts() in engine/game/netDispatch.cc)

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