30 FPS issue with Physic Engine

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
schulzor2004
Posts: 29
Joined: Mon Jan 12, 2009 2:43 pm

30 FPS issue with Physic Engine

Post by schulzor2004 »

Hi Norbo,

Deadline for DreamBuildPlay is very close now. So I didn't have the time to use your 0.10 Version, cause too many things have changed. So I am still working with 0.09... So my problem is, and I really hope, you can help me:

Update and Draw-Cycle do not fit into 60fps but in 30fps. The update cycle needs about 10ms and der draw cycle about 20ms. So XNA does not use automatically 30fps. It tries to run Update function with 60fps and draw function is only called about 2-5 fps, even it would fit in FPS.

So I did following, I changed the TargetElapsedTime:

Code: Select all

this.TargetElapsedTime = TimeSpan.FromSeconds(1.0f/30.0f);
this.IsFixedTimeStep = true;
After that I had to change the Space internalTimeStepping to true, to get no Slomo (I think internally it still runs with 60fps=:

Code: Select all

Space.simulationSettings.useInternalTimeStepping = true;
Space.simulationSettings.timeStep = 1.0f/30.0f;
In the Update function, I had to make another update call (giving the elapsed time instead of gameTime):

Code: Select all

space.update((float)gameTime.ElapsedGameTime.TotalSeconds);
Now the game runs smoothly with 30fps but I have some issues with some of my Physic-Objects, for instance a vehicle: there now the wheels get a little bit behind the vehicle, when driving. Another thing is a swinging rope, the behaves very strange now (consists of some DistanceConstraints). So I think, I did something wrong in my above code. Is this the right way, to achieve 30FPS instead of 60FPS??

Norbo, you are my last hope ;-) Many thanks for helping!
schulzor2004
Posts: 29
Joined: Mon Jan 12, 2009 2:43 pm

Re: 30 FPS issue with Physic Engine

Post by schulzor2004 »

Another aproach i am looking at, is doing everything as fast as possible to get it within 60fps. What I can see is, that space.update needs about 8.5 ms. All entities in there are deactivated, but there are about 240 entities in this space. Most of the entities are Boxes for collision detection. So there seems to be a huge overhead, when there are many objects in the space, even none of the entities is active... do I do anything wrong or is this a normal behaviour?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: 30 FPS issue with Physic Engine

Post by Norbo »

When Space.simulationSettings.timeStep is set to 1.0f/30.0f, it means the engine will internally update only once every 1/30 seconds. This can be a little too infrequent for some systems like the solver, which can cause problems with constraints.

The vehicle wheels may be helped to some extent by changing the timeStep to 1/60f as well. However, if I remember correctly I fixed a problem with the wheel positioning when using internal time stepping in v0.10.0.

Since you are using the game with a fixed time step, you might also try just calling the update method twice without internal time stepping and seeing how that looks.

However, doing any of these things will cause your update time to increase. If the physics are the main culprit, it is likely that your best bet is to move to v0.10.0 and use multithreading. If you end up going this direction, just post any questions about the conversion process you have and I'll answer them as quickly as possible.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: 30 FPS issue with Physic Engine

Post by Norbo »

On the Xbox, that might be about right, but it might also be some other systems running besides entities. It also depends on how the entities are configured (broad phase still has to run on inactive objects).
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: 30 FPS issue with Physic Engine

Post by Norbo »

As an example, I just ran a 240 inactive box test and it is taking 1.8 ms per frame. Taking this to 1000 inactive entities increased the time to 3.8 ms.

There was a slight overhead when I had the 240 boxes floating inside a StaticTriangleGroup, increasing the time spent per frame to 2.3 ms.

These tests were on v0.10.0 running on the xbox, but a bunch of inactive objects probably isn't significantly slower in v0.9.0.
schulzor2004
Posts: 29
Joined: Mon Jan 12, 2009 2:43 pm

Re: 30 FPS issue with Physic Engine

Post by schulzor2004 »

Ok, so I try it with 0.10, so my first question:

I used in 0.09 makeNonDynamic and makePhysical to switch them between an immovable and a physical object... how is this done in 0.10?

Thank you norbo!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: 30 FPS issue with Physic Engine

Post by Norbo »

Their new names are "becomeDynamic" and "becomeKinematic."

Also watch out for the collision groups; this method won't automatically change the collision group of the entity to the space's default. For example, if you call becomeKinematic on a dynamic object, it will still have the space's default dynamic collision group. You should pass in the space.simulationSettings.collisionDetection.defaultKinematicCollisionGroup as a parameter to set it, or just set it directly in the entity's collision rules after you call the function.
schulzor2004
Posts: 29
Joined: Mon Jan 12, 2009 2:43 pm

Re: 30 FPS issue with Physic Engine

Post by schulzor2004 »

ok, I have rewritten it now (there are still many issues, that do not work, for example, I have rewritten the characterconroller...). But it is enough for a short test, and the result is: it is only 2 ms faster than before, not enough for me at the moment.... :-( I try the other things you have mentioned, cause with 30 fps it would be good enough for me...
schulzor2004
Posts: 29
Joined: Mon Jan 12, 2009 2:43 pm

Re: 30 FPS issue with Physic Engine

Post by schulzor2004 »

Hi norbo,

is there a problem, when I dynamically remove/add existing entities while running the game? My first tests look promising...
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: 30 FPS issue with Physic Engine

Post by Norbo »

There shouldn't be any problems so long as you're not adding/removing dozens of entities per frame. The actual add/remove operation has a little overhead, but if you can get the update time low enough by doing it, it's definitely worth it.
Post Reply