iDevGames Forums
iPhone game loop - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: iPhone game loop (/thread-7907.html)



iPhone game loop - agreendev - Jul 27, 2010 06:24 AM

I've been trying to game my engine's physics updates seperate from my draw calls using the following method:

http://gafferongames.com/game-physics/fix-your-timestep/

But I'm unclear as to how I should actually implement this. Is the actual application 'loop' implemented by the timers created within my GLView? The way I'm understanding this site is that this should all be implemented in the 'game loop', which to me right now is only comprised of the draw call tied to CADisplayLink, but I want the two to be completely separate, correct? Should I be keeping track of when the draws happen, store that time and create a separate timer function that fires off as quick as possible, and within there add the code for determining the animation update? I still have yet to grasp where the actual 'loop' of execution is, so I'm just getting hung up in trying control the flow of execution without going through the draw call.

Thanks in advance for any help.


RE: iPhone game loop - Skorche - Jul 27, 2010 11:05 AM

Well, if you are using a timer or a CADisplayLink, then that is what is controlling the body of your loop. You just need to grab the current time at the beginning of each loop to figure out how many fixed steps to perform to catch up and how much interpolation to use (if you are doing that).


RE: iPhone game loop - AnotherJake - Jul 27, 2010 11:32 AM

Exactly. And after you've calculated how many steps you can do, there will be a tiny amount of time left over; that's your interpolation value if you want to use it. You don't have to go to the extra trouble of interpolation unless you want super precise animation. It's a bit of a pain in the rear to implement it but it looks real nice.