Created
December 8, 2019 16:55
-
-
Save matyklug18/dcf2fd513468d626dc15f2ffb81f6825 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (!close) | |
{ | |
double now = System.nanoTime(); | |
int updateCount = 0; | |
if (!paused) | |
{ | |
while( now - lastUpdateTime > TIME_BETWEEN_UPDATES && updateCount < MAX_UPDATES_BEFORE_RENDER ) | |
{ | |
update(); | |
lastUpdateTime += TIME_BETWEEN_UPDATES; | |
updateCount++; | |
} | |
if ( now - lastUpdateTime > TIME_BETWEEN_UPDATES) | |
{ | |
lastUpdateTime = now - TIME_BETWEEN_UPDATES; | |
} | |
render(); | |
lastRenderTime = now; | |
int thisSecond = (int) (lastUpdateTime / 1000000000); | |
if (thisSecond > lastSecondTime) | |
{ | |
lastSecondTime = thisSecond; | |
} | |
while ( now - lastRenderTime < TARGET_TIME_BETWEEN_RENDERS && now - lastUpdateTime < TIME_BETWEEN_UPDATES) | |
{ | |
Thread.yield(); | |
try {Thread.sleep(1);} catch(Exception e) {} | |
now = System.nanoTime(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment