Making it easier to share efficient cross-platform code with others keeps me busy. I continue sharing a few thoughts about build systems, software licenses and code re-usability.

Premake

Last time I spoke about meta build systems, and following some suggestions I decided to finally give premake a try.  I’m happy to report that it is doing a great job so far. Even though I had never used premake before, it only took an afternoon to have it auto generate Visual Studio, Mac OSX Xcode projects and Unix Makefiles the way I like it.

Premake takes away the suffering from cmake: its project files use relative paths so you can share its generated project files with others. Also it is easy to customize the various project configurations within one solution (32/64bit etc). You can see the result in a code base called Physics Effects that I recently open sourced together with Sony Computer Entertainment Japan. Just download a zipfile from https://github.com/erwincoumans/bullet3 and open the build directory, click on vc2008.bat and open build/vs2008/MySolution.sln

Physics Effects is a low level collision detection and rigid body dynamics library, optimized by Sony for the PlayStation 3 SPUs and for their new PSP2 ARM handheld. I’m using this Physics Effects code base as a start for Bullet 3, and optimize it for multi-threaded CPU, OpenCL and DirectCompute at AMD.

Open source licenses

In order to share code with game developers and film studios, you need to pick the right software license. I’ve been advocating the use of permissive software licenses such as BSD, MIT, Apache or zlib/libpng for many years now, and fortunately many physics libraries are now available under permissive licenses, such as Bullet, Box2D, ODE, OpenTissue, Newton Dynamics, Xenocollide, jiglib etc.

In general it is best to avoid using code released under viral licenses such as LGPL and GPL in shipping games. Those licenses conflict with many non disclosure agreements (NDAs) and publishers won’t allow you to use those licenses. Just pick a permissive license if you want to share code with other game developers. If you are interested learning more about all aspects of open source, check out the book called ‘Producing Open Source’, there is a free download at http://producingoss.com

Code re-usability

In particular keeping your code free of external dependencies is an ongoing challenge.
Vector math libraries, container classes and memory allocators easily cause conflicts.

Ideally you can share small independent code snippets that compile, link and run without further dependencies. For example John Ratcliff’s code suppository snippets and Sean Barrett’s minimalist and dependency free coding style, previously mentioned by Alex Evans.

Unfortunately when sharing collision detection and game physics snippets, it is often impractical to write code without at least a vector math library. At minimum it is convenient to have access to operators working on a float3/float4 vectors, unit quaternions and 3×3 and perhaps 4×4 matrices.

Switching to different underlying vector math library can be very labor intensive and error-prone, if you miss certain subtle details of those libraries. In some cases when merging several large software components, it can be better to leave each component using their own vector math libraries, rather than rewriting all using a common vector math library.

While merging Physics Effects with Bullet, I plan to replace Bullet’s current math library with Sony’s Vector Math library and let you know how things go.