Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » FPS: how to calculate & limit

This thread is locked; no one can reply to it. rss feed Print
FPS: how to calculate & limit
Joseph lastname
Member #1,581
October 2001

Hey,

I'm at the point now where my engine needs to have a constant FPS. I haven't used the allegro timer routines yet, and I'm not sure where to start with this...

How do I set up a timer to calculate FPS, and then, how do I limit the FPS to a constant rate? ie: 30fps.

Thanks

23yrold3yrold
Member #1,134
March 2001
avatar

Click on the FAQ in my sig and look for "How can I make my game run at the same speed on any computer?" in the General section. Also click on Pixelate and look in issue 8 for a timer tutorial that might also help.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Joseph lastname
Member #1,581
October 2001

OK, thanks... I got that working.

but now I have another question:

I want to be able to load the defualt FPS from a file. I already have a cfg file set up, but when I use a varible in BPS(), my program crashs.

ie:

load_cfg();
install_int_ex(timer_increase, BPS_TO_TIMER(sys.fps));

sys.fps is a part of a global type.
It works fine when I use a number..

and also, what varible holds the actual FPS?

thanks

SystemDown
Member #663
September 2000
avatar

Have you checked if the variable you're passing in is zero? the BPS_TO_TIMER() macro divides a long value by the number you give it, so a divide by zero error might be happening.
Otherwise.. I don't know what's going on there.

To store the FPS, I have used this method before and it works fine for me (sorry about lack of comments, but I think it's pretty straightforward)

1volatile int speed_count = 0;
2volatile int frame_count = 0;
3volatile int fps = 0;
4 
5 
6void fps_proc ()
7{
8 fps = frame_count;
9 frame_count = 0;
10}
11END_OF_FUNCTION(fps_proc);
12 
13 
14void inc_speed_counter ()
15{
16 speed_count++;
17}
18END_OF_FUNCTION(inc_speed_counter);
19 
20 
21 
22void gameLoop ()
23{
24 while (!gameOver) {
25 while (speed_count > 0) {
26 updateLogic();
27 speed_count--;
28 }
29 updateScreen();
30 frame_count++;
31 }
32}

---
BEER: It's not just for breakfast anymore.

Joseph lastname
Member #1,581
October 2001

hmm.... It's not dividing by zero.. but it's still crashing....

I can't figure this out..

I got the FPS though... thanks..

Johnny13
Member #805
October 2000
avatar

Why need a defualt FPS? and load from file?::)
Framerate should counted in realtime

Alg3D Praise my Games!!<code>#define SPAMMER (post>=666&&postperday>=6)</code><Mr.spellcaster>What post? <Mr.spellcaster>A useful post by me.

Go to: