Trying to understand game speed regulation

This is a discussion on Trying to understand game speed regulation within the Game Programming forums, part of the General Programming Boards category; I'm working on a space shooter to learn Allegro, but working with regulating game speed is still a bit hazy. ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    42

    Trying to understand game speed regulation

    I'm working on a space shooter to learn Allegro, but working with regulating game speed is still a bit hazy.

    I understand volatiles and locking just fine. I was able to program the game to display fps and all.

    When it comes to regulating game speed, I'm still a little confused. The tutorials I've read haven't really helped me to understand why things go where. I get close, but I'm not grasping the whole concept.

    Can someone try to explain how the concept works?

  2. #2
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301
    basically, you don't want to try to refresh the screen more than the screen refreshes itself. I'd suggest putting in a delay in order to keep the FPS at between 30-50 fps.

  3. #3
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    This is the BEST site for explaining things like game engines - it gets down pretty dirty into things.

    www.gamasutra.com

    .
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    42
    Well, I understand the whole point of it, with the whole keeping game speed constant across systems and all. My problem is the concept involved in the implimentation of it.

    For example, one tutorial explains it like this (I've included only the relevant parts)

    Code:
        volatile long speed_counter = 0; //A long integer which will store the value of the speed counter. 
        void increment_speed_counter() //A function to increment the speed counter
        {
            speed_counter++; // This will just increment the speed counter by one.
        }
        END_OF_FUNCTION(increment_speed_counter); //Make sure you tell it that it's the end of the function
    
        LOCK_VARIABLE(speed_counter); //Used to set the timer - which regulates the game's
        LOCK_FUNCTION(increment_speed_counter); //speed.
        install_int_ex(increment_speed_counter, BPS_TO_TIMER(60)); //Set our BPS
    
    ...
    
    while(!key[KEY_ESC]) //If the user hits escape, quit the program
    {
        while(speed_counter > 0)
        {
            //input
            speed_counter--;
        }
    
    ...
    
        //output
    }
    
    ...
    That's a clipped version of what the site describes, minus paragraphs inbetween that describe what's going on.

    What's evading me is exactly what this does. As far as I can tell, 60 times per second, it increments the speed_counter. When it hits the input phase, it checks the users keypresses until the speed_counter hits 0. Then the program does whatever, blits to the screen, and loops around again. How does this help to regulate the game speed?

    -edit-
    I fixed a few misspellings.
    Last edited by Vorok; 01-13-2003 at 06:29 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I am very new . . . :(
    By Eternalglory47 in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2008, 11:29 AM
  2. Speed of pointers vs. speed of arrays/structs
    By Kempelen in forum C Programming
    Replies: 32
    Last Post: 06-27-2008, 10:16 AM
  3. Flight Simulator Wind Speed!!
    By Dilmerv in forum C++ Programming
    Replies: 6
    Last Post: 03-19-2006, 11:40 PM
  4. Replies: 6
    Last Post: 01-08-2006, 01:49 PM
  5. increased net speed
    By PING in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-29-2005, 06:05 AM

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