Games - timing

This is a discussion on Games - timing within the Game Programming forums, part of the General Programming Boards category; How are timing in games usually achieved? By that I mean in more professional games, not the pong thingy everyone ...

  1. #1
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Games - timing

    How are timing in games usually achieved? By that I mean in more professional games, not the pong thingy everyone makes first. I used to do do a dummy loop and use timing functions to see when it's time for updating. This however eats CPU, though giving a reliable FPS. Lately I started using the WM_TIMER. This has several advantages, however it is incredibly inaccurate and unreliable (lesser priority than other messages I've heard). If you tell it to fire 40 times/second it actually only fires 30 times/second or so. How are timing best made?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    13
    I don't know very much about programming, but maybe the Allegro library could help?

    "Whether you think that you can, or that you can't, you are usually right."

  3. #3
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Research hi res timers if your compiler supports it...

    Don't have any sites, but look at and for these functions:

    bool QueryPerformanceFrequency(LARGE_INTEGER *freq);
    bool QueryPerformanceCounter(LARGE_INTEGER *perfCount);

    For me they are in winbase.h.

    I can give you an example if you want....have to find it.
    Do not make direct eye contact with me.

  4. #4
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Got it....here's part of it if you want to take a look through it.
    Attached Files Attached Files
    Do not make direct eye contact with me.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    One way is to find out how much of a second is between frames and then multiply this value with the pixels per second the object is moving.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    If you cannot gain access to the timers it is possible to do it in assembly code if, and this is a big if, your inline assembler lets you.

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Thanks, but the high performance timer is merely a better version of timeGetTime(). It still needs a CPU eating dead loop, which I don't want to use.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Magos, you could always yield the process a few ms within the game loop if that was an issue. Another way to avoid the dead loop would to try something like this
    Code:
    // main game loop
    while(...) {
           timestamp = GetTickCount();
    
           // some sort of sleep function
           Sleep(33 - (GetTickCount() - timestamp))
    }
    This limits the fps of the game, though.

    What you probably want to do is use the high res times and then fall back on GetTickCount if they are not supported.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Programming opportunities! (Midway Games, Inc)
    By Midwayrecruiter in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 08-20-2008, 11:02 AM
  2. When done right, PC games are amazing
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-13-2008, 05:32 PM
  3. Violent video games?
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 58
    Last Post: 04-26-2006, 01:43 PM
  4. Video Games Industry. 5 years left.
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 12-10-2002, 09:52 PM

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