[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: time tutorial



On 10-Dec-1999 Lutz Sammer wrote:
> Erik wrote:
>> 
>>         -Erik <erik@smluc.org> [http://math.smsu.edu/~br0ke]
>> 
>> The opinions expressed by me are not necessarily opinions. In all
>> probability, they are random rambling, and to be ignored. Failure to ignore
>> may result in severe boredom or confusion. Shake well before opening. Keep
>> Refrigerated.
>> 
> 
> Your wish is an order,
> 

really? wait right there while I make my wishlist...

> First to avoid zero times or infinite results, scale your results and
> add
> a call counter to the result.
> 
>       static clock_t last_clock;
>       static int clock_counter;
>       int new_clock;
>       
>       new_clock=clock();
>       if ( new_clock == last_clock ) {
>               return last_clock*100 + clock_counter ++;
>       }
>       clock_counter=0;
>       last_lock=new_clock;
>       return last_clock*100;
> 

the problem with a 0 time delta is that the FPS counter will go buggy. The game
physics will still be pretty much on the mark (they'll just record that there
was no change in anything, which is what you'd expect if there was no change in
time). This still leaves the FPS's quantitized, so I think the alterior method
I described, of using the time for several frames, would be a much better
choice. If other people disagree, then I'll fix up the paper... :)

> 
> Second you forget the "tsc" (time stamp counter) register, which is
> available atleast
> on any ">=586" and alphas.
> This gives you the exact time, no overhead (task-switches, calls, ...),
> here is the code:
> 
> /**
> **      Read the tsc (time-stamp counter) register of the processor.
> **
> **      @return the rtc register
> */
> static __inline u_int64_t rdtsc(void)
> {
>#ifdef __i386__
>     u_int64_t rv;
> 
>     __asm __volatile(".byte 0x0f, 0x31" : "=A" (rv));
>#endif
>#ifdef __alpha__
>     int rv;
> 
>     __asm __volatile("rpcc %0" : "=r" (rv));
>#endif
> 
>     return rv;
> }

The overhead to grab the time is neglegible compared to the time to draw a
simple screen. I'd hope that people would use as portable a means as they can
without degradating the quality of the software. While it's important to know
asm and asm is very useful in doing things like boot code and device drivers,
I'd hope it'd be used in something like games as little as possable. While it's
neat to know about tsc/rtc, I'd hope it doesn't get used in this way :)

> 
> Johns
> -------------------------------------------------------------------------
> ALE Clone: Free W*rCr*ft II source: http://yi.org/johns
> 

(where's the starcrap clone??? :)

        -Erik <erik@smluc.org> [http://math.smsu.edu/~br0ke]

The opinions expressed by me are not necessarily opinions. In all
probability, they are random rambling, and to be ignored. Failure to ignore
may result in severe boredom or confusion. Shake well before opening. Keep
Refrigerated.