mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 13:21:51 +09:00
actorblock only renders when F3 is on
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -108,5 +108,5 @@ class BlockProp {
|
||||
val extra = Codex()
|
||||
|
||||
val isActorBlock: Boolean
|
||||
get() = nameKey.contains("ACTORBLOCK")
|
||||
get() = tags.contains("ACTORBLOCK")
|
||||
}
|
||||
@@ -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<String>) {
|
||||
if (args.size == 2) {
|
||||
@@ -15,7 +15,7 @@ object CommandDict {
|
||||
"ActorsList",
|
||||
"Authenticator",
|
||||
"AVTracker",
|
||||
"Batch",
|
||||
"Call",
|
||||
"Echo",
|
||||
"EchoConsole",
|
||||
"EchoError",
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user