From 6c7fe9cf2b38ca723634799770f157391a4c4b57 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 23 Feb 2020 15:57:33 +0900 Subject: [PATCH] amending last commit --- .../worlddrawer/LightmapRendererNew.kt | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt index 4729c195c..af79026fd 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt @@ -167,6 +167,8 @@ object LightmapRenderer { } } + private val cellsToUpdate = ArrayList() + internal fun fireRecalculateEvent(vararg actorContainers: List?) { try { world.getTileFromTerrain(0, 0) // test inquiry @@ -322,6 +324,74 @@ object LightmapRenderer { // * No-op masks cause some ambient ray to disappear when they're on the screen edge // * Naive optimisation (mark-and-iterate) attempt was a disaster + //mark cells to update + // Round 1 + /*cellsToUpdate.clear() + lightsourceMap.forEach { (addr, light) -> + val (wx, wy) = LandUtil.resolveBlockAddr(world, addr) + // mark cells to update + for (y in 0 until overscan_open) { + for (x in 0 until overscan_open - y) { + val lx = (wx + x).convX(); val ly = (wy + y).convY() + if (lx in 0 until LIGHTMAP_WIDTH && ly in 0 until LIGHTMAP_HEIGHT) + cellsToUpdate.add((ly.toLong() shl 32) or lx.toLong()) + } + } + } + cellsToUpdate.forEach { + calculateAndAssign(lightmap, it.toInt(), (it shr 32).toInt()) + } + // Round 2 + cellsToUpdate.clear() + lightsourceMap.forEach { (addr, light) -> + val (wx, wy) = LandUtil.resolveBlockAddr(world, addr) + + // mark cells to update + for (y in 0 downTo -overscan_open + 1) { + for (x in 0 until overscan_open + y) { + val lx = (wx + x).convX(); val ly = (wy + y).convY() + if (lx in 0 until LIGHTMAP_WIDTH && ly in 0 until LIGHTMAP_HEIGHT) + cellsToUpdate.add((ly.toLong() shl 32) or lx.toLong()) + } + } + } + cellsToUpdate.forEach { + calculateAndAssign(lightmap, it.toInt(), (it shr 32).toInt()) + } + // Round 3 + cellsToUpdate.clear() + lightsourceMap.forEach { (addr, light) -> + val (wx, wy) = LandUtil.resolveBlockAddr(world, addr) + + // mark cells to update + for (y in 0 downTo -overscan_open + 1) { + for (x in 0 downTo -overscan_open + 1 - y) { + val lx = (wx + x).convX(); val ly = (wy + y).convY() + if (lx in 0 until LIGHTMAP_WIDTH && ly in 0 until LIGHTMAP_HEIGHT) + cellsToUpdate.add((ly.toLong() shl 32) or lx.toLong()) + } + } + } + cellsToUpdate.forEach { + calculateAndAssign(lightmap, it.toInt(), (it shr 32).toInt()) + } + // Round 4 + cellsToUpdate.clear() + lightsourceMap.forEach { (addr, light) -> + val (wx, wy) = LandUtil.resolveBlockAddr(world, addr) + + // mark cells to update + for (y in 0 until overscan_open) { + for (x in 0 downTo -overscan_open + 1 + y) { + val lx = (wx + x).convX(); val ly = (wy + y).convY() + if (lx in 0 until LIGHTMAP_WIDTH && ly in 0 until LIGHTMAP_HEIGHT) + cellsToUpdate.add((ly.toLong() shl 32) or lx.toLong()) + } + } + } + cellsToUpdate.forEach { + calculateAndAssign(lightmap, it.toInt(), (it shr 32).toInt()) + }*/ // per-channel operation for bit more aggressive optimisation