Archive for the ‘Uncategorized’ Category

A wxPython console

Monday, December 10th, 2007

An in-engine console is an indispensable asset when developing games. It can display a log of engine messages, allow simple querying of engine values and even provide a full programming environment for the engine. I had initially thought of implementing a console like Quake: toggled with ~ and rendered in-game at the top of the screen. I quickly decided against this route and chose to create a console using wxPython.

A wxPython console can provide a native OS interface with scrollbars, selectable text, copy and paste, etc all for free. These were features I’d never have time to implement in a Quake style console. Besides, I wanted to integrate wxPython into c2 anyway so I would have a way to create simple tools for the engine.

The console I ended up with is a simple dialog box that provides an interactive python prompt. It doesn’t have to interact with the engine directly, it just runs commands in a python environment which happens to have the engine interface imported. So the console can be used in any wxPython application. You can download it here. The only requirement is that you have wxPython.

XInput

Friday, December 7th, 2007

If you’re interested in using the Xbox 360 controller there are two things you need to know: XInputGetState and XInputSetState. There are a few more functions if you want to interface with the headset attached to the controller, but for input that’s it. Once I understood these two simple functions I had Xbox 360 controller support in C2 in 10 minutes (literally). DirectInput in comparison is a nightmare, acquiring devices, checking if the device has been lost, etc. Why bother?

Reference:
http://msdn2.microsoft.com/en-us/library/bb173048.aspx

Physics Integration

Sunday, October 14th, 2007

My goal for this weekend was to get a collision and physics library into C2.

We used ODE for PubCrawl and it didn’t leave me with much confidence. This time I chose to use the Bullet Physics Library because I’ve heard good things about it. Bullet is geared more towards game engines and is much simpler than ODE. I was able to get a quick test program up using Bullet in about a day. After another day I had integrated Bullet physics into the engine itself very nicely.

In C2 physics can be added to any SceneNodes by creating and attaching a PhysicsObject. A PhysicsObject does two things:

1) provides a description of an object for simulating physics
2) updates the transformation of the SceneNode after simulation each frame

For example a PhysicsObject can be created with a mass of 10 and a sphere collision shape of radius 2. The simulation is run: objects are moved, collisions are found and resolved. Then the PhysicsObject copies it’s simulated transformation to the SceneNode’s transformation. Then the scene is rendered.

The PhysicsObject class is actually a very simple wrapper around Bullet rigid bodies. It is mainly meant to keep the engine from using Bullet directly. This hides library and header dependencies. Once compiled into a library only the C2 engine headers are necessary to use the engine. If this were not the case using the engine would be a nightmare of dependencies.

I was able to add physics information to the scene file format as well. Any SceneNode with physics definitions has a PhysicsObject created and attached to itself on load. It’s very gratifying to write a quick scene file and load it up and watch objects fall and collide. It is surprising that good physics can be had at such a low investment of time. I highly recommend the Bullet Physics Library to anyone interested in adding physics to their game engine.

The next step in the physics system is to add constraints. Constraints would allow large static objects made up of multiple PhysicsObjects that act as one. Dynamic constraints would allow objects to move relative to each other in interesting ways. There also needs to be a way to fire scripts events on collision.

Portal was awesome and the ending is fantastic.
“The cake is a lie…”

The BuildBot

Monday, October 8th, 2007

Our build servers were turned back on over the weekend. They weren’t being used because we have drastically changed how our projects are built. Perforce and Visual Studio files have been replaced with Mercurial and CMake. So, I spent the weekend reconfiguring the buildbot setup Tony had on the servers. I had never configured buildbot before and I was surprised to find it was so easy. I only had to change the repository location and build commands on the buildmaster server. I didn’t have to touch any of the build slaves.

This time around we’ve got both linux and win32 versions of C2 building any time we want. It used to be very difficult to manage both versions of the engine. On win32 we used Visual Studio projects and on linux it was scons or make files. Any change on win32 had to be manually added to the linux project files and vice-versa. Even worse, making a change on a different platform usually meant rebooting into another operating system. With CMake there is now one build file for all platforms and it’s easily edited in a text editor.

The buildbot setup has been extremely beneficial for my linux oriented workflow. I can work on the engine on linux and have buildbot compile it for win32 without the incovenience of booting into windows myself. Judicious unittests catch many issues that can be rectified without having to run the engine proper. In the worst case I rdesktop into our win32 build server from linux and run Visual Studio to fix any build problems. Unfortunately the build server doesn’t have the graphics hardware required to run the engine outright so I still have to boot into windows to test the actual game.

Develop Conference

Saturday, September 29th, 2007

I just recently found out about Develop Conference. It seems to be a European Game Developer’s Conference. They’ve posted some of the presentations, so it’s worth checking out.  One presentation I found particularly interesting was Deferred Rendering in Killzone 2.

New Tools

Saturday, September 15th, 2007

In developing C2 I wanted to look at libraries and development tools I don’t normally use.

I’ve always hated developing an input system that works on both linux and windows. Looking for a cross platform input library I was surprised to find that there are actually two really good libraries: OpenInput and Object-oriented Input System (OIS). OpenInput is a C library while OIS is (suprise) object oriented. I went with OIS because it has a large community and it fits really well into C2. The library supports keyboards, mice, and joysticks out of the box. The only thing that’s missing is an XInput binding for proper Xbox360 controllers on win32. However, it is pretty easy to add a new input device to the OIS system.

I started C2 under Subversion and everything was good…then I switched to git and everything was great. Git is a decentralized version control system. Instead of having one repository that everyone checks their code into, everyone has their own copy of the repository. Everyone can check into their own repository and then push and pull changes from other repositories. The ‘central’ repository is just the one that everyone decides to push their changes onto. One way to think about it is that everyone works in their own branch and then decides to merge their branch into the main repository. This is a real benefit because you can work on and check in code that may not work without disrupting anyone else. I check it constantly and I really like this feature. Also merging in git is very simple.

The only problem with git is that it has no win32 port. Which wasn’t really a problem for me until I started the win32 version of C2. I was completely unable to check in code I was working on in windows. I found Mercurial which is basically the same as git but is well supported on win32. Mercurial also uses SVN commands and has SVN style output. Mercurial also has this sweet reference card that I enjoy.

Finally, something I haven’t looked into too much yet is a cross platform sound library. In the past I’ve used OpenAL however I’m going to look at Fmod for C2. Fmod looks pretty powerful, I’ll let you know how that goes.

Compiling on win32 for free

Wednesday, September 5th, 2007

I installed Windows XP over the weekend so I could get a win32 version of C2 compiled and running. I couldn’t find my copy of Visual Studio 2005 Professional Enterprise Edition (or whatever the hell it’s called) so I opted to install Microsoft’s free compiler. I discovered that Microsoft offers Express (free) versions of it’s Visual product line complete with IDE. The process to get everything up and ready to compile win32 apps is a little involved but entirely worth it.

1) Install Visual C++ Express
2) Install Visual C++ Express SP1
3) Install the Windows Platform SDK (yes, the Windows Server 2003 one)
4) Configure Visual C++ Express to use the Platform SDK

On linux C2 is built using CMake so I wanted to use CMake, if possible, to build on win32. As it turns out, using CMake on win32 is painless. I installed the CMake windows installer and ran CMake on C2 expecting nothing to work. It quickly found Visual C++ Express and dumped out a few Visual C++ project files. I could edit and compile the project from the Visual C++ IDE. The CMake files were even added as dependencies so project files would be regenerated when a CMake file was modified. After a few hours of fixing up platform specific issues I had a win32 version of C2 running without problems.

I don’t know exactly what is missing from the Express version of Visual C++ but it does everything I need it for.  So far, I’m very pleased.  The best part is it’s completely free.

I’ve been busy

Thursday, August 30th, 2007

I moved into a house with Gavin, Tony, and Nate in Fitchburg. I’m free of the drudgeries of the crumbling UW-Madison campus, it’s boisterous inhabitants and parking tickets. The rent is the same as I was paying on campus except I now enjoy a huge house, yard and there’s a park across the street.

The partially finished basement has become an amazing rec-room. A new 7.1 Surround Sound system, courtesy of Tony, compliments my 1080p TV nicely. BluRay movies on the PS3 are awesome, and games are even better. We’re thinking of replacing our aging media system with LinuxMCE. There are some cool videos that show off it’s amazing features.

Which brings me to Linux.

My installation of Windows exploded quite a while back and I took the opportunity to get back to Linux. In the past I’ve always found myself crawling back to windows for some reason. This time, however, I’ve been very satisfied.

Tony turned me on to the wmii window manager. It’s got all the features of my old fvwm config with all the features I never wanted to even attempt configure in fvwm. Tiling window management and the dmenu have greatly increased my efficiency while working on my various programming projects.

Which brings me to my new game engine.

Catharsis was growing out of control. Trying to allow for every possible use of the engine caused the source code expand to over 60,000 lines of C++. The entire engine had become much too bloated and difficult to work with. There were also features I had never gotten to adding and would be difficult to integrate into the engine in it’s existing state.

When I switched to linux I decided to write a streamlined and economical version of Catharsis named c2. I wanted to make the engine usable and small. C2 is about 2,000 lines of code, 5,000 when you count utility libraries. Those 5,000 lines of code amount to an engine of about the same capability as Catharsis plus a few extras. I’ll leave the details of c2 for another post.

Which brings me to BioShock: Go play it!

HD is here

Monday, February 12th, 2007

This past month I have been experiencing an increasing desire to get an HDTV. A ton of games I am interested in come out in March and I can’t stand to play them in an interlaced format. Saturday I finally cracked and bought one.

I got a nice deal at Circuit City on a Mitsubishi LT-46131. It’s a 46 inch 1080p LCD panel. The image is, unsurprisingly, incredible. The savings in space compared to my monolithic 32″ CRT television is also amazing. It’s got some cool features like split screen between any two inputs, so you can watch TV and play a game simultaneously on one screen.

Tony bought a few Blue-Ray movies for his PS3, and the native 1080p resolution truely is a sight to behold. We spent the night plugging in all our consoles and looking at things in HD. Broadcast HD channels even look great, though broadcast TV, in general, infuriates me for other reasons.

I’m hoping to play the final build of The Butterfly Effect multiplayer on 46″ of HD goodness with wireless XBox360 controllers courtesy of the Wireless Gaming Receiver I bought last month.

Building Assets

Saturday, January 20th, 2007

Building an entire game’s worth of source assets (from Maya, Photoshop, etc) into engine usable assets is a very time consuming process. It is a process ripe for automation.

During the development of PubCrawl we lacked the time and infrastructure to create a complete system for building assets, we were relegated to a manual build process. Tony would copy source assets from a network share on Denrei’s computer and build a game asset from each source asset using our command line tools. The game assets would then be copied into PubCrawl’s game file system. The entire process was horrendously error prone; it was not uncommon to spend precious time trying to figure out why something wasn’t showing up in the game only to discover that the wrong game asset had been copied into the game path.

A major factor preventing us from creating an asset build system was that our source assets were completely unmanaged. The source assets that Denrei created existed only on his computer. We tried checking source assets into our Subversion repository, a process which took nearly an hour any time they were checked in. Then we tried storing the source assets in a seperate repository from the source code. Tony tried valiantly to integrate it into our existing systems, but it was just not to be.

Then we discovered Perforce and all our problems evaporated. Now both code and assets are stored in one repository on our Linux server and the repository is easily accessible for scripting. The stage was set for an automated asset build system.

What I created was SNAX: the Stolen Notebook Automated eXporter. It is written in Python and designed to fit into our Buildbot/Perforce build system. It is also designed to be very extensible. I’ll get into how SNAX works, but first some background is in order.

Building Dependantly
Build systems generally work by explicitly defining dependencies between files and executing commands to resolve those dependencies. For example:

depgraph.gif

This graph is traversed from the ‘project1’ node down to find what dependencies are not met and what steps are necessary to resolve those dependencies. In this example if data.o were missing a command is executed to recreate it from data.c and data.h. The effect of this system is that only nodes that fail their dependency check are updated. If only one file has been modified only that file and those depending on it are processed.

However, a dependency based system requires that the dependency relationships for all files be completely defined. This is great for source code because a lot of files result in one executable. Assets, on the other hand, have a one-to-one or one-to-many relationship between game asset and source asset. Two source assets never result in one game asset.

Further complicating things, source assets can create arbitrarily named intermediate files. It is common in to define general dependency rules to simplify dependency definitions. A common rule for source code is that .o files depend on .h and .c files of the same name. This concisely defines a number of dependencies and also automatically handles new .h and .c files with out modifying the dependency definition. However, when the names of files are arbitrary it is impossible to use this rule. For example a Maya file named ‘level01.mb’ might produce materials named ‘wood.material’, ‘grass.material’, ‘rock.material’, etc. There is no simple way to define these dependencies, they must all be specified. It is as if the above dependency graph were reversed, with .c and .h files being produced from .o files and the names of files didn’t correspond. Each dependency has to be explicitly defined before any building could begin.

Creating and maintaining a dependency graph definition of source assets complicated by the explosion of game assets generated from source assets seemed like more trouble than it was worth… so I decided against dependency based building.

Forwards is Backwards
SNAX works in a forward direction as opposed to the dependency systems reverse traversal. Each node takes in a list of files, does a build operation, and outputs a list of built files which is passed to it’s child nodes, and so on.

buildnode.jpg

These nodes are linked together in a graph that is traversed forward. For example, to build materials and scenes from source assets a Maya binary is built into a collada file, materials and scenes are then exported from the collada file. It looks like this:

mayabuild.jpg

The advantage of this is the simplicity of defining the graph. It isn’t necessary to specify what files build to what files, only what file types build to what other types. The nodes themselves handle passing around the specific files. The definition for building scenes and materials from Maya binaries is simple:

<File filename="*.mb" builder="maya_to_collada">
  <File filename="*.dae" builder="collada_to_material"/>
  <File filename="*.dae" builder="collada_to_scene"/>
</File>

There are a couple cool features here. The builder names in the above XML correspond directly to python functions making it very easy to add new builder operations. Also, building only specific assets is easily handled by passing only the source files to be considered to the root of the forward builder. Tony used this to make the build server rebuild only the modified source assets after each check in to Perforce. Full rebuilds can also be forced from the buildbot web interface.

Conclusions
Building in a forward manner simplifies build definitions and reduces user error. In a dependency graph based system it would be easy to forget to update a dependency definition because they must be defined for each game asset file. Dependency based builds err towards doing too little whereas forward building may do too much. I prefer to do too much work to ensure that the latest game assets are always built.

For now forward building is the simplest method. We don’t have a huge number of source assets for our current project so even rebuilding all game asset takes under 3 minutes. For a larger project the limitations of forward building could become more problematic. In a project with many source assets a dependency based build system would allow very explicit definitions of what should be processed and what is output. The dependency build system can filter out unused source assets by not including them in the dependency graph. This could be emulated in the forward build system by explicitly maintaining a list of source assets and passing into the forward build system. But at that point it may be easier and more robust to simply use a dependency build system.