Rough Scene/SceneManager implementation

This commit is contained in:
2025-08-18 20:48:59 +01:00
parent 9cf088cc6c
commit eb3a5e7dd1
5 changed files with 58 additions and 3 deletions

View File

@@ -0,0 +1,8 @@
package org.hirw.game;
public abstract class Scene {
public Scene() {}
abstract void update();
}

View File

@@ -0,0 +1,20 @@
package org.hirw.game;
import java.util.EnumMap;
import java.util.Map;
import lombok.Getter;
final class SceneManager {
private static final EnumMap<SceneType, Scene> SCENES =
new EnumMap<>(
Map.of(
SceneType.SPLASH, new SplashScene(),
SceneType.MENU, new SplashScene(),
SceneType.GAME, new SplashScene()));
@Getter private static Scene scene = SCENES.get(SceneType.SPLASH);
public static void setScene(SceneType sType) {
scene = SCENES.get(sType);
}
}

View File

@@ -0,0 +1,7 @@
package org.hirw.game;
public enum SceneType {
SPLASH,
MENU,
GAME
}

View File

@@ -0,0 +1,19 @@
package org.hirw.game;
import static org.lwjgl.opengl.GL11.*;
import java.util.Objects;
import org.hirw.game.util.Time;
public class SplashScene extends Scene {
private float ramp = 0.0f;
public void update() {
if (Objects.isNull(Window.get().getGlfwWindow())) {
return;
}
glClearColor(this.ramp, this.ramp, this.ramp, 0.0f);
this.ramp += 0.5f * Time.deltaTime();
}
}

View File

@@ -5,6 +5,7 @@ import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*; import static org.lwjgl.system.MemoryUtil.*;
import lombok.Getter;
import org.hirw.game.util.Time; import org.hirw.game.util.Time;
import org.lwjgl.Version; import org.lwjgl.Version;
import org.lwjgl.glfw.*; import org.lwjgl.glfw.*;
@@ -13,7 +14,7 @@ import org.lwjgl.opengl.*;
public class Window { public class Window {
private int width, height; private int width, height;
private final String title; private final String title;
private long glfwWindow; @Getter private long glfwWindow;
private static Window window = null; private static Window window = null;
@@ -78,13 +79,13 @@ public class Window {
glfwShowWindow(glfwWindow); glfwShowWindow(glfwWindow);
GL.createCapabilities(); GL.createCapabilities();
glClearColor(1.0f, 0.0f, 2.0f, 0.0f); glClearColor(0.0f, 0.0f, 2.0f, 0.0f);
} }
private void loop() { private void loop() {
while (!glfwWindowShouldClose(glfwWindow)) { while (!glfwWindowShouldClose(glfwWindow)) {
Time.update(); Time.update();
System.out.println(Time.deltaTime()); SceneManager.getScene().update();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(glfwWindow); glfwSwapBuffers(glfwWindow);
glfwPollEvents(); glfwPollEvents();