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;
|
||||
|
||||
|
@ -38,7 +38,7 @@ public abstract class BaseGame {
|
|||
/**
|
||||
* Create with given window size and title
|
||||
*
|
||||
* @param windowSize the size of the game's window
|
||||
* @param windowSize the size of the game's window
|
||||
* @param windowTitle the title of the game's window
|
||||
*/
|
||||
public BaseGame(Vec2i windowSize, String windowTitle) {
|
||||
|
@ -89,7 +89,7 @@ public abstract class BaseGame {
|
|||
/**
|
||||
* Play sample once or looped
|
||||
*
|
||||
* @param sample the sample to be played
|
||||
* @param sample the sample to be played
|
||||
* @param looping loops forever if true, otherwise play once
|
||||
*/
|
||||
protected void playSample(ISample sample, boolean looping) {
|
||||
|
@ -141,28 +141,40 @@ 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
|
||||
rootNode.tick();
|
||||
update(1.0 / 60.0);
|
||||
var rc3d = window.renderStart3D();
|
||||
render3D(rc3d);
|
||||
window.renderFinish3D(rc3d);
|
||||
var rc = window.renderStart();
|
||||
renderPre(rc);
|
||||
rootNode.render(rc);
|
||||
render(rc);
|
||||
window.renderFinish(rc);
|
||||
if(currentFrameTime >= 1.0 / 60.0) {
|
||||
rootNode.tick();
|
||||
update(1.0 / 60.0);
|
||||
var rc3d = window.renderStart3D();
|
||||
render3D(rc3d);
|
||||
window.renderFinish3D(rc3d);
|
||||
var rc = window.renderStart();
|
||||
renderPre(rc);
|
||||
rootNode.render(rc);
|
||||
render(rc);
|
||||
window.renderFinish(rc);
|
||||
|
||||
window.runScaler();
|
||||
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