mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 13:04:05 +09:00
actors are now active/dormant depending on the distance to the player, only the active actors are to be updated. Actors outside of the camera (actually a distance to the player) are not rendered
Former-commit-id: 5f80c2ef3592aab5567723087c264e05458e98b3 Former-commit-id: 7714c6f5a6d7a48d4f5adfe8f6990b249bdb80b0
This commit is contained in:
@@ -2,10 +2,10 @@ package net.torvald.terrarum.mapdrawer
|
||||
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameactors.Luminous
|
||||
import net.torvald.terrarum.gamemap.WorldTime
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.tileproperties.TilePropCodex
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.gameactors.Visible
|
||||
import net.torvald.terrarum.tileproperties.TileNameCode
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.Graphics
|
||||
@@ -27,8 +27,8 @@ object LightmapRenderer {
|
||||
/**
|
||||
* 8-Bit RGB values
|
||||
*/
|
||||
//private val lightmap: Array<IntArray> = Array(Terrarum.game.map.height) { IntArray(Terrarum.game.map.width) }
|
||||
private val lightmap: Array<IntArray> = Array(LIGHTMAP_HEIGHT) { IntArray(LIGHTMAP_WIDTH) }
|
||||
private val lanternMap = ArrayList<Lantern>(Terrarum.game.ACTORCONTAINER_INITIAL_SIZE)
|
||||
|
||||
private val AIR = TileNameCode.AIR
|
||||
|
||||
@@ -165,9 +165,19 @@ object LightmapRenderer {
|
||||
* for all staticLightMap[y][x]
|
||||
*/
|
||||
|
||||
//purgePartOfLightmap(for_x_start - overscan_open, for_y_start - overscan_open, for_x_end + overscan_open, for_y_end + overscan_open)
|
||||
purgeLightmap()
|
||||
|
||||
// scan for luminous actors and store their lighting info to the lanterns
|
||||
lanternMap.clear()
|
||||
Terrarum.game.actorContainer.forEach { it ->
|
||||
if (it is Luminous && it is Visible)
|
||||
lanternMap.add(Lantern(
|
||||
it.hitbox.centeredX.div(TSIZE).round(),
|
||||
it.hitbox.centeredY.div(TSIZE).round(),
|
||||
it.luminosity
|
||||
))
|
||||
}
|
||||
|
||||
try {
|
||||
// Round 1
|
||||
for (y in for_y_start - overscan_open..for_y_end) {
|
||||
@@ -229,23 +239,16 @@ object LightmapRenderer {
|
||||
// END MIX TILE
|
||||
|
||||
// mix luminous actor
|
||||
for (actor in Terrarum.game.actorContainer) {
|
||||
if (actor is Luminous && actor is ActorWithBody) {
|
||||
val tileX = Math.round(actor.hitbox.pointedX / TSIZE)
|
||||
val tileY = Math.round(actor.hitbox.pointedY / TSIZE) - 1
|
||||
val actorLuminosity = actor.luminosity
|
||||
if (x == tileX && y == tileY) {
|
||||
lightLevelThis = maximiseRGB(lightLevelThis, actorLuminosity) // maximise to not exceed 1.0 with normal (<= 1.0) light
|
||||
break
|
||||
}
|
||||
}
|
||||
for ((posX, posY, luminosity) in lanternMap) {
|
||||
if (posX == x && posY == y)
|
||||
lightLevelThis = maximiseRGB(lightLevelThis, luminosity) // maximise to not exceed 1.0 with normal (<= 1.0) light
|
||||
}
|
||||
|
||||
|
||||
if (!doNotCalculateAmbient) {
|
||||
// calculate ambient
|
||||
var ambient: Int = 0
|
||||
var nearby: Int = 0
|
||||
var nearby: Int
|
||||
for (yoff in -1..1) {
|
||||
for (xoff in -1..1) {
|
||||
/**
|
||||
@@ -595,6 +598,8 @@ object LightmapRenderer {
|
||||
fun Int.even(): Boolean = this and 1 == 0
|
||||
fun Int.odd(): Boolean = this and 1 == 1
|
||||
|
||||
data class Lantern(val posX: Int, val posY: Int, val luminosity: Int)
|
||||
|
||||
val histogram: Histogram
|
||||
get() {
|
||||
var reds = IntArray(MUL) // reds[intensity] ← counts
|
||||
|
||||
Reference in New Issue
Block a user