Making Bullet more portable

Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Making Bullet more portable

Post by Wavesonics »

Hi, first let me say, thanks for the awesome library. I just ported it to the Wii for our project and am very pleased with it.

But there is where I came up with some ideas. I've been porting a-l-o-t of libraries lately and thus have seen quite a few schemes which different libraries use to make them easily portable. And by far, of the libraries I've seen, the best has been Xerces C++ XML parser.

Now, many libraries are easily portable by simply overriding new and delete to deal with memory management, but when libraries require platform specific utilities, (threading, timing, ect...) it required a bit more.

As everyone knows, the goal of a portable library to be be able to make ports which change as little code as possible (ideally, no code modification at all to the core library it's self).

Now in bullet there was only one real area that required porting (a couple small things in one or two other areas, but this is the important one), platform specific timing.

You can #ifdef _SOME_PLATFORM_ till the cows come home, but in the end you aren't going to hit every platform that someone could want to port to. So the idea is to make an architecture which provides, easy clean way to add a new platform with out having to try and stick things into an #ifdef #else chain in the moddle of coded logic, and then have to redo it every time you upgrade the library.

How Xerces gets around this is having one common header called Platform.h, and this is the only Xerces source file that you have to modify when porting, which means during upgrades it's as simple as dropping 3 lines of code into the new Platform.h from the upgrade, and you are good to go again.

This Platform.h detects the platform based on compiler defines, and then includes the proper platform file:

#ifdef _WIN32_
#include <windowsUtil.h>
#endif

#ifdef _LINUX_ // I know this isn't the actual define
#include <posixUtil.h>
#endif

ect...

Then these util files provide certain functions which satisfy what is essentially a classless interface, such as:

double getTimeInMilliseconds();

Also, some platforms require some other includes, and type defs to make the rest of the files compile, and those can all be handled in the Platform specific util.h file.

So by making trivial modifications to one file, and adding one more file that won't be affected by library upgrades, you make make the library exceedingly easy to port to any possible platform.

What do you guys think? If you guys like it I could work up a quick patch for the SVN.
Sly
Posts: 16
Joined: Wed Apr 23, 2008 9:57 am

Re: Making Bullet more portable

Post by Sly »

You mean similar to the header already in Extras\BulletMultiThreaded\PlatformDefinitions.h?