strange timer behaviour
Frank Drebin

ok i got the default game loop
speed_counter is incremented 100 times per second.

while (!key[KEY_ESC])
{
   while (speed_counter>0)
   {
      game();
      speed_counter--;
   }
   draw_game();
   //while (speed_counter==0) rest(1);
}

this way i get 100+ FPS.
if i uncomment the rest(1)-line my FPS-counter stays at 64.
so shouldn't i get here FPS around 100, too?

Jonatan Hedborg

Are you using vsync or tripple-buffering?

Frank Drebin

no just double buffering.
the strange thing is that i uncommented this line once before and then it worked fine...
this was with an older compiler but this shouldn't matter!

Kitty Cat

Resting isn't accurate. Resting for 1ms will cause you to rest closer to 10ms (giving you 100 FPS max). Then add in the time to do the logic and render each frame, and possible background tasks in the system, and you'll get less than 100 FPS. What's your speed if you use rest(0) instead of rest(1)?

Frank Drebin

for rest(0) it's the same thing.
and i know that the timer isn't that accurate but when i did this before the FPS were around 100 (+- 5) but not constant 64...

Arthur Kalliokoski

Maybe something has turned on your vid card vsync. Just a week ago my favorite old DOS editor could use the extended keys again for no reason that I could see.

"I hate computers, they're so nasty and complex. I could just pinch them" Marvin the Martian

Frank Drebin

in this case is there any way to disable vsync or do i have to reintstall the older version of mingw?

Kitty Cat

I doubt its your compiler. There should be an option in your video card settings to force vsync on or off, or leave it application defined.

I doubt it's a vsync issue though. What version of Allegro do you have?

Goalie Ca

Calling rest(1) forces the OS to put the process on the queue and hence reschedule it. 10ms time slices isn't too uncommon. Quick guess, you using windows?

ps: This is why its not a "real-time" os.

Frank Drebin

yes its in windows (and linux) and newest allegro
even if rest(1) would delay more than 10 ms there would be only a few frames less but not that much

Thomas Fjellstrom
Quote:

even if rest(1) would delay more than 10 ms

Tasks/Threads get 10ms slices, its more than possible to loose 100ms after doing your slice, it all depends on the system load, and the priorities all threads are running at.

edit, You CANNOT depend on the scheduler doing anything in a non real time OS.

Frank Drebin

ok i reinstalled the older verision of the compiler with no success.
i said my timer runs 100 times per second and with rest(1) i get 64FPS.
i have tested timers that runs 50 and 40 times per second and here i get the 50 and 40+-1 FPS.
so whats the difference betwenn a 50 and a 100 BPS timer ???

BrknPhoenix

edit: Eh nevermind, not entirely sure what you're getting at

Kitty Cat
Quote:

so whats the difference betwenn a 50 and a 100 BPS timer

About twice as many tics (meaning more logic calls, and more attempted frames drawn). If your system is just barely keeping up at 100FPS with no resting, it can lose several frames if you try to rest any.

Frank Drebin

i know that 100 is twice as fast as a 50 BPS timer...
i meant what makes the difference in the FPS?

and without rest(1) i get around 150 FPS so this shouldn't be the problem.

[edit]
even this code doesn't work - test it yourself !

1#include <allegro.h>
2 
3volatile int speed_counter=0;
4volatile int fps=0;
5volatile int frames=0;
6BITMAP* bbuffer;
7 
8void increment_speed_counter()
9{
10 speed_counter++;
11}
12END_OF_FUNCTION(increment_speed_counter);
13 
14void update_fps()
15{
16 fps=frames;
17 frames=0;
18}
19END_OF_FUNCTION(update_fps);
20 
21void init()
22{
23 allegro_init();
24 install_keyboard();
25 set_color_depth(16);
26 set_gfx_mode(GFX_AUTODETECT_FULLSCREEN,640,480,0,0);
27 install_timer();
28 LOCK_VARIABLE(speed_counter);
29 LOCK_VARIABLE(fps);
30 LOCK_VARIABLE(frames);
31 LOCK_FUNCTION(increment_speed_counter);
32 LOCK_FUNCTION(update_fps);
33 install_int_ex(increment_speed_counter,BPS_TO_TIMER(100));
34 install_int_ex(update_fps,BPS_TO_TIMER(1));
35}
36 
37int main()
38{
39 init();
40 
41 bbuffer=create_bitmap(640,480);
42
43 while (!key[KEY_ESC])
44 {
45 while (speed_counter>0)
46 {
47 speed_counter--;
48 }
49 clear_bitmap(bbuffer);
50 textprintf_ex(bbuffer,font,0,0,makecol(255,255,255),-1,"FPS: %i",fps);
51 blit(bbuffer,screen,0,0,0,0,640,480);
52 frames++;
53 while (speed_counter==0) rest(1);
54 }
55 
56 destroy_bitmap(bbuffer);
57
58 return 0;
59}
60END_OF_MAIN()

Kitty Cat

Both rest(0) and rest(1) give me 55~60 FPS with that. Granted though, X isn't the best at getting the fastest speed.

Frank Drebin

yes someone try it in windows!

Thread #585737. Printed from Allegro.cc