Going back in time a bit?

Official forum for the Chipmunk2D Physics Library.

Going back in time a bit?

Postby qkarx » Sun Sep 19, 2010 1:53 am

I'm using the glorious chipmunk library in an iPhone game, and I want to save the state of the space on exit.
I do so by using SpaceManager (as well as storing other relevant values) when the app terminates, and it works perfectly. The only problem is that the app-terminate callback is only called a second or so after the home button was pressed, causing the game to save a state about a second ahead of when the user decided to quit. This can be problematic when the user re-opens the app and suddenly the game is over (this is a fast-paced game!)

My question is if it is possible to save the game state as it was about a second or so backwards in time? I've tried entering a negative value for cpSpaceStep, but it doesn't seem to work.

Thanks!
qkarx
 
Posts: 1
Joined: Sun Sep 19, 2010 1:39 am

Re: Going back in time a bit?

Postby slembcke » Sun Sep 19, 2010 9:38 am

Unfortunately no, there is no way to reverse simulate physics.
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: Going back in time a bit?

Postby mobilebros » Mon Sep 20, 2010 4:43 pm

I wonder if (in your specific case) it'd be enough to loop over all relevant objects and just reverse their position (a tad!) using what you know about the velocity....
mobilebros
 
Posts: 90
Joined: Tue Aug 04, 2009 9:53 am

Re: Going back in time a bit?

Postby dieterweb » Tue Sep 21, 2010 3:49 am

Can you not just save the old positions/velocities/...? Maybe only save every n-th frame and interpolate the frames in between.
Visit our game Blog: http://zombiesmash.gamedrs.com or follow us on twitter: http://twitter.com/zombiesmash
dieterweb
 
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany

Re: Going back in time a bit?

Postby bollu » Wed Sep 22, 2010 7:02 am

Why not negate all values? That may work because physics depends on only "frame in time" (as far as i know but I'm only in 9th grade :D so I'm not sure). I don't know whether it'll work or not but It's worth a try!
bollu
 
Posts: 37
Joined: Tue Sep 14, 2010 4:33 am

Re: Going back in time a bit?

Postby jason_rogers » Fri Sep 24, 2010 4:25 am

I guess technically you could as bollu says rewind yourself by calculating all the physics in reverse, but if you go that far you could as well recode chipmunk ^^

dietweb solution seems the most likely from what you descibe, writting all the information of the shapes and bodies then when you reopen your app you'll have all you data.but then doing such a write would impact on the perf of your game even if you did it once evey second.

What I would like to bring up is the game design "flaw" I think originated this issue. if your game is such fast paced game as you put it, even if you managed to save 2 sec before in time, the time the user react s to the app having reopened he will have died again. I mean if so "little" time is important in the game, the user might get suprised being plunged in the fast paced so suddenly lol (I know it happens to me so often when playing I get back in the game without paying too much attention and bam... dead).

I find it strange this callback issue, I was thinking, ok there is a callback when the application closes, but is there a way to listen at the keys of the devices like volume up and down etc. if there is you could tirgger your own callback for saving

Hope this helps

jason
jason_rogers
 
Posts: 81
Joined: Fri Aug 27, 2010 1:00 am


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest

cron