diff --git a/src/net/torvald/terrarum/blockproperties/Block.kt b/src/net/torvald/terrarum/blockproperties/Block.kt index 6100b37c4..d36cc1f77 100644 --- a/src/net/torvald/terrarum/blockproperties/Block.kt +++ b/src/net/torvald/terrarum/blockproperties/Block.kt @@ -127,4 +127,12 @@ object Block { const val WATER = 4095 const val NULL = -1 + + val actorblocks = listOf( + ACTORBLOCK_NO_COLLISION, + ACTORBLOCK_FULL_COLLISION, + ACTORBLOCK_ALLOW_MOVE_DOWN, + ACTORBLOCK_NO_PASS_RIGHT, + ACTORBLOCK_NO_PASS_LEFT + ) } diff --git a/src/net/torvald/terrarum/gameactors/Hitbox.kt b/src/net/torvald/terrarum/gameactors/Hitbox.kt index 53197c0ba..dd8b54ce6 100644 --- a/src/net/torvald/terrarum/gameactors/Hitbox.kt +++ b/src/net/torvald/terrarum/gameactors/Hitbox.kt @@ -10,7 +10,7 @@ import org.dyn4j.geometry.Vector2 * * Created by minjaesong on 2016-01-15. */ -class Hitbox(x1: Double, y1: Double, width: Double, height: Double, var suppressWarning: Boolean = false) { +class Hitbox (x1: Double, y1: Double, width: Double, height: Double, var suppressWarning: Boolean = true) { @Volatile var hitboxStart: Point2d private set diff --git a/src/net/torvald/terrarum/modulebasegame/Ingame.kt b/src/net/torvald/terrarum/modulebasegame/Ingame.kt index 0a2377975..7c15588ff 100644 --- a/src/net/torvald/terrarum/modulebasegame/Ingame.kt +++ b/src/net/torvald/terrarum/modulebasegame/Ingame.kt @@ -568,15 +568,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { ) } - private fun filterVisibleActors() { visibleActorsRenderBehind = actorsRenderBehind.filter { it.inScreen() } visibleActorsRenderMiddle = actorsRenderMiddle.filter { it.inScreen() } visibleActorsRenderMidTop = actorsRenderMidTop.filter { it.inScreen() } visibleActorsRenderFront = actorsRenderFront.filter { it.inScreen() } visibleActorsRenderOverlay=actorsRenderOverlay.filter { it.inScreen() } - - //printdbg(this, "total visible actors: ${visibleActorsRenderMiddle.size}") } private fun repossessActor() { diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index 565a366e5..7394bd803 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -66,6 +66,13 @@ object IngameRenderer : Disposable { AppLoader.disposableSingletonsPool.add(this) } + var renderingActorsCount = 0 + private set + var renderingUIsCount = 0 + private set + /*var renderingParticleCount = 0 + private set*/ + operator fun invoke( gamePaused: Boolean, world: GameWorldExtension, @@ -78,6 +85,14 @@ object IngameRenderer : Disposable { player: ActorWithBody? = null, uisToDraw: ArrayList? = null ) { + renderingActorsCount = (actorsRenderBehind?.size ?: 0) + + (actorsRenderMiddle?.size ?: 0) + + (actorsRenderMidTop?.size ?: 0) + + (actorsRenderFront?.size ?: 0) + + (actorsRenderOverlay?.size ?: 0) + //renderingParticleCount = particlesContainer?.size ?: 0 + renderingUIsCount = uisToDraw?.size ?: 0 + if (uisToDraw != null) { uiListToDraw = uisToDraw diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 2c64d8cf8..40e4644e3 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -4,6 +4,7 @@ import net.torvald.terrarum.IngameInstance import net.torvald.terrarum.Point2i import net.torvald.terrarum.Terrarum import net.torvald.terrarum.blockproperties.Block +import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.gameactors.ActorWBMovable import net.torvald.terrarum.gameworld.GameWorld @@ -45,10 +46,26 @@ open class FixtureBase(blockBox0: BlockBox, val blockBoxProps: BlockBoxProps = B // posY: bottom of the blockBox // using the actor's hitbox - // TODO: obviously check for collision - for (x in posX until posX + blockBox.width) { - for (y in posY until posY + blockBox.height) { + // check for existing blocks (and fixtures) + var hasCollision = false + checkForCollision@ + for (y in posY until posY + blockBox.height) { + for (x in posX until posX + blockBox.width) { + val tile = world.getTileFromTerrain(x, y) + if (BlockCodex[tile].isSolid || tile in Block.actorblocks) { + hasCollision = true + break@checkForCollision + } + } + } + + if (hasCollision) return false + + + // fill the area with the filler blocks + for (y in posY until posY + blockBox.height) { + for (x in posX until posX + blockBox.width) { if (blockBox.collisionType == BlockBox.ALLOW_MOVE_DOWN) { // if the collision type is allow_move_down, only the top surface tile should be "the platform" // lower part must not have such property (think of the table!) @@ -72,7 +89,7 @@ open class FixtureBase(blockBox0: BlockBox, val blockBoxProps: BlockBoxProps = B Terrarum.ingame!!.addNewActor(this) - return true // TODO for the tests' sake, just get fucking spawned + return true } diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/TikiTorchTester.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/TikiTorchTester.kt index b0d7c39f2..372db0295 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/TikiTorchTester.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/TikiTorchTester.kt @@ -32,8 +32,6 @@ class TikiTorchTester(originalID: ItemID) : GameItem(originalID) { override fun startPrimaryUse(delta: Float): Boolean { val torch = FixtureTikiTorch() - //println("aroisetn") - return torch.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - torch.blockBox.height + 1) // return true when placed, false when cannot be placed } diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index 2308fd24d..c060a7e9d 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -10,6 +10,7 @@ import net.torvald.terrarum.Terrarum.mouseTileY import net.torvald.terrarum.controller.TerrarumController import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.modulebasegame.Ingame +import net.torvald.terrarum.modulebasegame.IngameRenderer import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory import net.torvald.terrarum.worlddrawer.CreateTileAtlas @@ -240,6 +241,9 @@ class BasicDebugInfoWindow : UICanvas() { Terrarum.fontSmallNumbers.draw(batch, "${ccM}Particles $ccG${(ingame as Ingame).particlesActive}", (2 + 41 * 8).toFloat(), Terrarum.HEIGHT - 10f) } + + Terrarum.fontSmallNumbers.draw(batch, "${ccY}Actors rendering $ccG${IngameRenderer.renderingActorsCount}", + 2f, Terrarum.HEIGHT - 18f) } /** diff --git a/work_files/graphics/items/dye64.psd b/work_files/graphics/items/dye64.psd index 24bbe887a..8461e4b71 100644 --- a/work_files/graphics/items/dye64.psd +++ b/work_files/graphics/items/dye64.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2b52e9142d2c8a67c889d591e9e4649217baf7a521615b72544f5f0907e04953 -size 164210 +oid sha256:0eab972cdfd3a916bc373ae8e406f4ed1eafc86c2155f060553e77241ecacefc +size 164962