NewtonBody object pool?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonBody object pool?

Postby Neo » Mon Dec 03, 2012 1:50 am

I'm trying to make an object pool for the stuff that are frequently created and destroried in the game(such as bullets and shells).
But I have no idea about how to store the NewtonBody in the object pool. In other words, what I want to do is to
create a NewtonBody but not put it in to the world immediately, instead, store it in the object pool until I take it out from the obejct pool.
Any ideas?
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: NewtonBody object pool?

Postby Julio Jerez » Mon Dec 03, 2012 9:22 am

the engine does not support creating bodies outside the world. Th epart tha is expenesive on creation bodies is making the collsion shape, you can make a teh copllsion shape in advance and reuse it for you body creation.

there is no peneaty for make a body in newton, you can make a dozen of sevral dozen in teh same frame and as long as teh collsion shape was premade, the cost of that is neglegible.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBody object pool?

Postby Neo » Mon Dec 03, 2012 10:40 am

Ok,I'll make a class to store the collision,and make body when needed.
Previously, the newton body of the object,like bullet, is created by the class itself.And it occasionally crash the game on the remove operation(seems that the object has already removed). That's why I have to switch to some other patterns which are more stable. :)
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: NewtonBody object pool?

Postby Julio Jerez » Mon Dec 03, 2012 10:58 am

the engine should not crash creating a body under any circuntances.
I was thinking to add a feature to move a body from one world to another, this could be used for what you want to do.
bascially you can make a world as a repository of bodies the you want to use. then you can call NetwonBodyBody (NewtoWorld* dstWorld)
and that will do the trick, do you thing that codul help?

however the engine should no crash, can you tell me more about that crash?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBody object pool?

Postby Neo » Mon Dec 03, 2012 12:50 pm

Oh...I think it's my bug.
Generally a shell hit something should then explode.
And after explostion has triggered, the object of shell should be deleted.
Actually it works right, but occasionally the game would crash at the code of delete operation. It seems that the shell has already been deleted.
I have no idea of how it happens, this bug doesn't occur frequently, every works right most of the time.There might be something wrong in my code. It's not newton engine's problem.
Use another world as a repository seems like a good idea. However,does a new world cost a lot memery ?
Neo
 
Posts: 127
Joined: Fri May 11, 2012 12:29 pm
Location: China,Sichuan

Re: NewtonBody object pool?

Postby Julio Jerez » Mon Dec 03, 2012 12:54 pm

do you know that newton body have a destructor callback?
when you create a body, you can assign a function callback that will be called when the body is about to be destroyed, this is usefull for debug that kind of bugs.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron