mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
resolving issue #5
Former-commit-id: 12d11b683a242172a7c3ec831efb7d65f552951f Former-commit-id: fd276318b77ac5ef9b1963e84fb33380ddbae45c
This commit is contained in:
@@ -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()
|
||||
)
|
||||
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user