Cleanup SplashScene class

This commit is contained in:
2025-10-22 22:46:20 +01:00
parent fbb38d1b86
commit 1aa9546b73
3 changed files with 21 additions and 5 deletions

View File

@@ -4,7 +4,7 @@ import java.util.EnumMap;
import java.util.Map;
import lombok.Getter;
final class SceneManager {
public final class SceneManager {
private static final SceneType DEFAULT_SCENE_TYPE = SceneType.SPLASH;
private static final EnumMap<SceneType, Scene> SCENES =
@@ -19,4 +19,8 @@ final class SceneManager {
public static void setScene(SceneType sType) {
scene = SCENES.get(sType);
}
public static void update() {
scene.update();
}
}

View File

@@ -6,14 +6,26 @@ import java.util.Objects;
import org.hirw.game.util.Time;
public class SplashScene extends Scene {
private float ramp = 0.0f;
private final float INITIAL_BRIGHTNESS = 0.0f;
private final float FADE_RATE = 0.5f;
private float brightness;
public SplashScene() {
this.brightness = INITIAL_BRIGHTNESS;
}
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();
fadeIn();
}
private void fadeIn() {
glClearColor(this.brightness, this.brightness, this.brightness, 0.0f);
final float fadeAmount = FADE_RATE * Time.deltaTime();
this.brightness += fadeAmount;
}
}

View File

@@ -90,7 +90,7 @@ public class Window {
private void loop() {
while (!glfwWindowShouldClose(glfwWindow)) {
Time.update();
SceneManager.getScene().update();
SceneManager.update();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
this.shader.update();
glfwSwapBuffers(glfwWindow);