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.SamplePlayer;
|
||||||
import com.danitheskunk.skunkworks.audio.nodes.TTS;
|
import com.danitheskunk.skunkworks.audio.nodes.TTS;
|
||||||
import com.danitheskunk.skunkworks.gfx.IRenderContext;
|
import com.danitheskunk.skunkworks.gfx.IRenderContext;
|
||||||
import com.danitheskunk.skunkworks.gfx.threedee.IRenderContext3D;
|
|
||||||
import com.danitheskunk.skunkworks.gfx.ITexture;
|
import com.danitheskunk.skunkworks.gfx.ITexture;
|
||||||
import com.danitheskunk.skunkworks.gfx.font.IFont;
|
import com.danitheskunk.skunkworks.gfx.font.IFont;
|
||||||
|
import com.danitheskunk.skunkworks.gfx.threedee.IRenderContext3D;
|
||||||
import com.danitheskunk.skunkworks.nodes.NodeRoot;
|
import com.danitheskunk.skunkworks.nodes.NodeRoot;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public abstract class BaseGame {
|
||||||
/**
|
/**
|
||||||
* Create with given window size and title
|
* 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
|
* @param windowTitle the title of the game's window
|
||||||
*/
|
*/
|
||||||
public BaseGame(Vec2i windowSize, String windowTitle) {
|
public BaseGame(Vec2i windowSize, String windowTitle) {
|
||||||
|
@ -89,7 +89,7 @@ public abstract class BaseGame {
|
||||||
/**
|
/**
|
||||||
* Play sample once or looped
|
* 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
|
* @param looping loops forever if true, otherwise play once
|
||||||
*/
|
*/
|
||||||
protected void playSample(ISample sample, boolean looping) {
|
protected void playSample(ISample sample, boolean looping) {
|
||||||
|
@ -141,28 +141,40 @@ public abstract class BaseGame {
|
||||||
* closes.
|
* closes.
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
double lastTime, currentTime, delta;
|
double lastTime, currentTime, delta, currentFrameTime;
|
||||||
|
|
||||||
|
currentFrameTime = 0;
|
||||||
|
|
||||||
lastTime = GLFW.glfwGetTime();
|
lastTime = GLFW.glfwGetTime();
|
||||||
while(!window.shouldClose()) {
|
while(!window.shouldClose()) {
|
||||||
currentTime = GLFW.glfwGetTime();
|
currentTime = GLFW.glfwGetTime();
|
||||||
delta = currentTime - lastTime;
|
delta = currentTime - lastTime;
|
||||||
lastTime = currentTime;
|
lastTime = currentTime;
|
||||||
|
currentFrameTime += delta;
|
||||||
engine.tick();
|
engine.tick();
|
||||||
window.tick();
|
window.tick();
|
||||||
//todo: frame rate control
|
//todo: frame rate control
|
||||||
rootNode.tick();
|
if(currentFrameTime >= 1.0 / 60.0) {
|
||||||
update(1.0 / 60.0);
|
rootNode.tick();
|
||||||
var rc3d = window.renderStart3D();
|
update(1.0 / 60.0);
|
||||||
render3D(rc3d);
|
var rc3d = window.renderStart3D();
|
||||||
window.renderFinish3D(rc3d);
|
render3D(rc3d);
|
||||||
var rc = window.renderStart();
|
window.renderFinish3D(rc3d);
|
||||||
renderPre(rc);
|
var rc = window.renderStart();
|
||||||
rootNode.render(rc);
|
renderPre(rc);
|
||||||
render(rc);
|
rootNode.render(rc);
|
||||||
window.renderFinish(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();
|
audioEngine.refill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -452,7 +452,6 @@ public class Window extends BaseWindow {
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue