From e9b0b0ddde8475860b8278e5d0b08543c8fe0a4d Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Fri, 27 Feb 2026 20:05:57 -0800 Subject: Adding a limit to how much time can be updated to smoothing things out --- core/src/main/java/coffee/liz/dyl/components/Velocity.java | 2 +- core/src/main/java/coffee/liz/dyl/screen/GameScreen.java | 3 ++- lwjgl3/src/main/java/coffee/liz/dyl/lwjgl3/Lwjgl3Launcher.java | 4 +--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/coffee/liz/dyl/components/Velocity.java b/core/src/main/java/coffee/liz/dyl/components/Velocity.java index eb981f7..170fa84 100644 --- a/core/src/main/java/coffee/liz/dyl/components/Velocity.java +++ b/core/src/main/java/coffee/liz/dyl/components/Velocity.java @@ -12,5 +12,5 @@ import lombok.Setter; @Getter @Setter public class Velocity implements Component { - private Vector2 velocity = Vector2.Zero; + private Vector2 velocity = Vector2.Zero.cpy(); } diff --git a/core/src/main/java/coffee/liz/dyl/screen/GameScreen.java b/core/src/main/java/coffee/liz/dyl/screen/GameScreen.java index 54dfda3..39017c5 100644 --- a/core/src/main/java/coffee/liz/dyl/screen/GameScreen.java +++ b/core/src/main/java/coffee/liz/dyl/screen/GameScreen.java @@ -9,6 +9,7 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class GameScreen implements Screen { + private static final float MAX_DELTA_SECONDS = 1 / 30f; private final DylGame game; private DylGameWorld dylGameWorld; @@ -25,7 +26,7 @@ public class GameScreen implements Screen { @Override public void render(final float delta) { - dylGameWorld.update(frameState, delta); + dylGameWorld.update(frameState, Math.min(delta, MAX_DELTA_SECONDS)); } @Override diff --git a/lwjgl3/src/main/java/coffee/liz/dyl/lwjgl3/Lwjgl3Launcher.java b/lwjgl3/src/main/java/coffee/liz/dyl/lwjgl3/Lwjgl3Launcher.java index 1902322..4aed564 100644 --- a/lwjgl3/src/main/java/coffee/liz/dyl/lwjgl3/Lwjgl3Launcher.java +++ b/lwjgl3/src/main/java/coffee/liz/dyl/lwjgl3/Lwjgl3Launcher.java @@ -21,9 +21,7 @@ public class Lwjgl3Launcher { //// Vsync limits the frames per second to what your hardware can display, and helps eliminate //// screen tearing. This setting doesn't always work on Linux, so the line after is a safeguard. configuration.useVsync(true); - //// Limits FPS to the refresh rate of the currently active monitor, plus 1 to try to match fractional - //// refresh rates. The Vsync setting above should limit the actual FPS to match the monitor. - configuration.setForegroundFPS(Lwjgl3ApplicationConfiguration.getDisplayMode().refreshRate + 1); + configuration.setForegroundFPS(Lwjgl3ApplicationConfiguration.getDisplayMode().refreshRate); //// If you remove the above line and set Vsync to false, you can get unlimited FPS, which can be //// useful for testing performance, but can also be very stressful to some hardware. //// You may also need to configure GPU drivers to fully disable Vsync; this can cause screen tearing. -- cgit v1.2.3-70-g09d2