added timing code, not yet variable frame rate

This commit is contained in:
DaniTheSkunk 2022-12-06 05:24:17 +00:00
parent 18fc57b6a5
commit 6baffc5f6c
2 changed files with 27 additions and 16 deletions

View File

@ -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;
@ -141,16 +141,20 @@ 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
if(currentFrameTime >= 1.0 / 60.0) {
rootNode.tick(); rootNode.tick();
update(1.0 / 60.0); update(1.0 / 60.0);
var rc3d = window.renderStart3D(); var rc3d = window.renderStart3D();
@ -163,6 +167,14 @@ public abstract class BaseGame {
window.renderFinish(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();
} }
} }

View File

@ -452,7 +452,6 @@ public class Window extends BaseWindow {
glEnd(); glEnd();
glfwSwapBuffers(window); glfwSwapBuffers(window);
} }