Physics stuff Float -> Double

Former-commit-id: 54ccee75769691aa6aaa2416767bd15270f63347
Former-commit-id: 61e892434f48adf11e3ca49b60928a930fd5cde9
This commit is contained in:
Song Minjae
2016-05-01 00:23:36 +09:00
parent fba0b80d24
commit c9f5fde3be
26 changed files with 225 additions and 291 deletions

View File

@@ -3,11 +3,11 @@ package net.torvald.point
/**
* Created by minjaesong on 16-01-15.
*/
class Point2f(x: Float, y: Float) {
class Point2d(x: Double, y: Double) {
var x: Float = 0.toFloat()
var x: Double = 0.toDouble()
private set
var y: Float = 0.toFloat()
var y: Double = 0.toDouble()
private set
init {
@@ -15,7 +15,7 @@ class Point2f(x: Float, y: Float) {
this.y = y
}
operator fun set(x: Float, y: Float) {
operator fun set(x: Double, y: Double) {
this.x = x
this.y = y
}

View File

@@ -101,7 +101,6 @@ constructor() : BasicGameState() {
// new ItemPropCodex() -- This is kotlin object and already initialised.
map = GameMap(8192, 2048)
map.gravitation = 9.8f
MapGenerator.attachMap(map)
MapGenerator.SEED = 0x51621D2
@@ -231,16 +230,16 @@ constructor() : BasicGameState() {
g.font = Terrarum.smallNumbers
g.drawString(
actor.referenceID.toString(),
actor.hitbox.posX,
actor.hitbox.pointedY + 4
actor.hitbox.posX.toFloat(),
actor.hitbox.pointedY.toFloat() + 4
)
if (DEBUG_ARRAY) {
g.color = GameFontBase.codeToCol["g"]
g.drawString(
i.toString(),
actor.hitbox.posX,
actor.hitbox.pointedY + 4 + 10
actor.hitbox.posX.toFloat(),
actor.hitbox.pointedY.toFloat() + 4 + 10
)
}
}
@@ -365,10 +364,10 @@ constructor() : BasicGameState() {
(this and 0xff00).ushr(8).shl(10) or
(this and 0xff0000).ushr(16).shl(20)
fun Float.sqr() = this * this
fun Double.sqr() = this * this
fun Int.sqr() = this * this
private fun distToActorSqr(a: Visible, p: Player): Float =
(a.hitbox.centeredX - p.hitbox.centeredX).sqr() + (a.hitbox.centeredY - p.hitbox.centeredY).sqr()
(a.hitbox.centeredX - p.hitbox.centeredX).sqr().toFloat() + (a.hitbox.centeredY - p.hitbox.centeredY).sqr().toFloat()
private fun Visible.inScreen() = distToActorSqr(this, player) <=
(Terrarum.WIDTH.plus(this.hitbox.width.div(2)).times(1 / Terrarum.game.screenZoom).sqr() +
Terrarum.HEIGHT.plus(this.hitbox.height.div(2)).times(1 / Terrarum.game.screenZoom).sqr())

View File

@@ -47,17 +47,6 @@ open class KVHashMap {
return get(key) as Int?
}
fun getAsFloat(key: String): Float? {
val value = get(key)
if (value is Int)
return value.toFloat()
else if (value is JsonPrimitive)
return value.asFloat
return value as Float?
}
fun getAsDouble(key: String): Double? {
val value = get(key)
@@ -66,7 +55,14 @@ open class KVHashMap {
else if (value is JsonPrimitive)
return value.asDouble
return value as Double?
try {
return value as Double?
}
catch (e: ClassCastException) {
System.err.println("[KVHashMap] ClassCastException for key '$key'")
e.printStackTrace(System.err)
}
return null
}
fun getAsString(key: String): String? {

View File

@@ -287,32 +287,6 @@ constructor(gamename: String) : StateBasedGame(gamename) {
return cfg
}
/**
* Return config from config set. If the config does not exist, default value will be returned.
* @param key
* *
* @return Config from config set or default config if it does not exist.
* *
* @throws NullPointerException if the specified config simply does not exist.
*/
fun getConfigFloat(key: String): Float {
var cfg = 0f
try {
cfg = gameConfig.getAsFloat(key)!!
}
catch (e: NullPointerException) {
try {
cfg = DefaultConfig.fetch().get(key).asFloat
}
catch (e1: NullPointerException) {
e.printStackTrace()
}
}
return cfg
}
/**
* Return config from config set. If the config does not exist, default value will be returned.
* @param key

View File

@@ -20,7 +20,7 @@ internal class SetAV : ConsoleCommand {
echo.execute("${ccW}Set actor value of specific target to desired value.")
echo.execute("${ccW}Usage: ${ccY}setav ${ccG}(id) <av> <val>")
echo.execute("${ccW}blank ID for player")
echo.execute("${ccR}Contaminated (float -> string) ActorValue will crash the game,")
echo.execute("${ccR}Contaminated (double -> string) ActorValue will crash the game,")
echo.execute("${ccR}so make sure it will not happen before you issue the command!")
echo.execute("${ccW}Use ${ccG}__true ${ccW}and ${ccG}__false ${ccW}for boolean value.")
}
@@ -35,7 +35,7 @@ internal class SetAV : ConsoleCommand {
catch (e: NumberFormatException) {
try {
`val` = arg.toFloat() // try for float
`val` = arg.toDouble() // try for double
}
catch (ee: NumberFormatException) {
if (arg.equals("__true", ignoreCase = true)) {

View File

@@ -16,12 +16,12 @@ class SpawnPhysTestBall : ConsoleCommand {
val mouseX = Terrarum.appgc.input.mouseX
val mouseY = Terrarum.appgc.input.mouseY
val elasticity = args[1].toFloat()
val elasticity = args[1].toDouble()
val ball = PhysTestBall()
ball.setPosition(
(mouseX + MapCamera.cameraX).toFloat(),
(mouseY + MapCamera.cameraY).toFloat()
(mouseX + MapCamera.cameraX).toDouble(),
(mouseY + MapCamera.cameraY).toDouble()
)
ball.elasticity = elasticity

View File

@@ -26,7 +26,7 @@ class TeleportPlayer : ConsoleCommand {
return
}
Terrarum.game.player.setPosition(x.toFloat(), y.toFloat())
Terrarum.game.player.setPosition(x.toDouble(), y.toDouble())
}
}

View File

@@ -87,8 +87,8 @@ class ActorInventory() {
return itemList.clone() as Map<Int, Int>
}
fun getTotalWeight(): Float {
var weight = 0f
fun getTotalWeight(): Double {
var weight = 0.0
for (item in itemList.entries) {
weight += ItemPropCodex.getProp(item.key).mass * item.value

View File

@@ -20,8 +20,8 @@ open class ActorWithBody constructor() : Actor(), Visible {
override var actorValue: ActorValue = ActorValue()
var hitboxTranslateX: Float = 0.toFloat()// relative to spritePosX
var hitboxTranslateY: Float = 0.toFloat()// relative to spritePosY
var hitboxTranslateX: Double = 0.toDouble()// relative to spritePosX
var hitboxTranslateY: Double = 0.toDouble()// relative to spritePosY
var baseHitboxW: Int = 0
var baseHitboxH: Int = 0
@@ -31,9 +31,9 @@ open class ActorWithBody constructor() : Actor(), Visible {
* veloY += 3.0
* +3.0 is acceleration. You __accumulate__ acceleration to the velocity.
*/
@Volatile var veloX: Float = 0.toFloat()
@Volatile var veloY: Float = 0.toFloat()
@Transient private val VELO_HARD_LIMIT = 10000f
@Volatile var veloX: Double = 0.0
@Volatile var veloY: Double = 0.0
@Transient private val VELO_HARD_LIMIT = 10000.0
var grounded = false
@@ -55,18 +55,18 @@ open class ActorWithBody constructor() : Actor(), Visible {
/**
* Positions: top-left point
*/
override val hitbox = Hitbox(0f,0f,0f,0f)
@Transient val nextHitbox = Hitbox(0f,0f,0f,0f)
override val hitbox = Hitbox(0.0,0.0,0.0,0.0)
@Transient val nextHitbox = Hitbox(0.0,0.0,0.0,0.0)
/**
* Physical properties.
* Values derived from ActorValue must be @Transient.
*/
@Transient var scale = 1f
@Transient var mass = 2f
@Transient private val MASS_LOWEST = 2f
@Transient var scale = 1.0
@Transient var mass = 2.0
@Transient private val MASS_LOWEST = 2.0
/** Valid range: [0, 1] */
var elasticity = 0f
var elasticity = 0.0
set(value) {
if (value < 0)
throw IllegalArgumentException("[ActorWithBody] Invalid elasticity value: $value; valid elasticity value is [0, 1].")
@@ -77,8 +77,8 @@ open class ActorWithBody constructor() : Actor(), Visible {
else
field = value * ELASTICITY_MAX
}
@Transient private val ELASTICITY_MAX = 0.993f
private var density = 1000f
@Transient private val ELASTICITY_MAX = 0.993
private var density = 1000.0
/**
* Gravitational Constant G. Load from gamemap.
@@ -86,18 +86,18 @@ open class ActorWithBody constructor() : Actor(), Visible {
* s^2 = 1/FPS = 1/60 if FPS is targeted to 60
* meter to pixel : 24/FPS
*/
@Transient private val METER = 24f
@Transient private val METER = 24.0
/**
* [m / s^2] * SI_TO_GAME_ACC -> [px / InternalFrame^2]
*/
@Transient private val SI_TO_GAME_ACC = METER / FastMath.sqr(Terrarum.TARGET_FPS.toFloat())
@Transient private val SI_TO_GAME_ACC = METER / (Terrarum.TARGET_FPS * Terrarum.TARGET_FPS).toDouble()
/**
* [m / s] * SI_TO_GAME_VEL -> [px / InternalFrame]
*/
@Transient private val SI_TO_GAME_VEL = METER / Terrarum.TARGET_FPS
@Transient private var gravitation: Float = 0.toFloat()
@Transient private val DRAG_COEFF = 1f
@Transient private var gravitation: Double = 0.toDouble()
@Transient private val DRAG_COEFF = 1.0
@Transient private val CONTACT_AREA_TOP = 0
@Transient private val CONTACT_AREA_RIGHT = 1
@@ -110,7 +110,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
/**
* A constant to make falling faster so that the game is more playable
*/
@Transient private val G_MUL_PLAYABLE_CONST = 1.4142f
@Transient private val G_MUL_PLAYABLE_CONST = 1.4142
@Transient private val EVENT_MOVE_TOP = 0
@Transient private val EVENT_MOVE_RIGHT = 1
@@ -127,7 +127,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
@Transient private val map: GameMap
@Transient private val MASS_DEFAULT: Float = 60f
@Transient private val MASS_DEFAULT: Double = 60.0
internal val physSleep: Boolean
get() = veloX.abs() < 0.5 && veloY.abs() < 0.5
@@ -138,7 +138,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
@Transient private var posAdjustX = 0
@Transient private var posAdjustY = 0
@Transient private val BASE_FRICTION = 0.3f
@Transient private val BASE_FRICTION = 0.3
init {
map = Terrarum.game.map
@@ -160,8 +160,8 @@ open class ActorWithBody constructor() : Actor(), Visible {
fun setHitboxDimension(w: Int, h: Int, tx: Int, ty: Int) {
baseHitboxH = h
baseHitboxW = w
hitboxTranslateX = tx.toFloat()
hitboxTranslateY = ty.toFloat()
hitboxTranslateX = tx.toDouble()
hitboxTranslateY = ty.toDouble()
}
/**
@@ -170,7 +170,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
* *
* @param y
*/
fun setPosition(x: Float, y: Float) {
fun setPosition(x: Double, y: Double) {
hitbox.set(
x - (baseHitboxW / 2 - hitboxTranslateX) * scale,
y - (baseHitboxH - hitboxTranslateY) * scale,
@@ -185,9 +185,9 @@ open class ActorWithBody constructor() : Actor(), Visible {
}
private fun updatePhysicalInfos() {
scale = actorValue.getAsFloat(AVKey.SCALE) ?: 1f
mass = (actorValue.getAsFloat(AVKey.BASEMASS) ?: MASS_DEFAULT) * FastMath.pow(scale, 3f)
if (elasticity != 0f) elasticity = 0f
scale = actorValue.getAsDouble(AVKey.SCALE) ?: 1.0
mass = (actorValue.getAsDouble(AVKey.BASEMASS) ?: MASS_DEFAULT) * Math.pow(scale, 3.0)
if (elasticity != 0.0) elasticity = 0.0
}
override fun run() = update(Terrarum.appgc, Terrarum.game.DELTA_T)
@@ -278,7 +278,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
* D = Cd (drag coefficient) * 0.5 * rho (density) * V^2 (velocity) * A (area)
*/
val A = scale * scale
val D = DRAG_COEFF * 0.5f * 1.292f * veloY * veloY * A
val D = DRAG_COEFF * 0.5 * 1.292 * veloY * veloY * A
veloY += clampCeil(
(W - D) / mass * SI_TO_GAME_ACC * G_MUL_PLAYABLE_CONST, VELO_HARD_LIMIT)
@@ -289,11 +289,11 @@ open class ActorWithBody constructor() : Actor(), Visible {
val friction = BASE_FRICTION * tileFriction.tileFrictionToMult()
if (veloX < 0) {
veloX += friction
if (veloX > 0) veloX = 0f // compensate overshoot
if (veloX > 0) veloX = 0.0 // compensate overshoot
}
else if (veloX > 0) {
veloX -= friction
if (veloX < 0) veloX = 0f // compensate overshoot
if (veloX < 0) veloX = 0.0 // compensate overshoot
}
}
@@ -302,12 +302,12 @@ open class ActorWithBody constructor() : Actor(), Visible {
if (veloY >= 0) { // check downward
if (isColliding(CONTACT_AREA_BOTTOM)) { // the ground has dug into the body
adjustHitBottom()
veloY = 0f // reset veloY, simulating normal force
veloY = 0.0 // reset veloY, simulating normal force
elasticReflectY()
grounded = true
}
else if (isColliding(CONTACT_AREA_BOTTOM, 0, 1)) { // the actor is standing ON the ground
veloY = 0f // reset veloY, simulating normal force
veloY = 0.0 // reset veloY, simulating normal force
elasticReflectY()
grounded = true
}
@@ -319,11 +319,11 @@ open class ActorWithBody constructor() : Actor(), Visible {
grounded = false
if (isColliding(CONTACT_AREA_TOP)) { // the ceiling has dug into the body
adjustHitTop()
veloY = 0f // reset veloY, simulating normal force
veloY = 0.0 // reset veloY, simulating normal force
elasticReflectY()
}
else if (isColliding(CONTACT_AREA_TOP, 0, -1)) { // the actor is touching the ceiling
veloY = 0f // reset veloY, simulating normal force
veloY = 0.0 // reset veloY, simulating normal force
elasticReflectY() // reflect on ceiling, for reversed gravity
}
else { // the actor is not grounded at all
@@ -335,7 +335,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
private fun adjustHitBottom() {
val newX = nextHitbox.pointedX // look carefully, getPos or getPointed
// int-ify posY of nextHitbox
nextHitbox.setPositionYFromPoint(FastMath.floor(nextHitbox.pointedY).toFloat())
nextHitbox.setPositionYFromPoint(Math.floor(nextHitbox.pointedY).toDouble())
var newYOff = 0 // always positive
@@ -354,7 +354,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
private fun adjustHitTop() {
val newX = nextHitbox.posX
// int-ify posY of nextHitbox
nextHitbox.setPositionY(FastMath.ceil(nextHitbox.posY).toFloat())
nextHitbox.setPositionY(Math.ceil(nextHitbox.posY).toDouble())
var newYOff = 0 // always positive
@@ -376,12 +376,12 @@ open class ActorWithBody constructor() : Actor(), Visible {
if (isColliding(CONTACT_AREA_RIGHT) && !isColliding(CONTACT_AREA_LEFT)) {
// the actor is embedded to the wall
adjustHitRight()
veloX = 0f // reset veloX, simulating normal force
veloX = 0.0 // reset veloX, simulating normal force
elasticReflectX()
}
else if (isColliding(CONTACT_AREA_RIGHT, 2, 0) && !isColliding(CONTACT_AREA_LEFT, 0, 0)) { // offset by +1, to fix directional quarks
// the actor is touching the wall
veloX = 0f // reset veloX, simulating normal force
veloX = 0.0 // reset veloX, simulating normal force
elasticReflectX()
}
else {
@@ -392,12 +392,12 @@ open class ActorWithBody constructor() : Actor(), Visible {
if (isColliding(CONTACT_AREA_LEFT) && !isColliding(CONTACT_AREA_RIGHT)) {
// the actor is embedded to the wall
adjustHitLeft()
veloX = 0f // reset veloX, simulating normal force
veloX = 0.0 // reset veloX, simulating normal force
elasticReflectX()
}
else if (isColliding(CONTACT_AREA_LEFT, -1, 0) && !isColliding(CONTACT_AREA_RIGHT, 1, 0)) {
// the actor is touching the wall
veloX = 0f // reset veloX, simulating normal force
veloX = 0.0 // reset veloX, simulating normal force
elasticReflectX()
}
else {
@@ -406,7 +406,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
else { // check both sides?
// System.out.println("updatehorizontal - |velo| < 0.5");
//if (isColliding(CONTACT_AREA_LEFT) || isColliding(CONTACT_AREA_RIGHT)) {
// veloX = 0f // reset veloX, simulating normal force
// veloX = 0.0 // reset veloX, simulating normal force
// elasticReflectX()
//}
}
@@ -416,7 +416,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
private fun adjustHitRight() {
val newY = nextHitbox.posY // look carefully, posY or pointedY
// int-ify posY of nextHitbox
nextHitbox.setPositionX(FastMath.floor(nextHitbox.posX + nextHitbox.width) - nextHitbox.width)
nextHitbox.setPositionX(Math.floor(nextHitbox.posX + nextHitbox.width) - nextHitbox.width)
var newXOff = 0 // always positive
@@ -434,7 +434,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
private fun adjustHitLeft() {
val newY = nextHitbox.posY
// int-ify posY of nextHitbox
nextHitbox.setPositionX(FastMath.ceil(nextHitbox.posX).toFloat())
nextHitbox.setPositionX(Math.ceil(nextHitbox.posX).toDouble())
var newXOff = 0 // always positive
@@ -451,14 +451,14 @@ open class ActorWithBody constructor() : Actor(), Visible {
}
private fun elasticReflectX() {
if (veloX != 0f && (veloX * elasticity).abs() > 0.5) {
if (veloX != 0.0 && (veloX * elasticity).abs() > 0.5) {
veloX = -veloX * elasticity
}
}
private fun elasticReflectY() {
if (veloY != 0f && (veloY * elasticity).abs() > 0.5) {
if (veloY != 0.0 && (veloY * elasticity).abs() > 0.5) {
veloY = -veloY * elasticity
}
}
@@ -556,18 +556,18 @@ open class ActorWithBody constructor() : Actor(), Visible {
veloY -= ((fluidDensity - this.density).toDouble()
* map.gravitation.toDouble() * submergedVolume.toDouble()
* Math.pow(mass.toDouble(), -1.0)
* SI_TO_GAME_ACC.toDouble()).toFloat()
* SI_TO_GAME_ACC.toDouble()).toDouble()
}
}*/
/*private val submergedVolume: Float
/*private val submergedVolume: Double
get() = submergedHeight * hitbox.width * hitbox.width
private val submergedHeight: Float
private val submergedHeight: Double
get() = Math.max(
getContactingAreaFluid(CONTACT_AREA_LEFT),
getContactingAreaFluid(CONTACT_AREA_RIGHT)
).toFloat()*/
).toDouble()*/
/**
@@ -591,7 +591,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
return friction
}
fun Int.tileFrictionToMult() = this / 16f
fun Int.tileFrictionToMult() = this / 16.0
/**
* Get highest density (specific gravity) value from tiles that the body occupies.
@@ -645,7 +645,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
return resistance
}
fun Int.resistanceToMult(): Float = 1f / (1 + this / 16f)
fun Int.resistanceToMult(): Double = 1.0 / (1 + this / 16.0)
private fun clampHitbox() {
hitbox.setPositionFromPoint(
@@ -682,9 +682,17 @@ open class ActorWithBody constructor() : Actor(), Visible {
override fun drawGlow(gc: GameContainer, g: Graphics) {
if (isVisible && spriteGlow != null) {
if (!sprite!!.flippedHorizontal()) {
spriteGlow!!.render(g, hitbox.posX - hitboxTranslateX * scale, hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2, scale)
spriteGlow!!.render(g,
(hitbox.posX - hitboxTranslateX * scale).toFloat(),
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
} else {
spriteGlow!!.render(g, hitbox.posX - scale, hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2, scale)
spriteGlow!!.render(g,
(hitbox.posX - scale).toFloat(),
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
}
}
}
@@ -692,9 +700,17 @@ open class ActorWithBody constructor() : Actor(), Visible {
override fun drawBody(gc: GameContainer, g: Graphics) {
if (isVisible && sprite != null) {
if (!sprite!!.flippedHorizontal()) {
sprite!!.render(g, hitbox.posX - hitboxTranslateX * scale, hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2, scale)
sprite!!.render(g,
(hitbox.posX - hitboxTranslateX * scale).toFloat(),
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
} else {
sprite!!.render(g, hitbox.posX - scale, hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2, scale)
sprite!!.render(g,
(hitbox.posX - scale).toFloat(),
(hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(),
(scale).toFloat()
)
}
}
}
@@ -707,20 +723,20 @@ open class ActorWithBody constructor() : Actor(), Visible {
if (sprite != null) sprite!!.update(delta)
}
private fun clampW(x: Float): Float =
private fun clampW(x: Double): Double =
if (x < TSIZE + nextHitbox.width / 2) {
TSIZE + nextHitbox.width / 2
} else if (x >= (map.width * TSIZE).toFloat() - TSIZE.toFloat() - nextHitbox.width / 2) {
(map.width * TSIZE).toFloat() - 1f - TSIZE.toFloat() - nextHitbox.width / 2
} else if (x >= (map.width * TSIZE).toDouble() - TSIZE.toDouble() - nextHitbox.width / 2) {
(map.width * TSIZE).toDouble() - 1.0 - TSIZE.toDouble() - nextHitbox.width / 2
} else {
x
}
private fun clampH(y: Float): Float =
private fun clampH(y: Double): Double =
if (y < TSIZE + nextHitbox.height) {
TSIZE + nextHitbox.height
} else if (y >= (map.height * TSIZE).toFloat() - TSIZE.toFloat() - nextHitbox.height) {
(map.height * TSIZE).toFloat() - 1f - TSIZE.toFloat() - nextHitbox.height
} else if (y >= (map.height * TSIZE).toDouble() - TSIZE.toDouble() - nextHitbox.height) {
(map.height * TSIZE).toDouble() - 1.0 - TSIZE.toDouble() - nextHitbox.height
} else {
y
}
@@ -746,21 +762,20 @@ open class ActorWithBody constructor() : Actor(), Visible {
private val isPlayerNoClip: Boolean
get() = this is Player && this.isNoClip()
private fun quantiseTSize(v: Float): Int = FastMath.floor(v / TSIZE) * TSIZE
fun setDensity(density: Int) {
if (density < 0)
throw IllegalArgumentException("[ActorWithBody] $density: density cannot be negative.")
this.density = density.toFloat()
this.density = density.toDouble()
}
private val AUTO_CLIMB_RATE: Int
get() = Math.min(TSIZE / 8 * FastMath.sqrt(scale), TSIZE.toFloat()).toInt()
get() = Math.min(TSIZE / 8 * Math.sqrt(scale), TSIZE.toDouble()).toInt()
fun Float.round() = Math.round(this).toFloat()
fun Float.roundToInt(): Int = Math.round(this)
fun Float.abs() = FastMath.abs(this)
fun Double.round() = Math.round(this).toDouble()
fun Double.roundToInt(): Int = Math.round(this).toInt()
fun Double.abs() = Math.abs(this)
fun Double.sqr() = this * this
fun Int.abs() = if (this < 0) -this else this
companion object {
@@ -785,7 +800,7 @@ open class ActorWithBody constructor() : Actor(), Visible {
return y and 0x7FFFFFFF shr 4
}
private fun clampCeil(x: Float, ceil: Float): Float {
private fun clampCeil(x: Double, ceil: Double): Double {
return if (Math.abs(x) > ceil) ceil else x
}
}

View File

@@ -9,7 +9,7 @@ interface CanBeAnItem {
fun attachItemData()
fun getItemWeight(): Float
fun getItemWeight(): Double
fun stopUpdateAndDraw()

View File

@@ -17,7 +17,7 @@ class DroppedItem constructor(itemID: Int) : ActorWithBody() {
isVisible = true
mass = if (itemID < 4096)
TilePropCodex.getProp(itemID).density / 1000f
TilePropCodex.getProp(itemID).density / 1000.0
else
ItemPropCodex.getProp(itemID).mass
}

View File

@@ -1,24 +1,24 @@
package net.torvald.terrarum.gameactors
import net.torvald.point.Point2f
import net.torvald.point.Point2d
/**
* Created by minjaesong on 16-01-15.
*/
class Hitbox(x1: Float, y1: Float, width: Float, height: Float) {
class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
@Volatile var hitboxStart: Point2f
@Volatile var hitboxStart: Point2d
private set
@Volatile var hitboxEnd: Point2f
@Volatile var hitboxEnd: Point2d
private set
var width: Float = 0.toFloat()
var width: Double = 0.toDouble()
private set
var height: Float = 0.toFloat()
var height: Double = 0.toDouble()
private set
init {
hitboxStart = Point2f(x1, y1)
hitboxEnd = Point2f(x1 + width, y1 + height)
hitboxStart = Point2d(x1, y1)
hitboxEnd = Point2d(x1 + width, y1 + height)
this.width = width
this.height = height
}
@@ -27,14 +27,14 @@ class Hitbox(x1: Float, y1: Float, width: Float, height: Float) {
* Returns bottom-centered point of hitbox.
* @return pointX
*/
val pointedX: Float
val pointedX: Double
get() = hitboxStart.x + width / 2
/**
* Returns bottom-centered point of hitbox.
* @return pointY
*/
val pointedY: Float
val pointedY: Double
get() = hitboxEnd.y
/**
@@ -47,48 +47,48 @@ class Hitbox(x1: Float, y1: Float, width: Float, height: Float) {
* *
* @param height
*/
operator fun set(x1: Float, y1: Float, width: Float, height: Float) {
hitboxStart = Point2f(x1, y1)
hitboxEnd = Point2f(x1 + width, y1 + height)
operator fun set(x1: Double, y1: Double, width: Double, height: Double) {
hitboxStart = Point2d(x1, y1)
hitboxEnd = Point2d(x1 + width, y1 + height)
this.width = width
this.height = height
}
fun setPosition(x1: Float, y1: Float) {
hitboxStart = Point2f(x1, y1)
hitboxEnd = Point2f(x1 + width, y1 + height)
fun setPosition(x1: Double, y1: Double) {
hitboxStart = Point2d(x1, y1)
hitboxEnd = Point2d(x1 + width, y1 + height)
}
fun setPositionX(x: Float) {
fun setPositionX(x: Double) {
setPosition(x, posY)
}
fun setPositionY(y: Float) {
fun setPositionY(y: Double) {
setPosition(posX, y)
}
fun setPositionFromPoint(x1: Float, y1: Float) {
hitboxStart = Point2f(x1 - width / 2, y1 - height)
hitboxEnd = Point2f(hitboxStart.x + width, hitboxStart.y + height)
fun setPositionFromPoint(x1: Double, y1: Double) {
hitboxStart = Point2d(x1 - width / 2, y1 - height)
hitboxEnd = Point2d(hitboxStart.x + width, hitboxStart.y + height)
}
fun setPositionXFromPoint(x: Float) {
fun setPositionXFromPoint(x: Double) {
setPositionFromPoint(x, pointedY)
}
fun setPositionYFromPoint(y: Float) {
fun setPositionYFromPoint(y: Double) {
setPositionFromPoint(pointedX, y)
}
fun translatePosX(d: Float) {
fun translatePosX(d: Double) {
setPositionX(posX + d)
}
fun translatePosY(d: Float) {
fun translatePosY(d: Double) {
setPositionY(posY + d)
}
fun setDimension(w: Float, h: Float) {
fun setDimension(w: Double, h: Double) {
width = w
height = h
}
@@ -97,19 +97,19 @@ class Hitbox(x1: Float, y1: Float, width: Float, height: Float) {
* Returns x value of start point
* @return top-left point posX
*/
val posX: Float
val posX: Double
get() = hitboxStart.x
/**
* Returns y value of start point
* @return top-left point posY
*/
val posY: Float
val posY: Double
get() = hitboxStart.y
val centeredX: Float
val centeredX: Double
get() = (hitboxStart.x + hitboxEnd.x) * 0.5f
val centeredY: Float
val centeredY: Double
get() = (hitboxStart.y + hitboxEnd.y) * 0.5f
}

View File

@@ -17,14 +17,14 @@ open class NPCIntelligentBase : ActorWithBody()
override var itemData: InventoryItem = object : InventoryItem {
override var itemID = HQRNG().nextInt()
override var mass: Float
get() = actorValue.get("mass") as Float
override var mass: Double
get() = actorValue.getAsDouble("mass")!!
set(value) {
actorValue.set("mass", value)
}
override var scale: Float
get() = actorValue.get("scale") as Float
override var scale: Double
get() = actorValue.getAsDouble("scale")!!
set(value) {
actorValue.set("scale", value)
}
@@ -70,7 +70,7 @@ open class NPCIntelligentBase : ActorWithBody()
}
override fun getItemWeight(): Float {
override fun getItemWeight(): Double {
return mass
}

View File

@@ -23,7 +23,7 @@ object PBCynthia {
p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT) ?: Player.BASE_HEIGHT, 9, 0)
p.setPosition((4096 * MapDrawer.TILE_SIZE).toFloat(), (300 * 16).toFloat())
p.setPosition((4096 * MapDrawer.TILE_SIZE).toDouble(), (300 * 16).toDouble())
return p
}

View File

@@ -33,14 +33,14 @@ object PBSigrid {
p.spriteGlow!!.setAsVisible()
p.actorValue = ActorValue()
p.actorValue[AVKey.SCALE] = 1.0f
p.actorValue[AVKey.SPEED] = 4.0f
p.actorValue[AVKey.SPEEDMULT] = 1.0f
p.actorValue[AVKey.SCALE] = 1.0
p.actorValue[AVKey.SPEED] = 4.0
p.actorValue[AVKey.SPEEDMULT] = 1.0
p.actorValue[AVKey.ACCEL] = Player.WALK_ACCEL_BASE
p.actorValue[AVKey.ACCELMULT] = 1.0f
p.actorValue[AVKey.JUMPPOWER] = 5f
p.actorValue[AVKey.ACCELMULT] = 1.0
p.actorValue[AVKey.JUMPPOWER] = 5.0
p.actorValue[AVKey.BASEMASS] = 80f
p.actorValue[AVKey.BASEMASS] = 80.0
p.actorValue[AVKey.PHYSIQUEMULT] = 1 // Constant 1.0 for player, meant to be used by random mobs
/**
* fixed value, or 'base value', from creature strength of Dwarf Fortress.
@@ -64,7 +64,7 @@ object PBSigrid {
p.inventory = ActorInventory(0x7FFFFFFF, true)
p.setPosition((4096 * MapDrawer.TILE_SIZE).toFloat(), (300 * 16).toFloat())
p.setPosition((4096 * MapDrawer.TILE_SIZE).toDouble(), (300 * 16).toDouble())
p.faction.add(FactionFactory.create("FactionSigrid.json"))

View File

@@ -23,9 +23,9 @@ class PhysTestBall : ActorWithBody {
override fun drawBody(gc: GameContainer, g: Graphics) {
g.color = color
g.fillOval(
hitbox.posX,
hitbox.posY,
hitbox.width,
hitbox.height)
hitbox.posX.toFloat(),
hitbox.posY.toFloat(),
hitbox.width.toFloat(),
hitbox.height.toFloat())
}
}

View File

@@ -6,7 +6,6 @@ import net.torvald.terrarum.gamecontroller.KeyMap
import net.torvald.terrarum.mapdrawer.MapDrawer
import net.torvald.terrarum.Terrarum
import net.torvald.spriteanimation.SpriteAnimation
import com.jme3.math.FastMath
import org.lwjgl.input.Controller
import org.lwjgl.input.Controllers
import org.newdawn.slick.GameContainer
@@ -23,7 +22,7 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
/**
* empirical value.
*/
@Transient private val JUMP_ACCELERATION_MOD = 170f / 10000f //linear mode
@Transient private val JUMP_ACCELERATION_MOD = 170.0 / 10000.0 //linear mode
@Transient private val WALK_FRAMES_TO_MAX_ACCEL = 6
@Transient private val LEFT = 1
@@ -38,8 +37,8 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
internal var walkPowerCounter = 0
@Transient private val MAX_JUMP_LENGTH = 17 // use 17; in internal frames
private var readonly_totalX = 0f
private var readonly_totalY = 0f
private var readonly_totalX = 0.0
private var readonly_totalY = 0.0
internal var jumping = false
@@ -72,8 +71,8 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
}
companion object {
@Transient internal const val ACCEL_MULT_IN_FLIGHT = 0.31f
@Transient internal const val WALK_ACCEL_BASE = 0.67f
@Transient internal const val ACCEL_MULT_IN_FLIGHT: Double = 0.31
@Transient internal const val WALK_ACCEL_BASE: Double = 0.67
@Transient const val PLAYER_REF_ID: Int = 0x51621D
@Transient const val BASE_HEIGHT = 40
@@ -116,14 +115,13 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
* @param absAxisVal (set AXIS_POSMAX if keyboard controlled)
*/
private fun walkHorizontal(left: Boolean, absAxisVal: Float) {
//if ((!super.isWalledLeft() && left) || (!super.isWalledRight() && !left)) {
readonly_totalX = veloX +
actorValue.getAsFloat(AVKey.ACCEL)!! *
actorValue.getAsFloat(AVKey.ACCELMULT)!! *
FastMath.sqrt(scale) *
applyAccelRealism(walkPowerCounter) *
(if (left) -1 else 1).toFloat() *
absAxisVal
actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale) *
applyAccelRealism(walkPowerCounter) *
(if (left) -1 else 1).toFloat() *
absAxisVal
veloX = readonly_totalX
@@ -132,16 +130,15 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
}
// Clamp veloX
veloX = absClamp(veloX, actorValue.getAsFloat(AVKey.SPEED)!!
* actorValue.getAsFloat(AVKey.SPEEDMULT)!!
* FastMath.sqrt(scale))
veloX = absClamp(veloX, actorValue.getAsDouble(AVKey.SPEED)!!
* actorValue.getAsDouble(AVKey.SPEEDMULT)!!
* Math.sqrt(scale))
// Heading flag
if (left)
walkHeading = LEFT
else
walkHeading = RIGHT
//}
}
/**
@@ -152,9 +149,9 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
*/
private fun walkVertical(up: Boolean, absAxisVal: Float) {
readonly_totalY = veloY +
actorValue.getAsFloat(AVKey.ACCEL)!! *
actorValue.getAsFloat(AVKey.ACCELMULT)!! *
FastMath.sqrt(scale) *
actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale) *
applyAccelRealism(walkPowerCounter) *
(if (up) -1 else 1).toFloat() *
absAxisVal
@@ -166,9 +163,9 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
}
// Clamp veloX
veloY = absClamp(veloY, actorValue.getAsFloat(AVKey.SPEED)!!
* actorValue.getAsFloat(AVKey.SPEEDMULT)!!
* FastMath.sqrt(scale))
veloY = absClamp(veloY, actorValue.getAsDouble(AVKey.SPEED)!!
* actorValue.getAsDouble(AVKey.SPEEDMULT)!!
* Math.sqrt(scale))
}
/**
@@ -194,23 +191,23 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
* @param x
*/
private fun applyAccelRealism(x: Int): Float {
return 0.5f + 0.5f * -FastMath.cos(10 * x / (WALK_FRAMES_TO_MAX_ACCEL * FastMath.PI))
private fun applyAccelRealism(x: Int): Double {
return 0.5 + 0.5 * -Math.cos(10 * x / (WALK_FRAMES_TO_MAX_ACCEL * Math.PI))
}
// stops; let the friction kick in by doing nothing to the velocity here
private fun walkHStop() {
/*if (veloX > 0) {
veloX -= actorValue.getAsFloat(AVKey.ACCEL)!! *
actorValue.getAsFloat(AVKey.ACCELMULT)!! *
FastMath.sqrt(scale)
veloX -= actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale)
// compensate overshoot
if (veloX < 0) veloX = 0f
} else if (veloX < 0) {
veloX += actorValue.getAsFloat(AVKey.ACCEL)!! *
actorValue.getAsFloat(AVKey.ACCELMULT)!! *
FastMath.sqrt(scale)
veloX += actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale)
// compensate overshoot
if (veloX > 0) veloX = 0f
@@ -227,16 +224,16 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
private fun walkVStop() {
/*if (veloY > 0) {
veloY -= WALK_STOP_ACCEL *
actorValue.getAsFloat(AVKey.ACCELMULT)!! *
FastMath.sqrt(scale)
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale)
// compensate overshoot
if (veloY < 0)
veloY = 0f
} else if (veloY < 0) {
veloY += WALK_STOP_ACCEL *
actorValue.getAsFloat(AVKey.ACCELMULT)!! *
FastMath.sqrt(scale)
actorValue.getAsDouble(AVKey.ACCELMULT)!! *
Math.sqrt(scale)
// compensate overshoot
if (veloY > 0) veloY = 0f
@@ -252,12 +249,12 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
private fun updateMovementControl() {
if (!noClip) {
if (grounded) {
actorValue[AVKey.ACCELMULT] = 1f
actorValue[AVKey.ACCELMULT] = 1.0
} else {
actorValue[AVKey.ACCELMULT] = ACCEL_MULT_IN_FLIGHT
}
} else {
actorValue[AVKey.ACCELMULT] = 1f
actorValue[AVKey.ACCELMULT] = 1.0
}
}
@@ -401,17 +398,17 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
private fun jump() {
if (jumping) {
val len = MAX_JUMP_LENGTH.toFloat()
val pwr = actorValue.getAsFloat(AVKey.JUMPPOWER)!! * (actorValue.getAsFloat(AVKey.JUMPPOWERMULT) ?: 1f)
val pwr = actorValue.getAsDouble(AVKey.JUMPPOWER)!! * (actorValue.getAsDouble(AVKey.JUMPPOWERMULT) ?: 1.0)
// increment jump counter
if (jumpCounter < len) jumpCounter += 1
// linear time mode
val init = (len + 1) / 2f
val init = (len + 1) / 2.0
var timedJumpCharge = init - init / len * jumpCounter
if (timedJumpCharge < 0) timedJumpCharge = 0f
if (timedJumpCharge < 0) timedJumpCharge = 0.0
val jumpAcc = pwr * timedJumpCharge * JUMP_ACCELERATION_MOD * FastMath.sqrt(scale)
val jumpAcc = pwr * timedJumpCharge * JUMP_ACCELERATION_MOD * Math.sqrt(scale)
veloY -= jumpAcc
}
@@ -419,34 +416,21 @@ class Player : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, Lan
// for mob ai:
//super.setVeloY(veloY
// -
// pwr * FastMath.sqrt(scale)
// pwr * Math.sqrt(scale)
//);
}
private fun jumpFuncLin(pwr: Float, len: Float): Float {
return -(pwr / len) * jumpCounter
}
private fun jumpFuncSqu(pwr: Float, len: Float): Float {
return pwr / (len * len) * (jumpCounter - len * jumpCounter - len) - pwr
}
private fun jumpFuncExp(pwr: Float, len: Float): Float {
val a = FastMath.pow(pwr + 1, 1 / len)
return -FastMath.pow(a, len) + 1
}
private fun isFuncDown(input: Input, fn: EnumKeyFunc): Boolean {
return input.isKeyDown(KeyMap.getKeyCode(fn))
}
private fun absClamp(i: Float, ceil: Float): Float {
private fun absClamp(i: Double, ceil: Double): Double {
if (i > 0)
return if (i > ceil) ceil else i
else if (i < 0)
return if (-i > ceil) -ceil else i
else
return 0f
return 0.0
}
private fun updateSprite(delta_t: Int) {

View File

@@ -151,7 +151,7 @@ object CollisionSolver {
val dist_y = (ay - by).abs() // 'ty'
val tangent = dist_y / dist_x
var t_ax: Float; var t_ay: Float
var t_ax: Double; var t_ay: Double
if (dist_x > dist_y) {
t_ax = this.hitbox.width / 2
t_ay = t_ax * tangent
@@ -164,11 +164,11 @@ object CollisionSolver {
return (t_ax.sqr() + t_ay.sqr()) < actor_dist_t_sqr
}
fun Float.abs() = if (this < 0) -this else this
fun Float.sqr() = this * this
fun Double.abs() = if (this < 0) -this else this
fun Double.sqr() = this * this
class CollisionMarkings(
val pos: Float,
val pos: Double,
val kind: Int,
val actor: ActorWithBody
) : Comparable<CollisionMarkings> {

View File

@@ -17,12 +17,12 @@ interface InventoryItem {
/**
* Weight of the item, Float
*/
var mass: Float
var mass: Double
/**
* Scale of the item. Real mass: mass * (scale^3)
*/
var scale: Float
var scale: Double
/**
* Effects applied while in pocket

View File

@@ -9,12 +9,12 @@ import org.newdawn.slick.GameContainer
class TileAsItem(tileNum: Int) : InventoryItem {
override var itemID: Int = 0
override var mass: Float = 0f
override var scale: Float = 1f
override var mass: Double = 0.0
override var scale: Double = 1.0
init {
itemID = tileNum
mass = TilePropCodex.getProp(tileNum).density / 1000f
mass = TilePropCodex.getProp(tileNum).density / 1000.0
}
override fun effectWhileInPocket(gc: GameContainer, delta_t: Int) {

View File

@@ -32,7 +32,7 @@ constructor(//properties
//public World physWorld = new World( new Vec2(0, -TerrarumMain.game.gravitationalAccel) );
//physics
/** \[m / s^2\] */
var gravitation: Float = 9.8.toFloat()
var gravitation: Double = 9.8
/** RGB in Integer */
var globalLight: Int = 0
val worldTime: WorldTime

View File

@@ -1,21 +1,21 @@
package net.torvald.terrarum.gamemap
import net.torvald.point.Point2f
import net.torvald.point.Point2d
import java.io.Serializable
class MapPoint {
var startPoint: Point2f? = null
var startPoint: Point2d? = null
private set
var endPoint: Point2f? = null
var endPoint: Point2d? = null
private set
constructor() {
}
constructor(p1: Point2f, p2: Point2f) {
constructor(p1: Point2d, p2: Point2d) {
setPoint(p1, p2)
}
@@ -23,13 +23,13 @@ class MapPoint {
setPoint(x1, y1, x2, y2)
}
fun setPoint(p1: Point2f, p2: Point2f) {
fun setPoint(p1: Point2d, p2: Point2d) {
startPoint = p1
endPoint = p2
}
fun setPoint(x1: Int, y1: Int, x2: Int, y2: Int) {
startPoint = Point2f(x1.toFloat(), y1.toFloat())
endPoint = Point2f(x2.toFloat(), y2.toFloat())
startPoint = Point2d(x1.toDouble(), y1.toDouble())
endPoint = Point2d(x2.toDouble(), y2.toDouble())
}
}

View File

@@ -594,6 +594,7 @@ object LightmapRenderer {
private fun Float.inv() = 1f / this
fun Float.floor() = FastMath.floor(this)
fun Float.round(): Int = Math.round(this)
fun Double.round(): Int = Math.round(this).toInt()
fun Float.ceil() = FastMath.ceil(this)
fun Int.even(): Boolean = this and 1 == 0
fun Int.odd(): Boolean = this and 1 == 1

View File

@@ -225,9 +225,9 @@ object MapCamera {
// position - (WH / 2)
cameraX = Math.round(FastMath.clamp(
player.hitbox!!.centeredX - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))
player.hitbox.centeredX.toFloat() - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))
cameraY = Math.round(FastMath.clamp(
player.hitbox!!.centeredY - renderHeight / 2, TSIZE.toFloat(), map.height * TSIZE - renderHeight - TSIZE.toFloat()))
player.hitbox.centeredY.toFloat() - renderHeight / 2, TSIZE.toFloat(), map.height * TSIZE - renderHeight - TSIZE.toFloat()))
}
fun renderBehind(gc: GameContainer, g: Graphics) {

View File

@@ -34,9 +34,9 @@ object TileStats {
val renderHeight = FastMath.ceil(Terrarum.HEIGHT.toFloat())
val noZoomCameraX = Math.round(FastMath.clamp(
player.hitbox!!.centeredX - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))
player.hitbox.centeredX.toFloat() - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))
val noZoomCameraY = Math.round(FastMath.clamp(
player.hitbox!!.centeredY - renderHeight / 2, TSIZE.toFloat(), map.width * TSIZE - renderHeight - TSIZE.toFloat()))
player.hitbox.centeredY.toFloat() - renderHeight / 2, TSIZE.toFloat(), map.width * TSIZE - renderHeight - TSIZE.toFloat()))
val for_x_start = MapCamera.div16(noZoomCameraX)
val for_y_start = MapCamera.div16(noZoomCameraY)

View File

@@ -26,11 +26,11 @@ class BasicDebugInfoWindow:UICanvas {
override var openCloseTime: Int = 0
private var prevPlayerX = 0f
private var prevPlayerY = 0f
private var prevPlayerX = 0.0
private var prevPlayerY = 0.0
private var xdelta = 0f
private var ydelta = 0f
private var xdelta = 0.0
private var ydelta = 0.0
val ccW = GameFontBase.colToCode["w"]
val ccG = GameFontBase.colToCode["g"]
@@ -130,41 +130,6 @@ class BasicDebugInfoWindow:UICanvas {
" (${Terrarum.game.map.worldTime.getFormattedTime()})")
printLineColumn(g, 2, 6, "Mass $ccG${player.mass}")
/**
* On screen
*/
// Hitbox
val zoom = Terrarum.game.screenZoom
g.color = Color(0x007f00)
g.drawRect(hitbox.hitboxStart.x * zoom - MapCamera.cameraX * zoom
, hitbox.hitboxStart.y * zoom - MapCamera.cameraY * zoom
, hitbox.width * zoom
, hitbox.height * zoom)
// ...and its point
g.fillRect(
(hitbox.pointedX - 1) * zoom - MapCamera.cameraX * zoom
, (hitbox.pointedY - 1) * zoom - MapCamera.cameraY * zoom
, 3f, 3f)
g.drawString(
"hitbox", (Terrarum.WIDTH - 15 * 8 - 2).toFloat().toFloat()
, line(1))
// Next hitbox
g.color = Color.blue
g.drawRect(nextHitbox.hitboxStart.x * zoom - MapCamera.cameraX * zoom
, nextHitbox.hitboxStart.y * zoom - MapCamera.cameraY * zoom
, nextHitbox.width * zoom
, nextHitbox.height * zoom)
// ...and its point
g.fillRect(
(nextHitbox.pointedX - 1) * zoom - MapCamera.cameraX * zoom
, (nextHitbox.pointedY - 1) * zoom - MapCamera.cameraY * zoom
, 3f, 3f)
g.drawString(
"nextHitbox", (Terrarum.WIDTH - 15 * 8 - 2).toFloat().toFloat()
, line(2))
drawHistogram(g, LightmapRenderer.histogram,
Terrarum.WIDTH - histogramW - 30,
Terrarum.HEIGHT - histogramH - 30