• Advertisement

Archived

This topic is now archived and is closed to further replies.

Timers and Using them.....

This topic is 6213 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok what I would like to do is set a timer up. So the player touches something and then the timer is set and while the timer is running a flag is not set. The player has certin abilities or something of that sort during the time the timer is running. There are several ways to approach this.. I could just increase a variable by 1 and once it reaches a certin number then turn it off. Thats very unprof. so I can use windows timers or just the GetTickCount(). The problem with the windows timers how would I incorporate that into my game. I don't really want to use the even handler to handle that code but I could and would.. still it seems like I'd be throwing code back and fourth. The GetTickCount() is working good for things like my intro I want to stop everything for 5 seconds so I simply do this: while((GetTickCount() - timer_start) < 5000); But that locks all the processing but if I try that and not lock the process It doesn't work out.. well it gets all screwed up.. how can I get this idea to work? Thanks for any help at all, Phoenix Edited by - Viri- on February 19, 2001 10:07:25 PM

Share this post


Link to post
Share on other sites
Advertisement
well even though it is unprof, it works well, which I think would be professional.
You could possiblely take the time to write a "queue" class. The purposing being that you could insert a "job" in a circularly linked list. And everytime you draw to the screen, update the job queue by going through all the jobs and seeing if and how they need to be drawn. You could each job be a structure that would hold how long the job should last, when it started, a function pointer to complete the next step of the job, etc. This would allow you to be able adjust animations and features of the program (in your case a person activiting a switch for a certain amount of time) to different cpu speeds and still take the same amount of time. This of course causes synching for network games and such. of course slower cpus would cause skipping in frames for some your more complicated animations or features. hope that helps.

Share this post


Link to post
Share on other sites
Well create a boolean variable and a function for the timer:

BOOL g_bAllowContinue = 0;

void AllowContinue()
{
static DWORD bob = timeGetTime();
if ((GetTickCount - timeGetTime) > 5000)
{
bob = timeGetTime();
g_bAllowContinue = 1;
}
else g_bAllowContinue = 0;
}

Keep calling AllowContinue and checking the bool variable to check if the user can continue, but not hanging the application.

Share this post


Link to post
Share on other sites
Oops, my bad.

if ((GetTickCount - timeGetTime) > 5000)

should look like:

if ((GetTickCount - bob) > 5000)

Share this post


Link to post
Share on other sites

  • Advertisement