Is there a way to copy a space safely?

Discuss new features and future development.

Is there a way to copy a space safely?

Postby fanhe » Sun Oct 23, 2011 9:47 pm

As title, I have not found such api. Is there a plan to add a similar api?
Thanks.
fanhe
 
Posts: 6
Joined: Fri Jan 07, 2011 4:26 am

Re: Is there a way to copy a space safely?

Postby slembcke » Mon Oct 24, 2011 9:23 am

Currently no. That's actually a lot more difficult than it sounds.

Adding serialization is one of my higher priority features to add in the future and that would allow for copying. Not sure when it will be done though.
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: Is there a way to copy a space safely?

Postby fanhe » Tue Oct 25, 2011 10:26 pm

Thanks for reply.
I will try other methods.
fanhe
 
Posts: 6
Joined: Fri Jan 07, 2011 4:26 am

Re: Is there a way to copy a space safely?

Postby ShiftZ » Fri Jan 13, 2012 12:53 pm

slembcke wrote:Currently no. That's actually a lot more difficult than it sounds.

Adding serialization is one of my higher priority features to add in the future and that would allow for copying. Not sure when it will be done though.


With that cool feature you can get hardest pain in ass you ever had with chipmunk. You'll have to reflect all internal structural changes you made in serialization and desrealization code. That might become a real problem when planning new feature.
ShiftZ
 
Posts: 114
Joined: Sat Mar 07, 2009 7:23 am

Re: Is there a way to copy a space safely?

Postby slembcke » Fri Jan 13, 2012 3:19 pm

Yeah, I know. It will be a pain, but I think it will open up a lot of opportunities. I'll probably develop the serialization stuff in a separate branch so that any other Chipmunk changes don't have to be developed in lockstep.
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: Is there a way to copy a space safely?

Postby nikki » Mon Jan 27, 2014 2:34 pm

Actually, because of the nice property listings in cpShape.h and cpBody.h, this isn't too bad. I support save/load in my game engine and the save/load of chipmunk bodies and shapes works out nicely. The code is around here.

What is the other data that should be save/load'd? I'm guessing 'global properties' such as iterations or gravity, and this would all be in cpSpace.
nikki
 
Posts: 1
Joined: Mon Jan 27, 2014 2:30 pm

Re: Is there a way to copy a space safely?

Postby slembcke » Fri Jan 31, 2014 2:36 pm

Saving out a list of the bodies/shapes/constraints gets you most of the way there in practice, and that's pretty easy with the exception of supporting *all* of the constraint types. The problem is that it doesn't store the persistent contact information, or the internal state of the collision detection structures. This is necessary for collision events (begin, separate, etc) to span across serialization calls correctly and for the collision detection to be deterministic. Ideally if you save a simulation and play it back again it shouldn't give you a different result. For that to work, it really has to recreate all of the data structures verbatim, and that's where it gets hard.
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: Is there a way to copy a space safely?

Postby log_2 » Sun Feb 15, 2015 12:22 am

fanhe wrote:Is there a way to copy a space safely?


Depends what you mean by copy. If you want to keep states of all spaces and switch between these states in memory in the current process (i.e. no write/load to disk between processes), then it isn't hard to already do this. All you need is to create custom allocator functions and define cpcalloc, cpfree etc to your functions. Then keep a global memory arena which your allocator uses, which is large enough to hold your spaces. When you want to save your spaces, just memcpy your arena to some other block of memory, and when you want to restore your space just memcpy it back.

I tried to do this with Casey Muratori's looped live reloading, but unfortunately chipmunk litters function pointer in with its data, so once the dll is reloaded the function pointers inside the memory arena are often no longer correct. I'm not sure how to fix this problem. Perhaps resetting the function pointers after the dll is loaded will work, but I will need to patch chipmunk to expose these functions so that the pointers can be reset.
log_2
 
Posts: 1
Joined: Sat Feb 14, 2015 11:37 pm


Return to Features/Development

Who is online

Users browsing this forum: No registered users and 4 guests

cron