mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-08 12:51:51 +09:00
tfw a jank idea seemingly fixes the long-winded platform bug
This commit is contained in:
@@ -344,6 +344,8 @@ open class ActorWithBody : Actor {
|
||||
internal var walledTop = false // UNUSED; only for BasicDebugInfoWindow
|
||||
internal var walledBottom = false // UNUSED; only for BasicDebugInfoWindow
|
||||
internal var colliding = false
|
||||
@Transient internal var feetTiles = Array<BlockProp?>(160) { null }
|
||||
@Transient internal var bodyTiles = Array<BlockProp?>(2400) { null }
|
||||
|
||||
var isWalkingH = false
|
||||
var isWalkingV = false
|
||||
@@ -528,6 +530,22 @@ open class ActorWithBody : Actor {
|
||||
walledTop = isWalled(hitbox, COLLIDING_TOP)
|
||||
walledBottom = isWalled(hitbox, COLLIDING_BOTTOM)
|
||||
colliding = isColliding(hitbox)
|
||||
var ptrFeet = 0
|
||||
var ptrBody = 0
|
||||
forEachFeetTile {
|
||||
if (ptrFeet < feetTiles.size) {
|
||||
feetTiles[ptrFeet] = it
|
||||
ptrFeet += 1
|
||||
}
|
||||
}
|
||||
forEachOccupyingTile {
|
||||
if (ptrBody < bodyTiles.size) {
|
||||
bodyTiles[ptrBody] = it
|
||||
ptrBody += 1
|
||||
}
|
||||
}
|
||||
feetTiles.fill(null, ptrFeet)
|
||||
bodyTiles.fill(null, ptrBody)
|
||||
if (isNoCollideWorld) {
|
||||
walledLeft = false
|
||||
walledRight = false
|
||||
@@ -965,6 +983,9 @@ open class ActorWithBody : Actor {
|
||||
|
||||
|
||||
// grounded = true
|
||||
|
||||
// another platform-related hacks
|
||||
if (this is ActorHumanoid) downDownVirtually = false
|
||||
}// end of collision not detected
|
||||
|
||||
|
||||
@@ -1285,26 +1306,26 @@ open class ActorWithBody : Actor {
|
||||
*
|
||||
* Very straightforward for the actual solid tiles, not so much for the platforms
|
||||
*/
|
||||
private fun shouldICollideWithThis(tile: ItemID) =
|
||||
protected fun shouldICollideWithThis(tile: ItemID) =
|
||||
// regular solid block
|
||||
(BlockCodex[tile].isSolid)
|
||||
|
||||
// the location and size of the platform in world coord
|
||||
protected var platformToIgnore: Hitbox? = null
|
||||
/*protected var platformToIgnore: Hitbox? = null
|
||||
|
||||
private fun standingOnIgnoredPlatform(): Boolean = platformToIgnore.let {
|
||||
return if (it != null)
|
||||
hitbox.startX >= it.startX && hitbox.endX < it.endX - PHYS_EPSILON_DIST &&
|
||||
it.startY <= hitbox.endY && hitbox.endY < it.endY - PHYS_EPSILON_DIST
|
||||
else false
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* If this tile should be treated as "collidable"
|
||||
*
|
||||
* Just like "shouldICollideWithThis" but it's intended to work with feet tiles
|
||||
*/
|
||||
private fun shouldICollideWithThisFeet(tile: ItemID) =
|
||||
protected fun shouldICollideWithThisFeet(tile: ItemID) =
|
||||
// regular solid block
|
||||
(BlockCodex[tile].isSolid) ||
|
||||
// or platforms that are not on the "ignored list" (the list is updated on the update())
|
||||
@@ -1313,8 +1334,8 @@ open class ActorWithBody : Actor {
|
||||
// platforms, moving downward AND not "going down"
|
||||
(this is ActorHumanoid && BlockCodex[tile].isPlatform &&
|
||||
externalV.y + (controllerV?.y ?: 0.0) >= 0.0 &&
|
||||
!this.isDownDown && this.axisY <= 0f) ||
|
||||
// platforms, moving downward
|
||||
!downDownVirtually && !this.isDownDown && this.axisY <= 0f) ||
|
||||
// platforms, moving downward, for the case of NOT ActorHumanoid
|
||||
(this !is ActorHumanoid && BlockCodex[tile].isPlatform &&
|
||||
externalV.y + (controllerV?.y ?: 0.0) >= 0.0)
|
||||
// TODO: as for the platform, only apply it when it's a feet tile
|
||||
@@ -1548,7 +1569,7 @@ open class ActorWithBody : Actor {
|
||||
/**
|
||||
* Get highest tile density from occupying tiles, fluid only
|
||||
*/
|
||||
private inline val tileDensityFluid: Int
|
||||
/*private inline val tileDensityFluid: Int
|
||||
get() {
|
||||
var density = 0
|
||||
forEachOccupyingFluid {
|
||||
@@ -1559,13 +1580,13 @@ open class ActorWithBody : Actor {
|
||||
}
|
||||
|
||||
return density
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Get highest density (specific gravity) value from tiles that the body occupies.
|
||||
* @return
|
||||
*/
|
||||
private inline val tileDensity: Int
|
||||
/*private inline val tileDensity: Int
|
||||
get() {
|
||||
var density = 0
|
||||
forEachOccupyingTile {
|
||||
@@ -1576,7 +1597,7 @@ open class ActorWithBody : Actor {
|
||||
}
|
||||
|
||||
return density
|
||||
}
|
||||
}*/
|
||||
|
||||
private fun clampHitbox() {
|
||||
if (world == null) return
|
||||
|
||||
@@ -179,6 +179,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
|
||||
var isUpDown = false; protected set
|
||||
var isDownDown = false; protected set
|
||||
var downDownVirtually = false; internal set
|
||||
var isLeftDown = false; protected set
|
||||
var isRightDown = false; protected set
|
||||
var isJumpDown = false; protected set
|
||||
@@ -220,7 +221,8 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
|
||||
if (isNoClip) {
|
||||
//grounded = true
|
||||
platformToIgnore = null
|
||||
// platformToIgnore = null
|
||||
downDownVirtually = false
|
||||
}
|
||||
|
||||
// reset control box of AI
|
||||
@@ -258,8 +260,8 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
val gamepad = App.gamepad
|
||||
|
||||
if (gamepad != null) {
|
||||
axisX = gamepad.getAxis(App.getConfigInt("control_gamepad_axislx"))
|
||||
axisY = gamepad.getAxis(App.getConfigInt("control_gamepad_axisly"))
|
||||
axisX = gamepad.getAxis(App.getConfigInt("control_gamepad_axislx"))
|
||||
axisY = gamepad.getAxis(App.getConfigInt("control_gamepad_axisly"))
|
||||
axisRX = gamepad.getAxis(App.getConfigInt("control_gamepad_axisrx"))
|
||||
axisRY = gamepad.getAxis(App.getConfigInt("control_gamepad_axisry"))
|
||||
|
||||
@@ -285,6 +287,18 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
isLeftDown = axisX < 0f
|
||||
isRightDown = axisX > 0f
|
||||
}
|
||||
|
||||
// platform-related hacks
|
||||
// allow latching down downDownVirtually only when standing on a platform AND not jumping upwards
|
||||
val occupyingTileHasPlatform = bodyTiles.filterNotNull().any { it.isPlatform }
|
||||
val feetTileIsAllPlatform = feetTiles.filterNotNull().all { it.isPlatform }
|
||||
if (isDownDown && feetTileIsAllPlatform && (controllerV?.y ?: 0.0) >= 0.0 ||
|
||||
occupyingTileHasPlatform && !feetTileIsAllPlatform) { // FIXME this does not account for reverse gravity
|
||||
downDownVirtually = true
|
||||
}
|
||||
if (downDownVirtually && !occupyingTileHasPlatform && !feetTileIsAllPlatform) {
|
||||
downDownVirtually = false
|
||||
}
|
||||
}
|
||||
|
||||
private inline val hasController: Boolean
|
||||
@@ -525,7 +539,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
|
||||
|
||||
// determine a platform to ignore
|
||||
world?.let { world ->
|
||||
/*world?.let { world ->
|
||||
var hasPlatformOnTheFeet = false
|
||||
forEachFeetTile { if (it?.isPlatform == true) hasPlatformOnTheFeet = true }
|
||||
|
||||
@@ -548,7 +562,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private fun applyAccel(x: Int): Double {
|
||||
@@ -573,7 +587,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
private fun walkVStop() {
|
||||
walkCounterY = 0
|
||||
isWalkingV = false
|
||||
platformToIgnore = null
|
||||
// platformToIgnore = null
|
||||
}
|
||||
|
||||
private fun getJumpAcc(pwr: Double, timedJumpCharge: Double): Double {
|
||||
|
||||
@@ -191,8 +191,8 @@ class BasicDebugInfoWindow : UICanvas() {
|
||||
|
||||
if (player != null) {
|
||||
printLineColumn(batch, 2, 6, "Mass $ccG${player.mass}")
|
||||
|
||||
printLineColumn(batch, 2, 7, "noClip $ccG${player.isNoClip}")
|
||||
printLineColumn(batch, 2, 8, "${0x1F.toChar()}DownVirt $ccG${player.downDownVirtually}")
|
||||
}
|
||||
|
||||
/*drawHistogram(batch, LightmapRenderer.histogram,
|
||||
|
||||
Reference in New Issue
Block a user