Game Development Community

Batch build Torque project

by Gilberto Catarino · 11/20/2009 (4:23 pm) · 1 comments

After you integrate this resource you will be able to compile a full torque project via command line (eg. TGBGame.exe -build binPath MyGameName Windows 1).

So first of all there are some functions that we will need to expose from the engine source code, and these functions are located in the file "fileSystemFunctions.cpp". What you will have to do is copy those functions into the file "consoleFunctions.cpp" and rename its name from "ConsoleToolFunction" to "ConsoleFunction". Those functions are the following:
getWorkingDirectory()
createPath()
pathCopy()


Build the Release(TGBGame.exe) and Debug(TGBGame_DEBUG.exe) versions of the engine and move it to the project root path.

Then in project root path in file "main.cs", add the following code after the function "loadPath( %path )", make sure you remove a similar "parseArgs" function from "common/main.cs", so we don't have duplicated code.
//---------------------------------------------------------------------------------------------
// parseArgs
// Parses the command line arguments and processes those valid for this mod.
//---------------------------------------------------------------------------------------------
function parseArgs()
{
   // Let the parent grab the arguments it wants first.
   // Parent::parseArgs();

   // Loop through the arguments.
   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 "-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>");
               
         case "-build":
            $argUsed[%i]++;
            if (%hasNextArg) {
               BuildProject(%nextArg, $Game::argv[%i+2], $Game::argv[%i+3], $Game::argv[%i+4]);
            }else
               error("Error: Missing Command Line argument. Usage: -build <destination path> <product name> <platform> <show warnings>");
            
            return "build"; // After build will quit                      
            
      }
   }
}

function BuildProject(%outputDir, %productName, %platform, %showWarnings)
{
   %outputDir = strreplace(%outputDir, "", "/");  
   
   // make sure certain things are valid before performing the action
   %haveError = false;
   
   %haveError = %productName $= "";
   if (%haveError)
   {
      messageBox("Project Builder", "You must specify a product name!", "Ok", "Stop");
      return;
   }
   
   %haveError = %outputDir $= "";
   if (%haveError)
   {
      messageBox("Project Builder", "An invalid path was specified for the 'Output Directory'!", "Ok", "Stop");
      return;
   }
   
   
   //-----------------------------------------------------------------------------
   
   
   //%platform = ProjectBuilderPlatformList.getText();
   %includeGameScripts = false; // Don't want the source code to go along with it
   
   %binary["Windows"] = "exe";
   %binary["Mac"] = "app";
   %binary["Linux"] = "bin";
   %binary["Wii"] = "";
   
   %fileList["Windows"] = "glu2d3d.dll" TAB "opengl2d3d.dll" TAB "OpenAl32.dll" TAB "unicows.dll";
   %fileList["Mac"] = "";
   %fileList["Linux"] = "";
   %fileList["Wii"]= "";
   
   %gamePath = getWorkingDirectory() @ "/";
   
   // rdbnote: use the product name for the executable, etc., not the game path
   
   // Copy base game data.
   createPath(%outputDir @ "/");
 
   if (%binary[%platform] !$= "")
      pathCopy(%gamePath @ "TGBGame." @ %binary[%platform], %outputDir @ "/" @ %productName @ "." @ %binary[%platform], false);
   
   %fileCount = getFieldCount(%fileList[%platform]);
   for (%i = 0; %i < %fileCount; %i++)
   {
      %file = getField(%fileList[%platform], %i);
      pathCopy(%gamePath @%file, %outputDir @ "/" @ %file, false);
   }
   
   // Clean all DSO files
   deleteFiles("*.dso");
         
   // Compile all scripts
   compileFiles("*.cs");
   compileFiles("*.gui");
   compileFiles("*.t2d");

   // Copy the folders to the destination we want (all files will go wit it)
   pathCopy(%gamePath @ "/common", %outputDir @ "/common", false);
   pathCopy(%gamePath @ "/game", %outputDir @ "/game", false);
   pathCopy(%gamePath @ "/resources", %outputDir @ "/resources", false);
   pathCopy(%gamePath @ "/main.cs", %outputDir @ "/main.cs", false);
   
   // Delete source code from the destination folder
   deleteFiles(%outputDir @ "/common/*.cs");
   deleteFiles(%outputDir @ "/common/*.gui");
   deleteFiles(%outputDir @ "/game/*.cs");
   deleteFiles(%outputDir @ "/game/*.gui");
   deleteFiles(%outputDir @ "/game/*.t2d");
   deleteFiles(%outputDir @ "/resources/*.cs");
   deleteFiles(%outputDir @ "/resources/*.gui");
}

function compileFiles(%pattern)
{     
   for(%file = findFirstFile(%pattern); %file !$= ""; %file = findNextFile(%pattern))  
      compile(%file);     
}

function deleteFiles(%pattern)
{
   %path = filePath(%pattern);
   addresPath(%path);

   for (%file = findFirstFile(%pattern); %file !$= ""; %file = findNextFile(%pattern))
      fileDelete(%file);
      
   removeResPath(%path);
}


Then after "setLogMode(6)" add this to make sure it wont run the game in case of build.
if (parseArgs() $= "build")
{
   quit();
   return;
}

You can also edit the function "displayHelp()" in file "common/main.cs" to make it look like this:
function displayHelp() {
   // Let the parent do its stuff.
   Parent::displayHelp();

   error("Common Mod options:n" @
         "  -fullscreen            Starts game in full screen moden" @
         "  -windowed              Starts game in windowed moden" @
         "  -autoVideo             Auto detect video, but prefers OpenGLn" @
         "  -openGL                Force OpenGL accelerationn" @
         "  -directX               Force DirectX accelerationn" @
         "  -voodoo2               Force Voodoo2 accelerationn" @
         "  -prefs <configFile>    Exec the config filen" @
         "  -build <destination path> <product name> <platform> <show warnings> builds the projectn");
}

This resource was made for Torque Game Builder 1.7.4 but i think it is similar for other torque products.

You can test this directly on torison by going to project settings->Configuration and creating several profiles.
In my project i have "release/debug/build win/build wii", on the build profiles make sure to deselect "enable precompile" as it it not necessary.

I hope this resource will help you as it helped me.

Special thanks to William Lee Sims and my project College Felipe Cabedo for pointing me out crucial info on this.

About the author

Recent Blogs


#1
11/20/2009 (9:32 pm)
Very nice! I can see this as being very handy for making beta releases.