Playing time - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Playing time (/thread-8185.html)
Playing time - Miglu - Oct 8, 2010 09:52 AM
What is the best way to get the playing time, so that it could be put on a scoreboard?
RE: Playing time - ThemsAllTook - Oct 8, 2010 11:00 AM
Since your post is so vague, I'll make some guesses to fill in the gaps. Presumably you're trying to measure the amount of real time that the player has spent in a gameplay session? This is as simple as getting the current time when gameplay starts (via whatever time measurement query you'd normally use), getting it again when it ends, and subtracting the previous measurement. Be aware of the difference between wall time and monotonic time, though; presumably you'll want to measure in monotonic time to prevent cheating by altering the system clock during gameplay.
RE: Playing time - Miglu - Oct 8, 2010 03:15 PM
called, like in the tutorial, except that this is an Objective-C method. I also have printf("%lu seconds, %lu nanoseconds\n", tp.tv_sec, tp.tv_nsec), but the values are always 0, even though I have startTime = mach_absolute_time() and endTime = mach_absolute_time() earlier in the code. What could the problem be?
RE: Playing time - Zorg - Oct 8, 2010 03:56 PM
The problem is probably that tp's value is being passed and that value is only being modified locally in mach_absolute_differenceEnd. You need to pass a pointer to a struct timespec, which is what the tutorial does.