As you may recall from earlier chapters, the common code base is treated as if it was just another add-on or Mod. It is implemented as a package in the common/main.cs module. For your game you will need to use this package or make your own like it. This is in order to gain access to many of the more mundane features of Torque, especially the "administrivia"-like functions that help make your game a finished product but that are not especially exciting in terms of game play features.
Here are the contents of the common/main.cs module.
//----------------------------------------------------------------------------- // Torque Game Engine // Copyright (C) GarageGames.com, Inc. //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Load up default console values. Exec("./defaults.cs"); //----------------------------------------------------------------------------- function InitCommon() { // All mods need the random seed set SetRandomSeed(); // Very basic functions used by everyone Exec("./client/canvas.cs"); Exec("./client/audio.cs"); } function InitBaseClient() { // Base client functionality Exec("./client/message.cs"); Exec("./client/mission.cs"); Exec("./client/missionDownload.cs"); Exec("./client/actionMap.cs"); Exec("./editor/editor.cs"); Exec("./client/scriptDoc.cs"); // There are also a number of support scripts loaded by the canvas // when it's first initialized. Check out client/canvas.cs } function InitBaseServer() { // Base server functionality Exec("./server/audio.cs"); Exec("./server/server.cs"); Exec("./server/message.cs"); Exec("./server/commands.cs"); Exec("./server/missionInfo.cs"); Exec("./server/missionLoad.cs"); Exec("./server/missionDownload.cs"); Exec("./server/clientConnection.cs"); Exec("./server/kickban.cs"); Exec("./server/game.cs"); } //----------------------------------------------------------------------------- package Common { function DisplayHelp() { Parent::DisplayHelp(); Error( "Common Mod options:\n"@ " -fullscreen Starts game in full screen mode\n"@ " -windowed Starts game in windowed mode\n"@ " -autoVideo Auto detect video, but prefers OpenGL\n"@ " -openGL Force OpenGL acceleration\n"@ " -directX Force DirectX acceleration\n"@ " -voodoo2 Force Voodoo2 acceleration\n"@ " -noSound Starts game without sound\n"@ " -prefs <configFile> Exec the config file\n" ); } function ParseArgs() { Parent::ParseArgs(); // Arguments override defaults... for (%i = 1; %i < $Game::argc ; %i++) { %arg = $Game::argv[%i]; %nextArg = $Game::argv[%i+1]; %hasNextArg = $Game::argc - %i > 1; switch$ (%arg) { //-------------------- case "-fullscreen": $pref::Video::fullScreen = 1; $argUsed[%i]++; //-------------------- case "-windowed": $pref::Video::fullScreen = 0; $argUsed[%i]++; //-------------------- case "-noSound": error("no support yet"); $argUsed[%i]++; //-------------------- case "-openGL": $pref::Video::displayDevice = "OpenGL"; $argUsed[%i]++; //-------------------- case "-directX": $pref::Video::displayDevice = "D3D"; $argUsed[%i]++; //-------------------- case "-voodoo2": $pref::Video::displayDevice = "Voodoo2"; $argUsed[%i]++; //-------------------- case "-autoVideo": $pref::Video::displayDevice = ""; $argUsed[%i]++; //-------------------- case "-prefs": $argUsed[%i]++; if (%hasNextArg) { Exec(%nextArg, true, true); $argUsed[%i+1]++; %i++; } else Error("Error: Missing Command Line argument. Usage: -prefs <path/script.cs>"); } } } function OnStart() { Parent::OnStart(); Echo("\n--------- Initializing MOD: Common ---------"); InitCommon(); } function OnExit() { Echo("Exporting client prefs"); Export("$pref::*", "./client/prefs.cs", False); Echo("Exporting server prefs"); Export("$Pref::Server::*", "./server/prefs.cs", False); BanList::Export("./server/banlist.cs"); OpenALShutdown(); Parent::OnExit(); } }; // Common package activatePackage(Common);
Two key things that happen during game initialization are calls to InitBaseServer and InitBaseClient, both of which are defined in common/main.cs. These are critical functions, and yet their actual activities are not that exciting to behold.
function InitBaseServer() { Exec("./server/audio.cs"); Exec("./server/server.cs"); Exec("./server/message.cs"); Exec("./server/commands.cs"); Exec("./server/missionInfo.cs"); Exec("./server/missionLoad.cs"); Exec("./server/missionDownload.cs"); Exec("./server/clientConnection.cs"); Exec("./server/kickban.cs"); Exec("./server/game.cs"); } function InitBaseClient() { Exec("./client/message.cs"); Exec("./client/mission.cs"); Exec("./client/missionDownload.cs"); Exec("./client/actionMap.cs"); Exec("./editor/editor.cs"); Exec("./client/scriptDoc.cs"); }
As you can see, both are nothing more than a set of script loading calls. All of the scripts loaded are part of the common code base. We will look at selected key modules from these calls in the rest of this section.