From 043e0557948f7691cfff71ad91debb5876148e97 Mon Sep 17 00:00:00 2001 From: fred-boy Date: Fri, 27 Sep 2019 18:53:15 +0700 Subject: [PATCH] Upgrade fluids logic --- .../cavedroid/game/GameFluidsThread.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java b/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java index d404c43..8f4a891 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameFluidsThread.java @@ -7,7 +7,7 @@ import static ru.deadsoftware.cavedroid.game.GameItems.*; public class GameFluidsThread extends Thread { - private static final int FLUID_UPDATE_INTERVAL_MS = 150; + private static final int FLUID_UPDATE_INTERVAL_MS = 100; private static final int FLUID_STATES = 5; private static final int[] WATER_IDS = {8, 60, 61, 62, 63}; @@ -105,20 +105,27 @@ public class GameFluidsThread extends Thread { private void fluidUpdater() { int midScreen = (int) (GP.renderer.getCamX() + GP.renderer.getWidth() / 2) / 16; - for (int y = 0; y < GP.world.getHeight(); y++) { - for (int x = 0; x < (int) (GP.renderer.getWidth() / 2) / 16 + 1; x++) { + for (int y = GP.world.getHeight() - 1; y >= 0; y--) { + for (int x = 0; x <= GP.world.getWidth() / 2; x++) { updateFluids(midScreen + x, y); updateFluids(midScreen - x, y); } } } + private boolean timeToUpdate() { + if (System.currentTimeMillis() - fluidLastUpdateTimestamp >= FLUID_UPDATE_INTERVAL_MS) { + fluidLastUpdateTimestamp = System.currentTimeMillis(); + return true; + } + return false; + } + @Override public void run() { while (!this.isInterrupted()) { - if (System.currentTimeMillis() - fluidLastUpdateTimestamp > FLUID_UPDATE_INTERVAL_MS) { + if (timeToUpdate()) { fluidUpdater(); - fluidLastUpdateTimestamp = System.currentTimeMillis(); } } } -- 2.29.2