C Board  

Go Back   C Board > General Programming Boards > FAQ Board

 
 
LinkBack Thread Tools Display Modes
Old 11-18-2002, 02:04 PM   #1
RoD
Banned
 
RoD's Avatar
 
Join Date: Sep 2002
Posts: 6,334
FAQ: Timers in C++

Ok i know this has been adressed before, and i even knew the answer not long ago, but when i went to the FAQ for a reference it wasn't in there, and since i need an answer and its an often asked question, i figured why not post, ask, then submit it into the FAQ for future readers, so here it is:

In C++ i want to set a time limit on my game. Not with decrements in for loops or anything, but with a timer, i think the functions i am looking for are in ctime.h or something like that. Thanks!


say int timer = 600(seconds)

while (timer >=1 || do_this != 'Q')
{

.....

}
RoD is offline  
Old 11-18-2002, 02:16 PM   #2
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,122
In windows.h, there is GetTickCount(), returning the number of milliseconds since windows started. You could use that.
Code:
DWORD StartTime = GetTickCount()
DWORD TimeFrame = 1000 * 60;

while((GetTickCount() - StartTime) < TimeFrame)
{
   ...
}
__________________
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  
Old 11-18-2002, 02:36 PM   #3
RoD
Banned
 
RoD's Avatar
 
Join Date: Sep 2002
Posts: 6,334
Thanks, that did it.
RoD is offline  
 

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wiki FAQ dwks General Discussions 192 04-29-2008 01:17 PM
FAQ Check/Lock RoD A Brief History of Cprogramming.com 2 10-15-2002 11:21 AM
Timers Mox Windows Programming 2 11-09-2001 04:34 AM


All times are GMT -6. The time now is 10:28 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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