Jump to content
  • Advertisement
Sign in to follow this  
Tingle

C++ and Time

This topic is 2990 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, im looking for a way to make a number increase in ms. that has the format of 1.000, so basicly that would be 1 second and 0.500 would be 500ms.

Id like this number to start increasing from 0 once the application starts.

How can I do this? Ive tried methods like:


int _tmain(int argc, _TCHAR* argv[])
{
FILETIME now;
float tempTime = 0;
float curTime = 0;
while(1)
{
GetSystemTimeAsFileTime(&now);
if(now.dwLowDateTime >= tempTime+0.00009f)
{
tempTime = now.dwLowDateTime;
curTime += 0.0001f;
}
std::cout << curTime << std::endl;
}
}


But for some reson that is to slow. or I dunno. Is there anything out there that allready does what I need?

Share this post


Link to post
Share on other sites
Advertisement

DWORD startTime = timeGetTime(); // initialized when app starts
float ftime;
while(..)
{
ftime = float(timeGetTime()-startTime)/1000.0f;
}

Share this post


Link to post
Share on other sites
Mhmm, im getting:

unresolved external symbol __imp__timeGetTime@0


#include "stdafx.h"
#include <iostream>
#include <Windows.h>

int main()
{
DWORD startTime = timeGetTime(); // initialized when app starts
float ftime = 0;
while(1)
{
ftime = float(timeGetTime()-startTime)/1000.0f;
std::cout << ftime << std::endl;
}
return 0;
}





Edit: nvm, I didnt link WINMM.LIB.

Thanks alot!

Share this post


Link to post
Share on other sites
Not sure on the accuracy of timeGetTime() but I've used QueryPerformanceCounter() and QueryPerformanceFrequency() for this kind of thing.

Share this post


Link to post
Share on other sites
Quote:
Original post by AndyEsser
Not sure on the accuracy of timeGetTime() but I've used QueryPerformanceCounter() and QueryPerformanceFrequency() for this kind of thing.


The accurace on timeGetTime is 1 ms and won't go below it, if you need more accurace QueryPerfomanceTimer is the only way. Make sure to bind it to one thread though otherwise you might get inaccuracies, http://msdn.microsoft.com/en-us/library/ms644904(VS.85).aspx

Share this post


Link to post
Share on other sites
Isn't there a limitation due to the multitasking nature of the operating system that the accuracy of any timer will only go to about 50ms?

Share this post


Link to post
Share on other sites
Quote:
...the accuracy of any timer will only go to about 50ms?

The discussion isn't really about timers, but requests for the current time.

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!