Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualL. Spiro

Posted 12 November 2013 - 07:11 AM

Hello, windows high res timer QueryPerformanceCounter always seems to act quirky whenever I use it.

You use it in a quirky way.
First-off you are always dropping some time with your current implementation, and I don’t mean the intentional way.

You should never call QueryPerformanceCounter() more than once per loop. If you need to know the “last time”, make a copy of the current time before updating it.
 
	while(destroyed != 2)
	{
		gameTimer->lastTime = gameTimer->currentTime;
		QueryPerformanceCounter(&gameTimer->currentTime);
		if(PeekMessage(&msg, 0, NULL, NULL, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		if(gameTimer->deltaTime >= 1.0f / 60.0f)
		{
			for(int i = 0; i < gameObjectList.size(); i++)
			{
				gameObjectList[i]->Update();
			}
			graphicsEngine->Render();
			gameTimer->deltaTime = 0.0f;
		}
		Sleep(1);
		gameTimer->CalculateDelta();
	}
Second-off you are converting the values to “float” while still in expanded form, meaning you are converting values such as 351,357,654,184 etc., which you should know better than to do. (Also, use static_cast for sake’s Pete.)
deltaTime += static_cast<float>(currentTime.QuadPart - lastTime.QuadPart) / frequency.QuadPart;
Third-off, don’t accumulate time as a float. Accumulate time in unsigned long long integers (I’m looking at gameTimer->deltaTime).


L. Spiro

#1L. Spiro

Posted 12 November 2013 - 04:48 AM

Hello, windows high res timer QueryPerformanceCounter always seems to act quirky whenever I use it.

You use it in a quirky way.
First-off you are always dropping some time with your current implementation, and I don’t mean the intentional way.

You should never call QueryPerformanceCounter() more than once per loop. If you need to know the “last time”, make a copy of the current time before updating it.

	while(destroyed != 2)
	{
		gameTimer->lastTime = gameTimer->currentTime;
		QueryPerformanceCounter(&gameTimer->currentTime);
		if(PeekMessage(&msg, 0, NULL, NULL, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		if(gameTimer->deltaTime >= 1.0f / 60.0f)
		{
			for(int i = 0; i < gameObjectList.size(); i++)
			{
				gameObjectList[i]->Update();
			}
			graphicsEngine->Render();
			gameTimer->deltaTime = 0.0f;
		}
		Sleep(1);
		gameTimer->CalculateDelta();
	}

Second-off you are converting the values to “float” while still in expanded form, meaning you are converting values such as 351,357,654,184 etc., which you should know better than to do. (Also, use static_cast for sake’s Pete.)
deltaTime += (static_cast<float>(currentTime.QuadPart - lastTime.QuadPart)) / frequency.QuadPart;

Third-off, don’t accumulate time as a float. Accumulate time in unsigned long long integers (I’m looking at gameTimer->deltaTime).


L. Spiro

PARTNERS