DEADSOFTWARE

Add update blocks logic actions
authorfredboy <fredboy@protonmail.com>
Fri, 19 Apr 2024 21:33:47 +0000 (04:33 +0700)
committerfredboy <fredboy@protonmail.com>
Fri, 19 Apr 2024 21:35:27 +0000 (04:35 +0700)
15 files changed:
core/src/ru/deadsoftware/cavedroid/game/GameComponent.java
core/src/ru/deadsoftware/cavedroid/game/GameInput.java
core/src/ru/deadsoftware/cavedroid/game/GameProc.java
core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
core/src/ru/deadsoftware/cavedroid/game/actions/CommonBlockActionUtils.kt [moved from core/src/ru/deadsoftware/cavedroid/game/actions/PlaceBlockActionUtils.kt with 71% similarity]
core/src/ru/deadsoftware/cavedroid/game/actions/UpdateBlockActionsModule.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/actions/UseItemActionsModule.kt [moved from core/src/ru/deadsoftware/cavedroid/game/actions/GameActionsModule.kt with 97% similarity]
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/IUpdateBlockAction.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGrassAction.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateRequiresBlockAction.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java
core/src/ru/deadsoftware/cavedroid/game/world/GameWorldBlocksLogicControllerTask.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/world/GameWorldFluidsLogicControllerTask.java [moved from core/src/ru/deadsoftware/cavedroid/game/world/GameFluidsThread.java with 92% similarity]

index 8b1b7eefffae23d60c3ba0b5645f0d6622cff0a9..81f4b88d9f52571677dd22e608127a214ea0ce68 100644 (file)
@@ -2,10 +2,11 @@ package ru.deadsoftware.cavedroid.game;
 
 import dagger.Component;
 import ru.deadsoftware.cavedroid.MainComponent;
-import ru.deadsoftware.cavedroid.game.actions.GameActionsModule;
+import ru.deadsoftware.cavedroid.game.actions.UpdateBlockActionsModule;
+import ru.deadsoftware.cavedroid.game.actions.UseItemActionsModule;
 
 @GameScope
-@Component(dependencies = MainComponent.class, modules = { GameModule.class, GameActionsModule.class })
+@Component(dependencies = MainComponent.class, modules = { GameModule.class, UseItemActionsModule.class, UpdateBlockActionsModule.class })
 public interface GameComponent {
     GameProc getGameProc();
 
index e26b06bad903c54c3bbc2dcc4cefec8887a0749d..17d6ad1ac758820a32f02f1fdedbac58c612f39d 100644 (file)
@@ -8,7 +8,7 @@ import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.utils.TimeUtils;
 import com.google.common.collect.Range;
 import ru.deadsoftware.cavedroid.MainConfig;
-import ru.deadsoftware.cavedroid.game.actions.PlaceBlockActionUtilsKt;
+import ru.deadsoftware.cavedroid.game.actions.CommonBlockActionUtilsKt;
 import ru.deadsoftware.cavedroid.game.actions.useitem.IUseItemAction;
 import ru.deadsoftware.cavedroid.game.mobs.Mob;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
@@ -212,9 +212,9 @@ public class GameInput {
             @CheckForNull final String actionKey = item.getActionKey();
             if (item.isBlock()) {
                 if (!bg) {
-                    PlaceBlockActionUtilsKt.placeToForegroundAction(mUseItemActionMap, item, x, y);
+                    CommonBlockActionUtilsKt.placeToForegroundAction(mUseItemActionMap, item, x, y);
                 } else {
-                    PlaceBlockActionUtilsKt.placeToBackgroundAction(mUseItemActionMap, item, x, y);
+                    CommonBlockActionUtilsKt.placeToBackgroundAction(mUseItemActionMap, item, x, y);
                 }
             } else if (actionKey != null) {
                 final IUseItemAction useItemAction = mUseItemActionMap.get(actionKey);
index f063f7a19a856c1f0d4b06e28f924f14574ced22..139a31ba61e8dbe98d54fb458944de45450a35f2 100644 (file)
@@ -1,8 +1,10 @@
 package ru.deadsoftware.cavedroid.game;
 
 import com.badlogic.gdx.utils.Disposable;
+import com.badlogic.gdx.utils.Timer;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
-import ru.deadsoftware.cavedroid.game.world.GameWorld;
+import ru.deadsoftware.cavedroid.game.world.GameWorldBlocksLogicControllerTask;
+import ru.deadsoftware.cavedroid.game.world.GameWorldFluidsLogicControllerTask;
 
 import javax.inject.Inject;
 
@@ -11,24 +13,34 @@ public class GameProc implements Disposable {
 
     public static final int MAX_CREATIVE_SCROLL = GameItems.getItemsSize() / 8;
 
-    private final GameWorld mGameWorld;
     private final GamePhysics mGamePhysics;
     private final GameInput mGameInput;
     private final GameRenderer mGameRenderer;
     private final MobsController mMobsController;
+    private final GameWorldFluidsLogicControllerTask mGameWorldFluidsLogicControllerTask;
+    private final GameWorldBlocksLogicControllerTask mGameWorldBlocksLogicControllerTask;
+
+    private final Timer mWorldLogicTimer = new Timer();
 
     @Inject
-    public GameProc(GameWorld gameWorld,
-                    GamePhysics gamePhysics,
+    public GameProc(GamePhysics gamePhysics,
                     GameInput gameInput,
                     GameRenderer gameRenderer,
-                    MobsController mobsController
+                    MobsController mobsController,
+                    GameWorldFluidsLogicControllerTask gameWorldFluidsLogicControllerTask,
+                    GameWorldBlocksLogicControllerTask gameWorldBlocksLogicControllerTask
     ) {
-        mGameWorld = gameWorld;
         mGamePhysics = gamePhysics;
         mGameInput = gameInput;
         mGameRenderer = gameRenderer;
         mMobsController = mobsController;
+        mGameWorldFluidsLogicControllerTask = gameWorldFluidsLogicControllerTask;
+        mGameWorldBlocksLogicControllerTask = gameWorldBlocksLogicControllerTask;
+
+        mWorldLogicTimer.scheduleTask(gameWorldFluidsLogicControllerTask, 0,
+                GameWorldFluidsLogicControllerTask.FLUID_UPDATE_INTERVAL_SEC);
+        mWorldLogicTimer.scheduleTask(gameWorldBlocksLogicControllerTask, 0,
+                GameWorldBlocksLogicControllerTask.WORLD_BLOCKS_LOGIC_UPDATE_INTERVAL_SEC);
     }
 
     public void setPlayerGameMode(int gameMode) {
@@ -38,12 +50,13 @@ public class GameProc implements Disposable {
     public void update(float delta) {
         mGamePhysics.update(delta);
         mGameInput.update();
-        mGameWorld.update();
         mGameRenderer.render(delta);
     }
 
     @Override
     public void dispose() {
-        mGameWorld.dispose();
+        mWorldLogicTimer.stop();
+        mGameWorldFluidsLogicControllerTask.cancel();
+        mGameWorldBlocksLogicControllerTask.cancel();
     }
 }
index 20401acd7e000fd4fd62efaea89a2909630d3898..ca9cf8b392c231dfc564ef3120eff9ba90469ec2 100644 (file)
@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.g2d.Sprite;
 import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
 import com.badlogic.gdx.math.Intersector;
+import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.math.Rectangle;
 import com.badlogic.gdx.math.Vector2;
 import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
@@ -370,7 +371,7 @@ public class GameRenderer extends Renderer {
 
     @Override
     public void render(float delta) {
-        int fps = (int) (1 / delta);
+        int fps = MathUtils.ceil(1 / delta);
         updateCameraPosition();
         mGameInput.moveCursor(this);
 
similarity index 71%
rename from core/src/ru/deadsoftware/cavedroid/game/actions/PlaceBlockActionUtils.kt
rename to core/src/ru/deadsoftware/cavedroid/game/actions/CommonBlockActionUtils.kt
index 52b97d0eafbf50fc1496dcbe662a4a0611a50410..43094309395f70e094031f760a0957e458c4ccef 100644 (file)
@@ -1,6 +1,8 @@
 package ru.deadsoftware.cavedroid.game.actions
 
 import com.badlogic.gdx.Gdx
+import ru.deadsoftware.cavedroid.game.actions.updateblock.IUpdateBlockAction
+import ru.deadsoftware.cavedroid.game.actions.updateblock.UpdateRequiresBlockAction
 import ru.deadsoftware.cavedroid.game.actions.useitem.IUseItemAction
 import ru.deadsoftware.cavedroid.game.actions.useitem.PlaceBlockItemToBackgroundAction
 import ru.deadsoftware.cavedroid.game.actions.useitem.PlaceBlockItemToForegroundAction
@@ -17,3 +19,7 @@ fun Map<String, IUseItemAction>.placeToBackgroundAction(item: Item, x: Int, y: I
     get(PlaceBlockItemToBackgroundAction.ACTION_KEY)?.perform(item, x, y)
         ?: Gdx.app.error(TAG, "action place_background_block not found")
 }
+
+fun Map<String, IUpdateBlockAction>.getRequiresBlockAction(): IUpdateBlockAction {
+    return requireNotNull(get(UpdateRequiresBlockAction.ACTION_KEY)) { "action requires_block not found" }
+}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/UpdateBlockActionsModule.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/UpdateBlockActionsModule.kt
new file mode 100644 (file)
index 0000000..be84127
--- /dev/null
@@ -0,0 +1,44 @@
+package ru.deadsoftware.cavedroid.game.actions
+
+import dagger.Binds
+import dagger.Module
+import dagger.multibindings.IntoMap
+import dagger.multibindings.StringKey
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.actions.updateblock.*
+
+@Module
+class UpdateBlockActionsModule {
+
+    @Binds
+    @IntoMap
+    @StringKey(UpdateSandAction.BLOCK_KEY)
+    @GameScope
+    fun bindUpdateSandAction(action: UpdateSandAction): IUpdateBlockAction {
+        return action;
+    }
+
+    @Binds
+    @IntoMap
+    @StringKey(UpdateGravelAction.BLOCK_KEY)
+    @GameScope
+    fun bindUpdateGravelAction(action: UpdateGravelAction): IUpdateBlockAction {
+        return action;
+    }
+
+    @Binds
+    @IntoMap
+    @StringKey(UpdateRequiresBlockAction.ACTION_KEY)
+    @GameScope
+    fun bindUpdateRequiresBlockAction(action: UpdateRequiresBlockAction): IUpdateBlockAction {
+        return action;
+    }
+
+    @Binds
+    @IntoMap
+    @StringKey(UpdateGrassAction.BLOCK_KEY)
+    @GameScope
+    fun bindUpdateGrassAction(action: UpdateGrassAction): IUpdateBlockAction {
+        return action;
+    }
+}
\ No newline at end of file
similarity index 97%
rename from core/src/ru/deadsoftware/cavedroid/game/actions/GameActionsModule.kt
rename to core/src/ru/deadsoftware/cavedroid/game/actions/UseItemActionsModule.kt
index 672c06279ad7c1dd3bb9d973d6ca02b7694eb5d0..a54e4a77e31403e9e2f7c1583221af2a8ddf42f3 100644 (file)
@@ -8,7 +8,7 @@ import ru.deadsoftware.cavedroid.game.GameScope
 import ru.deadsoftware.cavedroid.game.actions.useitem.*
 
 @Module
-class GameActionsModule {
+class UseItemActionsModule {
 
     @Binds
     @IntoMap
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/IUpdateBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/IUpdateBlockAction.kt
new file mode 100644 (file)
index 0000000..9cc4aea
--- /dev/null
@@ -0,0 +1,7 @@
+package ru.deadsoftware.cavedroid.game.actions.updateblock
+
+interface IUpdateBlockAction {
+
+    fun update(x: Int, y: Int)
+
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGrassAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGrassAction.kt
new file mode 100644 (file)
index 0000000..a50c541
--- /dev/null
@@ -0,0 +1,23 @@
+package ru.deadsoftware.cavedroid.game.actions.updateblock
+
+import ru.deadsoftware.cavedroid.game.GameItems
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.world.GameWorld
+import javax.inject.Inject
+
+@GameScope
+class UpdateGrassAction @Inject constructor(
+    private val gameWorld: GameWorld,
+) : IUpdateBlockAction {
+
+    override fun update(x: Int, y: Int) {
+        val blockOnTop = gameWorld.getForeMapBlock(x, y - 1)
+        if (blockOnTop.collision || blockOnTop.fluid) {
+            gameWorld.setForeMap(x, y, GameItems.getBlockId("dirt"))
+        }
+    }
+
+    companion object {
+        const val BLOCK_KEY = "grass"
+    }
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt
new file mode 100644 (file)
index 0000000..53fcd62
--- /dev/null
@@ -0,0 +1,28 @@
+package ru.deadsoftware.cavedroid.game.actions.updateblock
+
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.mobs.FallingGravel
+import ru.deadsoftware.cavedroid.game.mobs.FallingSand
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import ru.deadsoftware.cavedroid.game.world.GameWorld
+import javax.inject.Inject
+
+@GameScope
+class UpdateGravelAction @Inject constructor(
+    private val gameWorld: GameWorld,
+    private val mobsController: MobsController,
+) : IUpdateBlockAction {
+
+    override fun update(x: Int, y: Int) {
+        val shouldFall = gameWorld.getForeMapBlock(x, y + 1).collision.not()
+
+        if (shouldFall) {
+            gameWorld.setForeMap(x, y, 0)
+            mobsController.addMob(FallingGravel(x * 16f, y * 16f))
+        }
+    }
+
+    companion object {
+        const val BLOCK_KEY = "gravel"
+    }
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateRequiresBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateRequiresBlockAction.kt
new file mode 100644 (file)
index 0000000..2e27373
--- /dev/null
@@ -0,0 +1,21 @@
+package ru.deadsoftware.cavedroid.game.actions.updateblock
+
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.world.GameWorld
+import javax.inject.Inject
+
+@GameScope
+class UpdateRequiresBlockAction @Inject constructor(
+    private val gameWorld: GameWorld,
+) : IUpdateBlockAction {
+
+    override fun update(x: Int, y: Int) {
+        if (!gameWorld.getForeMapBlock(x, y + 1).collision) {
+            gameWorld.destroyForeMap(x, y)
+        }
+    }
+
+    companion object {
+        const val ACTION_KEY = "requires_block"
+    }
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt
new file mode 100644 (file)
index 0000000..26fb978
--- /dev/null
@@ -0,0 +1,27 @@
+package ru.deadsoftware.cavedroid.game.actions.updateblock
+
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.mobs.FallingSand
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import ru.deadsoftware.cavedroid.game.world.GameWorld
+import javax.inject.Inject
+
+@GameScope
+class UpdateSandAction @Inject constructor(
+    private val gameWorld: GameWorld,
+    private val mobsController: MobsController,
+) : IUpdateBlockAction {
+
+    override fun update(x: Int, y: Int) {
+        val shouldFall = gameWorld.getForeMapBlock(x, y + 1).collision.not()
+
+        if (shouldFall) {
+            gameWorld.setForeMap(x, y, 0)
+            mobsController.addMob(FallingSand(x * 16f, y * 16f))
+        }
+    }
+
+    companion object {
+        const val BLOCK_KEY = "sand"
+    }
+}
\ No newline at end of file
index 43fc1641033616ec6645795ead6daed286dc82e3..d3e56c1a760ba6d9991870343bc2502efee48942 100644 (file)
@@ -1,12 +1,8 @@
 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;
-import ru.deadsoftware.cavedroid.game.mobs.FallingGravel;
-import ru.deadsoftware.cavedroid.game.mobs.FallingSand;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.model.world.generator.WorldGeneratorConfig;
 import ru.deadsoftware.cavedroid.game.objects.Block;
@@ -16,25 +12,16 @@ import javax.annotation.CheckForNull;
 import javax.inject.Inject;
 
 @GameScope
-public class GameWorld implements Disposable {
-
-    private static final int UPDATE_RANGE = 16;
+public class GameWorld {
 
     private final DropController mDropController;
     private final MobsController mMobsController;
 
-    private final Timer mGameFluidsTimer;
-    private final GameFluidsThread mGameFluidsThread;
-
     private final int mWidth;
     private final int mHeight;
     private final int[][] mForeMap;
     private final int[][] mBackMap;
 
-    private boolean mShouldUpdate;
-    private int mUpdateX;
-    private int mUpdateY;
-
     @Inject
     public GameWorld(DropController dropController,
                      MobsController mobsController,
@@ -59,11 +46,6 @@ public class GameWorld implements Disposable {
             mWidth = mForeMap.length;
             mHeight = mForeMap[0].length;
         }
-
-        mGameFluidsThread = new GameFluidsThread(this, mMobsController);
-
-        mGameFluidsTimer = new Timer();
-        mGameFluidsTimer.scheduleTask(mGameFluidsThread, 0, GameFluidsThread.FLUID_UPDATE_INTERVAL_SEC);
     }
 
     public int getWidth() {
@@ -181,9 +163,6 @@ public class GameWorld implements Disposable {
         } else if (GameItems.isSlab(value) && getForeMap(x, y) == value) {
             placeSlab(x, y, value);
         }
-        mUpdateX = x - 8;
-        mUpdateY = y - 8;
-        mShouldUpdate = true;
     }
 
     public void placeToBackground(int x, int y, int value) {
@@ -208,52 +187,4 @@ public class GameWorld implements Disposable {
         }
         placeToBackground(x, y, 0);
     }
-
-    private void updateBlock(int x, int y) {
-        if (getForeMap(x, y) == 10) {
-            if (!hasForeAt(x, y + 1) || !getForeMapBlock(x, y + 1).hasCollision()) {
-                setForeMap(x, y, 0);
-                mMobsController.addMob(new FallingSand(x * 16, y * 16));
-                updateBlock(x, y - 1);
-            }
-        }
-
-        if (getForeMap(x, y) == 11) {
-            if (!hasForeAt(x, y + 1) || !getForeMapBlock(x, y + 1).hasCollision()) {
-                setForeMap(x, y, 0);
-                mMobsController.addMob(new FallingGravel(x * 16, y * 16));
-                updateBlock(x, y - 1);
-            }
-        }
-
-        if (hasForeAt(x, y) && getForeMapBlock(x, y).requiresBlock()) {
-            if (!hasForeAt(x, y + 1) || !getForeMapBlock(x, y + 1).hasCollision()) {
-                destroyForeMap(x, y);
-                updateBlock(x, y - 1);
-            }
-        }
-
-        if (getForeMap(x, y) == 2) {
-            if (hasForeAt(x, y - 1) && (getForeMapBlock(x, y - 1).hasCollision() ||
-                    GameItems.isFluid(getForeMap(x, y - 1)))) {
-                setForeMap(x, y, 3);
-            }
-        }
-    }
-
-    public void update() {
-        if (mShouldUpdate) {
-            for (int y = mUpdateY; y < mUpdateY + UPDATE_RANGE; y++) {
-                for (int x = mUpdateX; x < mUpdateX + UPDATE_RANGE; x++) {
-                    updateBlock(x, y);
-                }
-            }
-            mShouldUpdate = false;
-        }
-    }
-
-    @Override
-    public void dispose() {
-        mGameFluidsThread.cancel();
-    }
 }
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorldBlocksLogicControllerTask.kt b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorldBlocksLogicControllerTask.kt
new file mode 100644 (file)
index 0000000..20f992a
--- /dev/null
@@ -0,0 +1,59 @@
+package ru.deadsoftware.cavedroid.game.world
+
+import com.badlogic.gdx.Gdx
+import com.badlogic.gdx.utils.TimeUtils
+import com.badlogic.gdx.utils.Timer.Task
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.actions.getRequiresBlockAction
+import ru.deadsoftware.cavedroid.game.actions.updateblock.IUpdateBlockAction
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import javax.inject.Inject
+
+@GameScope
+class GameWorldBlocksLogicControllerTask @Inject constructor(
+    private val gameWorld: GameWorld,
+    private val updateBlockActions: Map<String, @JvmSuppressWildcards IUpdateBlockAction>,
+    private val mobsController: MobsController,
+) : Task() {
+
+    private var currentRelativeChunk = 0
+
+    private fun getChunkStart(): Int {
+        val playerX = mobsController.player.mapX
+        val playerChunk = playerX / CHUNK_WIDTH
+        val currentChunk = playerChunk - CHUNKS / 2 + currentRelativeChunk
+
+        return currentChunk * 16
+    }
+
+    private fun updateBlock(x: Int, y: Int) {
+        val block = gameWorld.getForeMapBlock(x, y)
+        val blockKey = block.key
+        val action = updateBlockActions[blockKey]
+            ?: updateBlockActions.getRequiresBlockAction().takeIf { block.requiresBlock }
+
+        action?.update(x, y)
+    }
+
+    override fun run() {
+        val startX = getChunkStart()
+
+        for (y in gameWorld.height downTo 0) {
+            for (x in startX ..< startX + CHUNK_WIDTH) {
+                updateBlock(x, y)
+            }
+        }
+
+        currentRelativeChunk = (currentRelativeChunk + 1) % CHUNKS
+    }
+
+    companion object {
+        private const val TAG = "GameWorldBlocksLogicControllerTask"
+
+        private const val CHUNK_WIDTH = 16
+        private const val CHUNKS = 3
+
+        const val WORLD_BLOCKS_LOGIC_UPDATE_INTERVAL_SEC = .1f
+    }
+
+}
similarity index 92%
rename from core/src/ru/deadsoftware/cavedroid/game/world/GameFluidsThread.java
rename to core/src/ru/deadsoftware/cavedroid/game/world/GameWorldFluidsLogicControllerTask.java
index 50fcef14c92ef32896859f10c79c6494c6929b69..d996cf42989c41a1025b54fb1c1fd2b77e053cf0 100644 (file)
@@ -1,13 +1,16 @@
 package ru.deadsoftware.cavedroid.game.world;
 
 import com.badlogic.gdx.utils.Timer;
+import ru.deadsoftware.cavedroid.game.GameScope;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 
+import javax.inject.Inject;
 import java.util.Arrays;
 
 import static ru.deadsoftware.cavedroid.game.GameItems.*;
 
-class GameFluidsThread extends Timer.Task {
+@GameScope
+public class GameWorldFluidsLogicControllerTask extends Timer.Task {
 
     public static final float FLUID_UPDATE_INTERVAL_SEC = 0.1f;
     private static final int FLUID_STATES = 5;
@@ -15,13 +18,12 @@ class GameFluidsThread extends Timer.Task {
     private static final int[] WATER_IDS = {8, 60, 61, 62, 63};
     private static final int[] LAVA_IDS = {9, 64, 65, 66, 67};
 
-    private long mFluidLastUpdateTimestamp = 0;
-
     private final GameWorld mGameWorld;
     private final MobsController mMobsController;
 
-    GameFluidsThread(GameWorld gameWorld,
-                     MobsController mobsController) {
+    @Inject
+    GameWorldFluidsLogicControllerTask(GameWorld gameWorld,
+                                       MobsController mobsController) {
         mGameWorld = gameWorld;
         mMobsController = mobsController;
     }