Re: [AD] use double for al_current_time and al_rest?

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I agree, calendar time is almost useless for games. However some helper functions can easily get the number of nanos/micros/millis/years between two calendar times.

Anyway, making some calculations I saw that a 64 bit-integer is big enough to have nanosecond precision for more than 1000 years without overflow. So this would be a nice representation for internal time and is a good return value for al_get_current_time. Some helper functions could convert this to a gregorian calendar time value easily.

As explained by Ron, the current time is not very useful, the time interval is better. But an interval could be calculated easily by subtraction of two calendar times.

Victor Williams Stafusa da Silva

Ron Novy <ron.novy@xxxxxxxxxx> escreveu:
Why not use a counter that is reset every call instead of a timer.  Use a function like al_get_counter or something and have it return a double or have multiple versions like al_get_counter (unsigned long) and al_get_counter_d (double)... This would give infinite resolution and make time relative to the app/game/thread using it...  You could also keep al_current_time as a count of total time but the user could also do this by adding all the calls to al_get_counter together in there own code...


/* Simple example where al_counter is incremented elsewhere */
static unsigned long al_counter = 0;
static unsigned long al_count_per_second = 60; /* Example */
unsigned long al_get_counter(void)
{
   unsigned long ret = al_counter;
   al_counter = 0;
   return ret;
}

double al_get_counter_d(void)
{
   double ret = (double)al_counter / (double)al_count_per_second;
   al_counter = 0;
   return ret;
}

Peter Wang <novalazy@xxxxxxxxxx> wrote:
On 2007-12-28, Victor wrote:
> IMHO the better definition of "current time" is not a long, fixed, int or double. It is some sort of structure containing day, month, year, hour, minute, second and milli-micro-or-nanoseconds.
> To measure the amount of time betewwen two different times, some helper functions can do it easily.

Calendar time is pretty useless for most game situations (and there are
standard C functions for that, albeit only with second granularity).
What most games need is the interval between two points in time, e.g.
between two frames, in a single unit if possible.

Peter


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
--
https://lists.sourceforge.net/lists/listinfo/alleg-developers


Never miss a thing. Make Yahoo your homepage. -------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/--
https://lists.sourceforge.net/lists/listinfo/alleg-developers


Abra sua conta no Yahoo! Mail, o único sem limite de espaço para armazenamento!

Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/