Skip to main content
GameDev.net gamedev.net
🔒 Locked

gettimeofday() Replacement For Windows

Started by NickGravelyn Jul 1, 2006 at 12:41 AM 4 replies 19.5k views
Original Post
NickGravelyn
NickGravelyn
I'm attempting to port a Mac OS X app to Windows and everything is going well. It's a simple GLUT app, so most of the code is quite portable. The only thing missing is the gettimeofday() function. Is there anything on Windows I can use as a work around for it?
Plasmator
Plasmator
I think it's similar to GetTickCount?
Edit: if you need microsecond resolution you can use QueryPerformanceCounter/Frequency.
NickGravelyn
NickGravelyn
So far using GetTickCount() and the QueryPerformanceCounter() I haven't been able to replicate the effect. Here's the original code:
	struct timeval now;	gettimeofday(&now, NULL);	float step = (float)(now.tv_sec  - lastTick.tv_sec) + 1.0e-6 * (now.tv_usec - lastTick.tv_usec);	lastTick = now;


Any ideas how to mimic this on Windows?
Plasmator
Plasmator
I think "time" (in the ctime header) returns what you're looking for but only in seconds. (not sure about the microsecond part tho, sorry)
Richy2k
Richy2k
If you aren't worried about accuracy being perfect, here are 2 snippets of mine, i dont know why I didnt use QueryPerformanceCounter:

eGenericError cTimer::Update(){	gettimeofday(&m_Time, NULL);	m_TempTime = (double)m_Time.tv_sec + (double)(m_Time.tv_usec / 1000000.0);	m_FrameTime = m_TempTime - m_NewTime;	m_NewTime = m_TempTime;	return SUCCESS;}


eGenericError cTimer::Update(){	m_TempTime = (Scalar)GetTickCount()/1000.0f;	m_FrameTime = m_TempTime - m_NewTime;	m_NewTime = m_TempTime;	return SUCCESS;}


A couple of old bits of timer code I used last year.
dalleboy
dalleboy
Try one of these:
GetSystemTimeAsFileTime - a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
GetSystemTime - a date and time using individual members for the month, day, year, weekday, hour, minute, second, and millisecond.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.