mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
light: lantern lookup should be faster
This commit is contained in:
@@ -53,3 +53,5 @@ data class Point2d(var x: Double, var y: Double) : Cloneable {
|
|||||||
fun distSqr(other: Point2d) = ((this.x - other.x).sqr() + (this.y - other.y).sqr())
|
fun distSqr(other: Point2d) = ((this.x - other.x).sqr() + (this.y - other.y).sqr())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class Point2i(val x: Int, val y: Int)
|
||||||
|
|||||||
@@ -49,6 +49,21 @@ class BasicDebugInfoWindow : UICanvas() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun formatNanoTime(l: Long?): String {
|
||||||
|
if (l == null) return "null"
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
|
l.toString().reversed().forEachIndexed { index, c ->
|
||||||
|
if (index > 0 && index % 3 == 0)
|
||||||
|
sb.append(' ')
|
||||||
|
|
||||||
|
sb.append(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.reverse().toString()
|
||||||
|
}
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
val player = ingame.actorNowPlaying
|
val player = ingame.actorNowPlaying
|
||||||
|
|
||||||
@@ -136,9 +151,10 @@ class BasicDebugInfoWindow : UICanvas() {
|
|||||||
printLine(batch, 10, "fluid@cursor ${ccY}Type $ccM${fluid.type.value} ${ccY}Fill $ccG${fluid.amount}f")
|
printLine(batch, 10, "fluid@cursor ${ccY}Type $ccM${fluid.type.value} ${ccY}Fill $ccG${fluid.amount}f")
|
||||||
|
|
||||||
|
|
||||||
|
// print time
|
||||||
var dbgCnt = 12
|
var dbgCnt = 12
|
||||||
AppLoader.debugTimers.forEach { t, u ->
|
AppLoader.debugTimers.forEach { t, u ->
|
||||||
printLine(batch, dbgCnt, "$ccM$t $ccG$u$ccY ns")
|
printLine(batch, dbgCnt, "$ccM$t $ccG${formatNanoTime(u as? Long)}$ccY ns")
|
||||||
dbgCnt++
|
dbgCnt++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,12 @@ import com.badlogic.gdx.graphics.Pixmap
|
|||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
import net.torvald.terrarum.Terrarum
|
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
import net.torvald.terrarum.ceilInt
|
|
||||||
import net.torvald.terrarum.concurrent.ParallelUtils.sliceEvenly
|
import net.torvald.terrarum.concurrent.ParallelUtils.sliceEvenly
|
||||||
import net.torvald.terrarum.concurrent.ThreadParallel
|
import net.torvald.terrarum.concurrent.ThreadParallel
|
||||||
import net.torvald.terrarum.floorInt
|
|
||||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||||
import net.torvald.terrarum.gameactors.Luminous
|
import net.torvald.terrarum.gameactors.Luminous
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
@@ -86,7 +83,7 @@ object LightmapRenderer {
|
|||||||
// it utilises alpha channel to determine brightness of "glow" sprites (so that alpha channel works like UV light)
|
// it utilises alpha channel to determine brightness of "glow" sprites (so that alpha channel works like UV light)
|
||||||
//private val lightmap: Array<Array<Color>> = Array(LIGHTMAP_HEIGHT) { Array(LIGHTMAP_WIDTH, { Color(0f,0f,0f,0f) }) } // Can't use framebuffer/pixmap -- this is a fvec4 array, whereas they are ivec4.
|
//private val lightmap: Array<Array<Color>> = Array(LIGHTMAP_HEIGHT) { Array(LIGHTMAP_WIDTH, { Color(0f,0f,0f,0f) }) } // Can't use framebuffer/pixmap -- this is a fvec4 array, whereas they are ivec4.
|
||||||
private var lightmap: Array<Color> = Array(LIGHTMAP_WIDTH * LIGHTMAP_HEIGHT) { Color(0f,0f,0f,0f) } // Can't use framebuffer/pixmap -- this is a fvec4 array, whereas they are ivec4.
|
private var lightmap: Array<Color> = Array(LIGHTMAP_WIDTH * LIGHTMAP_HEIGHT) { Color(0f,0f,0f,0f) } // Can't use framebuffer/pixmap -- this is a fvec4 array, whereas they are ivec4.
|
||||||
private val lanternMap = ArrayList<Lantern>((Terrarum.ingame?.ACTORCONTAINER_INITIAL_SIZE ?: 2) * 4)
|
private val lanternMap = HashMap<Point2i, Color>((Terrarum.ingame?.ACTORCONTAINER_INITIAL_SIZE ?: 2) * 4)
|
||||||
|
|
||||||
private val AIR = Block.AIR
|
private val AIR = Block.AIR
|
||||||
|
|
||||||
@@ -402,10 +399,10 @@ object LightmapRenderer {
|
|||||||
|
|
||||||
val normalisedColor = it.color.cpy().mul(DIV_FLOAT)
|
val normalisedColor = it.color.cpy().mul(DIV_FLOAT)
|
||||||
|
|
||||||
lanternMap.add(Lantern(x, y, normalisedColor))
|
lanternMap[Point2i(x, y)] = normalisedColor
|
||||||
// Q&D fix for Roundworld anomaly
|
// Q&D fix for Roundworld anomaly
|
||||||
lanternMap.add(Lantern(x + world.width, y, normalisedColor))
|
lanternMap[Point2i(x + world.width, y)] = normalisedColor
|
||||||
lanternMap.add(Lantern(x - world.width, y, normalisedColor))
|
lanternMap[Point2i(x - world.width, y)] = normalisedColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -459,11 +456,8 @@ object LightmapRenderer {
|
|||||||
}
|
}
|
||||||
// END MIX TILE
|
// END MIX TILE
|
||||||
|
|
||||||
for (i in 0 until lanternMap.size) {
|
// blend lantern
|
||||||
val lmap = lanternMap[i]
|
lightLevelThis maxBlend (lanternMap[Point2i(x, y)] ?: colourNull)
|
||||||
if (lmap.posX == x && lmap.posY == y)
|
|
||||||
lightLevelThis.set(lightLevelThis maxBlend lmap.color) // maximise to not exceed 1.0 with normal (<= 1.0) light
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate ambient
|
// calculate ambient
|
||||||
/* + * +
|
/* + * +
|
||||||
@@ -863,11 +857,6 @@ object LightmapRenderer {
|
|||||||
hdr(this.a)
|
hdr(this.a)
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
|
||||||
* color values are normalised -- 0.0 to 1.0 for 0..1023
|
|
||||||
*/
|
|
||||||
data class Lantern(val posX: Int, val posY: Int, val color: Color)
|
|
||||||
|
|
||||||
private fun Color.nonZero() = this.r != 0f || this.g != 0f || this.b != 0f || this.a != 0f
|
private fun Color.nonZero() = this.r != 0f || this.g != 0f || this.b != 0f || this.a != 0f
|
||||||
|
|
||||||
val histogram: Histogram
|
val histogram: Histogram
|
||||||
|
|||||||
Reference in New Issue
Block a user