cpspaceRemoveShape() should use a different callback.

Discuss new features and future development.

cpspaceRemoveShape() should use a different callback.

Postby Scarlet » Mon May 21, 2012 12:29 pm

A while back a had a problem with cpspaceRemoveShape() http://chipmunk-physics.net/forum/viewtopic.php?f=1&t=2010

I saw the issue was fixed, but even still I think cpspaceRemoveShape() should have its own callback and not use the separate callback.

For example, when Shape A separates from Shape B you "play a sound and update the score in the separate callback".( Maybe something like a runner crossing a Finish Line.) But say Shape A can be destroyed by a missile. The missile can remove Shape A from the Space. If Shape A is in contact with shape B at the time of being destroyed, this will trigger the "sound and score update in the separate callback" when it is not wanted.

It feels weird to have collision callbacks occur outside the step. To me separate from natural physics is very different than separate by space removal.

To counter this problem I usually give an extra Boolean property to my objects. But I think this should be unnecessary.
Scarlet
 
Posts: 13
Joined: Tue Aug 16, 2011 2:55 pm

Re: cpspaceRemoveShape() should use a different callback.

Postby slembcke » Mon May 21, 2012 1:59 pm

Hmm. So I guess I see where you are coming from, but I can't really add another callback and have it be backwards compatible. It would also make a bit of a mess of the API maybe. I'll have to think about if there is a good way to do this... Perhaps a function like cpArbiterIsRemoval() or something like that, which would return true when it's due to a removal.

Anyway, Unity's physics doesn't give you separate events when objects are removed, which led to a lot of frustrating bugs before we really figured out what was going on. We had been writing code that assumed that that begin/separate were always called as matched pairs (with the exception of disposing of an entire scene maybe). The really frustrating thing was that to work around it, you had to keep your own list of all of the colliding pairs of things that you'd want to call the separate code for when removing things. So that is where the current design came from. At least in every case where I've ever used separate callbacks, having it call them during removals has made complete sense. Although I don't think I've ever put much logic in them. Usually just decrementing a counter or some other piece of state that tracks overlapping pairs.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: cpspaceRemoveShape() should use a different callback.

Postby Scarlet » Mon May 21, 2012 2:29 pm

Thanks for considering. By the way do you think cpArbiterIsRemoval() or another solution will be out soon?

I plan on getting Chipmunk Pro in mid June for my next game. it would be cool if this feature is implemented by then!
Scarlet
 
Posts: 13
Joined: Tue Aug 16, 2011 2:55 pm


Return to Features/Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron