Skip to main content
grammar and punctuation; removed blacklisted engine tag
Source Link
Gnemlock
  • 5.3k
  • 5
  • 30
  • 60

Correct What is the correct way to update mya physics frame rate?

I've searched around here and Googlethe Internet, and at last I looked at Fix your Timestep!eventually read a suggested article on the web which most of the people suggest, "Fix your Timestep!". In according to thataccordance with the article, I came up with an update method like this, but I still have problems. Whenever I instantiate more and more objects, in my scene, I'llI get much slower physical interactionsinteraction. I've fixed other sub-systems, that they were wasting cycles during the update process, and now I've tracked my physics performance drop to this point. I think the way I'm updating my physics is somehow wrong, because I'm using a fixed timing of 1.0 / 60.0 for my Box2D engine. Can someone help and point out my

What are the mistakes I'm making in my update process? What is the correct way to update a physics frame rate? Here is my code:

void Core::Update() {   // Input   this->cInput->Update();   // Physics   this->cPhysics->Update();   // Keep frame rate   static const double desiredTime = 1.0 / 60.0;   static double currentTime = (double)time(NULL); static double accumulator = 0.0;  double newTime = (double)time(NULL); double frameTime = newTime - currentTime; if(frameTime > 0.25){ frameTime = 0.25; } currentTime = newTime; accumulator += frameTime; while(accumulator >= desiredTime) { accumulator -= desiredTime; } // Render this->cRender->Update(); } 

I've read that you shouldn't tie your physics frame rate with render frame rate and that's why I've put this->cPhysics->Update(); above.

Edit

My new update method is something like this:

 // Keep frame rate static const double desiredTime = 1.0 / 60.0; static double currentTime = (double)(GetTickCount()); static double accumulator = 0.0; double newTime = (double)(GetTickCount()); double frameTime = newTime - currentTime; if(frameTime > 0.25){ frameTime = 0.25; } currentTime = newTime; accumulator += frameTime; while(accumulator >= desiredTime) { // Input this->cInput->Update(); // Physics this->cPhysics->Update(desiredTime); // Scripts this->cScripts->Update(); accumulator -= desiredTime; } 

ActuallyI've read that you shouldn't tie your physics frame rate to the render frame rate, so I use this->cPhysics->Update();. I've used my previous approach, but with a slight change.change; I'm not sure if what I'm doing is right, but it solved my performance issue. First, I changed currentTime to get time in milliseconds, instead of seconds. At the end, I've moved all of my update codes except render's update code to a time step loop, except for the renderers update. Would someone tell meI still do not know if this is the correct? way to go.

Correct way to update my physics frame rate

I've searched around here and Google and at last I looked at Fix your Timestep! article on the web which most of the people suggest. In according to that article I came up with an update method like this, but I still have problems. Whenever I instantiate more and more objects in my scene, I'll get much slower physical interactions. I've fixed other sub-systems that they were wasting cycles during update process and now I've tracked my physics performance drop to this point. I think the way I'm updating my physics is somehow wrong because I'm using a fixed timing of 1.0 / 60.0 for my Box2D engine. Can someone help and point out my mistakes in my update process?

void Core::Update() {   // Input   this->cInput->Update();   // Physics   this->cPhysics->Update();   // Keep frame rate   static const double desiredTime = 1.0 / 60.0;   static double currentTime = (double)time(NULL); static double accumulator = 0.0;  double newTime = (double)time(NULL); double frameTime = newTime - currentTime; if(frameTime > 0.25){ frameTime = 0.25; } currentTime = newTime; accumulator += frameTime; while(accumulator >= desiredTime) { accumulator -= desiredTime; } // Render this->cRender->Update(); } 

I've read that you shouldn't tie your physics frame rate with render frame rate and that's why I've put this->cPhysics->Update(); above.

Edit

My new update method is something like this:

 // Keep frame rate static const double desiredTime = 1.0 / 60.0; static double currentTime = (double)(GetTickCount()); static double accumulator = 0.0; double newTime = (double)(GetTickCount()); double frameTime = newTime - currentTime; if(frameTime > 0.25){ frameTime = 0.25; } currentTime = newTime; accumulator += frameTime; while(accumulator >= desiredTime) { // Input this->cInput->Update(); // Physics this->cPhysics->Update(desiredTime); // Scripts this->cScripts->Update(); accumulator -= desiredTime; } 

Actually I've used my previous approach, but with a slight change. I'm not sure what I'm doing is right but it solved my performance issue. First I changed currentTime to get time in milliseconds instead of seconds. At the end, I've moved all of my update codes except render's update to time step loop. Would someone tell me if this is correct?

What is the correct way to update a physics frame rate?

I've searched around the Internet, and eventually read a suggested article, "Fix your Timestep!". In accordance with the article, I came up with an update method, but I still have problems. Whenever I instantiate more objects, in my scene, I get much slower physical interaction. I've fixed other sub-systems, that they were wasting cycles during the update process, and I've tracked my physics performance drop to this point. I think the way I'm updating my physics is somehow wrong, because I'm using a fixed timing of 1.0 / 60.0 for my Box2D engine.

What are the mistakes I'm making in my update process? What is the correct way to update a physics frame rate? Here is my code:

void Core::Update() { // Input this->cInput->Update(); // Physics this->cPhysics->Update(); // Keep frame rate static const double desiredTime = 1.0 / 60.0; static double currentTime = (double)(GetTickCount()); static double accumulator = 0.0; double newTime = (double)(GetTickCount()); double frameTime = newTime - currentTime; if(frameTime > 0.25){ frameTime = 0.25; } currentTime = newTime; accumulator += frameTime; while(accumulator >= desiredTime) { // Input this->cInput->Update(); // Physics this->cPhysics->Update(desiredTime); // Scripts this->cScripts->Update(); accumulator -= desiredTime; } 

I've read that you shouldn't tie your physics frame rate to the render frame rate, so I use this->cPhysics->Update();. I've used my previous approach, but with a slight change; I'm not sure if what I'm doing is right, but it solved my performance issue. First, I changed currentTime to get time in milliseconds, instead of seconds. At the end, I've moved all of my update code to a time step loop, except for the renderers update. I still do not know if this is the correct way to go.

deleted 166 characters in body
Source Link
MahanGM
  • 377
  • 4
  • 22
 // Keep frame rate static const double desiredTime = 1.0 / 60.0; static double currentTime = this->frameStart;(double)(GetTickCount()); static double accumulator = 0.0; double newTime = (double)(GetTickCount()); double frameTime = newTime - currentTime; if(frameTime > 0.25){ frameTime = 0.25; } currentTime = newTime; accumulator += frameTime; while(accumulator >= desiredTime) { // Input this->cInput->Update(); // Physics this->cPhysics->Update(desiredTime); // Scripts this->cScripts->Update(); accumulator -= desiredTime; } 

Actually I've used my previous approach, but with a slight change. I'm not sure what I'm doing is right but it solved my performance issue. First I changed currentTime to get a frameStart variable which is fetched before game loop with GetTickCount() / 1000. It means I'm getting this in seconds and while I'm setting a GetTickCount() value for my newTime variabletime in milliseconds instead of seconds. At the end, I've moved all of my update codes except render's update to time step loop. Would someone tell me if this is correct?

 // Keep frame rate static const double desiredTime = 1.0 / 60.0; static double currentTime = this->frameStart; static double accumulator = 0.0; double newTime = (double)(GetTickCount()); double frameTime = newTime - currentTime; if(frameTime > 0.25){ frameTime = 0.25; } currentTime = newTime; accumulator += frameTime; while(accumulator >= desiredTime) { // Input this->cInput->Update(); // Physics this->cPhysics->Update(desiredTime); // Scripts this->cScripts->Update(); accumulator -= desiredTime; } 

Actually I've used my previous approach, but with a slight change. I'm not sure what I'm doing is right but it solved my performance issue. First I changed currentTime to get a frameStart variable which is fetched before game loop with GetTickCount() / 1000. It means I'm getting this in seconds and while I'm setting a GetTickCount() value for my newTime variable in milliseconds. At the end, I've moved all of my update codes except render's update to time step loop. Would someone tell me if this is correct?

 // Keep frame rate static const double desiredTime = 1.0 / 60.0; static double currentTime = (double)(GetTickCount()); static double accumulator = 0.0; double newTime = (double)(GetTickCount()); double frameTime = newTime - currentTime; if(frameTime > 0.25){ frameTime = 0.25; } currentTime = newTime; accumulator += frameTime; while(accumulator >= desiredTime) { // Input this->cInput->Update(); // Physics this->cPhysics->Update(desiredTime); // Scripts this->cScripts->Update(); accumulator -= desiredTime; } 

Actually I've used my previous approach, but with a slight change. I'm not sure what I'm doing is right but it solved my performance issue. First I changed currentTime to get time in milliseconds instead of seconds. At the end, I've moved all of my update codes except render's update to time step loop. Would someone tell me if this is correct?

added 1233 characters in body
Source Link
MahanGM
  • 377
  • 4
  • 22

Edit

My new update method is something like this:

 // Keep frame rate static const double desiredTime = 1.0 / 60.0; static double currentTime = this->frameStart; static double accumulator = 0.0; double newTime = (double)(GetTickCount()); double frameTime = newTime - currentTime; if(frameTime > 0.25){ frameTime = 0.25; } currentTime = newTime; accumulator += frameTime; while(accumulator >= desiredTime) { // Input this->cInput->Update(); // Physics this->cPhysics->Update(desiredTime); // Scripts this->cScripts->Update(); accumulator -= desiredTime; } 

Actually I've used my previous approach, but with a slight change. I'm not sure what I'm doing is right but it solved my performance issue. First I changed currentTime to get a frameStart variable which is fetched before game loop with GetTickCount() / 1000. It means I'm getting this in seconds and while I'm setting a GetTickCount() value for my newTime variable in milliseconds. At the end, I've moved all of my update codes except render's update to time step loop. Would someone tell me if this is correct?

Edit

My new update method is something like this:

 // Keep frame rate static const double desiredTime = 1.0 / 60.0; static double currentTime = this->frameStart; static double accumulator = 0.0; double newTime = (double)(GetTickCount()); double frameTime = newTime - currentTime; if(frameTime > 0.25){ frameTime = 0.25; } currentTime = newTime; accumulator += frameTime; while(accumulator >= desiredTime) { // Input this->cInput->Update(); // Physics this->cPhysics->Update(desiredTime); // Scripts this->cScripts->Update(); accumulator -= desiredTime; } 

Actually I've used my previous approach, but with a slight change. I'm not sure what I'm doing is right but it solved my performance issue. First I changed currentTime to get a frameStart variable which is fetched before game loop with GetTickCount() / 1000. It means I'm getting this in seconds and while I'm setting a GetTickCount() value for my newTime variable in milliseconds. At the end, I've moved all of my update codes except render's update to time step loop. Would someone tell me if this is correct?

Tweeted twitter.com/#!/StackGameDev/status/363763680720482304
edited title
Link
MahanGM
  • 377
  • 4
  • 22
Loading
Source Link
MahanGM
  • 377
  • 4
  • 22
Loading