Skip to main content
gamedev.net
🔒 Locked

timeGetTime

Started by giugio Feb 22, 2009 at 6:03 AM 1 replies 1.8k views
Original Post
giugio
giugio
hy. I have this function: I'm not understand what do.

int d3d::EnterMsgLoop( bool (*ptr_display)(float timeDelta) )
{
	MSG msg;
	::ZeroMemory(&msg, sizeof(MSG));

	static float lastTime = (float)timeGetTime(); 

	while(msg.message != WM_QUIT)
	{
		if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			::TranslateMessage(&msg);
			::DispatchMessage(&msg);
		}
	
		else
        {	
			float currTime  = (float)timeGetTime();
			float timeDelta = (currTime - lastTime)*0.001f;

			ptr_display(timeDelta);

			lastTime = currTime;
        }
    }
	
    return msg.wParam;
}

xissburg
xissburg
Duh...seems a standard Win32 main loop. I think ptr_display is a function that renders the scene and it uses the delta time (time taken to render one frame..) to do something else like updating an object position or so...please specify what you want. You didn't tell whats your problem...
.
bubu LV
bubu LV
This is not good code:

static float lastTime = (float)timeGetTime(); ...float currTime  = (float)timeGetTime();float timeDelta = (currTime - lastTime)*0.001f;


float has only 24-bit precision, but timeGetTime() returns full 32-bit integer. Better use following code:

DWORD lastTime = timeGetTime(); ...DWORD currTime  = timeGetTime();float timeDelta = (currTime - lastTime) * 0.001f;display(timeDelta);lastTime = currTime;

Topic Locked

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

Sign in to reply to this topic.