Monday, October 24, 2005

Physics Optimizations

OPAL sure provides a lot of features, but I had to utilize it to the outmost to get the size of the simulation that I wanted.

First of all, grouping objects was essential for performance. So, for example a building would be made out of various blocks, which usually stay close to each spatially, so they can be grouped and their collision be optimized, because instead of checking for every block, collision can check their bounding box for the entire group. This is how ODE, physics engine, optimizes collision checks.

Second, OPAL is awesome that it can rebuild objects on the fly from static to non-static type. I used this feature to make sleeping objects static. And static object take the minimum processing power during collision.

With the above optimizations I was able to easily handle scene made out of 2000+ boxes. On the screenshot, you can see the system in action. Note that this is running on NVidia 5200 Go on a laptop, so performace is decent.

The third point is not implemented yet. Its goal is to stabilize some shakiness of the vehicle caused by a dozen of joints, which ODE does handle well at certain configurations. It will dampen small linear and angular acceleration at small values.

Simple XML tool in C++

XML is really a great format. It gives a lot of freedom. I can define any structure with it.

And this is really useful for game development. Especially in C++. Its build times are rather long, so storing and modifying parameters inside the code is not very useful. Testing and experimenting takes a long time in this case. If, however, the data is moved out of the code, as it should be done, the problem of performance is gone. Just go to your favorite XML editor, edit the data, save, then and simply restart the application without any recompilation.

So, I have tried to move as much as I could to XML files, so long as it did not take away a lot of time to do so. One of the things that I had stumbled upon was uneasy reading of XML files in C++ libraries what were available to me. In particular, I used tinyXML. However, reading many small and simple files across the entire framework took just too much effort for its price. So I figured it was time to create a simple wrapper around tinyXML. This way I could expose just enough features that I need, and thus keeping it very simple.

The product is the following: XML tools: a simple reader and looper of simple XML files. See their examples for yourself.

Boy, that really made it very easy to use XML anywhere. One line of code for one value from XML file. Quiet perfect.