This is the sidebar
Welcome to the QuakeC programming introduction. This article is intended for people who already have their fair share of experience in other programming languages like Java or C/C++. As you know, there is already the QuakeC reference guide which gives you an overview of the language used in server-side and client-side quake code. You will actually need to read that page at some point. Anyways, this page will provide the following information:
To summarize this page: It explains how to setup an environment in which you can efficiently develop SVQC (server-side QC) and CSQC (client-side QC).
Keep in mind that this page does not provide coding tutorials. Some of these may be created another time at another place.
From the programming perspective, Nexuiz consists of two parts:
The game engine provides the capability to run a dedicated (console-only) server as well as acting as a client (which you use to play the game). As you know, DarkPlaces runs on Windows, Linux and Mac systems. To achieve that, the developers have to do quite a bit of work, as they'll have to use different APIs for accessing the hardware that Nexuiz interacts with (such as the keyboard, mouse, joystick, soundcard...), as each operation system provides different APIs for that purpose. This is the reason why all the game-specific logic, e.g. the program code of the game modes, weapons, items, etc. is not written in the engine, as this would mean to write it in the language of the engine, and would also mean that you have to compile the whole engine each time you do a change in the game code.
Instead, the game logic is implemented in its own language, QuakeC, which is compiled by its own compiler, in our case FTEQCC (FTE QuakeC Compiler). The compiled code generated by FTEQCC gets into a file which is the placed inside the data dir of Nexuiz. When you launch the engine, it will look for that file and run the compiled code which is in that file in a virtual machine. This has three advantages:
However, it also has disadvantages:
For compilation the FTEQCC needs a file called progs.src which basically contains a list of all .qc and .qh files (note the intended similarity to .c and .h files). FTEQCC then compiles all these qc and qh files after another and puts the result in a .dat file. Remember that I was talking about 1 file that is interpreted by the engine? In fact, you actually need 3 of these files (and you also need to run FTEQCC 3 times while you specify a different progs.src file each time):
All 3 dat files need to be placed in the data directory of Nexuiz, as the engine expects them to be there.
Another note: FTEQCC also creates a lno file for each dat file. For Nexuiz these lno files are not important or needed. In case that you distribute a mod you created, you won't have to publish the lno files, only the dat files.
Hereby I assume that you are familiar with the basics of SVN and know how to check out code from a given location. Usually you would now have to download Nexuiz and it's QuakeC code, the DP engine and FTEQCC from SVN, compile FTEQCC and DP and then use your fresh FTEQCC binary to compile the code inside /data/qrsrc. However, the compilation of DP or FTEQCC can be non-trivial, especially for the ones that are not used to Makefiles and the C compiler.
This is the reason why beginners should use a premade build-system. However, the build systems are platform specific.
For windows you can get the build-system made by divVerent, located here. After you downloaded and extracted the zip file, all you have to do is to start the build.bat file and wait. The script will do all the work for you:
Note 1: The compiled FTEQCC binary is the console version which makes sense as it is executed in the batch file, however, there is also a GUI version of FTEQCC that you can get in one Nexuiz source package builds also done by divVerent, e.g. here.
Note 2: For the future I would recommend that you take a closer look at the build.bat file and create your own modified versions of it, e.g. one that only compiles the Nexuiz game code with FTEQCC - you will need this one often when you change the game code in your future QuakeC coder career and you want to compile it fast.
Note 3: To start the game, all you need to do is to start the run-wgl.bat or run-sdl.bat file. The three dat files generated by FTEQCC will already be in the correct place, you don't need to worry about that!
Soulbringer has written a bash script to automatically do the dirty work for linux users. It keeps a checkout of SVN clean and exports your installs/updates to a folder with the revision number i.e. Nexuiz_SVN_5277. For this reason, it's recommended you have at least 4gb's free.
The dependencies are as follows (ubuntu or debian-based users can paste the following into the terminal to install them):
sudo apt-get install build-essential xserver-xorg-dev x11proto-xf86dri-dev x11proto-xf86dga-dev x11proto-xf86vidmode-dev libxxf86dga-dev libxcb-xf86dri0-dev libxpm-dev libxxf86vm-dev libsdl1.2-dev libsdl-image1.2-dev libsdl1.2debian-alsa subversion libclalsadrv-dev libasound2-dev libxext-dev zenity
Then download the script to a folder... say ~/nexuiz_svn and chmod it +x (executable)
mkdir ~/nexuiz_svn cd ~/nexuiz_svn wget http://z.nexuizninjaz.com/bash_scripts/sb_install_010209.sh chmod +x sb_install_010209.sh
type the following to display help:
./sb_install_010209.sh -h
most of you will want just the client:
./sb_install_010209.sh -t c
To update, just run the command again, the script will automatically create a new folder with revision number for you.
Note: this script isn't very verbose. It's not hanging, just be patient.
You can create a shortcut to the latest revision with the following script:
#!/bin/bash # for use with soulbringer's nexuiz install script # used to find the latest nexuiz revision and run it # find the dir this file is in base_dir=$(dirname $(which $0) | sed 's/\/.$//' ) # change to that directory cd $base_dir # change to the latest nexuiz revision directory cd $(ls | grep Nexuiz_SVN_ | tail -n1) # start nexuiz ./nexuiz-glx
(edit nexuiz-glx to nexuiz-sdl if you prefer this version)
save the code above as nexuiz_start.sh in the same folder your keep the sb_install script in then chmod +x nexuiz_start.sh
You can now call this file from a shortcut with:
/path/to/your/nexuiz_svn_directory/nexuiz_start.sh
TODO: Someone else has to do the mac part!
Please test some of the other clients and recommend the good, free ones here:
http://en.wikipedia.org/wiki/Comparison_of_Subversion_clients
http://subversion.tigris.org/links.html#clients
Even though the build-system mentioned above comes with a command-line svn client used for checking out the sources and updating them, you will need at least one good SVN client with a graphical user interface. If you are ambitious and, within given time, do more or less big changes to the QuakeC code base, you will find out that you will have to do a lot of conflict merging when you update your SVN copy, because it is likely that you changed parts of the code that were, in the meantime, also changed by the official developers. The other reason to use a handsome SVN tool is the ability to create and apply patches to your code base without being a victim of command line tools as well as having a good graphical diff utility which comes with these SVN tools nowadays.
Eclipse in combination with Subclipse is the only tool I know of that allows you to have a truly non-destructive update procedure. Normally, when you use other tools and you update your code and a conflict is detected, SVN will mess with your file system, create ”.mine” files, etc, and you better hope that your merge tool is good enough to do the job after the catastrophy happened. With Eclipse+Subclipse, there is the possibility to have a look at the files that would be affected, even before you actually update. You will also see which files would become conflicted, you can deal with the conflict before hand and save the merged file.
Anyways, the following instructions assume that you already have some knowledge about Eclipse, especially the use of its update manager!
Installation instructions
Project setup
Now you are ready to work with Eclipse:
Hint 1: It makes sense to rid of files like .project files inside the synchronizing view. You can do that by right clicking on that file and select add to svn:ignore !
Hint 2: I have to admit that the team synchronization view will very often present you “conflicted” files that actually are not really conflicted, but could have been merged otherwise (or other tools would have been able to merge them without problems). You will recognize whether this is the case if you have a look at the small colored square on the right side of the diff viewer. Only if that square is red, you will have to deal with real conficts. If it has another color, e.g. blue, you can just right click on that file and click on Update. Subclipse's SVN client will merge your changes without problems.
Hint 3: Sometimes you might want to update to a particular, older revision. To do this, right click on your project, select Team → Switch. The URL you need to setup should already be correct (you might have to click on “Browse” and just close that window again). Do not, never ever, do the tempting thing to right click on your project and select the “replace with → Revision or url”.
Tortoise SVN is a very well known SVN client for Windows. It works as a shell extension, which means that you can right click on files and folders in your windows explorer and do the SVN operations you like.
The functionalities of SVN tools are very similar in general (across the different OSes). What I particular like about Tortoise SVN is the abilty to merge conflicts when you patch Quake sources that are already patched. Other than that it has a good change log viewer (you can search for strings in the change log description, this is really helpful), a good file differ and the merge utility is also good once you found out how to use it. Of course Tortoise SVN can apply and create patch files without problems.
From my experience, most Linux SVN gui's haven't been too good. RapidSVN is buggy as heck and kdesvn doesn't work properly in gnome. I've recently come to use Nautilus SVN which integrates with your file browser nicely.
The Linux tortoise SVN equivalent
http://code.google.com/p/nautilussvn/
Refer to their installation wiki page and use the 'manual installation' script for the latest version.
I assume that you are already used to some kind of comfort when working with a programming language. An example would be working with Java using a proper IDE such as Eclipse or Netbeans, or creating C/C++ code using an IDE like MS Visual Studio (or any other good commercial or even open source IDE). What these IDEs usually provide is at least an editor that allows syntax highlighting as well as various other features, such as finding the definition or implementation of a selected function by only pressing a key combination, looking for occurences of the selected symbol, or navigating through the source files efficiently.
As QuakeC is similar to C, you might think that you can use any IDE that has sufficient C support to get all the features you are used to when creating C code. However, the only IDE I found that was really able to recognize all symbols (including global variables and global functions), look for occurrences of selected symbols (well, text) in the code and is able to navigate through the code is the IDE Code::Blocks! Code::Blocks is platform independent!
On the official page you can download the binary release for your OS. If you are using Linux, you can also install Code::Blocks from your package manager, the package name will be similar to “codeblocks”. If you are using Windows, you can even download a version that includes the GNU C/C++ compiler from MinGW (if you don't know what MinGW is, then this is the right package for you to download, especially if you choose to modify the engine code and want to recompile the engine, for which you will need a C/C++ compiler, which you will already get shipped with Code::Blocks in this case). If you are on Linux, there is no special Code::Blocks package that includes a C/C++ compiler, because your linux package manager will usually provide the ability to install the GNU C compiler package using your distro repository.
Anyways, after you downloaded and installed Code::Blocks I recommend that you download the QuakeC syntax highlighter add-on. The zip contains the lexer_qc.xml and lexer_qc.sample files, which you have to put into your share/CodeBlocks/lexers directory! If you are on an ubuntu system, this directory is located in /usr/share/codeblocks/lexers. After that, make sure that in the Settings → Environment → File extension handling dialog the wildcards *.qc and *.qh are present and setup that they are opened inside the Code::Blocks editor. Also, you will discover that e.g. the background will be grey. If you don't like that bg-color or want to change the color of other elements, change them at Settings → Editor → Syntax Highlighting (select the QuakeC syntax highlighting and then modify the colors you want to change).
Then create a new, empty project somewhere on your hard disk. To do this click on File → New → Project. Select Emtpy project and click on Go. In the wizard that opens, enter a name for your project. When you come to the compiler-selection dialog, it doesn't matter which compiler you setup, as you will have to compile QuakeC outside of CodeBlocks anyway. After you finished setting up the project, right click on your project and select add files recursively. Select the qsrc directory and click OK. Then click on Wildcard select and enter *.qh;*.qc as wildcard, click OK and approve that you want to clear your previous selection. Finally click on OK.
Apart from that I recommend that you use one of the recent nightly builds of Code::Blocks (you can find them in this forum), because they have useful additional features. At least these two of them are interesting for you:
Now some more details about the features of Code::Blocks:
I've created a video demonstration (Download as Xvid, 66 MB) that shows the features in action.
Important: For me an unpleasant bug occurs: everytime I close Code::Blocks and open it again, I find out that I've got no entries in the Symbols tab anymore, and jumping to declarations or implementations of a function doesn't work anymore. To fix this, I just add the files recursively to my project again (right click on your Project and select add files recursively as explained above, you don't need to delete the files that already are in your project, they will be automatically replaced).
Now that you know how to setup your development environment you should start getting to know QuakeC. First of all, you will need to learn the basics of the C programming language, because QuakeC is based on it and the QuakeC reference guide will assume that the C basics are known to you already. Then continue and read the QuakeC reference guide!
I guess that most of the people who try to understand QuakeC or probably even the engine code does this for a reason: most of you would like to see their code make it into the Nexuiz codebase - and as long as it is a modification that makes sense, the chances aren't bad!
However, you should keep in mind to structure your work. It is likely that you are working on different modifications, possibly even at the same time. With “different modifications” I mean that you are working on different features that are basically independent.
In general it is highly recommended to backup your work regularly using patch files. You can create patches with most of the available SVN tools, such as the tools presented above! There are several advantages:
Apart from that, if you are working on the SVN codebase, you need to know that there can be a massive amounts of commits within a short time. Try to keep your SVN copy up to date by updating from time to time. The longer you wait the bigger the efforts get to solve conflicts that were introduced in the meanwhile.
TODO: If anyone has more general tips, put them here!
GFDLcontent Unless mentioned on the licensing page, the work on this page is licensed under the GNU Free Documentation License. The author states that the text and images can be used within the restrictions of this license (for example, they can be incorporated into certain free encyclopedias such as Wikipedia). | |
Kindly hosted by NexuizNinjaz.com |