mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
actorwbmovable: alias vars are latched to its update; sprite that's out of screen won't render
This commit is contained in:
@@ -330,16 +330,17 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
hitbox.translate(dx, dy)
|
||||
}
|
||||
|
||||
inline val centrePosVector: Vector2
|
||||
get() = Vector2(hitbox.centeredX, hitbox.centeredY)
|
||||
inline val centrePosPoint: Point2d
|
||||
get() = Point2d(hitbox.centeredX, hitbox.centeredY)
|
||||
inline val feetPosVector: Vector2
|
||||
get() = Vector2(hitbox.centeredX, hitbox.endY)
|
||||
inline val feetPosPoint: Point2d
|
||||
get() = Point2d(hitbox.centeredX, hitbox.endY)
|
||||
inline val feetPosTile: IntArray
|
||||
get() = intArrayOf(hIntTilewiseHitbox.centeredX.floorInt(), hIntTilewiseHitbox.endY.floorInt())
|
||||
// get() methods are moved to update(), too much stray object being created is definitely not good
|
||||
val centrePosVector: Vector2 = Vector2(0.0,0.0)
|
||||
//get() = Vector2(hitbox.centeredX, hitbox.centeredY)
|
||||
val centrePosPoint: Point2d = Point2d(0.0, 0.0)
|
||||
//get() = Point2d(hitbox.centeredX, hitbox.centeredY)
|
||||
val feetPosVector: Vector2 = Vector2(0.0,0.0)
|
||||
//get() = Vector2(hitbox.centeredX, hitbox.endY)
|
||||
val feetPosPoint: Point2d = Point2d(0.0,0.0)
|
||||
//get() = Point2d(hitbox.centeredX, hitbox.endY)
|
||||
val feetPosTile: Point2i = Point2i(0,0)
|
||||
//get() = Point2i(hIntTilewiseHitbox.centeredX.floorInt(), hIntTilewiseHitbox.endY.floorInt())
|
||||
|
||||
override fun run() = update(AppLoader.UPDATE_RATE.toFloat())
|
||||
|
||||
@@ -435,6 +436,9 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
clampHitbox()
|
||||
}
|
||||
|
||||
|
||||
// update all the other variables //
|
||||
|
||||
// cheap solution for sticking into the wall while Left or Right is held
|
||||
walledLeft = isWalled(hitbox, COLLIDING_LEFT)
|
||||
walledRight = isWalled(hitbox, COLLIDING_RIGHT)
|
||||
@@ -448,6 +452,14 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
walledBottom = false
|
||||
colliding = false
|
||||
}
|
||||
|
||||
centrePosVector.set(hitbox.centeredX, hitbox.centeredY)
|
||||
centrePosPoint.set(hitbox.centeredX, hitbox.centeredY)
|
||||
feetPosVector.set(hitbox.centeredX, hitbox.endY)
|
||||
feetPosPoint.set(hitbox.centeredX, hitbox.endY)
|
||||
feetPosTile.x = hIntTilewiseHitbox.centeredX.floorInt()
|
||||
feetPosTile.y = hIntTilewiseHitbox.endY.floorInt()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1375,28 +1387,33 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
|
||||
val offsetY = sprite.cellHeight * scale - hitbox.height - hitboxTranslateY * scale - 1
|
||||
|
||||
|
||||
if (WorldCamera.xCentre > leftsidePadding && centrePosPoint.x <= rightsidePadding) {
|
||||
// camera center neg, actor center pos
|
||||
sprite.render(batch,
|
||||
(hitbox.startX - offsetX).toFloat() + world!!.width * TILE_SIZE,
|
||||
(hitbox.startY - offsetY).toFloat(),
|
||||
(scale).toFloat()
|
||||
)
|
||||
}
|
||||
else if (WorldCamera.xCentre < rightsidePadding && centrePosPoint.x >= leftsidePadding) {
|
||||
// camera center pos, actor center neg
|
||||
sprite.render(batch,
|
||||
(hitbox.startX - offsetX).toFloat() - world!!.width * TILE_SIZE,
|
||||
(hitbox.startY - offsetY).toFloat(),
|
||||
(scale).toFloat()
|
||||
)
|
||||
}
|
||||
else {
|
||||
sprite.render(batch,
|
||||
(hitbox.startX - offsetX).toFloat(),
|
||||
(hitbox.startY - offsetY).toFloat(),
|
||||
(scale).toFloat()
|
||||
)
|
||||
// FIXME test me: this extra IF statement is supposed to not draw actors that's outside of the camera.
|
||||
// basic code without offsetX/Y DOES work, but obviously offsets are not tested.
|
||||
if (hitbox.startX - offsetX in WorldCamera.x - hitbox.width - offsetX..WorldCamera.x + WorldCamera.width + offsetX &&
|
||||
hitbox.endY + offsetY in WorldCamera.y - hitbox.height - offsetY..WorldCamera.y + WorldCamera.height + offsetY) {
|
||||
if (WorldCamera.xCentre > leftsidePadding && centrePosPoint.x <= rightsidePadding) {
|
||||
// camera center neg, actor center pos
|
||||
sprite.render(batch,
|
||||
(hitbox.startX - offsetX).toFloat() + world!!.width * TILE_SIZE,
|
||||
(hitbox.startY - offsetY).toFloat(),
|
||||
(scale).toFloat()
|
||||
)
|
||||
}
|
||||
else if (WorldCamera.xCentre < rightsidePadding && centrePosPoint.x >= leftsidePadding) {
|
||||
// camera center pos, actor center neg
|
||||
sprite.render(batch,
|
||||
(hitbox.startX - offsetX).toFloat() - world!!.width * TILE_SIZE,
|
||||
(hitbox.startY - offsetY).toFloat(),
|
||||
(scale).toFloat()
|
||||
)
|
||||
}
|
||||
else {
|
||||
sprite.render(batch,
|
||||
(hitbox.startX - offsetX).toFloat(),
|
||||
(hitbox.startY - offsetY).toFloat(),
|
||||
(scale).toFloat()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.InputAdapter
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
@@ -157,15 +158,46 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
internal fun blockPosToRefID(x: Int, y: Int) = 1048576 + (y * gameWorld.width + x)
|
||||
|
||||
private var _testMarkerDrawCalls = 0L
|
||||
|
||||
private fun generateNewBlockMarkerVisible(x: Int, y: Int) = object : ActorWithBody(Actor.RenderOrder.OVERLAY) {
|
||||
override var referenceID: ActorID? = blockPosToRefID(x, y) // custom refID
|
||||
override val hitbox = Hitbox(x * 16.0, y * 16.0, 16.0, 16.0)
|
||||
|
||||
override fun drawBody(batch: SpriteBatch) {
|
||||
batch.color = blockMarkerColour
|
||||
batch.draw(blockMarkings.get(2,0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
|
||||
batch.draw(blockMarkings.get(2,0), hitbox.startX.toFloat() + world.width * TILE_SIZE, hitbox.startY.toFloat())
|
||||
batch.draw(blockMarkings.get(2,0), hitbox.startX.toFloat() - world.width * TILE_SIZE, hitbox.startY.toFloat())
|
||||
drawSpriteInGoodPosition(blockMarkings.get(2,0), batch)
|
||||
}
|
||||
|
||||
private fun drawSpriteInGoodPosition(sprite: TextureRegion, batch: SpriteBatch) {
|
||||
val leftsidePadding = world.width.times(TILE_SIZE) - WorldCamera.width.ushr(1)
|
||||
val rightsidePadding = WorldCamera.width.ushr(1)
|
||||
|
||||
if (hitbox.startX in WorldCamera.x - hitbox.width..WorldCamera.x + WorldCamera.width.toDouble() &&
|
||||
hitbox.startY in WorldCamera.y - hitbox.height..WorldCamera.y + WorldCamera.height.toDouble()) {
|
||||
if (WorldCamera.xCentre > leftsidePadding && hitbox.centeredX <= rightsidePadding) {
|
||||
// camera center neg, actor center pos
|
||||
batch.draw(sprite,
|
||||
hitbox.startX.toFloat() + world.width * TILE_SIZE,
|
||||
hitbox.startY.toFloat()
|
||||
)
|
||||
}
|
||||
else if (WorldCamera.xCentre < rightsidePadding && hitbox.centeredY >= leftsidePadding) {
|
||||
// camera center pos, actor center neg
|
||||
batch.draw(sprite,
|
||||
hitbox.startX.toFloat() - world.width * TILE_SIZE,
|
||||
hitbox.startY.toFloat()
|
||||
)
|
||||
}
|
||||
else {
|
||||
batch.draw(sprite,
|
||||
hitbox.startX.toFloat(),
|
||||
hitbox.startY.toFloat()
|
||||
)
|
||||
}
|
||||
|
||||
_testMarkerDrawCalls += 1
|
||||
}
|
||||
}
|
||||
|
||||
override fun drawGlow(batch: SpriteBatch) { }
|
||||
@@ -342,7 +374,11 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
private fun renderGame() {
|
||||
_testMarkerDrawCalls = 0L
|
||||
|
||||
IngameRenderer.invoke(world as GameWorldExtension, actorsRenderOverlay = if (showSelection) actorsRenderOverlay + essentialOverlays else essentialOverlays, uisToDraw = uiContainer)
|
||||
|
||||
AppLoader.setDebugTime("Test.MarkerDrawCalls", _testMarkerDrawCalls)
|
||||
}
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
|
||||
@@ -75,7 +75,7 @@ open class ProjectileSimple(
|
||||
lifetimeCounter += delta
|
||||
if (walledTop || walledBottom || walledRight || walledLeft || lifetimeCounter >= lifetimeMax ||
|
||||
// stuck check
|
||||
BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain(feetPosTile[0], feetPosTile[1]) ?: Block.STONE].isSolid
|
||||
BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain(feetPosTile.x, feetPosTile.y) ?: Block.STONE].isSolid
|
||||
) {
|
||||
flagDespawn()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user