[SOLVED] Disabling bodies from simulation

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

[SOLVED] Disabling bodies from simulation

Postby Gianluca » Mon Jan 10, 2011 6:39 am

Hello, (and happy new year)
I need to totally disable some bodies during the simulation for a certain interval and then re-enable them. In this period, I want that the NewtonUpdate speed up as if the bodies simply does not exists.

My first idea was to set a Null Collision to bodies and to set a Null all callbacks regarding the bodies.
In that way, I suppose that the NewtonUpdate should simply skip the bodies and do nothing.
I tested the execution time of an empty NewtonWorld, of a NewtonWorld with 100 bodies active, and of a NewtonWorld with 100 bodies disabled as above.
There is no time difference between the last two conditions. Why ?? If there is no collision on bodies, and if there is no callbacks to call... why NewtonUpdate takes exactly the same time as if the bodies has collision and callbacks set ???

What can I do in order to disable all bodies in a NewtonWorld and reach more or less the execution time as a truly empty NewtonWorld ???
(I would prefer to avoid the destruction of the body)

Thanks,
Gianluca.
Last edited by Gianluca on Mon Jan 10, 2011 12:14 pm, edited 1 time in total.
Gianluca
 
Posts: 53
Joined: Fri Nov 11, 2005 4:37 am
Location: Rome - Italy

Re: Disabling bodies from simulation

Postby JernejL » Mon Jan 10, 2011 6:51 am

You can try freezing it and set a material which never collides with any other.

Or just delete the body, i use this and it works ok.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Disabling bodies from simulation

Postby Gianluca » Mon Jan 10, 2011 7:01 am

I tried freezing it and using a material that never collides... but anyway, the 80% of execution time is spent on collision handling... and the time needed for one step of NewtonUpdate is the same as the bodies are not freezed and with the default material.
That's way, my second test was to set also a Null Collision and to nullify any callback.
But the execution time remain the same.

Ok, at the end I can destroy the body... but I prefer to avoid that solution.

Anyway, I'm wondering what's the difference between an empty Newton world and a newton world with bodies without collisions and callbacks.
Why in the latter case netwonupdate spend time on collision handling and dynamics updating ??

Thanks,
Gianluca.
Gianluca
 
Posts: 53
Joined: Fri Nov 11, 2005 4:37 am
Location: Rome - Italy

Re: Disabling bodies from simulation

Postby JernejL » Mon Jan 10, 2011 9:45 am

i do destroying & creating of bodies at runtime, it works really fast.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Disabling bodies from simulation

Postby Julio Jerez » Mon Jan 10, 2011 12:15 pm

Gianluca wrote:My first idea was to set a Null Collision to bodies and to set a Null all callbacks regarding the bodies.
In that way, I suppose that the NewtonUpdate should simply skip the bodies and do nothing.
I tested the execution time of an empty NewtonWorld, of a NewtonWorld with 100 bodies active, and of a NewtonWorld with 100 bodies disabled as above.
There is no time difference between the last two conditions. Why ?? If there is no collision on bodies, and if there is no callbacks to call... why NewtonUpdate takes exactly the same time as if the bodies has collision and callbacks set ???


that was true of sdk 1.xx, in 1.xx inactive bodies where keetd in a separate list, and each body had a pointer to the list node.
Sicne the list where of the same kind, it was constanat time to move a body from one list to the next.
that made newton take almost zero time in a update popultated with bodies with NULL collision or sleeping bodies.
Newton 1.xx did not have a Force And TorqueCallback loop, activation and diactivation were handled by moving bodies from one list to the next.

with Newton 2.00 one for the main issue is mutithreading, so the above scheme made activation and dactivation happen in a critical section
and what became the become the biggest performnace bottlenect on the engine.
Newton 2.00 uses a much simpler approach, the body has a flag that indicate if it is sleepping or not.
then there is a loop that go over the list calling force and torque callback (even if the body is sleeping) and take care of the sleepping state of the body.
The loop is runned uncoditianlly on each call to newton update. and it is uses as the hartbeat of the simulation.

As it is now there is not way the newton 2.00 can ignore bodies.
what we can do is add the funtionality to remove a body from the simulation,

something like:
NewronRemoveBody(world, body)
NetwonInsertBody(world, body)
this can maybe be used to move bodies from one work to anotherr which is a funtionality Newton never had.
and it will handle NULL bodies, because make a body with Null collision deos no mean it sodu no get force and torque callback.

does that sound like a solution to you?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [SOLVED] Disabling bodies from simulation

Postby Gianluca » Mon Jan 10, 2011 1:05 pm

Thank you Julio... but my idea works.
When I posted there was a bug in my code that slow down everything.
But now it works.
Essentialy, if I freeze a body and I set a null collision and I unset the callbacks... NewtonUpdate as the same speed is the body would be destroyed :-)

I edited the title to [SOLVED]... but I forget to write how.

However, If you would add the two function you mentioned... it would be even better.

Thank you,
Gianluca M.
Gianluca
 
Posts: 53
Joined: Fri Nov 11, 2005 4:37 am
Location: Rome - Italy

Re: [SOLVED] Disabling bodies from simulation

Postby Julio Jerez » Mon Jan 10, 2011 1:10 pm

Ok I will add those functions this satuday, it should be very simple.

I did not now why I did not think of that.
That will be of great help for people doing mutiplayer worlds with mutiple worlds
if they can move a body from one world to the other
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [SOLVED] Disabling bodies from simulation

Postby Gianluca » Tue Jan 11, 2011 5:16 am

Thank you very much.

A final favour, the project where I use newton is shared amongs variour laboratories... so, before I can update the newton I need to get newton libraries for all platforms... there are strict rules that I have to respect, and I cannot update if the same version is not available on all platforms (win, lnx, mac).

Can you compile the mac version as soon as possibile ???

Thank you very much,
Gianluca.
Gianluca
 
Posts: 53
Joined: Fri Nov 11, 2005 4:37 am
Location: Rome - Italy

Re: [SOLVED] Disabling bodies from simulation

Postby Julio Jerez » Tue Jan 11, 2011 10:58 am

I will compile the Mac this weekend.

Th ereason is is delayed is that need to make the demo framework usin the Mac GUI since I abandome wxWidget.
however I still can compile all the libraries and post the SDK.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [SOLVED] Disabling bodies from simulation

Postby collerblade » Thu Feb 24, 2011 6:17 pm

Julio
We need this functions. I could not find in the new version (2.30). Have u implemented them?

Code: Select all
NewtonRemoveBody(world, body);
NewtonInsertBody(world, body);


And i have another question. How can i awake the slept bodies?


Thx CollerbladE
collerblade
 
Posts: 88
Joined: Mon Apr 05, 2010 12:09 pm

Re: [SOLVED] Disabling bodies from simulation

Postby Julio Jerez » Thu Feb 24, 2011 7:20 pm

Oh with the Opensource stuff I fogot.
I will add it this weekend.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [SOLVED] Disabling bodies from simulation

Postby KingSnail » Wed May 04, 2011 5:24 pm

Bumping this because I dont think this is implemented yet?
Have you forgotten about this? :P
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron