Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » I can only get like 85 FPS

This thread is locked; no one can reply to it. rss feed Print
I can only get like 85 FPS
blargmob
Member #8,356
February 2007
avatar

Howdy,

Wow. I've been having lots of problems lately.

Anyway. I'm using this routine for setting my FPS and game speed:

void increment_speed_counter()
{
   speed_counter++;
}

install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));

With this I successfully get my target FPS which is equal to the paramater I pass to BPS_TO_TIMER(). But when I change the paramater to anything over....like 85, I can only get an FPS of 85 or so. No matter what. If I pass 500, I can only get 85. Is there a way to fix this?

---
"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski

CGamesPlay
Member #2,559
July 2002
avatar

Well, your monitor only refreshes a certain number of times per second. More than this, you aren't actually redrawing the screen. Your FPS is probably maxing out at your monitor's refresh rate (85 Hz). If this is wrong, show the code that calculates the FPS.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

blargmob
Member #8,356
February 2007
avatar

The code for just getting the FPS looks a little something like this:

1int framerate = 0;
2int framecounter = 0;
3 
4void getfr();
5 
6void Game()
7{
8 install_int(getfr,1000);
9 
10 while(!gameover)
11 {
12 updategamelogic();
13 renderstuff();
14 framecounter++;
15 }
16}
17 
18void getfr()
19{
20 framerate=framecounter;
21 framecounter=0;
22}

---
"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski

CGamesPlay
Member #2,559
July 2002
avatar

Does renderstuff() call any of these?
vsync, show_video_bitmap, poll_scroll

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Kris Asick
Member #1,424
July 2001

When doing anything beyond Double Buffering, such as page flipping, vsyncing, or triple buffering, there will be periods of time where your program will wait for your monitor to signal that it's ready for a new frame. In such cases, your monitor will be dictating the maximum framerate you can achieve.

60, 75, and 85 are common refresh rates. At lower resolutions on more powerful systems with CRT monitors, 100 and 120 may also be seen.

CGamesPlay is pointing out the commands in Allegro which REQUIRE a vertical retrace sync from your monitor, thus maxing your framerate out at such numbers.

Some of the palette commands also require a vsync(), though I don't know which ones off-hand.

Having a higher framerate is pointless because your monitor won't be able to display it. When you achieve higher framerates in other programs, this is because those programs are not syncing to the monitor and are thus updating faster than the monitor can, so even if their framerates are 160 or so, the monitor will still only be able to actually display 85 of those frames.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Dustin Dettmer
Member #3,935
October 2003
avatar

Quote:

Having a higher framerate is pointless because your monitor won't be able to display it. When you achieve higher framerates in other programs, this is because those programs are not syncing to the monitor and are thus updating faster than the monitor can, so even if their framerates are 160 or so, the monitor will still only be able to actually display 85 of those frames.

Whats worse, is these game applications are actually going to get an actual FPS a lot lower then 85!

CGamesPlay
Member #2,559
July 2002
avatar

Not really. The monitor always has the most recent frame ready to display, and the game speed is only going at real-time. The game gets 85 FPS, and they are always the newest frame, closest to the actual state of the game at the time of refresh.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Kris Asick
Member #1,424
July 2001

Quote:

Whats worse, is these game applications are actually going to get an actual FPS a lot lower then 85!

Actually, what happens if the framerate goes over the monitor refresh rate is that shearing effects occur. Frames get rendered while the monitor is in the process of drawing a frame, so a portion of the frame rendered is the previous frame and a portion is the next frame. If the framerate is high enough, this isn't so bad, but nearing the 30 mark, this effect can really detract from a gaming experience. (Especially with 2D since in 3D games, movement by perspective doesn't usually change so dramatically.)

Also note that when vsyncing, if the framerate drops even slightly below the monitor refresh rate, the framerate gets chopped in half! (So if the game can't handle 85 but can handle 82, you won't get 82, you'll get 42.5! The next down would be 28.3333, then 21.25, etc.)

Or lets say you design your game specifically for 85, but the person playing it has a refresh rate of 100. In this scenario, that person will only get 50 FPS!

Vsyncing is best left to real-time engines. If you do it in a fixed-time environment, you also need to incorporate frame-dropping in case the user's system doesn't exactly match the rate the game wants. (IE: In my game PixelShips, there's a brief moment at startup where it detects the monitor refresh rate. The game is designed for 70 FPS. If the monitor refresh is 70, the game times by vsyncing, but if not, it goes by an Allegro timer instead and doesn't vsync.)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

If the monitor refresh is 70, the game times by vsyncing

How do you count the number of VBIs that occur, in the case that one or more was missed? AFAIK, there's no cross-platform method to do that, if any modern platforms even allow it at all.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Kris Asick
Member #1,424
July 2001

Quote:

How do you count the number of VBIs that occur, in the case that one or more was missed?

There's no instantaneous way to do it reliably... so I improvised:

All PixelShips does is start its Allegro timer for 70 BPS, then runs 70 vsynced() blits to the screen. Once those blits are done, it checks how many times the Allegro timer did its thing. If there's less than a 2 or 3 frame difference, it goes with the vsyncing instead of the timer.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Kitty Cat
Member #2,815
October 2002
avatar

Don't forget to take into account timer drift. More than likely, the soundcard, mobo, video card, nor your monitor will run at exactly the same speed, so even if they all run an xx-hz timer, they'll slowly drift apart.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Kris Asick
Member #1,424
July 2001

I know. Since there's no sound or music though I didn't particularly care if there was any drift. 72 FPS or 68 FPS is still very close to 70.

Besides, I made PixelShips seven years ago. I was still an Allegro newb. ;)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

gillius
Member #119
April 2000

Isn't this problem solved by triple buffering? Triple buffering lets the game render frames as fast as it can independently of the refresh, because the renderer won't have to wait for vertical blank to occur before moving on to the next frame.

However, if refresh is 80hz, and you are rendering at 60hz, it might look choppier than vsyncing at 40hz... I'm not sure. Or maybe what I'm remembering is that 60fps without vsync can look worse than 40fps with vsync. I also think that variable 40-60fps can also look worse than constant 40fps always.

But from a technical point of view, it is possible to use vsync AND get a framerate that isn't an exact division of the refresh rate.

Gillius
Gillius's Programming -- http://gillius.org/

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

Isn't this problem solved by triple buffering?

Tripple buffering solves the shearing and framerate division problems that Kris described.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Kris Asick
Member #1,424
July 2001

thinks about it for a moment

Yes, triple buffering would solve those problems. For some reason I didn't think it would when I wrote my first response.

I haven't much experience with triple buffering, so when I wrote my response I was simply thinking, "Triple buffering uses vsync, so it counts." ::)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Dustin Dettmer
Member #3,935
October 2003
avatar

Quote:

Not really. The monitor always has the most recent frame ready to display, and the game speed is only going at real-time. The game gets 85 FPS, and they are always the newest frame, closest to the actual state of the game at the time of refresh.

Damnit.. I think you're right. I remember there being some case where it was actually a hurt framerate. Its a waste of CPU (and hence battery life) at least.

Go to: