7 Regulating FPS

Video


Table of Contents

  1. Introduction
  2. Initializing Allegro
  3. Keyboard Input
  4. Drawing Graphics
  5. Playing Sound
  6. Drawing Text
  7. Regulating FPS
  8. Enumerations and Random Numbers
  9. Bounding Box Collision Detection
  10. Planning the Game
  11. Super Basic Game Structure
  12. Wrapping up

Downloads

Download entire guide as ODT


 

Part 7 – Regulating FPS

Now just a minute! We haven’t learned everything we need to know to make a game yet, even though we now know about graphics, sound, input, and drawing text! We also need to regulate the FPS. Why?

Have you ever popped in an old PC game, only to find it runs way too fast? (ie Sonic 3 & Knuckles for PC is the only game I can think of that does that to me). We need to regulate the FPS using a timer so that it won’t run at different speeds on different grades of computers.

Unless you just want to spite people with better PCs than you and make it harder for them to play because the game is too fast… :'(

Allegro Timer

Code from Loomsoft, altered by me

volatile long fps = 0;
            void IncFps() { fps++; }

            int main()
            {
	            // Do the Allegro initialization BEFORE the timer locks
	            LOCK_VARIABLE( fps );
	            LOCK_FUNCTION( IncFps );
    	            install_int_ex( IncFps, BPS_TO_TIMER(90) );
	            // The rest of the program goes here

© Rachel J. Morris, 2009

Print Friendly