Fixed render loop slowing down update loop if OpenGL performance was being limited by a power target

This commit is contained in:
Pazaz 2022-04-27 14:46:14 -04:00
parent e6aaa283ff
commit 0f5da09916
4 changed files with 30 additions and 8 deletions

View file

@ -534,7 +534,10 @@ public abstract class GameShell extends Applet implements Runnable, FocusListene
updateDelta = currentTime - lastUpdateTime;
if (updateDelta >= FIXED_UPDATE_RATE * 1_000_000) {
this.mainLoopWrapper();
logicCycles = timer.count(minimumDelay, (int)FIXED_UPDATE_RATE);
for (int cycle = 0; cycle < logicCycles; ++cycle) {
this.mainLoopWrapper();
}
lastUpdateTime = currentTime;
flush(signLink, canvas);
}
@ -544,13 +547,7 @@ public abstract class GameShell extends Applet implements Runnable, FocusListene
this.mainInputLoop();
this.mainRedrawWrapper();
lastDrawTime = currentTime;
if (VARIABLE_RENDER_RATE > minimumDelay) {
timer.sleep(minimumDelay, (int) VARIABLE_RENDER_RATE);
} else {
// encourage thread switching
Thread.yield();
}
Thread.yield();
}
}
} catch (@Pc(198) Exception ex) {

View file

@ -87,4 +87,8 @@ public final class MillisTimer extends Timer {
this.anInt3553 &= 0xFF;
return local139;
}
public int count(int arg0, int arg1) {
return 1;
}
}

View file

@ -37,4 +37,23 @@ public final class NanoTimer extends Timer {
}
return local31;
}
@Override
public int count(int arg0, int arg1) {
@Pc(9) long local9 = (long) arg0 * 1000000L;
@Pc(14) long local14 = this.aLong142 - System.nanoTime();
if (local9 > local14) {
local14 = local9;
}
@Pc(31) int local31 = 0;
@Pc(33) long local33 = System.nanoTime();
while (local31 < 10 && (local31 < 1 || this.aLong142 < local33)) {
local31++;
this.aLong142 += (long) arg1 * 1000000L;
}
if (local33 > this.aLong142) {
this.aLong142 = local33;
}
return local31;
}
}

View file

@ -22,4 +22,6 @@ public abstract class Timer {
@OriginalMember(owner = "client!s", name = "b", descriptor = "(I)V")
public abstract void reset();
public abstract int count(int arg0, int arg1);
}