As title, I have not found such api. Is there a plan to add a similar api?
Thanks.
Is there a way to copy a space safely?
-
- Posts: 6
- Joined: Fri Jan 07, 2011 4:26 am
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Is there a way to copy a space safely?
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.
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 6
- Joined: Fri Jan 07, 2011 4:26 am
- Contact:
Re: Is there a way to copy a space safely?
Thanks for reply.
I will try other methods.
I will try other methods.
-
- Posts: 114
- Joined: Sat Mar 07, 2009 7:23 am
- Contact:
Re: Is there a way to copy a space safely?
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.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.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Is there a way to copy a space safely?
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 1
- Joined: Mon Jan 27, 2014 2:30 pm
- Contact:
Re: Is there a way to copy a space safely?
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.
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.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Is there a way to copy a space safely?
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 1
- Joined: Sat Feb 14, 2015 11:37 pm
- Contact:
Re: 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.fanhe wrote:Is there a way to copy a space safely?
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.
Who is online
Users browsing this forum: No registered users and 1 guest