Update render.cpp
Improve accuracy & Decrease framerate when focus is lost.
This commit is contained in:
@@ -64,11 +64,18 @@ void Render::render_loop() {
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
float dT = (std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count());
|
||||
|
||||
|
||||
//If we have more than 1000 fps.
|
||||
if (dT < 1000) {
|
||||
if (dT < 1000 && engine->window->getFlag(RWindowFlags::IN_FOCUS)) {
|
||||
int remaining = 1000 - dT;
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(remaining));
|
||||
dT = 1000;
|
||||
dT += remaining;
|
||||
}
|
||||
|
||||
//Decrease framerate when focus is lost.
|
||||
if (!engine->window->getFlag(RWindowFlags::IN_FOCUS)) {
|
||||
dT = 41666.67f - dT;
|
||||
std::this_thread::sleep_for(std::chrono::microseconds((int) dT));
|
||||
}
|
||||
engine->frameDelta = (dT / 1000000);
|
||||
}
|
||||
|
Reference in New Issue
Block a user