Fixed slowdown when FPS got lower than TPS
This commit is contained in:
@@ -17,7 +17,8 @@ public class ThreadHandler {
|
|||||||
private final Array<Runnable> toRun = new Array<>();
|
private final Array<Runnable> toRun = new Array<>();
|
||||||
private final ThreadProvider impl;
|
private final ThreadProvider impl;
|
||||||
private float delta = 1f;
|
private float delta = 1f;
|
||||||
private long frame = 0;
|
private float smoothDelta = 1f;
|
||||||
|
private long frame = 0, lastDeltaUpdate;
|
||||||
private float framesSinceUpdate;
|
private float framesSinceUpdate;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@ public class ThreadHandler {
|
|||||||
|
|
||||||
Timers.setDeltaProvider(() -> {
|
Timers.setDeltaProvider(() -> {
|
||||||
float result = impl.isOnThread() ? delta : Gdx.graphics.getDeltaTime()*60f;
|
float result = impl.isOnThread() ? delta : Gdx.graphics.getDeltaTime()*60f;
|
||||||
return Math.min(Float.isNaN(result) ? 1f : result, 12f);
|
return Math.min(Float.isNaN(result) ? 1f : result, 15f);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ public class ThreadHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getTPS(){
|
public int getTPS(){
|
||||||
return (int)(60/delta);
|
return (int)(60/smoothDelta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getFrameID(){
|
public long getFrameID(){
|
||||||
@@ -138,8 +139,6 @@ public class ThreadHandler {
|
|||||||
long elapsed = TimeUtils.nanosToMillis(TimeUtils.timeSinceNanos(time));
|
long elapsed = TimeUtils.nanosToMillis(TimeUtils.timeSinceNanos(time));
|
||||||
long target = (long) ((1000) / 60f);
|
long target = (long) ((1000) / 60f);
|
||||||
|
|
||||||
delta = Math.max(elapsed, target) / 1000f * 60f;
|
|
||||||
|
|
||||||
if (elapsed < target) {
|
if (elapsed < target) {
|
||||||
impl.sleep(target - elapsed);
|
impl.sleep(target - elapsed);
|
||||||
}
|
}
|
||||||
@@ -151,6 +150,14 @@ public class ThreadHandler {
|
|||||||
rendered = false;
|
rendered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long actuallyElapsed = TimeUtils.nanosToMillis(TimeUtils.timeSinceNanos(time));
|
||||||
|
delta = Math.max(actuallyElapsed, target) / 1000f * 60f;
|
||||||
|
|
||||||
|
if(TimeUtils.timeSinceMillis(lastDeltaUpdate) > 1000){
|
||||||
|
lastDeltaUpdate = TimeUtils.millis();
|
||||||
|
smoothDelta = delta;
|
||||||
|
}
|
||||||
|
|
||||||
frame ++;
|
frame ++;
|
||||||
framesSinceUpdate = 0;
|
framesSinceUpdate = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user