summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 50346da)
raw | patch | inline | side by side (parent: 50346da)
author | fred-boy <fredboy@protonmail.com> | |
Thu, 26 Sep 2019 18:11:36 +0000 (01:11 +0700) | ||
committer | fred-boy <fredboy@protonmail.com> | |
Sun, 29 Sep 2019 04:39:17 +0000 (11:39 +0700) |
core/src/ru/deadsoftware/cavedroid/game/GameProc.java | patch | blob | history |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java
index c2fca908a889f7dff2591e2239fee7df1b64b609..53b2b9060ed6eca4fd65e0aa73d4c4380837d47e 100644 (file)
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Random;
public class GameProc implements Serializable, Disposable {
+ private static final int FLUID_UPDATE_INTERVAL_MS = 100;
+
static boolean DO_UPD = false;
static int UPD_X = -1, UPD_Y = -1;
public ArrayList<Mob> mobs;
public ArrayList<Drop> drops;
+ private long fluidLastUpdateTimestamp = 0;
public boolean isTouchDown, isKeyDown;
public int ctrlMode, touchDownX, touchDownY, touchDownBtn, keyDownCode;
}
maxCreativeScroll = GameItems.getItemsSize() / 8;
- fluidThread = new Thread(() -> {
- while (!fluidThread.isInterrupted()) {
- fluidUpdater();
- }
- });
+ createFluidThread();
fluidThread.start();
GameSaver.save(this);
}
+ private void createFluidThread() {
+ fluidThread = new Thread(() -> {
+ while (!fluidThread.isInterrupted()) {
+ if (System.currentTimeMillis() - fluidLastUpdateTimestamp > FLUID_UPDATE_INTERVAL_MS) {
+ fluidUpdater();
+ fluidLastUpdateTimestamp = System.currentTimeMillis();
+ }
+ }
+ });
+ }
+
public void resetRenderer() {
if (CaveGame.TOUCH) {
renderer = new GameRenderer(320,
}
private void fluidUpdater() {
+ int midScreen = (int) (renderer.getCamX() + renderer.getWidth() / 2) / 16;
for (int y = 0; y < world.getHeight(); y++) {
- for (int x = (int) renderer.getCamX() / 16 - 1;
- x < (int) (renderer.getCamX() + renderer.getWidth()) / 16 + 1; x++) {
- updateFluids(x, y);
+ for (int x = 0; x < (int) (renderer.getWidth() / 2) / 16 + 1; x++) {
+ updateFluids(midScreen + x, y);
+ updateFluids(midScreen - x, y);
}
}
}
isTouchDown = false;
}
}
+
+ if (fluidThread == null || !fluidThread.isAlive()) {
+ createFluidThread();
+ fluidThread.start();
+ }
}
@Override