April 08, 2007
Jarrett Billingsley schrieb:
> "Manfred Nowak" <svv1999@hotmail.com> wrote in message news:ev3jhs$28o4$1@digitalmars.com...
>> Jarrett Billingsley wrote
>>
>>> Unfortunately if David is looking to use this as a timestamp
>> In the OP it says:
>>
>> | playing with a slow down class
>>
>> -manfred
> 
> I... don't know what that is. 
> 

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;
	}
}
April 08, 2007
david wrote:
> Jarrett Billingsley schrieb:
>> "Manfred Nowak" <svv1999@hotmail.com> wrote in message news:ev3jhs$28o4$1@digitalmars.com...
>>> Jarrett Billingsley wrote
>>>
>>>> Unfortunately if David is looking to use this as a timestamp
>>> In the OP it says:
>>>
>>> | playing with a slow down class
>>>
>>> -manfred
>>
>> I... don't know what that is.
> 
> 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;
>     }
> }

Aka, you want it to lock the application to a certain "frame rate", aye?  I'm really not sure what the technical term is either, so I usually just state the obvious descriptor: "frame rate lock".  ;P  In this case, perfect precision may not be neccessary anyhow... but I guess that all depends on what you are implementing with it.

-- Chris Nicholson-Sauls
April 08, 2007
"david" <tazz@gmx.at> wrote in message news:ev9brv$jo0$1@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 ;)


1 2
Next ›   Last »