Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Frame time limiting problems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 lipsryme   Members   -  Reputation: 1106

Like
0Likes
Like

Posted 22 November 2012 - 01:33 PM

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 ?

Sponsor:

#2 Drayan   Members   -  Reputation: 124

Like
3Likes
Like

Posted 22 November 2012 - 04:41 PM

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 Posted Image.

Regards,
Drayan

Edited by Drayan, 22 November 2012 - 04:42 PM.


#3 lipsryme   Members   -  Reputation: 1106

Like
0Likes
Like

Posted 23 November 2012 - 08:15 AM

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, 23 November 2012 - 11:24 AM.


#4 L. Spiro   Crossbones+   -  Reputation: 17268

Like
1Likes
Like

Posted 23 November 2012 - 12:47 PM

I have posted a full solution to this here: Fixed-Time-Step Implementation
The problem you are having is also addressed there, but if you don’t see it feel free to tell me why and I will try to upgrade my tutorial with your advice.


L. Spiro




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS