added framerate control
This commit is contained in:
parent
cf4f121069
commit
7a79c19c98
@ -151,11 +151,14 @@ public class Engine {
|
|||||||
smiley2.translate(new Vector3f(0.0f,0.0f,10.0f));
|
smiley2.translate(new Vector3f(0.0f,0.0f,10.0f));
|
||||||
|
|
||||||
long timer = System.currentTimeMillis();
|
long timer = System.currentTimeMillis();
|
||||||
|
long lastFrame = System.currentTimeMillis();
|
||||||
int frame = 0;
|
int frame = 0;
|
||||||
|
boolean nextFrame = false;
|
||||||
|
|
||||||
while(engine.isRunning()){
|
while(engine.isRunning()){
|
||||||
// Game logic should fit here
|
// Game logic should fit here
|
||||||
double time = glfwGetTime();
|
double time = glfwGetTime();
|
||||||
|
lastFrame = System.currentTimeMillis();
|
||||||
|
|
||||||
smiley.translate(new Vector3f( (float) Math.sin(time), (float) Math.cos(time), 0.0f));
|
smiley.translate(new Vector3f( (float) Math.sin(time), (float) Math.cos(time), 0.0f));
|
||||||
|
|
||||||
@ -173,6 +176,11 @@ public class Engine {
|
|||||||
frame = 0;
|
frame = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while(!nextFrame){
|
||||||
|
nextFrame = System.currentTimeMillis() - lastFrame >= 16.66f;
|
||||||
|
}
|
||||||
|
|
||||||
|
nextFrame = false;
|
||||||
if(engine.shouldClose()) engine.setRunning(false);
|
if(engine.shouldClose()) engine.setRunning(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user