mirror of
https://git.eaglercraft.rip/eaglercraft/eaglercraft-1.5.git
synced 2025-01-22 15:31:53 -05:00
Better sync
This commit is contained in:
parent
290e775165
commit
eb6131cacf
1 changed files with 18 additions and 12 deletions
|
@ -1614,26 +1614,32 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean sync(int limitFramerate, long[] timerPtr) {
|
public static boolean sync(int limitFramerate, long[] timerPtr) {
|
||||||
boolean limitFPS = limitFramerate > 0 && limitFramerate < 1000;
|
boolean limitFPS = limitFramerate > 0 && limitFramerate <= 1000;
|
||||||
boolean blocked = false;
|
boolean blocked = false;
|
||||||
|
|
||||||
if(limitFPS) {
|
if(limitFPS) {
|
||||||
|
long frameMillis = (1000l / limitFramerate);
|
||||||
if(timerPtr[0] == 0l) {
|
if(timerPtr[0] == 0l) {
|
||||||
timerPtr[0] = steadyTimeMillis();
|
timerPtr[0] = steadyTimeMillis() + frameMillis;
|
||||||
}else {
|
}else {
|
||||||
long millis = steadyTimeMillis();
|
long millis = steadyTimeMillis();
|
||||||
long frameMillis = (1000l / limitFramerate);
|
long remaining = timerPtr[0] - millis;
|
||||||
long frameTime = millis - timerPtr[0];
|
if(remaining > 0) {
|
||||||
if(frameTime > 2000l || frameTime < 0l) {
|
if(isWebGL) {
|
||||||
frameTime = frameMillis;
|
immediateContinue(); // cannot stack setTimeouts, or it will throttle
|
||||||
timerPtr[0] = millis;
|
millis = steadyTimeMillis();
|
||||||
}else {
|
remaining = timerPtr[0] - millis;
|
||||||
timerPtr[0] += frameMillis;
|
if(remaining > 0) {
|
||||||
|
sleep((int)remaining);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
sleep((int)remaining);
|
||||||
}
|
}
|
||||||
if(frameTime >= 0l && frameTime < frameMillis) {
|
|
||||||
sleep((int)(frameMillis - frameTime));
|
|
||||||
blocked = true;
|
blocked = true;
|
||||||
}
|
}
|
||||||
|
if((timerPtr[0] += frameMillis) < millis) {
|
||||||
|
timerPtr[0] = millis;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
timerPtr[0] = 0l;
|
timerPtr[0] = 0l;
|
||||||
|
|
Loading…
Reference in a new issue