C Board  

Go Back   C Board > General Programming Boards > Game Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-05-2004, 03:15 PM   #1
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,125
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.
Magos is offline   Reply With Quote
Old 03-05-2004, 05:23 PM   #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."
Rev. Jack Ed is offline   Reply With Quote
Old 03-05-2004, 06:15 PM   #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.
Lurker is offline   Reply With Quote
Old 03-05-2004, 06:50 PM   #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
File Type: zip timer.zip (799 Bytes, 49 views)
__________________
Do not make direct eye contact with me.
Lurker is offline   Reply With Quote
Old 03-06-2004, 02:36 AM   #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.
okinrus is offline   Reply With Quote
Old 03-06-2004, 06:15 AM   #6
Super Moderator
 
Bubba's Avatar
 
Join Date: Aug 2001
Posts: 7,819
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.
__________________
If you aim at everything you will hit something but you won't know what it is.
Bubba is offline   Reply With Quote
Old 03-06-2004, 08:00 AM   #7
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,125
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.
Magos is offline   Reply With Quote
Old 03-06-2004, 11:32 AM   #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.
okinrus is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming opportunities! (Midway Games, Inc) Midwayrecruiter Projects and Job Recruitment 0 08-20-2008 11:02 AM
When done right, PC games are amazing Bubba General Discussions 6 08-13-2008 05:32 PM
Violent video games? Bubba General Discussions 58 04-26-2006 01:43 PM
Video Games Industry. 5 years left. ethic A Brief History of Cprogramming.com 26 12-10-2002 10:52 PM


All times are GMT -6. The time now is 08:41 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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