Fixed Point Implementation

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
Mollusk
Posts: 8
Joined: Thu Mar 13, 2008 11:56 pm

Re: Fixed Point Implementation

Postby Mollusk » Sat Mar 15, 2008 3:06 am

Yeah, it probably didn't get recompiled at first, not sure why, but it works now.

Performance seems to be MUCH better than the floating point version ! And it's nearly perfect now.

http://www.palib.info/blog/flvplayer.sw ... gleBug.flv
This video shows the angle bug : I'm just creating a box, letting it fall on the ground. The upper left numbers show the angle of each box created (the first one being the ground)

kavaler
Posts: 67
Joined: Wed Jan 02, 2008 3:19 am

Re: Fixed Point Implementation

Postby kavaler » Sat Mar 15, 2008 3:54 am

do you have position correction enabled? I notice on the testbed that blocks will turn as you show if the position correction is not enabled.

Mollusk
Posts: 8
Joined: Thu Mar 13, 2008 11:56 pm

Re: Fixed Point Implementation

Postby Mollusk » Sat Mar 15, 2008 3:56 am

Didn't know about that, I'll give it a try, thanks :)

nimodo
Posts: 75
Joined: Sat Feb 09, 2008 4:00 pm

Re: Fixed Point Implementation

Postby nimodo » Sat Mar 15, 2008 4:42 am

kavaler wrote:Regarding the two gif's in previous messages that show some very bad behavior, this doesn't happen in the testbed on my system regardless of the various settings (warm start, position correction or TOI). I use an Intel/Linux box with gcc 4.1.2. Perhaps you could post the code so that I could see what it does on my machine.


This would be nice! I added the Sources to my Windows Mobile thread
viewtopic.php?f=5&t=395&p=3214#p3214



ps: no behavour change with your patchupdate

0xtob
Posts: 13
Joined: Thu Dec 06, 2007 7:36 am

Re: Fixed Point Implementation

Postby 0xtob » Sat Mar 15, 2008 3:23 pm

Hey kavaler! I'm really glad our patch got added to the SVN! With your new fixes I'm not experiencing any problems in Pocket Physics any more! Great work!

kavaler
Posts: 67
Joined: Wed Jan 02, 2008 3:19 am

Re: Fixed Point Implementation

Postby kavaler » Sat Mar 15, 2008 6:42 pm

I tried the PocketTest.zip file and what I found was that once I fixed some of the integration issues the demo worked. What was required to get things to compile (for me) was:

1. The file Examples/PocketTest/Main.cpp was in a unicode format which gcc does not understand (emacs does but vi does not). I converted into a standard ASCII file.

2. Reference to some of the include files needed to be changed (gl->GL, box2d->Box2D). Maybe some compilers/OS does look at case for include files?

3. Lots of references in printf with float32 variables. This must be explicitly cast to float because printf does not know how to print Fixed variable.

4. The first shape created in Tests/VaryingFriction.h is too big. Change 100.0 to 50.0.

5. RenderGIF does not compile at all because it references a "color" field in the b2Color type, which does not exist. eliminated the references so things would compile.

6. Fixed a type issue in Main.cpp with settings.Hz (have to cast 0.0 to float32(0.0)).

7. #defined _MAX_PATH to 1024

I compiled the fixed point stuff with the following (from a Makefile):

Code: Select all

c++ -g -O2 -I../../Contrib -I../../Include -DGLUI_FREEGLUT -DTARGET_FLOAT32_IS_FIXED -c -o Gen/fixed/Main.o Main.cpp
c++ -g -O2 -I../../Contrib -I../../Include -DGLUI_FREEGLUT -DTARGET_FLOAT32_IS_FIXED -c -o Gen/fixed/Test.o Test.cpp
c++ -g -O2 -I../../Contrib -I../../Include -DGLUI_FREEGLUT -DTARGET_FLOAT32_IS_FIXED -c -o Gen/fixed/Render.o Render.cpp
c++ -g -O2 -I../../Contrib -I../../Include -DGLUI_FREEGLUT -DTARGET_FLOAT32_IS_FIXED -c -o Gen/fixed/RenderGIF.o RenderGIF.cpp
c++ -g -O2 -I../../Contrib -I../../Include -DGLUI_FREEGLUT -DTARGET_FLOAT32_IS_FIXED -c -o Gen/fixed/RenderOGL.o RenderOGL.cpp
RenderOGL.cpp:183:7: warning: no newline at end of file
c++ -g -O2 -I../../Contrib -I../../Include -DGLUI_FREEGLUT -DTARGET_FLOAT32_IS_FIXED -c -o Gen/fixed/Tests/BroadPhaseTest.o Tests/BroadPhaseTest.cpp
c++ -g -O2 -I../../Contrib -I../../Include -DGLUI_FREEGLUT -DTARGET_FLOAT32_IS_FIXED -c -o Gen/fixed/Tests/Biped.o Tests/Biped.cpp
c++ -g -O2 -I../../Contrib -I../../Include -DGLUI_FREEGLUT -DTARGET_FLOAT32_IS_FIXED -c -o Gen/fixed/Tests/BipedDef.o Tests/BipedDef.cpp
c++ -g -O2 -I../../Contrib -I../../Include -DGLUI_FREEGLUT -DTARGET_FLOAT32_IS_FIXED -c -o Gen/fixed/Tests/TestEntries.o Tests/TestEntries.cpp
g++ -rdynamic -o Gen/fixed/testbed Gen/fixed/Main.o Gen/fixed/Test.o Gen/fixed/Render.o Gen/fixed/RenderGIF.o Gen/fixed/RenderOGL.o Gen/fixed/Tests/BroadPhaseTest.o Gen/fixed/Tests/Biped.o Gen/fixed/Tests/BipedDef.o Gen/fixed/Tests/TestEntries.o ../../Source/Gen/fixed/libbox2d.a -L../../Contrib/freeglut -L../../Contrib/glui  -L../../Source/Gen/fixed -lbox2d -lglui -lglut -lgd -lGLU -lGL


Then I ran it my machine and it works just like the testbed works. Squares slide down the ramps and stop at various points. They do not go through the ramp and do not fly away.

kavaler
Posts: 67
Joined: Wed Jan 02, 2008 3:19 am

Re: Fixed Point Implementation

Postby kavaler » Sun Mar 16, 2008 1:29 am

Mollusk: After looking at your video I think the problem is in your drawing code. If you look at the angles they are pretty good. 0.00080 corresponds to about 0.1 degree, or one part in 1250. Even a box that is 600 pixels long shouldn't show any tilt.

kavaler
Posts: 67
Joined: Wed Jan 02, 2008 3:19 am

Re: Fixed Point Implementation

Postby kavaler » Sun Mar 16, 2008 2:11 am

I have put the lastest fixed point code patch (versus rev 132 in SVN) in the Patch 2.0 thread. I am hoping that it will make it into the SVN code.

Mollusk
Posts: 8
Joined: Thu Mar 13, 2008 11:56 pm

Re: Fixed Point Implementation

Postby Mollusk » Sun Mar 16, 2008 2:39 am

Ok, that sounds highly possible too ^^ It's just that I don't have the problem in floats, the boxes were perfectly at 0 ^^

Ok, seems that for negative angles it rounds to -1 when it's between -1 and 0... I fixed that, now the boxes are straight ;)

Did a quick test with more than 20 big stacked box :
Emulator : 9fps regardless of fixed/float
PocketPC : 15fps in float, 17fps in fixed :/

kavaler
Posts: 67
Joined: Wed Jan 02, 2008 3:19 am

Re: Fixed Point Implementation

Postby kavaler » Sun Mar 16, 2008 3:14 am

I would have expected better performance gains. Have you benchmarked the basic fixed vs. floating multiply operation? The fixed point code does basically the same number of operations except for the extra shifts left and right for scaling. If that processor does a poor job with shifting that might explain some of the problem. Otherwise, the only things I can think of are the number of iterations is higher for the fixed point code (that is, the actual number used) because it takes longer for things to settle. Try reducing this number and see if you get better performance. Or, the most likely thing: something else is limiting your performance.


Return to “General Discussion”



Who is online

Users browsing this forum: Google [Bot] and 3 guests