Game Development Community

How to replicate a precompile without going through Torsion?

by Terence Tan · in Torsion · 07/15/2008 (2:21 am) · 3 replies

Been developing our automated build scripts, and one thing on my list is to figure out how to precompile all our scripts...

I know Torsion does it (from what I read on Tom's blog an alternate script is executed?)

#1
07/15/2008 (3:39 pm)
This is the precompile.cs file that torsion uses to.
// Start the console logger in a "open, write, close" mode.
setLogMode( 1 );

// PRECOMPILE_START
// PRECOMPILE_END

function onExit()
{
   // This is just here to keep the thing
   // from bitching... curious that it does
   // not appear in the function dump.
}

quit();

Not much in there... Torsion fills in a line for every file to compile between those comments, eg..

// PRECOMPILE_START 
compile( "C:/blablablab/file.cs" );
// PRECOMPILE_END

Torsion uses C++ file/director queries to find all .cs and .gui files in the project directory and puts a line like that in the precompile.cs file. Then torsion runs the engine executable with -precompile.cs which means to the engine, execute that script file on startup instead of the normal main.cs. Since main.cs does not get executed and precompile.cs calls quit() at the end, this effectively starts up the engine just to precompile these scripts and then closes it.
#2
07/15/2008 (4:19 pm)
Here's an excerpt from how I set a recent auto build script up.

I have a bash script that does all the dirty work such as grabbing the latest version from svn, updating build/version numbers in the various files, performing clean rebuilds of the dev and shipping exe's, remote build of the linux version, drm application, installer creation and so forth. As part of that process it runs compileScripts just after building the dev.exe

compileScripts( )
{
   # Does the dev build exe exist?
   if [ ! -f "example/Torque_DEV.exe" ] ; then
      echo "WARNING: Development build of YourGame not found."
      echo "         Unable to recompile shell scripts and dump UFT files."
      echo "Press enter to continue anyway (NOT RECOMMENDED)"
      read dummy
   fi

   # Clean DSO's
   find example/ -name "*.dso" -exec rm {} \;
   
   # Clean UTF Font Cache
   rm -f example/common/ui/cache/*.uft
   
   echo "Running game to perform Pre Build setup"   
   
   cd example
   ./Torque_DEV.exe -preBuild
   
   cd ${ROOT_DIR}
   echo "Pre Build Complete"
}

main.cs is then modified to accept the preBuild arg
// Hook into build process
      case "-preBuild":
         $preBuild = true;
         $argUsed[$i]++;

which is run at the very end of the main.cs file via

if ($PreBuild)
   preBuild();
else
   startupPhase1();

startupPhase1(); is just a function that does the usual setModPaths, loadMods($userMods), parse args, call onStart etc.

the preBuild function is as follows

function preBuild( )
{
   if (isusingBrowser())
   {
      error("Cannot perform Pre Build on browser version");
      quit();
   }
   if (isShippingBuild())
   {
      error("Cannot perform Pre Build on shipping version");
      quit();
   }
   
   echo("Performing PRE Build Startup");
   
   setModPaths("common;"@$userMods);

   // Make sure EVERYTHING is compiled before we continue
   %spec = "*.cs";
   // compile all matching cs files into dso's (if any)
   for (%file = findFirstFile(%spec); %file !$= ""; %file = findNextFile(%spec))
      compile(%file);   
      
   %spec = "*.gui";
   // compile all matching gui files into dso's (if any)
   for (%file = findFirstFile(%spec); %file !$= ""; %file = findNextFile(%spec))
      compile(%file);
   
   nextToken($userMods, currentMod, ";");

   loadMods($userMods);
   
   parseArgs();
   
   onStart();
   
   // dump font cache (we assume build scripts have cleared this folder
   populateAllFontCacheRange(1,128);
   writeFontCache();
   
   echo("Pre Build Complete, quitting");
   quit();
   
}

This ensures all profiles for the game are created and available prior to dumping out the uft cache.

As with most things Torque, there's probably a load more ways you can accomplish the same thing. One thing is for sure, having a good automated build script will save a lot of time and remove any chance of a mistake when making a late night build :)
#3
07/16/2008 (5:26 pm)
Cool,

Thanks guys...

Yeah I need to cleanup my build scripts a bit. I have it cleaning up after artists just in case (duh..let's leave a psd file in the asset directory...huh huh)....