Re: [AD] use double for al_current_time and al_rest? |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
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, Victorwrote:
> 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
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |