From ad734a75619510406a701e461b4ee55d86b898a2 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 4 Oct 2024 18:55:34 +0900 Subject: [PATCH] illegal tile monitoring in-game --- assets/mods/basegame/wires/ports.tga | 2 +- assets/mods/basegame/wires/wireports.csv | 2 +- .../terrarum/modulebasegame/WorldSimulator.kt | 32 +++++++++++++++++++ .../modulebasegame/gameactors/FixtureBase.kt | 13 +++++++- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/assets/mods/basegame/wires/ports.tga b/assets/mods/basegame/wires/ports.tga index 95d6d9285..33b37c6b2 100644 --- a/assets/mods/basegame/wires/ports.tga +++ b/assets/mods/basegame/wires/ports.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f9674a6d9fe8e47b7f3563f38592497494766454c1bf0be60e131113228d2456 +oid sha256:fabe4a500202846e042b6679bad30e271ea5c3ee1c33e25313e5f95ec6f6ef2c size 4114 diff --git a/assets/mods/basegame/wires/wireports.csv b/assets/mods/basegame/wires/wireports.csv index e1d8103f4..8c34e540d 100644 --- a/assets/mods/basegame/wires/wireports.csv +++ b/assets/mods/basegame/wires/wireports.csv @@ -2,4 +2,4 @@ "digital_bit";"basegame";"wires/ports.tga";0;0 "power_low";"basegame";"wires/ports.tga";1;0 "power_high";"basegame";"wires/ports.tga";2;0 -"10base2";"basegame";"wires/ports.tga";2;0 \ No newline at end of file +"axle";"basegame";"wires/ports.tga";3;0 \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/WorldSimulator.kt b/src/net/torvald/terrarum/modulebasegame/WorldSimulator.kt index 74bcea764..72f533c4a 100644 --- a/src/net/torvald/terrarum/modulebasegame/WorldSimulator.kt +++ b/src/net/torvald/terrarum/modulebasegame/WorldSimulator.kt @@ -15,6 +15,7 @@ import net.torvald.terrarum.gameworld.GameWorld.Companion.FLUID import net.torvald.terrarum.modulebasegame.TerrarumIngame.Companion.inUpdateRange import net.torvald.terrarum.modulebasegame.gameactors.* import net.torvald.terrarum.modulebasegame.gameitems.AxeCore +import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.realestate.LandUtil.CHUNK_H import net.torvald.terrarum.realestate.LandUtil.CHUNK_W import org.dyn4j.geometry.Vector2 @@ -77,6 +78,9 @@ object WorldSimulator { /** Must be called BEFORE the actors update -- actors depend on the R-Tree for various things */ operator fun invoke(player: ActorHumanoid?, delta: Float) { + if (ingame.WORLD_UPDATE_TIMER % 600L == 0L) { + App.measureDebugTime("WorldSimulator.removeIllegalTiles") { removeIllegalTiles() } + } //printdbg(this, "============================") @@ -101,6 +105,34 @@ object WorldSimulator { + fun removeIllegalTiles() { + // remove actorblocks that has no fixture association + ingame.actorNowPlaying?.let { player -> + val absoluteBlockBoxes = ingame.actorContainerActive.filter { it is FixtureBase } + .mapNotNull { (it as FixtureBase).getBlockBoxPositionsAbsolute() }.flatten().map { + LandUtil.getBlockAddr(world, it.first, it.second) + } + + val RADIUS_W = 32 + val RADIUS_H = 24 + val px = player.intTilewiseHitbox.centeredX.toInt() + val py = player.intTilewiseHitbox.centeredY.toInt() + + for (y in py - RADIUS_H..py + RADIUS_H) { + for (x in px - RADIUS_W..px + RADIUS_W) { + // is this block actorblock? + if (BlockCodex[world.getTileFromTerrain(x, y)].isActorBlock) { + // is this actorblock has no fixture association? + if (!absoluteBlockBoxes.contains(LandUtil.getBlockAddr(world, x, y))) { + // then, kill it + world.setTileTerrain(x, y, Block.AIR, false) + } + } + } + } + } + } + fun buryGrassImmediately() { ingame.terrainChangeQueue.toList().forEach { if (it != null) { diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 837797576..50716b861 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -173,14 +173,25 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { } /** + * Returns BlockBox definition as a list of individual blocks, relative to the given coord. + * * @param posX start position of the BlockBox, top-left * @param posY start position of the BlockBox, top-left - * @return real block positions, in List of Pair(x, y) + * @return block positions, in List of Pair(x, y) */ open fun getBlockBoxPositions(posX: Int, posY: Int): List> { return (posX until posX + blockBox.width).toList().cartesianProduct((posY until posY + blockBox.height).toList()) } + /** + * Returns BlockBox definition as a list of individual blocks, absolute position in the world. + * + * @return in-world block positions, in List of Pair(x, y); `null` if the actor is not placed on the world + */ + fun getBlockBoxPositionsAbsolute(): List>? = worldBlockPos?.let { (posX, posY) -> + return getBlockBoxPositions(posX, posY) + } + open fun canSpawnHere0(posX: Int, posY: Int): Boolean { val everyBlockboxPos = getBlockBoxPositions(posX, posY)