Playing time

Posts: 131
Joined: 2010.08
Post: #1
What is the best way to get the playing time, so that it could be put on a scoreboard?
Quote this message in a reply
Posts: 1,563
Joined: 2003.10
Post: #2
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.
Quote this message in a reply
Posts: 131
Joined: 2010.08
Post: #3
I have
- (void) mach_absolute_differenceEnd: (uint64_t) end Start: (uint64_t) start Tp: (struct timespec) tp {  
        uint64_t difference = end - start;  
        static mach_timebase_info_data_t info = {0,0};  

        if (info.denom == 0)  

        uint64_t elapsednano = difference * (info.numer / info.denom);  

        tp.tv_sec = elapsednano * 1e-9;
        tp.tv_nsec = elapsednano - (tp.tv_sec * 1e9);

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?
Quote this message in a reply
Posts: 35
Joined: 2010.01
Post: #4
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.
Quote this message in a reply
Post Reply