Box2D Nintendo DS

Ah thanks for that tip!
AS3 has functions for Numbers called
toFixed() and toPrecision() so that will make it easy to try.
Mike
Sorry, I'm still not getting why you'd want fixed point in Java? It has no fixed point support, so you are obliged to emulate it with classes. Then you are not really taking advantage of any fixed point operations a mobile phone might have (as you will be emulating fixed point with ordinary integer operations). You might as well emulate floating point if you're forced into emulation, at least that will be done by the java engine rather than your own code.

Also, I remember now that N: Way of the Ninja stores it's level replay codes by storing what the user input was, and is able to recreate the physics perfectly. So it must be possible. I don't know if it does any precision truncation though.
Quote:
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).

In my expiriences Box2D is still too heavyweight for today's phones...if you want to be successful you need to run it on most phones currently in the market.
As a school project I am porting Box2D to Symbian. These phones are much more powerful, so we'll see how it will perform.

Quote:
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.

I don't think it would be enough to just swap it. You would need to carefully examine all these calculations and variables to prevent over/under-flows.
BorisTheBrave wrote:
Sorry, I'm still not getting why you'd want fixed point in Java? It has no fixed point support, so you are obliged to emulate it with classes. Then you are not really taking advantage of any fixed point operations a mobile phone might have (as you will be emulating fixed point with ordinary integer operations). You might as well emulate floating point if you're forced into emulation, at least that will be done by the java engine rather than your own code.

Also, I remember now that N: Way of the Ninja stores it's level replay codes by storing what the user input was, and is able to recreate the physics perfectly. So it must be possible. I don't know if it does any precision truncation though.


I forgot to mention that some phones even can't emulate floats:) (these with CLDC-1.0)

However, if I run SPMark on my N70, I get following results:
int addition - 67309 kOps/s
int multiplication - 53883 kOps/s
float addition - 1966 kOps/s
float multiplication - 2417 kOps/s

I think that it's obvious floats are much much slower then ints...and when I emulate fixed-points it is not much slower if I use shifts (and even if I use "long" when performing multiplication/division).
For Java phone games, usually people do not use a fixed point class at all or rely on floating point emulation - they manually inline their fixed point code and make sure they don't overflow by hand. It's a terrible and inefficient way to write code, but it's pretty much required for Java ME games because as Hardwire noted, many phones can't even do the emulation. And these phones often only support Java, so if you want to target the platform, you've got to hand-write your fixed point.

It's awful, I know, which is why I'm staying away from it for the moment; however, that's why people want to do it, because it's the only way to hit that market.
I use inline fixed point throughout my J2ME game Shade. Without it there would be no way I could get close to a decent frame rate with all the perspective shift stuff I'm doing. And, like ewjordan says, the trade-off is terrible looking code filled with <<16 and >>16 all over the place 😳 I'm not so convinced any more that it's a "market" worth putting much effort into, though. It's fine (and kind of fun) for indie and hobby stuff but too damn hard to make any money there.

Bill
the2bears wrote:
I use inline fixed point throughout my J2ME game Shade. Without it there would be no way I could get close to a decent frame rate with all the perspective shift stuff I'm doing. And, like ewjordan says, the trade-off is terrible looking code filled with <<16 and >>16 all over the place 😳 I'm not so convinced any more that it's a "market" worth putting much effort into, though. It's fine (and kind of fun) for indie and hobby stuff but too damn hard to make any money there.

Bill


I develop using Vector2 class until everything works fine. Then I profile to determine which parts of the code are "crucial" and inline them. The good thing is that when I start inlining everything works ok and I don't need to look at this ugly inlined code again:)

I am indie myself, too, but I know that I could get really decent (in comparison with PC game developers for example) salary if I took a full-time job.
Hardwire, I merged your fixes into my box2d tree, so they'll be in the next release.

It turns out merging changes by hand diffing against the official SVN and uploading the diff to my website certainly isn't an easy or clean way to manage the fixed "branch" of Box2D. Also, it's impossible to keep up with the official SVN, since every time SVN is updated, I would have to check out the new revision, apply the fixed point patch to it and make sure it compiles and runs. Luckily, Erin agreed to accept a patch once Box2D 2.0 is final, which is probably going to make things easier. I'm not sure though if the fixed point changes should be in the official main branch, since I'm still struggling with several numerical problems and would not consider the fixed-point version very stable.

So, a question for the SCM savvy prople in here: What would be a good way to manage the fixed point changes such that they are easy to maintain?
0xtob wrote:
Hardwire, I merged your fixes into my box2d tree, so they'll be in the next release.

It turns out merging changes by hand diffing against the official SVN and uploading the diff to my website certainly isn't an easy or clean way to manage the fixed "branch" of Box2D. Also, it's impossible to keep up with the official SVN, since every time SVN is updated, I would have to check out the new revision, apply the fixed point patch to it and make sure it compiles and runs. Luckily, Erin agreed to accept a patch once Box2D 2.0 is final, which is probably going to make things easier. I'm not sure though if the fixed point changes should be in the official main branch, since I'm still struggling with several numerical problems and would not consider the fixed-point version very stable.

So, a question for the SCM savvy prople in here: What would be a good way to manage the fixed point changes such that they are easy to maintain?


I detected another problem with the fixed-point version.
I set 30hz and 10 iterations. Gravity -10.0f. Then I set up the pyramid demo, but with only 10 rows and columns:
Code:
   {
      b2PolygonDef sd;
      sd.SetAsBox(50.0f, 10.0f);

      b2BodyDef bd;
      bd.position.Set(0.0f, -10.0f);
      bd.AddShape(m_world->Create(&sd));
      m_world->Create(&bd);
   }

   {
      b2PolygonDef sd;
      float32 a = 0.5f;
      sd.SetAsBox(a, a);
      sd.density = 5.0f;

      b2Vec2 x(-10.0f, 0.75f);
      b2Vec2 y;
      b2Vec2 deltaX(0.5625f, 2.0f);
      b2Vec2 deltaY(1.125f, 0.0f);

      for (int32 i = 0; i < 10; ++i)
      {
         y = x;

         for (int32 j = i; j < 10; ++j)
         {
            b2BodyDef bd;
            bd.AddShape(m_world->Create(&sd));
            bd.position = y;
            m_world->Create(&bd);

            y += deltaY;
         }

         x += deltaX;
      }
   }


One thing is that with TARGET_FLOAT32_IS_FIXED the pyramid falls and doesn't sleep. But it's ok, I expected this kind of problems:)
Another thing is that after few seconds an assert is raised. It is on line 145. denom is <0. If I removed this assert, nothing bad happened, but probably it is not very ok 😛
If you won't be able to reproduce this problem, just ignore it, because I use a bit different version of Box2D with same changes regarding Symbian platform.
One more issue: when I use fixedpoint, object's will never sleep even if the simulation looks almost the same as when I use floats. Objects calm down, don't move a lot, but they won't sleep. Maybe there is a problem with some "delta" const ?

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