mirror of
https://git.eaglercraft.rip/eaglercraft/eaglercraft-1.5.git
synced 2025-01-22 07:21:52 -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) {
|
||||
boolean limitFPS = limitFramerate > 0 && limitFramerate < 1000;
|
||||
boolean limitFPS = limitFramerate > 0 && limitFramerate <= 1000;
|
||||
boolean blocked = false;
|
||||
|
||||
if(limitFPS) {
|
||||
long frameMillis = (1000l / limitFramerate);
|
||||
if(timerPtr[0] == 0l) {
|
||||
timerPtr[0] = steadyTimeMillis();
|
||||
timerPtr[0] = steadyTimeMillis() + frameMillis;
|
||||
}else {
|
||||
long millis = steadyTimeMillis();
|
||||
long frameMillis = (1000l / limitFramerate);
|
||||
long frameTime = millis - timerPtr[0];
|
||||
if(frameTime > 2000l || frameTime < 0l) {
|
||||
frameTime = frameMillis;
|
||||
timerPtr[0] = millis;
|
||||
}else {
|
||||
timerPtr[0] += frameMillis;
|
||||
}
|
||||
if(frameTime >= 0l && frameTime < frameMillis) {
|
||||
sleep((int)(frameMillis - frameTime));
|
||||
long remaining = timerPtr[0] - millis;
|
||||
if(remaining > 0) {
|
||||
if(isWebGL) {
|
||||
immediateContinue(); // cannot stack setTimeouts, or it will throttle
|
||||
millis = steadyTimeMillis();
|
||||
remaining = timerPtr[0] - millis;
|
||||
if(remaining > 0) {
|
||||
sleep((int)remaining);
|
||||
}
|
||||
}else {
|
||||
sleep((int)remaining);
|
||||
}
|
||||
blocked = true;
|
||||
}
|
||||
if((timerPtr[0] += frameMillis) < millis) {
|
||||
timerPtr[0] = millis;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
timerPtr[0] = 0l;
|
||||
|
|
Loading…
Reference in a new issue