allegro timer

This is a discussion on allegro timer within the Game Programming forums, part of the General Programming Boards category; I'm need a pretty precise clock for a game I'm making with allegro, but I can't seem to get the ...

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    allegro timer

    I'm need a pretty precise clock for a game I'm making with allegro, but I can't seem to get the allegro timer to run the way it's supposed to. I wrote this code to try to get it to tick 1000 times a second, but it just counts seconds:
    Code:
    #include "allegro.h"
    
    volatile long timer;
    
    void timerisr() {
      ++timer;
    }
    END_OF_FUNCTION(timerisr);
    
    int main() {
      allegro_init();
      install_timer();
      install_keyboard();
      set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0);
      BITMAP *buffer = create_bitmap(SCREEN_W,SCREEN_H);
      LOCK_VARIABLE(timer);
      LOCK_FUNCTION(timerisr);
      install_int(timerisr,MSEC_TO_TIMER(1));
      while (!key[KEY_ESC]) {
        clear_bitmap(buffer);
        textprintf_centre(buffer,font,SCREEN_W/2,SCREEN_H/2,15,"%d",timer);
        blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
      }
      destroy_bitmap(buffer);
    }
    END_OF_MAIN();
    In my game I've been calling install_int(timerisr,1), and the way I did it here with
    install_int(timerisr,MSEC_TO_TIMER(1)) didn't work either. Does anybody know what I'm doing wrong?
    Last edited by ichijoji; 12-07-2004 at 12:53 AM.
    Illusion and reality become impartiality and confidence.

  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    I've taken this from the description of install_int() in Allegro's readme file
    int install_int_ex(void (*proc)(), int speed);
    Adds a function to the list of user timer handlers or, if it is already
    installed, retroactively adjusts its speed (i.e makes as though the speed
    change occured precisely at the last tick). The speed is given in hardware
    clock ticks, of which there are 1193181 a second. You can convert from
    other time formats to hardware clock ticks with the macros:

    SECS_TO_TIMER(secs) - give the number of seconds between
    each tick
    MSEC_TO_TIMER(msec) - give the number of milliseconds
    between ticks
    BPS_TO_TIMER(bps) - give the number of ticks each second
    BPM_TO_TIMER(bpm) - give the number of ticks per minute
    Using MSEC_TO_TIMER(1) should give you what you need. Maybe you were thinking of the install_timer() function instead, which works the same but has its speed natively in milliseconds.

  3. #3
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    I tried MSEC_TO_TIMER(1), and it counts once every second. Maybe allegro isn't installed right or is conflicting with my system?
    Illusion and reality become impartiality and confidence.

  4. #4
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    That's odd. I guess it's a possibility that allegro is installed correctly, but I doubt it. Have you made any other programs with allergo before? When I can get home in a few minutes I will play around with it and see if I figure it out.

  5. #5
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    This is the first problem I've had. Everything else works just like it's supposed to.
    Illusion and reality become impartiality and confidence.

  6. #6
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    For some reason I can't compile your code, so I can't do much. Maybe you should try re-installing allegro, it may help. I really have no idea why it won't work anymore.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 03:00 AM
  2. allegro timer in a class
    By MadHatter in forum Game Programming
    Replies: 7
    Last Post: 12-06-2002, 10:06 PM
  3. Using a timer in allegro
    By Ion Blade in forum Game Programming
    Replies: 6
    Last Post: 09-15-2002, 05:50 PM
  4. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-21-2002, 12:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21