getUTCtime() increases irregularly

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Apr 8 08:44:54 PDT 2007


"david" <tazz at gmx.at> wrote in message news:ev9brv$jo0$1 at digitalmars.com...
> Sorry, here's a draft of the class.
> I'm sure there is a proper name for its funtionality,
> I just don't know it.
>
> david
>
>
> import std.date : d_time, getUTCtime;
>
> // todo: perhaps check in syncCycle if startCycle has been called before 
> at all (costs how much time?)
> /**
>  * prevents a program from running too fast by mapping code to time 
> intervals
>  * note: timer increments are only in quantities of ~15 or ~16 
> milliseconds,
>  * inbetween these intervals there is no increment $(BR)
>  * therefore, the timing can be off ~15 or ~16 milliseconds
>  */
> /** Example:
>  * Assures that after code A is finished at least 100 milliseconds have 
> passed before code C is executed
>  * ---
>  * Sync sync = new Sync;
>  * ... some code A ...
>  * sync.startCycle();
>  * ... some code B ...
>  * sync.syncCycle(100);
>  * ... some code C ...
>  * ---
>  */
> class Sync
> {
> d_time startTime;
> d_time passedTime;
>
> /// set the current time as the reference point
> void startCycle()
> {
> startTime = getUTCtime();
> }
>
> /** wait until msecs milliseconds have passed
> *  since startCycle() has been called last $(BR)
> *  if msecs or more milliseconds have passed already, return immediately
> */
> void syncCycle(d_time msecs)
> {
> passedTime = getUTCtime() - startTime;
> while (passedTime < msecs) // todo: replace passedTime by expression 
> "getUTC... - startT..."
> passedTime = getUTCtime() - startTime;
> }
> }

Ahhh, I guess this would be a "frame rate limiter", at least that's what 
I've heard it called a lot.

Well hey, if getUTCtime() increases with exactly 16ms increments -- there 
you go, perfect 60FPS ;) 




More information about the Digitalmars-d-learn mailing list