Box2D Nintendo DS

Here's another update to the patch of the SVN version:
http://blog.dev-scene.com/0xtob/2008/01/27/box2d-ds-updated/
0xtob wrote:
Here's another update to the patch of the SVN version:
http://blog.dev-scene.com/0xtob/2008/01/27/box2d-ds-updated/


I made some fixes to make it work under VisualStudio2005, so if you are interested, let me know.
I'd love that. It would be nice to compare it to the floating point version
also it would be very valuable to anyone wanting to do network games.
I'm actually surprised there isn't more interest as this would add a lot of
value to an already valuable library.
Mike
mike950 wrote:
I'd love that. It would be nice to compare it to the floating point version
also it would be very valuable to anyone wanting to do network games.
I'm actually surprised there isn't more interest as this would add a lot of
value to an already valuable library.
Mike


http://data.hardwire.cz/nic/Box2D_rev80_fixed.zip
I marked all my changed with //HARDWIRE
I added #define TARGET_FLOAT32_IS_FIXED directly to b2Settings.h, so delete it if you wan't to try non-fixed-point version.
I had to made some changes in projects' settings and copy freeglut and glui from v1.4.3 to make it work in Release configuration.
Thank you!
I wonder if skatehead if you're listening you could port this version to AS3?
Am I right, with this version the simulation will run the same on all computers
regardless of CPU?
Would it make sense to make this the official version then if I'm right?
Mike
Both in AS3 and Java, there is no way to overload the arithmetic operators +,-,*,/, which makes conversion to fixed point math an extremely irritating (and largely manual) process. It's not as simple as typdef-ing or even find/replacing a few things, even if you do have a good fixed point class set up. So this might be a lot more work than it would initially seem, and I doubt if skatehead will have the time to take it on (I know I decided against it for the Java version).

There are also some good reasons not to use fixed point for a default version, not the least of which is that on many desktops the floating point operations actually run faster than equivalent fixed point ones, especially when you add in all the object overhead in AS3 or Java. The only reasonably fast way to do fixed point in either language is to inline it all, which only worsens the nightmare of porting it.
I don't really see why you'd want fixed point in Java or AS3. Both are virtual machines, so it's not like they have anything to gain, even on a fixed point architecture. And presumably, as virtual machines, they aren't affected by architecture differences, and maybe already run identically already? Can anyone confirm this?
BorisTheBrave wrote:
I don't really see why you'd want fixed point in Java or AS3. Both are virtual machines, so it's not like they have anything to gain, even on a fixed point architecture. And presumably, as virtual machines, they aren't affected by architecture differences, and maybe already run identically already? Can anyone confirm this?


One good reason can be if you want to use Box2D on mobile phones, which don't have hardware support for floats and must emulate them.
However, as ewjordan pointed out to make it really usable you would have to manually inline ALL aritmetic operations performed by Vector class. Otherwise it would be too slow for current mobile phones.
I can't confirm it for AS3 or Java but I wrote a multiplayer game a while back
for shockwave that used simple physics and couldn't figure out why I was getting
different results for MAC and PC even with identical inputs.
I hope you're right though at least for AS3.
If you don't have to worry about it since it's a virtual machine then I would say
yeah don't need to worry about fixed point.
I wonder how many programmers realize that their programs could potentially
give different results depending on the cpu it's being run on?
I'm guessing not a lot.
Mike
Quote:
One good reason can be if you want to use Box2D on mobile phones, which don't have hardware support for floats and must emulate them.

This is indeed the reason I would have loved to do a fixed point Java port, as mobile phones are one of the larger markets for Java games. It's truly a shame that the language itself does not make this easy - don't get me started on all the things that Java disallows because they want the language to be idiot-proof, it's enough to drive a person mad. In my opinion it is a huge mistake to give up a genuinely useful feature because a poor programmer might abuse it, but I guess the folks at Sun feel differently. Or they're just plain lazy, which there is ample evidence for as well (Google "type erasure" and I'm sure you'll find some rants on this).

I considered writing an automated text-based conversion utility to swap out floats for fixed point, but it's a lot of work to get it running right, since you actually need to parse all the classes and keep track of all the member floats and all that stuff. It's a big task to get it working right, and with the next generations of phones we might actually see FPUs, thus making the whole effort seem like a pointless exercise.

As far as the different processors/different results issue, one thing you might try is to manually clip all the floating point values associated with each body to some resolution at each time step. Whenever you do get different numbers, it's usually a result of internal precision differences, which means that except for actual floating point overflows, you're going to get the same results to within the last few bits. The problem is that these errors propagate and grow, so if you cut them off by reducing precision before they can grow, you might avoid problems down the line. This might introduce other issues in the engine, though, so tread carefully and don't blame me if it doesn't work!

In Java, there is a strictfp modifier that supposedly ensures identical results across platforms at the cost of speed; I don't know if there's anything similar in AS3, though.

Original thread: https://box2d.org/forum/viewtopic.php?t=124