1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 02:12:45 +01:00

Merge pull request #489 from husho/fixawfulframerate

Fixed: accumulated time during pauses caused terrible framerate
This commit is contained in:
darkf 2018-05-31 23:22:29 -05:00 committed by GitHub
commit 4a9444fdee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -370,7 +370,7 @@ int RWGame::run() {
namespace chrono = std::chrono;
auto lastFrame = chrono::steady_clock::now();
float deltaTime = GAME_TIMESTEP;
const float deltaTime = GAME_TIMESTEP;
float accumulatedTime = 0.0f;
// Loop until we run out of states.
@ -423,39 +423,42 @@ int RWGame::run() {
chrono::duration<float>(currentFrame - lastFrame).count();
lastFrame = currentFrame;
// Clamp frameTime, so we won't freeze completely
if (frameTime > 0.1f) {
frameTime = 0.1f;
}
if (!world->isPaused()) {
accumulatedTime += frameTime;
accumulatedTime += frameTime;
auto deltaTimeWithTimeScale = deltaTime * world->state->basic.timeScale;
RW_PROFILE_BEGIN("Update");
while (accumulatedTime >= deltaTime && !world->isPaused()) {
if (!StateManager::currentState()) {
break;
// Clamp frameTime, so we won't freeze completely
if (frameTime > 0.1f) {
frameTime = 0.1f;
}
RW_PROFILE_BEGIN("physics");
world->dynamicsWorld->stepSimulation(
deltaTimeWithTimeScale, kMaxPhysicsSubSteps, deltaTime);
auto deltaTimeWithTimeScale =
deltaTime * world->state->basic.timeScale;
RW_PROFILE_BEGIN("Update");
while (accumulatedTime >= deltaTime) {
if (!StateManager::currentState()) {
break;
}
RW_PROFILE_BEGIN("physics");
world->dynamicsWorld->stepSimulation(
deltaTimeWithTimeScale, kMaxPhysicsSubSteps, deltaTime);
RW_PROFILE_END();
RW_PROFILE_BEGIN("state");
StateManager::get().tick(deltaTimeWithTimeScale);
RW_PROFILE_END();
RW_PROFILE_BEGIN("engine");
tick(deltaTimeWithTimeScale);
RW_PROFILE_END();
getState()->swapInputState();
accumulatedTime -= deltaTime;
}
RW_PROFILE_END();
RW_PROFILE_BEGIN("state");
StateManager::get().tick(deltaTimeWithTimeScale);
RW_PROFILE_END();
RW_PROFILE_BEGIN("engine");
tick(deltaTimeWithTimeScale);
RW_PROFILE_END();
getState()->swapInputState();
accumulatedTime -= deltaTime;
}
RW_PROFILE_END();
RW_PROFILE_BEGIN("Render");
RW_PROFILE_BEGIN("engine");