Re: [AD] Timer patch

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


On 2008-01-30, Ryan Dickie <goalieca@xxxxxxxxxx> wrote:
> 
> I changed counter to double (only used internally to determine how long to
> rest) but left count as long. There's no reason to touch it.
> 
> Just to keep things organized i've attached two patches. The first
> time.patch will change al_rest() and al_current_time() to doubles. I've also
> moved the events.h timestamp change into there.  Also cleaned up the ^M's
> and patches the latest wtime.c. The second patch 'periodic' will change the
> periodic timer to double (windows version excluded).
> 
> -- Ryan Dickie

So the switch to doubles has been decided?  My first reaction was no, but the
1000/60 example is convincing.

Peter

> Index: demo/src/UFO.cpp
> ===================================================================
> --- demo/src/UFO.cpp	(revision 9954)
> +++ demo/src/UFO.cpp	(working copy)
> @@ -19,10 +19,10 @@
>        p->die();
>        my_play_sample(RES_COLLISION);
>        return false;
> -   }
> +   }
>  
> -   if (al_current_time() > (unsigned long)nextShot) {
> -      nextShot = al_current_time() + SHOT_SPEED;
> +   if ( (al_current_time() * 1000) > nextShot) {

Delete the extra space.

> +      nextShot = (int)(al_current_time() * 1000) + SHOT_SPEED;
>        ResourceManager& rm = ResourceManager::getInstance();
>        Player *p = (Player *)rm.getData(RES_PLAYER);
>        float px = p->getX();
> @@ -71,7 +71,7 @@
>     points = 500;
>     ufo = true;
>  
> -   nextShot = al_current_time() + SHOT_SPEED;
> +   nextShot = (int)(al_current_time() * 1000.0) + SHOT_SPEED;
>  
>     ResourceManager& rm = ResourceManager::getInstance();
>     bitmaps[0] = (ALLEGRO_BITMAP *)rm.getData(RES_UFO0);

> Index: demo/src/Player.cpp
> ===================================================================
> --- demo/src/Player.cpp	(revision 9954)
> +++ demo/src/Player.cpp	(working copy)
> @@ -63,9 +63,10 @@
>        default:
>           shotRate = INT_MAX;
>           break;
> -   }
> -   if (((unsigned long)(lastShot+shotRate) < al_current_time()) && input->b1()) {
> -      lastShot = al_current_time();
> +   }
> +
> +   if ( (lastShot+shotRate) < (al_current_time() * 1000) && input->b1()) {

ditto.


> Index: demo/src/logic.cpp
> ===================================================================
> --- demo/src/logic.cpp	(revision 9954)
> +++ demo/src/logic.cpp	(working copy)
> @@ -9,12 +9,12 @@
>  const int MAX_UFO_TIME = 50000;
>  
>  bool logic(int step)
> -{
> -   if (lastUFO < 0) lastUFO = al_current_time();
> +{
> +   if (lastUFO < 0) lastUFO = (long)(al_current_time() * 1000);
>  
> -   if (canUFO && (al_current_time() > (unsigned long)(lastUFO+MIN_UFO_TIME))) {
> +   if (canUFO && ( al_current_time() * 1000 > (lastUFO+MIN_UFO_TIME))) {

ditto.

> Index: src/unix/utime.c
> ===================================================================
> --- src/unix/utime.c	(revision 9954)
> +++ src/unix/utime.c	(working copy)
> @@ -17,12 +17,11 @@
>  
>  
>  #include <sys/time.h>
> -#include <sys/select.h>
> +#include <math.h>
>  
>  #include "allegro5/altime.h"
>  
>  
> -
>  /* Marks the time Allegro was initialised, for al_current_time(). */
>  static struct timeval initial_time;
>  
> @@ -39,17 +38,16 @@
>  
>  
>  /* al_current_time:
> - *  Return the current time, in microseconds, since some arbitrary
> + *  Return the current time, with microsecond resolution, since some arbitrary
>   *  point in time.
>   */

Delete "with microsecond resolution".

> -unsigned long al_current_time(void)
> +double al_current_time(void)
>  {
>     struct timeval now;
> -
> -   gettimeofday(&now, NULL);
> -
> -   return ((now.tv_sec  - initial_time.tv_sec)  * 1000 +
> -           (now.tv_usec - initial_time.tv_usec) / 1000);
> +   gettimeofday(&now, 0); //null = timezone afaik

Put that gettimeofday line back how it used to be.


> Index: include/allegro5/altime.h
> ===================================================================
> --- include/allegro5/altime.h	(revision 9954)
> +++ include/allegro5/altime.h	(working copy)
> @@ -11,17 +11,18 @@
>  
>  
>  /* Function: al_current_time
> - *  Return the number of milliseconds since the Allegro library was
> + *  Return the number of seconds since the Allegro library was
>   *  initialised.  The return value is undefined if Allegro is uninitialised.
> + *  microsecond resolution.
>   */
> -AL_FUNC(unsigned long, al_current_time, (void));
> +AL_FUNC(double, al_current_time, (void));

What do you think about not using the Allegro initialisation time as the base?
I only did that to delay the overflow of a 32-bit integer.


> Index: include/allegro5/events.h
> ===================================================================
> --- include/allegro5/events.h	(revision 9954)
> +++ include/allegro5/events.h	(working copy)
> @@ -142,7 +142,7 @@
>  #define _AL_EVENT_HEADER(srctype)                    \
>     ALLEGRO_EVENT_TYPE type;                          \
>     srctype *source;                                  \
> -   unsigned long timestamp;                          \
> +   double timestamp;                          \
>     signed int _refcount;            /* internal */   \
>     union ALLEGRO_EVENT *_next;      /* internal */   \
>     union ALLEGRO_EVENT *_next_free  /* internal */

Fix the spaces.


> --- src/unix/utimernu.c	(revision 9954)
> +++ src/unix/utimernu.c	(working copy)
> @@ -25,24 +25,18 @@
>  #include "allegro5/internal/aintern_events.h"
>  
>  
> -
> -/* readability typedefs */
> -typedef long msecs_t;
> -typedef long usecs_t;
> -
> -
>  /* forward declarations */
> -static usecs_t timer_thread_handle_tick(usecs_t interval);
> +static double timer_thread_handle_tick(double interval);
>  static void timer_handle_tick(ALLEGRO_TIMER *this);
>  
> -
> +   double new_delay = 0.032768;

Delete that.

>  struct ALLEGRO_TIMER
>  {
>     ALLEGRO_EVENT_SOURCE es;
>     bool started;
> -   usecs_t speed_usecs;
> +   double speed_secs;
>     long count;
> -   long counter;		/* counts down to zero=blastoff */
> +   double counter;		/* counts down to zero=blastoff */
>  };
>  
>  






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