For this example build script, we are using Perforce and some additional software, specifically:
Before starting with the actual scripts, the computer that will function as the build server needs to be set up properly. The following steps need to be done:
The example build scripts provided in this book require the use of a so-called Diff software. In the examples provided here, we use the software Beyond Compare 3. The software can be downloaded from http://www.scootersoftware.com/download.php.
Of course, different types of software can be used and you will just need to adjust the appropriate portions of the build script. In order to follow the examples provided in this book, the free trial version of Beyond Compare 3 will be sufficient.
This section assumes that you have a physical build server and a VCS set up already. We will be using Perforce in our example build scripts, but you can easily adjust the scripts to use SVN, Git, or any other VCS instead.
The actual build script is rather long, so let's break it down into smaller sections and look at each section individually. To make it easier for you, the places in the script that you need to change and replace with your own folder names and project dependent settings will be pointed out in detail.
To write your own script, start by creating a new text file inside your build scripts folder and call it CreateBuild.bat
. Then edit it with a text editing program, such as Notepad++ and copy or type the script lines from this book. To make things easier, a text editor with syntax highlighting should be used.
The purpose of this first part of the script is just to print out some status information as follows:
Tip
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
These first six lines are simply clearing the console and printing the current time and date onto the screen (or into a logfile). Nothing is actually happening yet. You can safely delete and modify these lines as you like.
Printing out console output is always helpful as it gives some feedback as to where in the script the process currently is. A full build on a regular PC can take over an hour, depending on the amount of assets that need to be compiled. Knowing the current stage of the build process can be helpful to you.
These outputs will give you an insight on where your build failed if it was unsuccessful.
The next lines of the script focus on a general folder setup as follows:
The first command in this block of code sets the drive that the build scripts and work in progress folder for the build will be located in; in our case, this is the G drive. You will need to adjust this to the drive that your temporary build folder is located in (as set in BuildWorkPath
).
The next four lines set the folder paths that are relevant for the build server. You will need to adjust each of these to point to your own folders.
BuildBotPath
should point to the folder that contains the build scripts, the preceding script included. The script will need to call helper scripts and expects these to be located in this folder. Specifying a script path at the beginning of the script makes it easy to create custom versions of the build scripts for different projects on the same server.
BuildSourcePath
is the path to where the local repository of the project is located on the hard disk of the build server. In case the build server is also used as a work machine, this should not be the path to the local work directory. The build bot should have its own login and local work directory for the versioning system.
BuildWorkPath
is a temporary folder that is only used for copying and compiling the build. After it is done, it will be moved to a final target folder. This folder is usually shared on a network drive. The move to the final folder doesn't happen until the entire build script is done, to avoid users copying down unfinished builds.
BuildTargetPath
is the final target folder for the build. This will be autogenerated from the project name and the current date. If you are planning on having more than one build per day, you could consider adding a time stamp to the folder. This autogenerated folder name will make sorting the builds by date very simple.
Lastly, you will need to provide the installation locations for Beyond Compare 3, WinRar, and Visual Studio, in the variables VisualStudioPath
, VisualStudioPath
, and WinRarPath
respectively.
Getting the latest files from your version control
Now, it's time to update the code and assets from Perforce as follows:
In this part of the script, you will need to replace everything that is printed in CAPITAL letters with your own version control data. The //PROJECTNAME/
term in the fourth line is the depot path of your repository that you want to retrieve. If you have chosen SVN or Git as your version control software, you will need to replace the appropriate calls.
If you are using your PC as a work station and build server simultaneously, and have more than one workspace mapped to the same machine, you might need to change the lines to the following, since the environment variables will probably not be set to the build server's user and workspace. This also applies if you don't have a password set up for your build bot user, as follows:
Now it is time to copy all the relevant data into the temporary work folder and compile it. This folder might or might not exist yet. If it does, it needs to be cleared first so that no old data mixes with the new clean build as follows:
Next, the data can be copied from the local repository folder to the work folder as follows:
This bit of the script calls upon
Beyond Compare, a folder diff tool, to copy the build into the work folder. This is done because not all of the files from the repository are required for the build. Source assets, for example, Photoshop, 3ds Max, or ZBrush files need to be removed. These files are commonly rather large and would unnecessarily bloat up the build size. Also, the build server's task is to create release candidates, and source assets are usually not shipped.
Beyond Compare 3 can filter out all files that are not desired in the final released build. The script bundle available for download with this book includes a script that filters out the most common source asset types. The script is called CopyBuildScript.txt
and is called upon in the preceding script block.
If Beyond Compare 3 is installed in a different location on your computer, you will need to adjust the path to BComp.com
in the script. If you are using a different folder diff tool, you can replace this part completely with the appropriate calls to your tool.
Another function the script performs is to remove the read-only flag on all copied files. Many version control systems such as Perforce set a read-only flag on all files in the local repository unless they are checked out, and the script takes care of this. The files need to be writable so that build script can compile, pack, and delete files later.
Now the code can finally be compiled as follows:
The first half of this script block creates a subfolder within the build folder to store the logfiles in. This is optional but can be very useful if there are any compilation errors for either code or assets. It is a good first place to start looking in when a build fails.
Next, the command-line version of the Visual Studio compiler is called upon to compile the first 64-bit and then 32-bit of the project.
Then, the path to the Visual Studio installation is set to the default installation location. If your Visual Studio is installed in a different directory, you will need to adjust this path.
You will also need to replace the CryEngine.sln
filename with your own solution filename should you change it.
Logfiles will be saved to the Logfiles
subfolder. The FreeSDK
release solution file is usually named differently than the full source release.
Tip
At the time of writing this book, the default solution file for the CryENGINE release requires the Visual Studio 2010 compilers. Future releases of CryENGINE might require Visual Studio 2012 or up. You will need to adjust the folder path in this case.
Compiling the code will create temporary files, such as for example *.pdb files containing debug information. These files need to be removed as they should not be part of a release candidate. They would increase the build size and could potentially be used to reverse engineer your code.
The following part of our build script will remove these files and folders:
These instructions are for a full source build of CryENGINE. If only the game code is compiled, the lines concerning Cry Action can be removed.
Tip
Instead of deleting the map and pdb
files, you can also choose to archive them somewhere on your server. This will allow you to track down crashes that are reported from your end users, if they submit you a callstack.
The code is compiled now, so it is time to take care of the assets as follows:
The preceding line makes several calls to the resource compiler located by default in the RC
folder under Bin32
, shipped with any version of CryENGINE, to compile the assets. The resource compiler's output will be piped into a separate text file inside the Logfiles
folder. Asset compilation will run over all data files (geometry, images, and so on) and process it. For images, this means compiling and converting them into platform specific and optimized .DDS
files.
The XML file that contains the job description is provided with the CryENGINE build. However, if you have changed your default game folder from GameSDK
to a folder of a different name, you will need to open the RCJob_Build_SDK_no_scripts.xml
file in a text editor and adjust the folder name in the default properties at the top of the file.
This step in the build process usually takes the longest. Using a build server with multiple CPU cores can significantly speed up the process. While giving a definitive speed advantage, multiple threads will create a less detailed log output. To get a log entry for every asset that was processed and error codes, remove the parameters /threads=cores /processes=cores
from the call in the preceding script.
Tip
To get a list of all the console parameters for the resource compiler in a text file, type ./Bin32/RC/rc.exe /help > RCCommands.txt
in the console in the build's root folder. It will create a file RCCommands.txt
in the root, containing documentation for each parameter.
For projects that create automated builds several times a day, it is sensible to create a separate build script that will only compile the code and copy the already compiled assets from the last build into it, for a faster turnaround time.
After all assets are processed by the resource compiler, the now duplicate .TIF
file can be removed as follows:
After the processing of the assets, the resource compiler will have created a DDS
file for all .TIF
files it could find in the directories. The .TIF
files are considered source files and should not be shipped to end users. They are also usually rather large and would unnecessarily bloat up the build. The Python script delete_redundant_tifs.py
traverses through the game folder and its subfolders and removes all those .TIF
files that have a corresponding .DDS
file. This script is included in the script bundle available for download and requires Python to run.
After this clean-up step, the assets need to be compressed into PAK
files:
PAK
files are simple ZIP files with a different ending. Common compression software, such as WinRAR and 7-Zip can open and create these files. In this example, we will use WinRAR to create the PAK
files.
After each PAK
file is created, the source folders are deleted with the rmdir
commands. This setup will create five different PAK
files, combining the various folders into easily shippable containers.
Tip
It is possible to let the resource compiler compile the assets and create the PAK
files automatically by using a job XML configuration file. Most CryENGINE releases ship with one or more example job XML files inside the RC
folder under Bin32
.
These example files usually need to be heavily modified before it will work for custom builds. The names and contents of these files change with each release so they are not used in this build script example to prevent version conflicts.
After this has finished, the source code can be either packed or removed as follows:
The zipped code should of course not be shipped to end users. However, it can be useful to keep the code that was used for compilation as part of the build inside the internal build archive. It sometimes becomes necessary during production to use an older build, for example, for demonstrations or for bug hunting. In these cases, it can be extremely useful to be able to access the code used for the creation of the build quickly and without version control hassle.
After this last step, the build is finished. It can now be moved to the target location, usually on a shared network drive, as follows:
The build script developed in this chapter is by no means the single and only way to create CryENGINE builds. This should serve as base line to get you started. During the development of your project, you will most likely want to extend and customize the build scripts to better suit your needs.