started implementing GameSkunkAdvance

This commit is contained in:
DaniTheSkunk 2022-12-17 13:24:00 +00:00
parent 1d32ce757f
commit fb3a988375
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,62 @@
package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.audio.AudioEngine;
import com.danitheskunk.skunkworks.gfx.Color;
import org.lwjgl.glfw.GLFW;
public abstract class GameSkunkAdvance {
protected BaseGamepad gamepad;
private AudioEngine audioEngine;
private Engine engine;
private IWindow window;
public GameSkunkAdvance(String title) {
engine = new Engine();
window = engine.openWindow(new Vec2i(304, 176), title);
window.setScaler("integer");
window.setWindowSize(new Vec2i(1280, 720));
gamepad = window.getGamepad(0);
audioEngine = new AudioEngine(48000, 256, 8);
}
public void run() {
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();
gamepad.tick();
//todo: frame rate control
if(currentFrameTime >= 1.0 / 60.0) {
update();
var p2d = window.getPipeline2D();
window.startFrame();
p2d.startFrame();
p2d.getRenderContext().clear(Color.WHITE);
//render(p2d.getRenderContext());
p2d.finishFrame();
window.finishFrame();
currentFrameTime -= 1.0 / 60.0;
} else {
try {
Thread.sleep(1);
} catch(InterruptedException e) {
throw new RuntimeException(e);
}
}
audioEngine.refill();
}
}
protected void update() {
}
}

View File

@ -0,0 +1,11 @@
package com.danitheskunk.skunkworks;
public class TestGSA extends GameSkunkAdvance {
public TestGSA() {
super("Game Skunk Advance Test");
}
public static void main(String[] args) {
new TestGSA().run();
}
}