The platform layer is the foundation of Torque. Running at the lowest level, it provides a common cross platform, cross architecture interface to the system for the game. The platform layer is responsible for handling the details of file and network IO, graphics initialization, device initialization and input, and time event generation. Standard library calls are proxied through the platform layer, so that the game code can be safe from platform specific ideosyncracies.
System header files are (pretty much) only included from the platform library. The platform layer is broken up into several sections - the cross-platform interface exposed to the game (engine/platform), and the platform specific libraries (engine/platformWin32, engine/platformMacOS, engine/platformX86UNIX).
The game is driven by a stream of events from the platform library. By journaling the stream of events from the platform layer, the game portion of the simulation session can be deterministically replayed for debugging purposes.
The events used by the platform layer are all subclasses of Event:
- General Events
- Input Events
Torque has a number of powerful utility libraries in the platform layer:
- Memory Manager - Located in engine/platform/platformMemory.cc, this is designed to quickly allocate memory on cache aligned boundaries and perform debugging checks for overruns, multiple block frees and memory leaks.
- The Profiler is a hierarchal time analysis toolkit that allows specific portions of the game to be timed - useful for finding performance bottlenecks.
- Thread management Torque has utility classes for creating threads, mutexes and semaphores.
- Standard library All standard library functions are redefined as dFuncname, for example sprintf becomes dSprintf(), strcpy becomes dStrcpy(), etc. The dFunctions take full advantage of Torque's feature set, and are guaranteed to work in the same way across all platforms; the library functions they replace may not do so.
The platform library has a common interface for opening and closing network ports, connecting to other hosts, translating network addresses and sending and receiving network data. TCP and UDP are supported.
The GameInterface class, defined in engine/platform/gameInterface.h, is the interface through which the platform and libraries communicate with the game, as well as the main handler for journaling. All platform events are passed through GameInterface::processEvent(), which in turn feeds them to separate virtual event handlers. One and only one instance of this class (or a subclass) should exist in the program. A single global pointer named Game points to it.