Getting Started with the Cafu Source Code
This text explains how you get and compile the Cafu source code.
Most steps that are explained below are only necessary once, when you get and compile the Cafu source code for the first time.
Getting the Source Code
This section explains how you initially get the Cafu source code. The Cafu source code can be obtained from a compressed archive or by checking it out from its Git repository.
Downloading a Compressed Archive
The easiest way to get the Cafu source code is to download a compressed archive for your platform from www.cafu.de/downloads.
The contents of the Windows (
zip) and Linux (
bz2) archives is the same (inclusive end-of-line style), but Linux users should still get the
bz2 archive type, as it properly sets the executable flags that are required for the build scripts.
Extract the archive contents into an arbitrary directory and you're ready for the next step.
Git Repository Access
Alternatively, you can also check out the Cafu source code directly from its Git repository.
Git is a version control system that allows the Cafu developers to work on their copy of the source code independently of each other, and to distribute the latest version of the source code to users and developers at any time. Moreover, many developers prefer to manage their project independently in their own version control system, but also wish to integrate the latest changes (e.g. bug-fixes and new features) from the official Cafu repository into theirs from time to time: Git makes the synchronization of the projects code with the original Cafu source code as convenient and automatic as possible.
You should prefer getting the source code from the repository over getting it from a compressed archive whenever possible: The code from the repository is always the latest and can easily be updated at any time. There is no better way to get and share new features and bug fixes conveniently and simple.
For Windows and many other systems, you can get Git from the Git downloads page. Popular Git clients with a graphical user interface are available at the Git downloads page as well.
With most Linux distributions, installing Git via the systems package manager is usually preferred. For example, under Ubuntu:
> sudo apt-get install git gitk
Then check out the source code at the command-line under Windows or Linux with this command:
> git clone https://bitbucket.org/cafu/cafu.git Cafu
Our Git project page is https://bitbucket.org/cafu/cafu, where you can browse the repository online, create forks, post pull requests, and find very good additional help.
Python and SCons
Cafu uses SCons as its software build system on all supported platforms.
SCons is a modern replacement for
SCons requires the Python scripting language to be installed,
so that you have to get and install both Python and SCons on your computer.
- first get and install Python 2.7 (not one of the newer, but backwards-incompatible 3.x editions!) from http://www.python.org/download/,
- then get and install SCons 2.3 (or any later version) from http://www.scons.org/download.php.
If in doubt, pick the Windows installers for both Python 2.7 and SCons 2.3: they are easy to use, lightweight, and automatically setup the proper environment variables.
- Pick the 32-bit edition of Python even on 64-bit systems! (Unfortunately, SCons does not yet work with the 64-bit builds of Python.) That is, python-2.7.5.msi is the right file for all Windows systems.
- On Windows Vista, 7 and 8, run the SCons installer via right-click, then select “Run as administrator”.
That is normally all, but you may wish to check if the Python installer added Python's
Scripts directory to the
PATH environment variable of your system.
For example, if Python was installed in
PATH should contain both
Otherwise, you have to add the proper directories manually: See http://support.microsoft.com/kb/310519 and http://vlaurie.com/computers2/Articles/environment.htm for additional information.
In order to verify that everything is working correctly, open a new command prompt and enter
> scons -v SCons by Steven Knight et al.: script: v2.3.0, 2013/03/03 09:48:35, by garyo on reepicheep engine: v2.3.0, 2013/03/03 09:48:35, by garyo on reepicheep engine path: ['C:\\Python27\\Scripts\\..\\Lib\\site-packages\\scons-2.3.0\\SCons'] Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 The SCons Foundation
The report of the SCons version indicates that both Python and SCons are ready for use. Please make sure that you use SCons version 2.3 or newer, older versions don't work!
Under Linux, just use the systems package manager in order to install SCons. The package manager will automatically install SCons and all software that SCons depends on, such as Python. For example, under Ubuntu:
> sudo apt-get install scons
This section lists additional software packages that must be installed on a Linux system before the Cafu source code can be compiled.
On a fresh, newly installed Ubuntu 8.04 (Hardy Heron) system, you'll additionally need the following packages.
They can be installed at the command prompt with the
apt-get install command, or via the easy to use “Synaptic Package Manager”.
Similar packages and package management systems also exist on RedHat Linux, SuSE, etc., where you can proceed analogously.
- A graphics driver with 3D hardware acceleration (the right driver is usually auto-detected and installed by the “Driver Manager”).
- build-essential – The compiler and basic tools required to compile C and C++ programs.
- libgtk2.0-dev – Developer files for GTK 2.0, needed for building wxGTK.
- libgl1-mesa-dev and libglu1-mesa-dev – OpenGL developer files, needed for building wxGTK and the Cafu rendering subsystem.
- libasound2-dev – ALSA developer files, needed for building OpenAL-Soft.
Make sure that when you're done, all packages from the list and their dependencies are installed on your Linux system.
Cafu can be compiled as 32-bit and 64-bit software on all platforms. The following compilers are supported:
| Visual C++ 2012|
Visual C++ 2010
Visual C++ 2008
|You can use the free Express Editions with Cafu. They are available at http://www.microsoft.com/express/vc/ and automatically install the related Microsoft Windows SDK.|
|Visual C++ 2005||Also suitable for Cafu in its free Express Edition. However, unlike the newer 2010 or 2008 versions, note that the Microsoft Windows SDK must be installed from a separate download in another step.|
|g++ 4.x||The famous GNU Compiler Collection with its C++ front-end, available on any Linux system.|
These are just the compilers that we regularly use here at CFS, other compilers should work as well. As the Cafu source code is very portable, compilers that are sufficiently standards compliant can be employed without further ado.
The compiler setup is fully automatic: No action is required in this step, and you can directly proceed to the next.
Optionally, if you want to change the default settings now or later, here is an overview of how it works:
- When SCons is run in the next step, it first determines if file
Cafu/CompilerSetup.pyalready exists. If it doesn't (e.g. when you do this for the first time), it automatically creates the file as a copy of
- Alternatively, you can also copy
Cafu/CompilerSetup.pymanually. This is only required once, and only if you want to edit
Cafu/CompilerSetup.pybefore SCons is run for the first time.
- You can edit
Cafu/CompilerSetup.pyin order to set the compiler and tools that are used to build Cafu, and to set the target architecture (such as
x86_64) that it is build for. Each setting is well documented, so you should have no problems to make the desired changes.
The default settings automatically determine the latest installed compiler and the current architecture, so in most cases the file works out-of-the-box and you have to change nothing at all. Also if you have doubts about the right settings, just continue and use the file as-is.
When you do this for the first time, we recommend that you don't bother with
Cafu/CompilerSetup.py at all. Just let the automatisms determine the settings, and come back here later if desired or required.
64-bit Windows with Visual C++ 2010 or 2012 Express Editions
On 64-bit Windows systems, SCons tries to find a 64-bit compiler, but Visual C++ 2010 Express Edition comes with a 32-bit compiler only. To tell SCons to use the 32-bit compiler instead, please edit file
Cafu/CompilerSetup.py as described here.
Even though the Visual C++ 2012 Express Edition is supposed to come with a 64-bit compiler, at this time unforunately the same edits must be done for it as well.
Compiling the Source Code
You are now ready compile the Cafu source code.
At the command prompt, change into the top-level
Cafu directory (where also the files
SConstruct are), then type:
This will start the compilation. When you do this for the first time, be prepared that it will take a while: Everything is being built from scratch, once for the debug and once for the release build. (When you repeat the same command in the future, e.g. after source code changes or updates, only the minimum set of files will be rebuilt and the entire process will complete much faster.)
Under Linux, if you have a multi-core system, you can speed this up by having several build jobs run in parallel:
> scons -j N
where N is the maximum number of jobs to start simultaneously. For example, try
-j 4 on a quad-core machine.
Adding Binary Assets
You may use the time while the build process is running to download some supplemental files. These files are not strictly required, but will help you with trying out the newly compiled programs as described below.
We recommend that you download and extract the following files:
Note that although these files are zip archives, they are for use on all platforms (Windows and Linux). With these files, you can immediately run the Cafu engine and see some example worlds when the compilation has finished.
Running the new Programs
When the SCons script has finished, all Cafu programs have been built in several build variants, namely
debugvariant contains additional program information and no code optimizations, and is often used during development and for finding and fixing bugs.
releasevariant has program optimizations enabled in order to maximize the execution speed, and it contains no debug information. This variant is usually shipped to end users.
profilevariant is almost like the
releasevariant, but also contains some debug information in order to make it suitable for use with a performance profiler. This variant is not being built by default, you have to call SCons with the proper parameters or edit the
CompilerSetup.pyscript in order to activate
As all variants can be built for each compiler on each platform, the build process organizes the binaries in a directory hierarchy of the form
That is, if your compiler is Visual C++ 2008 (abbreviated as
vc9) and your platform is Windows (abbreviated as
win32), and you want to run the release variant of the new programs, then the related binaries are relative to the path
Another important consideration is that all programs assume the top-level
Cafu directory as their working directory.
Combining these facts provides you with several options on how you can run the new programs:
- Copy the programs of the platform, compiler and build variant of your choice from
Cafu/build/$platform/$compiler/$variant/…directly into the
Cafudirectory. This is what we do at CFS for the prepackaged binary releases, as end-users can then simply and directly double-click each executable in the Windows Explorer.
- Create a Windows link (
.lnk) or batch (
.bat) file in the proper working directory that calls the desired program in its original location.
- For developers, the most flexible and recommended approach is to run the program directly from the command prompt: First change the current working directory to
Cafu, then type the relative path to the desired program (TAB completion – also on Windows – proves to be a great help here!).
For example, running the debug version of CaWE under Windows looks like this (note that the example also shows the current working directory at the left, the actual command follows the
Running the release version of Cafu under Linux looks like this:
If you have downloaded the binary assets as instructed above, you can now run your self-compiled Cafu engine
build\win32\vc9\release\Ca3DE\Cafu.exe and enjoy one of the included demo levels!
Congratulations! When you get here, you have managed to successfully compile the Cafu source code and run the resulting binaries. You may now wish to familiarize yourself more completely with the world of Cafu.
One way to do this is to approach Cafu from a map designers perspective, for example by exploring the Cafu World Editor CaWE. CaWE is not only a map editor, it also contains the GUI editor, a font conversion tool, a materials viewer and a model editor. CaWE can also act as a bridge towards scripting: map scripting, GUI scripting, materials scripting and vegetation scripting are powerful features in Cafu, and it doesn't stop there!
Programmers should definitively have a look at the other sections in this chapter (At the Core: The Cafu Source Code), such as IDEs and Text Editors or Starting your own Game. If instead you prefer to dig into the source code right away – just pick your favorite piece of code, and start reading and hacking.
Consider Using the Autodesk FBX SDK in order to add support for several additional file formats in the Model Editor.
Or you just browse the files and folders in the
Cafu directory, and start with whatever you feel most attracted to.
In any case, if you have questions or comments, or if you need help, write us a message at the support forums at any time!