diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt index 720220e08..fae33128f 100644 --- a/src/net/torvald/terrarum/StateInGame.kt +++ b/src/net/torvald/terrarum/StateInGame.kt @@ -529,18 +529,27 @@ constructor() : BasicGameState() { fun Double.sqr() = this * this fun Int.sqr() = this * this + fun min(vararg d: Double): Double { + var ret = Double.MAX_VALUE + d.forEach { if (it < ret) ret = it } + return ret + } private fun distToActorSqr(a: ActorWithBody, p: ActorWithBody) = - Math.min(// take min of normal position and wrapped (x < 0) position + min(// take min of normal position and wrapped (x < 0) position (a.hitbox.centeredX - p.hitbox.centeredX).sqr() + (a.hitbox.centeredY - p.hitbox.centeredY).sqr(), (a.hitbox.centeredX - p.hitbox.centeredX + world.width * TILE_SIZE).sqr() + + (a.hitbox.centeredY - p.hitbox.centeredY).sqr(), + (a.hitbox.centeredX - p.hitbox.centeredX - world.width * TILE_SIZE).sqr() + (a.hitbox.centeredY - p.hitbox.centeredY).sqr() ) private fun distToCameraSqr(a: ActorWithBody) = - Math.min( + min( (a.hitbox.posX - MapCamera.cameraX).sqr() + (a.hitbox.posY - MapCamera.cameraY).sqr(), (a.hitbox.posX - MapCamera.cameraX + world.width * TILE_SIZE).sqr() + + (a.hitbox.posY - MapCamera.cameraY).sqr(), + (a.hitbox.posX - MapCamera.cameraX - world.width * TILE_SIZE).sqr() + (a.hitbox.posY - MapCamera.cameraY).sqr() ) diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index de6d8e84d..0598251d3 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -914,6 +914,11 @@ open class ActorWithBody : Actor() { (hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(), (scale).toFloat() ) + spriteGlow!!.render(g, + (hitbox.posX - hitboxTranslateX * scale).toFloat() - world.width * TILE_SIZE, + (hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(), + (scale).toFloat() + ) } else { spriteGlow!!.render(g, @@ -927,6 +932,11 @@ open class ActorWithBody : Actor() { (hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(), (scale).toFloat() ) + spriteGlow!!.render(g, + (hitbox.posX - scale).toFloat() - world.width * TILE_SIZE, + (hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(), + (scale).toFloat() + ) } } } @@ -951,6 +961,11 @@ open class ActorWithBody : Actor() { (hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(), (scale).toFloat() ) + sprite!!.render(g, + (hitbox.posX - hitboxTranslateX * scale).toFloat() - world.width * TILE_SIZE, + (hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(), + (scale).toFloat() + ) } else { sprite!!.render(g, @@ -964,6 +979,11 @@ open class ActorWithBody : Actor() { (hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(), (scale).toFloat() ) + sprite!!.render(g, + (hitbox.posX - scale).toFloat() - world.width * TILE_SIZE, + (hitbox.posY + hitboxTranslateY * scale - (baseSpriteHeight - baseHitboxH) * scale + 2).toFloat(), + (scale).toFloat() + ) } } } diff --git a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt index a5acd8793..77bd84db4 100644 --- a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt @@ -190,6 +190,7 @@ object LightmapRenderer { lanternMap.add(Lantern(x, y, it.luminosity)) // Q&D fix for Roundworld anormaly lanternMap.add(Lantern(x + world.width, y, it.luminosity)) + lanternMap.add(Lantern(x - world.width, y, it.luminosity)) } } } @@ -237,7 +238,8 @@ object LightmapRenderer { private fun calculate(x: Int, y: Int): Int = calculate(x, y, false) private fun calculate(x: Int, y: Int, doNotCalculateAmbient: Boolean): Int { - // O(9n) == O(n) where n is a size of the map. + // O(9n) == O(n) where n is a size of the map + // TODO devise multithreading on this var lightLevelThis: Int = 0 val thisTerrain = Terrarum.ingame.world.getTileFromTerrain(x, y)