Jump to content
  • Advertisement
Sign in to follow this  
brechtjah

Counting time C++ win32

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

Hi, I need to write a program with time based events, however, I want to count the playtime, as in: - It is now 8.06, I start the game, the game starts counting playtime seconds. - 8.51, program has counted 60*45 seconds so far The reason I need to count the playtime is because I want something to happen at ten minutes, at twenty, twenty five, etcetera. If anyone could shed some light for me on how to get started or maybe some links, that would be very helpful...

Share this post


Link to post
Share on other sites
Advertisement
GetTickCount returns the time since Windows started, in milliseconds (though beware, it has something in the order of 10s of millisecond resolution).

If you get this time when you start your program, and then subtract the current time from that start time (and divide by 1000), you'll have the number of elapsed seconds since your program started, i.e., something like:

static DWORD StartTime;

void InitializeTime()
{
StartTime = GetTickCount();
}

float GetTime()
{
return (GetTickCount() - StartTime) / 1000.0f;
}

Share this post


Link to post
Share on other sites
I'd wrap that into a class so you can use it for multiple events that start at different times. For instance, a player can start an event at a random time in a game, and the time it starts will be variable.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!