Jump to content
  • Advertisement
Sign in to follow this  
blueshogun96

Using timers

This topic is 2867 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

Now, I'm not sure if such functionality exists, but is it possible to create a timer of some sort that will trigger an "event" at a certain frequency?

If that didn't make sense, let me explain it again. Lets say you want to create a timer that has a frequency of 16.6 Hz, and every time that much time goes by, an event is triggered. Would that be possible? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
First of all what language and platform are you using. If it is Windows/c++ then look into queryperformancecounter and queryperformancefrequency. There is plenty of documentation on the net about how to use these functions.
You need to create a timer class and check it once every loop and if the time is greater than your frequency a method gets called and the timer gets reset

Share this post


Link to post
Share on other sites
Rather than putting the code to check events into a timer class, it may be better to let each event "time" itself, given the current time.

I'm assuming you have some sort of run-loop in your application, rather than a static display that waits for events to update.

If you want accurate timing ( at 16.6Hz that may not be necessary, depending on your API ), create a timer class, using (as clearz suggests) QPC/QPF if you're using Windows, that determines an accurate time.

Then, each time through the run-loop:
1. Update the timer. For low frequencies like 16.6Hz, Windows' timeGetTime() may suffice and you don't need a timer class.
2. for each event, event->Update(timer.GetCurrentTime()), and let the event determine if something should be triggered.

That may allow you greater flexibility in your event class.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!