From: fredboy Date: Fri, 19 Apr 2024 17:59:18 +0000 (+0700) Subject: Use libgdx's timer for fluids X-Git-Tag: alpha0.5.2~5 X-Git-Url: http://deadsoftware.ru/gitweb?p=cavedroid.git;a=commitdiff_plain;h=0ca73172de739b618768541647d71216951e9450 Use libgdx's timer for fluids --- diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameFluidsThread.java b/core/src/ru/deadsoftware/cavedroid/game/world/GameFluidsThread.java index c5eb833..50fcef1 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/world/GameFluidsThread.java +++ b/core/src/ru/deadsoftware/cavedroid/game/world/GameFluidsThread.java @@ -1,15 +1,15 @@ package ru.deadsoftware.cavedroid.game.world; +import com.badlogic.gdx.utils.Timer; import ru.deadsoftware.cavedroid.game.mobs.MobsController; import java.util.Arrays; -import java.util.TimerTask; import static ru.deadsoftware.cavedroid.game.GameItems.*; -class GameFluidsThread extends TimerTask { +class GameFluidsThread extends Timer.Task { - public static final int FLUID_UPDATE_INTERVAL_MS = 100; + public static final float FLUID_UPDATE_INTERVAL_SEC = 0.1f; private static final int FLUID_STATES = 5; private static final int[] WATER_IDS = {8, 60, 61, 62, 63}; diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java index 692eabc..43fc164 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java +++ b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java @@ -1,6 +1,7 @@ package ru.deadsoftware.cavedroid.game.world; import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.utils.Timer; import kotlin.Pair; import ru.deadsoftware.cavedroid.game.GameItems; import ru.deadsoftware.cavedroid.game.GameScope; @@ -13,7 +14,6 @@ import ru.deadsoftware.cavedroid.game.objects.DropController; import javax.annotation.CheckForNull; import javax.inject.Inject; -import java.util.Timer; @GameScope public class GameWorld implements Disposable { @@ -63,7 +63,7 @@ public class GameWorld implements Disposable { mGameFluidsThread = new GameFluidsThread(this, mMobsController); mGameFluidsTimer = new Timer(); - mGameFluidsTimer.scheduleAtFixedRate(mGameFluidsThread, 0, GameFluidsThread.FLUID_UPDATE_INTERVAL_MS); + mGameFluidsTimer.scheduleTask(mGameFluidsThread, 0, GameFluidsThread.FLUID_UPDATE_INTERVAL_SEC); } public int getWidth() { @@ -254,6 +254,6 @@ public class GameWorld implements Disposable { @Override public void dispose() { - mGameFluidsTimer.cancel(); + mGameFluidsThread.cancel(); } } \ No newline at end of file