added timing code, not yet variable frame rate
This commit is contained in:
parent
18fc57b6a5
commit
6baffc5f6c
|
@ -7,9 +7,9 @@ import com.danitheskunk.skunkworks.audio.nodes.Node;
|
|||
import com.danitheskunk.skunkworks.audio.nodes.SamplePlayer;
|
||||
import com.danitheskunk.skunkworks.audio.nodes.TTS;
|
||||
import com.danitheskunk.skunkworks.gfx.IRenderContext;
|
||||
import com.danitheskunk.skunkworks.gfx.threedee.IRenderContext3D;
|
||||
import com.danitheskunk.skunkworks.gfx.ITexture;
|
||||
import com.danitheskunk.skunkworks.gfx.font.IFont;
|
||||
import com.danitheskunk.skunkworks.gfx.threedee.IRenderContext3D;
|
||||
import com.danitheskunk.skunkworks.nodes.NodeRoot;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
|
@ -141,16 +141,20 @@ public abstract class BaseGame {
|
|||
* closes.
|
||||
*/
|
||||
public void run() {
|
||||
double lastTime, currentTime, delta;
|
||||
double lastTime, currentTime, delta, currentFrameTime;
|
||||
|
||||
currentFrameTime = 0;
|
||||
|
||||
lastTime = GLFW.glfwGetTime();
|
||||
while(!window.shouldClose()) {
|
||||
currentTime = GLFW.glfwGetTime();
|
||||
delta = currentTime - lastTime;
|
||||
lastTime = currentTime;
|
||||
currentFrameTime += delta;
|
||||
engine.tick();
|
||||
window.tick();
|
||||
//todo: frame rate control
|
||||
if(currentFrameTime >= 1.0 / 60.0) {
|
||||
rootNode.tick();
|
||||
update(1.0 / 60.0);
|
||||
var rc3d = window.renderStart3D();
|
||||
|
@ -163,6 +167,14 @@ public abstract class BaseGame {
|
|||
window.renderFinish(rc);
|
||||
|
||||
window.runScaler();
|
||||
currentFrameTime -= 1.0 / 60.0;
|
||||
} else {
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch(InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
audioEngine.refill();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -452,7 +452,6 @@ public class Window extends BaseWindow {
|
|||
|
||||
glEnd();
|
||||
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue