From 8b8fc0e93c2e1a53be20845c7d7c752dd1f2e8ac Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 19 Jul 2022 22:14:40 +0900 Subject: [PATCH] actorblock only renders when F3 is on --- assets/mods/basegame/blocks/blocks.csv | 16 +++-- .../terrarum/blockproperties/BlockCodex.kt | 3 +- .../terrarum/blockproperties/BlockProp.kt | 2 +- .../terrarum/console/{Batch.kt => Call.kt} | 2 +- .../torvald/terrarum/console/CommandDict.kt | 2 +- .../modulebasegame/gameactors/FixtureBase.kt | 58 +++++++++++++++++- .../gameactors/FixtureSwingingDoorBase.kt | 61 +------------------ .../terrarum/worlddrawer/BlocksDrawer.kt | 33 ++++++---- 8 files changed, 90 insertions(+), 87 deletions(-) rename src/net/torvald/terrarum/console/{Batch.kt => Call.kt} (93%) diff --git a/assets/mods/basegame/blocks/blocks.csv b/assets/mods/basegame/blocks/blocks.csv index 083c638fb..32607210e 100644 --- a/assets/mods/basegame/blocks/blocks.csv +++ b/assets/mods/basegame/blocks/blocks.csv @@ -104,12 +104,12 @@ id;drop;world;name;shdr;shdg;shdb;shduv;str;dsty;mate;solid;plat;wall;grav;dlfn; 273;273;273;BLOCK_SCAFFOLDING_EBONY;0.0312;0.0312;0.0312;0.0312;1;1400;WOOD;0;1;0;6;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;PLATFORM 274;274;274;BLOCK_SCAFFOLDING_BIRCH;0.0312;0.0312;0.0312;0.0312;1;670;WOOD;0;1;0;6;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;PLATFORM 275;275;275;BLOCK_SCAFFOLDING_BLOODROSE;0.0312;0.0312;0.0312;0.0312;1;900;WOOD;0;1;0;6;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;PLATFORM -4090;N/A;N/A;ACTORBLOCK_TILING_PLACEHOLDER;0.1252;0.1252;0.1252;0.1252;48;2400;ROCK;1;0;1;N/A;0;4;16;0.0000;0.0000;0.0000;0.0000;N/A;N/A;0.0;INTERNAL,DORENDER -4091;N/A;N/A;ACTORBLOCK_NO_COLLISION;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;0;0;N/A;0;0;4;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL -4092;N/A;N/A;ACTORBLOCK_FULL_COLLISION;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;0;0;N/A;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL -4093;N/A;N/A;ACTORBLOCK_ALLOW_MOVE_DOWN;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;1;0;N/A;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL -4094;N/A;N/A;ACTORBLOCK_NO_PASS_RIGHT;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;0;0;N/A;0;0;4;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL -4095;N/A;N/A;ACTORBLOCK_NO_PASS_LEFT;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;0;0;N/A;0;0;4;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL +4090;N/A;N/A;ACTORBLOCK_TILING_PLACEHOLDER;0.1252;0.1252;0.1252;0.1252;48;2400;ROCK;1;0;1;N/A;0;4;16;0.0000;0.0000;0.0000;0.0000;N/A;N/A;0.0;INTERNAL,ACTORBLOCK,DORENDER +4091;N/A;N/A;ACTORBLOCK_NO_COLLISION;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;0;0;N/A;0;0;4;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL,ACTORBLOCK +4092;N/A;N/A;ACTORBLOCK_FULL_COLLISION;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;0;0;N/A;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL,ACTORBLOCK +4093;N/A;N/A;ACTORBLOCK_ALLOW_MOVE_DOWN;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;1;0;N/A;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL,ACTORBLOCK +4094;N/A;N/A;ACTORBLOCK_NO_PASS_RIGHT;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;0;0;N/A;0;0;4;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL,ACTORBLOCK +4095;N/A;N/A;ACTORBLOCK_NO_PASS_LEFT;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;0;0;N/A;0;0;4;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL,ACTORBLOCK 65536;N/A;N/A;BLOCK_WATER;0.1016;0.0744;0.0508;0.0826;100;1000;WATR;0;0;0;0;0;0;16;0.0000;0.0000;0.0000;0.0000;005599A6;16;0.0;NATURAL 65537;N/A;N/A;BLOCK_LAVA;0.9696;0.9696;0.9696;0.9696;100;2600;ROCK;0;0;0;0;0;0;16;0.7664;0.2032;0.0000;0.0000;FF4600E6;32;0.0;NATURAL -1;N/A;N/A;BLOCK_NULL;4.0000;4.0000;4.0000;4.0000;-1;2600;NULL;0;0;1;N/A;0;0;16;0.0000;0.0000;0.0000;0.0000;N/A;N/A;0.0;INTERNAL @@ -178,9 +178,7 @@ id;drop;world;name;shdr;shdg;shdb;shduv;str;dsty;mate;solid;plat;wall;grav;dlfn; ## Actorblocks ## # # Actorblocks are virtual/placeholder blocks that accompanies actors (usually fixtures). -# Any tile that contains "ACTORBLOCK" in its "name" will be recognised as one, so avoid having the particular string on -# the name if your tile is not Actorblock! -# +# Actorblocks are recognised by the "ACTORBLOCK" tag. # ## Tags ## # diff --git a/src/net/torvald/terrarum/blockproperties/BlockCodex.kt b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt index 5e9ec34b1..6148c12b6 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockCodex.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt @@ -1,7 +1,6 @@ package net.torvald.terrarum.blockproperties import net.torvald.gdx.graphics.Cvec -import net.torvald.terrarum.App import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.ReferencingRanges.PREFIX_VIRTUALTILE import net.torvald.terrarum.gameitems.ItemID @@ -139,6 +138,8 @@ class BlockCodex { throw NullPointerException("Blockprop with raw id $rawIndex does not exist.") } }*/ + fun hasProp(blockID: ItemID?): Boolean = if (blockID == null) false else blockProps.containsKey(blockID) + operator fun get(blockID: ItemID?): BlockProp { if (blockID == null || blockID == Block.NULL) { return nullProp diff --git a/src/net/torvald/terrarum/blockproperties/BlockProp.kt b/src/net/torvald/terrarum/blockproperties/BlockProp.kt index 18c09b26d..ff1002340 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockProp.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockProp.kt @@ -108,5 +108,5 @@ class BlockProp { val extra = Codex() val isActorBlock: Boolean - get() = nameKey.contains("ACTORBLOCK") + get() = tags.contains("ACTORBLOCK") } \ No newline at end of file diff --git a/src/net/torvald/terrarum/console/Batch.kt b/src/net/torvald/terrarum/console/Call.kt similarity index 93% rename from src/net/torvald/terrarum/console/Batch.kt rename to src/net/torvald/terrarum/console/Call.kt index c74a3d146..7b73fd187 100644 --- a/src/net/torvald/terrarum/console/Batch.kt +++ b/src/net/torvald/terrarum/console/Call.kt @@ -7,7 +7,7 @@ import kotlin.io.path.Path /** * Created by minjaesong on 2016-03-07. */ -internal object Batch : ConsoleCommand { +internal object Call : ConsoleCommand { @Throws(Exception::class) override fun execute(args: Array) { if (args.size == 2) { diff --git a/src/net/torvald/terrarum/console/CommandDict.kt b/src/net/torvald/terrarum/console/CommandDict.kt index 2b7652c0c..69c32496c 100644 --- a/src/net/torvald/terrarum/console/CommandDict.kt +++ b/src/net/torvald/terrarum/console/CommandDict.kt @@ -15,7 +15,7 @@ object CommandDict { "ActorsList", "Authenticator", "AVTracker", - "Batch", + "Call", "Echo", "EchoConsole", "EchoError", diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 01ec5cfb9..5f883c847 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -112,7 +112,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { } /** - * Adds this instance of the fixture to the world + * Adds this instance of the fixture to the world. Physical dimension is derived from [blockBox]. * * @param posX0 tile-wise bottem-centre position of the fixture (usually [Terrarum.mouseTileX]) * @param posY0 tile-wise bottem-centre position of the fixture (usually [Terrarum.mouseTileY]) @@ -171,7 +171,63 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { return true + } + /** + * Identical to `spawn(Int, Int)` except it takes user-defined hitbox dimension instead of taking value from [blockBox]. + * Useful if [blockBox] cannot be determined on the time of the constructor call. + * + * @param posX tile-wise bottem-centre position of the fixture + * @param posY tile-wise bottem-centre position of the fixture + * @param thbw tile-wise Hitbox width + * @param thbh tile-wise Hitbox height + * @return true if successfully spawned, false if was not (e.g. space to spawn is occupied by something else) + */ + open fun spawn(posX0: Int, posY0: Int, thbw: Int, thbh: Int): Boolean { + val posX = (posX0 - thbw.div(2)) fmod world!!.width + val posY = posY0 - thbh + 1 + + // set the position of this actor + worldBlockPos = Point2i(posX, posY) + + // define physical position + this.hitbox.setFromWidthHeight( + posX * TILE_SIZED, + posY * TILE_SIZED, + blockBox.width * TILE_SIZED, + blockBox.height * TILE_SIZED + ) + + // check for existing blocks (and fixtures) + var hasCollision = false + forEachBlockbox { x, y, _, _ -> + if (!hasCollision) { + val tile = world!!.getTileFromTerrain(x, y) + if (BlockCodex[tile].isSolid || BlockCodex[tile].isActorBlock) { + hasCollision = true + } + } + } + if (hasCollision) { + printdbg(this, "cannot spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, has tile collision; xy=($posX,$posY) tDim=(${blockBox.width},${blockBox.height})") + return false + } + printdbg(this, "spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, xy=($posX,$posY) tDim=(${blockBox.width},${blockBox.height})") + + + // fill the area with the filler blocks + placeActorBlocks() + + + this.isVisible = true + + + // actually add this actor into the world + INGAME.queueActorAddition(this) + spawnRequestedTime = System.nanoTime() + + + return true } /** force disable despawn when inventory is not empty */ diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt index be0e024bf..773d76877 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt @@ -10,7 +10,6 @@ import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.Hitbox import net.torvald.terrarum.gameactors.Lightbox import net.torvald.terrarum.gameactors.Luminous -import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack /** @@ -19,7 +18,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack * * Created by minjaesong on 2022-07-15. */ -class FixtureSwingingDoorBase : FixtureBase, Luminous { +open class FixtureSwingingDoorBase : FixtureBase, Luminous { /* OVERRIDE THESE TO CUSTOMISE */ open val tw = 2 // tilewise width of the door when opened @@ -78,64 +77,6 @@ class FixtureSwingingDoorBase : FixtureBase, Luminous { override fun spawn(posX: Int, posY: Int) = spawn(posX, posY, tilewiseHitboxWidth, tilewiseHitboxHeight) - // TODO move this function over FixtureBase once it's done and perfected - /** - * Identical to `spawn(Int, Int)` except it takes user-defined hitbox dimension instead of taking value from [blockBox]. - * Useful if [blockBox] cannot be determined on the time of the constructor call. - * - * @param posX tile-wise bottem-centre position of the fixture - * @param posY tile-wise bottem-centre position of the fixture - * @param thbw tile-wise Hitbox width - * @param thbh tile-wise Hitbox height - * @return true if successfully spawned, false if was not (e.g. space to spawn is occupied by something else) - */ - protected fun spawn(posX0: Int, posY0: Int, thbw: Int, thbh: Int): Boolean { - val posX = (posX0 - thbw.div(2)) fmod world!!.width - val posY = posY0 - thbh + 1 - - // set the position of this actor - worldBlockPos = Point2i(posX, posY) - - // define physical position - this.hitbox.setFromWidthHeight( - posX * TILE_SIZED, - posY * TILE_SIZED, - blockBox.width * TILE_SIZED, - blockBox.height * TILE_SIZED - ) - - // check for existing blocks (and fixtures) - var hasCollision = false - forEachBlockbox { x, y, _, _ -> - if (!hasCollision) { - val tile = world!!.getTileFromTerrain(x, y) - if (BlockCodex[tile].isSolid || BlockCodex[tile].isActorBlock) { - hasCollision = true - } - } - } - if (hasCollision) { - printdbg(this, "cannot spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, has tile collision; xy=($posX,$posY) tDim=(${blockBox.width},${blockBox.height})") - return false - } - printdbg(this, "spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, xy=($posX,$posY) tDim=(${blockBox.width},${blockBox.height})") - - - // fill the area with the filler blocks - placeActorBlocks() - - - this.isVisible = true - - - // actually add this actor into the world - INGAME.queueActorAddition(this) - spawnRequestedTime = System.nanoTime() - - - return true - } - override fun reload() { super.reload() diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt index 6436273f9..44e0cd4df 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.worlddrawer import com.badlogic.gdx.Gdx +import com.badlogic.gdx.Input.Keys import com.badlogic.gdx.graphics.* import com.badlogic.gdx.math.Matrix4 import com.jme3.math.FastMath @@ -9,6 +10,7 @@ import net.torvald.terrarum.App.measureDebugTime import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE import net.torvald.terrarum.blockproperties.Block +import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.WorldSimulator @@ -341,19 +343,24 @@ internal object BlocksDrawer { else renderTag.tileNumber val tileNumber = if (thisTile == Block.AIR) 0 - // special case: fluids - else if (mode == FLUID) tileNumberBase + connectLut47[nearbyTilesInfo] - // special case: occlusion - else if (mode == OCCLUSION) - tileNumberBase + connectLut47[nearbyTilesInfo] - // rest of the cases: terrain and walls - else tileNumberBase + when (renderTag.maskType) { - CreateTileAtlas.RenderTag.MASK_NA -> 0 - CreateTileAtlas.RenderTag.MASK_16 -> connectLut16[nearbyTilesInfo] - CreateTileAtlas.RenderTag.MASK_47 -> connectLut47[nearbyTilesInfo] - CreateTileAtlas.RenderTag.MASK_TORCH, CreateTileAtlas.RenderTag.MASK_PLATFORM -> nearbyTilesInfo - else -> throw IllegalArgumentException("Unknown mask type: ${renderTag.maskType}") - } + // special case: actorblocks and F3 key + else if (BlockCodex.hasProp(thisTile) && BlockCodex[thisTile].isActorBlock && + !BlockCodex[thisTile].tags.contains("DORENDER") && !KeyToggler.isOn(Keys.F3)) + 0 + // special case: fluids + else if (mode == FLUID) + tileNumberBase + connectLut47[nearbyTilesInfo] + // special case: occlusion + else if (mode == OCCLUSION) + tileNumberBase + connectLut47[nearbyTilesInfo] + // rest of the cases: terrain and walls + else tileNumberBase + when (renderTag.maskType) { + CreateTileAtlas.RenderTag.MASK_NA -> 0 + CreateTileAtlas.RenderTag.MASK_16 -> connectLut16[nearbyTilesInfo] + CreateTileAtlas.RenderTag.MASK_47 -> connectLut47[nearbyTilesInfo] + CreateTileAtlas.RenderTag.MASK_TORCH, CreateTileAtlas.RenderTag.MASK_PLATFORM -> nearbyTilesInfo + else -> throw IllegalArgumentException("Unknown mask type: ${renderTag.maskType}") + } var thisTileX = tileNumber % App.tileMaker.TILES_IN_X var thisTileY = tileNumber / App.tileMaker.TILES_IN_X