Box2D Forums

It is currently Fri May 24, 2013 4:35 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Fri Dec 07, 2007 9:23 pm 
Offline

Joined: Thu Oct 04, 2007 5:46 am
Posts: 19
ewjordan wrote:
CommanderKeith is working out some of this in Java, but I think his solution is extremely Java specific.


Hi,

My way of saving state just invloves making a copy of the World by saving every single field in World and all its field's fields etc. The method I'm using is automatic - uses reflection to read and copy every object's fields. Isn't there something similar in other languages?

Erin gave me the idea to do this back when I asked if negative time updates were possible to go backwards in time and he said no, but that if you saved game state like 'prince of persia' then you can go back to the saved world and update forward to where you want to be. That's pretty much what I did (of course there are complications and I haven't quite got it to work with JBox2D yet, but it works with more simple things).

Cheers,
Keith

PS: I think XML is the wrong way to go, it would be too slow and with all of the parsing it would only be a solution for saving and loading games, not really for sync'ing server and client worlds by sending the whole game world to clients many times per second.


Top
 Profile  
 
PostPosted: Fri Dec 21, 2007 2:02 am 
Offline

Joined: Fri Dec 07, 2007 3:09 pm
Posts: 241
So...

In the meantime, while we're going about figuring out the best way to save the game state... the general consensus about saving and loading maps/levels is that we should keep a copy of the BodyDefs? Can't seem to restore the proper information from a b2Body.

I think I'm going to use XML for this in case Erin adds (and probably) will add more variables to the bodies..the binary data would become corrupt. This way I can at least see what's missing and use default values. Might also be useful to hand-tweak if my editor isn't sufficient.


Top
 Profile  
 
PostPosted: Fri Dec 21, 2007 3:06 am 
Offline

Joined: Tue Dec 11, 2007 3:05 am
Posts: 106
Maybe a b2Body.saveData() and loadData() function in the core would be useful. ;)


Top
 Profile  
 
PostPosted: Sun Dec 23, 2007 7:47 pm 
Offline

Joined: Fri Dec 07, 2007 3:09 pm
Posts: 241
Yeah...it would be... but the question is, is that b2's responsibility?

The way I'm doing it now with my editor...

Every time I create a body, I push the bodydef onto an std::vector
When I save I just pull the data from the bodydefs.
When I delete an object however... I need to correlate the b2Body with with the b2BodyDef. So I'm storing the index of the b2BodyDef in the vector in the userData. Then when I delete a body, I just need to retrieve the index and delete the b2BodyDef too. Problem is...soon as you delete something, the std::vector updates all the indices, which screws everything else up. So now I either need to decrement all the indices stored in userData every time I delete something, or I need to switch over to an array of b2BodyDef's and take a bit of a memory hit.

Thoughts?


Last edited by darkzerox on Sun Dec 23, 2007 10:52 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sun Dec 23, 2007 9:23 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
In my experience user data objects are best kept in a pool. You'll need to figure out the pool size ahead of time and use a free list.

If your user data object storage must be of variable size then you can store a GUID in the body user data and use a hashtable to go from GUID to user data object. The GUID can just be the body creation number (e.g. the 23rd body created since app launch).


Top
 Profile  
 
PostPosted: Mon Aug 06, 2012 5:49 pm 
Offline

Joined: Tue Apr 03, 2012 11:55 am
Posts: 3
sorry for bringing this old post up, but have you came up with a complete solution?
some kind of library extension or patch to box2d
Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group