mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
av fuck
This commit is contained in:
@@ -23,6 +23,8 @@ class Float16() {
|
|||||||
bits = Float16.fromFloat(fval)
|
bits = Float16.fromFloat(fval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// operators are stripped: you don't calculate from FP16; this is only for storing values //
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun toFloat(hbits: Short): Float {
|
fun toFloat(hbits: Short): Float {
|
||||||
val hbits = hbits.toInt().and(0xFFFF)
|
val hbits = hbits.toInt().and(0xFFFF)
|
||||||
|
|||||||
@@ -520,14 +520,14 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
if (moveDelta.y > 0.0) {
|
if (moveDelta.y > 0.0) {
|
||||||
if (isTouchingSide(hitbox, COLLIDING_TOP)) { // hit the ceiling
|
if (isTouchingSide(hitbox, COLLIDING_TOP)) { // hit the ceiling
|
||||||
hitAndReflectY() //hitAndForciblyReflectY()
|
hitAndReflectY() //hitAndForciblyReflectY()
|
||||||
//grounded = false
|
grounded = false
|
||||||
}
|
}
|
||||||
else if (isTouchingSide(hitbox, COLLIDING_BOTTOM)) { // actor hit something on its bottom
|
else if (isTouchingSide(hitbox, COLLIDING_BOTTOM)) { // actor hit something on its bottom
|
||||||
hitAndReflectY()
|
hitAndReflectY()
|
||||||
grounded = true
|
grounded = true
|
||||||
}
|
}
|
||||||
else { // the actor is not grounded at all
|
else { // the actor is not grounded at all
|
||||||
//grounded = false
|
grounded = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// or was moving upward?
|
// or was moving upward?
|
||||||
@@ -593,13 +593,15 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
}
|
}
|
||||||
fun debug3(wut: Any?) {
|
fun debug3(wut: Any?) {
|
||||||
// vvvvv set it true to make debug print work
|
// vvvvv set it true to make debug print work
|
||||||
if (false) println(wut)
|
if (true) println(wut)
|
||||||
}
|
}
|
||||||
fun debug4(wut: Any?) {
|
fun debug4(wut: Any?) {
|
||||||
// vvvvv set it true to make debug print work
|
// vvvvv set it true to make debug print work
|
||||||
if (false) println(wut)
|
if (true) println(wut)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//val moveDelta = externalForce + controllerMoveDelta
|
||||||
|
|
||||||
// I kinda need these notes when I'm not caffeinated
|
// I kinda need these notes when I'm not caffeinated
|
||||||
//
|
//
|
||||||
// First of all: Rules
|
// First of all: Rules
|
||||||
@@ -617,7 +619,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
if (percentage < 0.0 || percentage > 1.0)
|
if (percentage < 0.0 || percentage > 1.0)
|
||||||
throw IllegalArgumentException("$percentage")
|
throw IllegalArgumentException("$percentage")
|
||||||
|
|
||||||
return externalForce * percentage
|
return externalForce * percentage//externalForce * percentage
|
||||||
}
|
}
|
||||||
fun getControllerXDelta(percentage: Double): Vector2 {
|
fun getControllerXDelta(percentage: Double): Vector2 {
|
||||||
if (percentage < 0.0 || percentage > 1.0)
|
if (percentage < 0.0 || percentage > 1.0)
|
||||||
@@ -634,12 +636,17 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
debug1("########################################")
|
||||||
|
debug1("hitbox: $hitbox")
|
||||||
|
|
||||||
val simulationHitbox = hitbox.clone()
|
val simulationHitbox = hitbox.clone()
|
||||||
|
|
||||||
if (externalForce.isZero) {
|
if (externalForce.isZero) {
|
||||||
debug1("externalForce is zero")
|
debug1("externalForce is zero")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
debug1("externalForce = $externalForce, controller = $controllerMoveDelta")
|
||||||
|
|
||||||
var ccdTick: Int = ccdSteps // 0..15: collision detected, 16: not
|
var ccdTick: Int = ccdSteps // 0..15: collision detected, 16: not
|
||||||
|
|
||||||
// do CCD first
|
// do CCD first
|
||||||
@@ -663,12 +670,12 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
var collisionNotFound = false
|
var collisionNotFound = false
|
||||||
if (ccdTick == ccdSteps) {
|
if (ccdTick == ccdSteps) {
|
||||||
hitbox.translate(externalForce)
|
hitbox.translate(externalForce)
|
||||||
debug2("no collision; endX = ${hitbox.endPointX}")
|
debug2("no collision; endY = ${hitbox.endPointY}")
|
||||||
collisionNotFound = true
|
collisionNotFound = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!collisionNotFound) {
|
if (!collisionNotFound) {
|
||||||
debug2("embedding before: ${simulationHitbox.endPointX}")
|
debug2("embedding before: ${simulationHitbox.endPointY}")
|
||||||
|
|
||||||
// find no-collision point using binary search
|
// find no-collision point using binary search
|
||||||
// trust me, X- and Y-axis must move simultaneously.
|
// trust me, X- and Y-axis must move simultaneously.
|
||||||
@@ -699,11 +706,26 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
debug2("binarySearch embedding: ${simulationHitbox.endPointY}")
|
debug2("binarySearch embedding: ${simulationHitbox.endPointY}")
|
||||||
|
|
||||||
|
|
||||||
// force set grounded-ness
|
// apply Normal Force
|
||||||
grounded = true
|
// next step (resolve controllerMoveDelta) requires this to be pre-handled
|
||||||
// reset walkY
|
if (isTouchingSide(simulationHitbox, COLLIDING_BOTTOM)) {
|
||||||
walkY = 0.0
|
if (gravitation.y > 0.0) grounded = true
|
||||||
debug1("!! grounded ${Random().nextInt(1000)}!!")
|
// reset walkY
|
||||||
|
walkY *= elasticity
|
||||||
|
debug1("!! grounded ${Random().nextInt(1000)}!!")
|
||||||
|
}
|
||||||
|
else if (isTouchingSide(simulationHitbox, COLLIDING_TOP)) {
|
||||||
|
if (gravitation.y < 0.0) grounded = true
|
||||||
|
// reset walkY
|
||||||
|
walkY *= elasticity
|
||||||
|
debug1("!! headbutt ${Random().nextInt(1000)}!!")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isTouchingSide(simulationHitbox, COLLIDING_LR)) {
|
||||||
|
// reset walkX
|
||||||
|
walkX *= elasticity
|
||||||
|
debug1("!! tackle ${Random().nextInt(1000)}!!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -715,6 +737,8 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
if (controllerMoveDelta != null) {
|
if (controllerMoveDelta != null) {
|
||||||
debug3("== ControllerMoveDelta ==")
|
debug3("== ControllerMoveDelta ==")
|
||||||
|
|
||||||
|
println("simulationHitbox = $simulationHitbox")
|
||||||
|
|
||||||
// X-Axis
|
// X-Axis
|
||||||
val simulationHitboxX = simulationHitbox.clone()
|
val simulationHitboxX = simulationHitbox.clone()
|
||||||
if (controllerMoveDelta!!.x != 0.0) {
|
if (controllerMoveDelta!!.x != 0.0) {
|
||||||
@@ -731,17 +755,20 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
simulationHitboxX.translate(getControllerXDelta(bmid))
|
simulationHitboxX.translate(getControllerXDelta(bmid))
|
||||||
|
|
||||||
// set new mid
|
// set new mid
|
||||||
|
// TODO LR-touching or colliding?
|
||||||
if (isTouchingSide(simulationHitboxX, COLLIDING_LEFT) || isTouchingSide(simulationHitboxX, COLLIDING_RIGHT)) {
|
if (isTouchingSide(simulationHitboxX, COLLIDING_LEFT) || isTouchingSide(simulationHitboxX, COLLIDING_RIGHT)) {
|
||||||
debug3("bmid = $bmid, new endX: ${simulationHitboxX.endPointX}, going back")
|
debug3("x bmid = $bmid, new endX: ${simulationHitboxX.endPointX}, going back")
|
||||||
high = bmid
|
high = bmid
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
debug3("bmid = $bmid, new endX: ${simulationHitboxX.endPointX}, going forth")
|
debug3("x bmid = $bmid, new endX: ${simulationHitboxX.endPointX}, going forth")
|
||||||
low = bmid
|
low = bmid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME FIXME edge-to-edge collision
|
||||||
|
|
||||||
// FIXME ceiling hit by jumping: mul controllerY by elasticity
|
// FIXME ceiling hit by jumping: mul controllerY by elasticity
|
||||||
// FIXME jitter on hitting body against a wall
|
// FIXME jitter on hitting body against a wall
|
||||||
// FIXME balls jitter af and stuck on a wall
|
// FIXME balls jitter af and stuck on a wall
|
||||||
@@ -762,12 +789,13 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
simulationHitboxY.translate(getControllerYDelta(bmid))
|
simulationHitboxY.translate(getControllerYDelta(bmid))
|
||||||
|
|
||||||
// set new mid
|
// set new mid
|
||||||
|
// TODO UD-touching or colliding?
|
||||||
if (isTouchingSide(simulationHitboxY, COLLIDING_TOP) || isTouchingSide(simulationHitboxY, COLLIDING_BOTTOM)) {
|
if (isTouchingSide(simulationHitboxY, COLLIDING_TOP) || isTouchingSide(simulationHitboxY, COLLIDING_BOTTOM)) {
|
||||||
debug3("bmid = $bmid, new endY: ${simulationHitboxY.endPointY}, going back")
|
debug3("y bmid = $bmid, new endY: ${simulationHitboxY.endPointY}, going back")
|
||||||
high = bmid
|
high = bmid
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
debug3("bmid = $bmid, new endY: ${simulationHitboxY.endPointY}, going forth")
|
debug3("y bmid = $bmid, new endY: ${simulationHitboxY.endPointY}, going forth")
|
||||||
low = bmid
|
low = bmid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -824,7 +852,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
debug2("externalForce: $externalForce, displacement: ${simulationHitbox - hitbox}")
|
debug2("final controller: $controllerMoveDelta, displacement: ${simulationHitbox - hitbox}")
|
||||||
|
|
||||||
|
|
||||||
hitbox.reassign(simulationHitbox)
|
hitbox.reassign(simulationHitbox)
|
||||||
@@ -860,15 +888,15 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
externalForce.x *= -elasticity
|
externalForce.x *= -elasticity
|
||||||
//if (this is Controllable) walkX *= -elasticity // commented; should be managed by displaceHitbox()
|
if (this is Controllable) walkX *= -elasticity // commented; should be managed by displaceHitbox()
|
||||||
|
|
||||||
//println("$this\t${externalForce.x}")
|
//println("$this\t${externalForce.x}")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hitAndReflectY() {
|
private fun hitAndReflectY() {
|
||||||
//println("** reflY **")
|
println("** reflY **")
|
||||||
externalForce.y *= -elasticity
|
externalForce.y *= -elasticity
|
||||||
//if (this is Controllable) walkY *= -elasticity // commented; should be managed by displaceHitbox()
|
if (this is Controllable) walkY *= -elasticity // commented; should be managed by displaceHitbox()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transient private val CEILING_HIT_ELASTICITY = 0.3
|
@Transient private val CEILING_HIT_ELASTICITY = 0.3
|
||||||
@@ -898,7 +926,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
//externalForce.y = 0.0
|
//externalForce.y = 0.0
|
||||||
|
|
||||||
|
|
||||||
//hitbox.translatePosY(0.5) // TODO why we need it?
|
//hitbox.translatePosY(0.5) // TODO why de we need it?
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw Error("Check this out bitch (moveDelta.y = ${moveDelta.y})")
|
throw Error("Check this out bitch (moveDelta.y = ${moveDelta.y})")
|
||||||
@@ -972,6 +1000,18 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
y1 = hitbox.posY
|
y1 = hitbox.posY
|
||||||
y2 = hitbox.endPointY - A_PIXEL
|
y2 = hitbox.endPointY - A_PIXEL
|
||||||
}
|
}
|
||||||
|
else if (option == COLLIDING_ALLSIDE) {
|
||||||
|
x1 = hitbox.posX - A_PIXEL
|
||||||
|
x2 = hitbox.endPointX
|
||||||
|
y1 = hitbox.posY - A_PIXEL
|
||||||
|
y2 = hitbox.endPointY
|
||||||
|
}
|
||||||
|
else if (option == COLLIDING_LR) {
|
||||||
|
x1 = hitbox.posX - A_PIXEL
|
||||||
|
x2 = hitbox.endPointX
|
||||||
|
y1 = hitbox.posY
|
||||||
|
y2 = hitbox.endPointY - A_PIXEL
|
||||||
|
}
|
||||||
else throw IllegalArgumentException()
|
else throw IllegalArgumentException()
|
||||||
|
|
||||||
val txStart = x1.div(TILE_SIZE).floorInt()
|
val txStart = x1.div(TILE_SIZE).floorInt()
|
||||||
|
|||||||
@@ -124,13 +124,9 @@ class BasicDebugInfoWindow : UICanvas {
|
|||||||
rawB.toString() + ")"
|
rawB.toString() + ")"
|
||||||
printLine(g, 8, "light@cursor $ccG$lightVal")
|
printLine(g, 8, "light@cursor $ccG$lightVal")
|
||||||
|
|
||||||
val tileNo: String
|
val tileNum = Terrarum.ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
|
||||||
val tileNumRaw = Terrarum.ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
|
|
||||||
val tilenum = tileNumRaw / PairedMapLayer.RANGE
|
|
||||||
val tiledmg = tileNumRaw % PairedMapLayer.RANGE
|
|
||||||
tileNo = if (tileNumRaw == -1) "—" else "$tilenum:$tiledmg"
|
|
||||||
|
|
||||||
printLine(g, 9, "tile@cursor $ccG$tileNo ($mtX, $mtY)")
|
printLine(g, 9, "tile@cursor $ccG$tileNum ($mtX, $mtY)")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Second column
|
* Second column
|
||||||
|
|||||||
Reference in New Issue
Block a user