Jump to content
  • Advertisement
Sign in to follow this  
lipsryme

Frame time limiting problems

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

I'm having problem trying to limit my rendering code (or at least the update loop) in my dx11 based application.

Here's my "game loop":

while(isRunning)
{
int errorCode = this->window->UpdateMessages();

this->timer->Frame();
double frameTime = this->timer->GetFrameTime();
static double frame = frameTime;
if(errorCode == 0)
{
if(frameTime >= (1000 / 60))
{
double deltaTime = frameTime / 1000.0; // delta frame time in seconds
// Update Input
if(this->engineDesc.cameraDesc.type != Static)
{
this->directInput->DetectInput((FreeCamera*)this->GetCamera(), this->profiler, deltaTime);
}
else
{
this->directInput->DetectInput(NULL, this->profiler, deltaTime);
}
// Call scene's Update()
this->scene->Update(deltaTime);
// Call renderer's Update()
this->renderer->Update(deltaTime);
// Call profiler's Update()
this->profiler->Update(frameTime);
}
// Call our Render function()
this->Render();
}
else if(errorCode == 2)
{
this->Stop();
}
}


And here the timer functions:

void Timer::Initialize()
{
QueryPerformanceFrequency((LARGE_INTEGER*)&this->frequency);
this->ticksPerMs = (double)(this->frequency / 1000);
QueryPerformanceCounter((LARGE_INTEGER*)&this->startTime);
return;
}
void Timer::Frame()
{
INT64 currentTime;
double timeDifference;
QueryPerformanceCounter((LARGE_INTEGER*)&currentTime);
timeDifference = (double)(currentTime - this->startTime);
this->frameTime = timeDifference / this->ticksPerMs;
this->startTime = currentTime;
}

double Timer::GetFrameTime()
{
return this->frameTime;
}


No matter what I try the picture is either black, white, or just still without any input or movement working.
Any ideas what I'm doing wrong ?

Share this post


Link to post
Share on other sites
Advertisement
Hi Lipsryme,

You want to limit your fps to 60. What I don't understand is why you divide your "timeDifference" by the ticks of the CPU. Maybe should you try to assign "frameTime" to "timeDifference".

I think that what you're doing by dividing by cpu's tick limit the "frameTime" and so don't trigger the "if" condition.
[source lang="cpp"]
if(frameTime >= (1000 / 60))
[/source]

So let's try with :

[source lang="cpp"]
void Timer::Frame()
{
INT64 currentTime;
double timeDifference;
QueryPerformanceCounter((LARGE_INTEGER*)&currentTime);
timeDifference = (double)(currentTime - this->startTime);
this->frameTime = timeDifference /* this->ticksPerMs*/;
this->startTime = currentTime;
}
[/source]

Tell me if it work, or not smile.png.

Regards,
Drayan Edited by Drayan

Share this post


Link to post
Share on other sites
Hmm if I do that I'm getting locked (or rather not locked) to around 21000ms per frame.
Which is probably not the correct time the frame takes but the actual value frameTime has now.

So that would basically be my ticks per frame or am I wrong ?.
And the only thing to do now would be to convert this to milliseconds ?
But isn't that what I was already doing with the / ticksPerMs ?

Update: Wait. I think I know what my problem is...let me try something...
Update2: Well I've got it working now using an elapsedTime variable which does the trick (tested it in a console application) but it does not work for the render method, even with vsync on. Update loop limiting at least works. Edited by lipsryme

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!