now dropped items can produce light (e.g. dropped torch)

This commit is contained in:
minjaesong
2022-09-11 17:10:01 +09:00
parent 430ad4e703
commit bec47e81e2
15 changed files with 140 additions and 140 deletions

View File

@@ -184,7 +184,7 @@ class BlockCodex {
// otherModname:id -> as-is
// id -> thisModname:id
prop.drop = record.get("drop").let { if (it == null) "" else if (it.contains(':')) it else "$modname:$it" }
prop.world = record.get("world").let { if (it == null) "" else if (it.contains(':')) it else "$modname:$it" }
prop.world = record.get("spawn").let { if (it == null) "" else if (it.contains(':')) it else "$modname:$it" }
prop.shadeColR = record.floatVal("shdr")
prop.shadeColG = record.floatVal("shdg")

View File

@@ -28,7 +28,7 @@ import java.util.Properties;
public class CSVEditor extends JFrame {
/** Default columns. When you open existing csv, it should overwrite this. */
private String[] columns = new String[]{"id", "drop", "world", "name", "shdr", "shdg", "shdb", "shduv", "str", "dsty", "mate", "solid", "wall", "grav", "dlfn", "fv", "fr", "lumr", "lumg", "lumb", "lumuv", "colour", "vscs", "refl","tags"};
private String[] columns = new String[]{"id", "drop", "spawn", "name", "shdr", "shdg", "shdb", "shduv", "str", "dsty", "mate", "solid", "wall", "grav", "dlfn", "fv", "fr", "lumr", "lumg", "lumb", "lumuv", "colour", "vscs", "refl","tags"};
private final int FOUR_DIGIT = 42;
private final int SIX_DIGIT = 50;
private final int TWO_DIGIT = 30;
@@ -515,7 +515,7 @@ public class CSVEditor extends JFrame {
private String captionProperties = """
id=ID of this block
drop=Which item the DroppedItem actually adds to your inventory
world=Which item the DroppedItem should impersonate when spawned
spawn=Which item the DroppedItem should impersonate when spawned
name=String identifier of the block
shdr=Shade Red (light absorption). Valid range 0.01.0+
shdg=Shade Green (light absorption). Valid range 0.01.0+

View File

@@ -41,6 +41,28 @@ open class ActorWithBody : Actor {
var physProp = PhysProperties.HUMANOID_DEFAULT
// copied from old interface Luminous
/**
* Arguments:
*
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*
* NOTE: MUST NOT SERIALISE (use `@Transient`)
*/
open var lightBoxList: List<Lightbox> = emptyList()
/**
* Arguments:
*
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*
* NOTE: MUST NOT SERIALISE (use `@Transient`)
*/
open var shadeBoxList: List<Lightbox> = emptyList()
// end of Luminous
protected constructor() : super()
constructor(renderOrder: RenderOrder, physProp: PhysProperties, id: ActorID? = null) : super(renderOrder, id) {

View File

@@ -22,8 +22,10 @@ class Lightbox() {
* For actors that either emits or blocks lights
*
* Created by minjaesong on 2016-02-19.
*
* the interface Luminous is merged with the ActorWithBody -- minjaesong on 2022-09-11
*/
interface Luminous {
/*interface Luminous {
/**
* Arguments:
@@ -44,4 +46,4 @@ interface Luminous {
* NOTE: MUST NOT SERIALISE (use `@Transient`)
*/
val shadeBoxList: List<Lightbox>
}
}*/

View File

@@ -3,7 +3,9 @@ package net.torvald.terrarum.gameitems
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.*
import net.torvald.terrarum.ReferencingRanges.PREFIX_ACTORITEM
import net.torvald.terrarum.ReferencingRanges.PREFIX_DYNAMICITEM
import net.torvald.terrarum.ReferencingRanges.PREFIX_VIRTUALTILE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithBody
@@ -407,3 +409,11 @@ fun mouseInInteractableRangeTools(actor: ActorWithBody, item: GameItem?, reachMu
//fun IntRange.pickRandom() = HQRNG().nextInt(this.last - this.first + 1) + this.first // count() on 200 million entries? Se on vitun hyvää idea
//fun IntArray.pickRandom(): Int = this[HQRNG().nextInt(this.size)]
//fun DoubleArray.pickRandom(): Double = this[HQRNG().nextInt(this.size)]
fun ItemID.isItem() = this.startsWith("item@")
fun ItemID.isWire() = this.startsWith("wire@")
fun ItemID.isDynamic() = this.startsWith("$PREFIX_DYNAMICITEM:")
fun ItemID.isActor() = this.startsWith("$PREFIX_ACTORITEM@")
fun ItemID.isVirtual() = this.startsWith("$PREFIX_VIRTUALTILE@")
fun ItemID.isBlock() = !this.contains('@')
fun ItemID.isWall() = this.startsWith("wall@")

View File

@@ -8,8 +8,7 @@ import net.torvald.terrarum.ReferencingRanges
import net.torvald.terrarum.ReferencingRanges.PREFIX_ACTORITEM
import net.torvald.terrarum.ReferencingRanges.PREFIX_DYNAMICITEM
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.*
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.CanBeAnItem
import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
@@ -132,27 +131,23 @@ class ItemCodex {
fun getItemImage(itemID: ItemID?): TextureRegion? {
if (itemID == null) return null
// dynamic item
if (itemID.startsWith("$PREFIX_DYNAMICITEM:")) {
if (itemID.isDynamic()) {
return getItemImage(dynamicToStaticID(itemID))
}
// item
else if (itemID.startsWith("item@")) {
else if (itemID.isItem()) {
return itemCodex[itemID]?.itemImage
}
// wires
else if (itemID.startsWith("wire@")) {
else if (itemID.isWire()) {
return itemCodex[itemID]?.itemImage
}
// wall
else if (itemID.startsWith("wall@")) {
else if (itemID.isWall()) {
val itemSheetNumber = App.tileMaker.tileIDtoItemSheetNumber(itemID.substring(5))
return BlocksDrawer.tileItemWall.get(
itemSheetNumber % App.tileMaker.TILES_IN_X,
itemSheetNumber / App.tileMaker.TILES_IN_X
)
}
// terrain
// else: terrain
else {
val itemSheetNumber = App.tileMaker.tileIDtoItemSheetNumber(itemID)
return BlocksDrawer.tileItemTerrain.get(

View File

@@ -9,7 +9,6 @@ import net.torvald.spriteanimation.HasAssembledSprite
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.terrarum.gameitems.GameItem
@@ -28,7 +27,7 @@ import org.dyn4j.geometry.Vector2
*
* Created by minjaesong on 2016-10-24.
*/
open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, Luminous, LandHolder, HistoricalFigure {
open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, LandHolder, HistoricalFigure {
protected constructor()
@@ -100,15 +99,10 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*/
override val lightBoxList: List<Lightbox>
get() = arrayOf(Lightbox(Hitbox(2.0, 2.0, baseHitboxW - 3.0, baseHitboxH - 3.0), actorValueColour)).toList() // things are asymmetric!!
// use getter; dimension of the player may change by time.
// scaling of the lightbox is performed on the LightmapRenderer. Getter is still required because of the changing actorValueColour. Lightbox.light cannot be `() -> Cvec` due to performance and serialising issue.
override val shadeBoxList: List<Lightbox>
get() = arrayOf(Lightbox(Hitbox(2.0, 2.0, baseHitboxW - 3.0, baseHitboxH - 3.0), actorValueShade)).toList() // things are asymmetric!!
// use getter; dimension of the player may change by time.
// scaling of the shadebox is performed on the LightmapRenderer. Getter is still required because of the changing actorValueColour. Lightbox.light cannot be `() -> Cvec` due to performance and serialising issue.
@Transient override var lightBoxList: List<Lightbox> = listOf(Lightbox(Hitbox(2.0, 2.0, baseHitboxW - 3.0, baseHitboxH - 3.0), Cvec(0)))
// the actual values are update on the update()
@Transient override var shadeBoxList: List<Lightbox> = listOf(Lightbox(Hitbox(2.0, 2.0, baseHitboxW - 3.0, baseHitboxH - 3.0), Cvec(0)))
// the actual values are update on the update()
@Transient val BASE_DENSITY = 980.0
@@ -201,6 +195,11 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
}
override fun update(delta: Float) {
// update lightbox
lightBoxList[0].light = actorValueColour
shadeBoxList[0].light = actorValueShade
super.update(delta)
if (vehicleRiding is IngamePlayer)

View File

@@ -3,16 +3,14 @@ package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.jme3.math.FastMath
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.ItemCodex
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.PhysProperties
import net.torvald.terrarum.gameactors.drawBodyInGoodPosition
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameitems.*
/**
* Created by minjaesong on 2016-03-15.
@@ -38,6 +36,14 @@ open class DroppedItem : ActorWithBody {
fun canBePickedUp() = timeSinceSpawned > NO_PICKUP_TIME && !flagDespawn
private val randKey1 = (Math.random() * 256).toInt()
private val randKey2 = (Math.random() * 256).toInt()
override var lightBoxList = listOf(Lightbox(this.hitbox.clone().setPosition(0.0, 0.0), Cvec(0)))
// the Cvec will be calculated dynamically on Update
override var shadeBoxList = listOf(Lightbox(this.hitbox.clone().setPosition(0.0, 0.0), Cvec(0)))
// the Cvec will be calculated dynamically on Update
/**
* @param topLeftX world-wise coord
* @param topLeftY world-wise coord
@@ -45,12 +51,12 @@ open class DroppedItem : ActorWithBody {
constructor(itemID: ItemID, topLeftX: Double, topLeftY: Double) : super(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT) {
this.itemID = itemID
if (itemID.startsWith("actor@"))
if (itemID.isActor())
throw RuntimeException("Attempted to create DroppedItem actor of a real actor; the real actor must be dropped instead.")
isVisible = true
avBaseMass = if (itemID.startsWith("item@") || itemID.startsWith("wire@"))
avBaseMass = if (itemID.isItem() || itemID.isWire())
(ItemCodex[itemID]?.mass ?: 2.0).coerceAtMost(2.0)
else
BlockCodex[itemID].density / 1000.0 // block and wall
@@ -73,7 +79,6 @@ open class DroppedItem : ActorWithBody {
Math.cos(Math.random() * Math.PI / 2 + Math.PI / 2) * magn
else
Math.cos(Math.random() * Math.PI) * magn
}
override fun drawBody(batch: SpriteBatch) {
@@ -104,6 +109,12 @@ open class DroppedItem : ActorWithBody {
}
override fun update(delta: Float) {
if (this.itemID.isBlock() || this.itemID.isItem()) {
BlockCodex[this.itemID].let {
this.lightBoxList[0].light = it.getLumCol(randKey1, randKey2)
}
}
super.update(delta)
timeSinceSpawned += delta

View File

@@ -22,7 +22,7 @@ import kotlin.math.absoluteValue
*
* Created by minjaesong on 2022-07-15.
*/
open class FixtureSwingingDoorBase : FixtureBase, Luminous {
open class FixtureSwingingDoorBase : FixtureBase {
/* OVERRIDE THESE TO CUSTOMISE */
var tw = 2 // tilewise width of the door when opened
@@ -45,8 +45,10 @@ open class FixtureSwingingDoorBase : FixtureBase, Luminous {
private var pixelwiseHitboxHeight = TILE_SIZE * tilewiseHitboxHeight
private var tilewiseDistToAxis = tw - twClosed
@Transient override val lightBoxList: ArrayList<Lightbox> = ArrayList()
@Transient override val shadeBoxList: ArrayList<Lightbox> = ArrayList()
@Transient override var lightBoxList = listOf(Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), Cvec(0)))
// the Cvec will be calculated dynamically on Update
@Transient override var shadeBoxList = listOf(Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), Cvec(0)))
// the Cvec will be calculated dynamically on Update
protected var doorState = 0 // -1: open toward left, 0: closed, 1: open toward right
protected var doorStateTimer: Second = 0f
@@ -123,8 +125,7 @@ open class FixtureSwingingDoorBase : FixtureBase, Luminous {
// define light/shadebox
// TODO: redefine when opened to left/right
(if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList).add(
Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), opacity))
(if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList)[0].light = opacity
// define physical size
setHitboxDimension(TILE_SIZE * tilewiseHitboxWidth, TILE_SIZE * tilewiseHitboxHeight, 0, 0)
@@ -148,8 +149,7 @@ open class FixtureSwingingDoorBase : FixtureBase, Luminous {
// define light/shadebox
// TODO: redefine when opened to left/right
(if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList).add(
Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), opacity))
(if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList)[0].light = opacity
}

View File

@@ -1,8 +1,6 @@
package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.gdx.graphics.Cvec
import net.torvald.random.HQRNG
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.CommonResourcePool
@@ -12,7 +10,6 @@ import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Lightbox
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameparticles.ParticleVanishingSprite
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -21,20 +18,12 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2016-06-17.
*/
internal class FixtureTikiTorch : FixtureBase, Luminous {
internal class FixtureTikiTorch : FixtureBase {
private val rng = HQRNG()
private val rndHash1 = rng.nextInt()
private val rndHash2 = rng.nextInt()
private val rndHash1 = (Math.random() * 256).toInt()
private val rndHash2 = (Math.random() * 256).toInt()
private var color: Cvec
get() = try { BlockCodex[Block.TORCH].getLumCol(rndHash1, rndHash2) } catch (e: NullPointerException) { Cvec() }
set(value) {
throw UnsupportedOperationException()
}
@Transient override val lightBoxList: ArrayList<Lightbox> = ArrayList(1)
@Transient override val shadeBoxList: ArrayList<Lightbox> = ArrayList(1)
@Transient override var lightBoxList = listOf(Lightbox(Hitbox(6.0, 5.0, 4.0, 3.0), BlockCodex[Block.TORCH].getLumCol(rndHash1, rndHash2)))
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 1, 2),
@@ -51,8 +40,6 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
setHitboxDimension(16, 32, 0, 0)
lightBoxList.add(Lightbox(Hitbox(6.0, 5.0, 4.0, 3.0), color))
makeNewSprite(FixtureBase.getSpritesheet("basegame", "sprites/fixtures/tiki_torch.tga", 16, 32)).let {
it.setRowsAndFrames(1,2)
}
@@ -64,18 +51,20 @@ internal class FixtureTikiTorch : FixtureBase, Luminous {
private var spawnTimer = 0f
override fun update(delta: Float) {
lightBoxList[0].light = BlockCodex[Block.TORCH].getLumCol(rndHash1, rndHash2)
super.update(delta)
if (spawnTimer >= nextDelay) {
(Terrarum.ingame as TerrarumIngame).addParticle(ParticleVanishingSprite(
CommonResourcePool.getAsTextureRegionPack("particles-tiki_smoke.tga"),
25f, true, hitbox.centeredX, hitbox.startY, false, rng.nextInt(256)
25f, true, hitbox.centeredX, hitbox.startY, false, (Math.random() * 256).toInt()
))
spawnTimer -= nextDelay
nextDelay = rng.nextFloat() * 0.25f + 0.25f
nextDelay = Math.random().toFloat() * 0.25f + 0.25f
(sprite as? SheetSpriteAnimation)?.delays?.set(0, rng.nextFloat() * 0.4f + 0.1f)
(sprite as? SheetSpriteAnimation)?.delays?.set(0, Math.random().toFloat() * 0.4f + 0.1f)
}
spawnTimer += delta

View File

@@ -1,13 +1,13 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.PhysProperties
import net.torvald.terrarum.gameitems.ItemID
/**
* Created by minjaesong on 2016-04-26.
*/
class ItemCarrying : ActorWithBody, Luminous {
class ItemCarrying : ActorWithBody {
var itemID: ItemID = ""; private set
@@ -20,30 +20,6 @@ class ItemCarrying : ActorWithBody, Luminous {
// just let the solver use AABB; it's cheap but works just enough
/**
* Recommended implementation:
*
override var color: Int
get() = actorValue.getAsInt(AVKey.LUMINOSITY) ?: 0
set(value) {
actorValue[AVKey.LUMINOSITY] = value
}
*/
private var color: Cvec
get() = throw UnsupportedOperationException()
set(value) {
}
/**
* Arguments:
*
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*/
override val lightBoxList: List<Lightbox>
get() = throw UnsupportedOperationException()
override val shadeBoxList: List<Lightbox>
get() = throw UnsupportedOperationException()
init {
}

View File

@@ -3,14 +3,15 @@ package net.torvald.terrarum.modulebasegame.gameactors
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.BlockCodex
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.Point2d
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Lightbox
import net.torvald.terrarum.gameactors.PhysProperties
import org.dyn4j.geometry.Vector2
import java.util.*
import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.*
/**
* Simplest projectile.
@@ -19,7 +20,7 @@ import net.torvald.terrarum.gameactors.*
*/
// TODO simplified, lightweight physics (does not call PhysicsSolver)
open class ProjectileSimple : ActorWithBody, Luminous, Projectile {
open class ProjectileSimple : ActorWithBody, Projectile {
private var type: Int = 0
var damage: Int = 0
@@ -38,8 +39,8 @@ open class ProjectileSimple : ActorWithBody, Luminous, Projectile {
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*/
@Transient override val lightBoxList = ArrayList<Lightbox>()
@Transient override val shadeBoxList = ArrayList<Lightbox>()
@Transient override var lightBoxList = listOf(Lightbox(Hitbox(-4.0, -4.0, 8.0, 8.0), color)) // lightbox sized 8x8 centered to the bullet
private val lifetimeMax = 2500
private var lifetimeCounter = 0f
@@ -57,8 +58,6 @@ open class ProjectileSimple : ActorWithBody, Luminous, Projectile {
setPosition(fromPoint.x, fromPoint.y)
posPre = Point2d(fromPoint.x, fromPoint.y)
// lightbox sized 8x8 centered to the bullet
lightBoxList.add(Lightbox(Hitbox(-4.0, -4.0, 8.0, 8.0), color))
//this.externalV.set(velocity)
damage = bulletDatabase[type][OFFSET_DAMAGE] as Int

View File

@@ -5,6 +5,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameitems.isWall
import net.torvald.terrarum.gameitems.mouseInInteractableRange
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -40,7 +41,7 @@ object BlockBase {
if (!ret1) return@mouseInInteractableRange -1L
}
val isWall = itemID.startsWith("wall@")
val isWall = itemID.isWall()
val terrainUnderCursor = ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y)
val wallUnderCursor = ingame.world.getTileFromWall(mouseTile.x, mouseTile.y)

View File

@@ -12,10 +12,8 @@ import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockProp
import net.torvald.terrarum.blockproperties.Fluid
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameworld.BlockAddress
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.ui.abs
import net.torvald.terrarum.realestate.LandUtil
@@ -349,46 +347,44 @@ object LightmapRenderer {
lanternMap.clear()
shadowMap.clear()
actorContainer.forEach {
if (it is Luminous) {
val lightBoxCopy = it.lightBoxList.subList(0, it.lightBoxList.size) // make copy to prevent ConcurrentModificationException
val shadeBoxCopy = it.shadeBoxList.subList(0, it.shadeBoxList.size) // make copy to prevent ConcurrentModificationException
val scale = it.scale
val lightBoxCopy = it.lightBoxList.subList(0, it.lightBoxList.size) // make copy to prevent ConcurrentModificationException
val shadeBoxCopy = it.shadeBoxList.subList(0, it.shadeBoxList.size) // make copy to prevent ConcurrentModificationException
val scale = it.scale
// put lanterns to the area the luminantBox is occupying
lightBoxCopy.forEach { (lightBox, colour) ->
val lightBoxX = it.hitbox.startX + (lightBox.startX * scale)
val lightBoxY = it.hitbox.startY + (lightBox.startY * scale)
val lightBoxW = lightBox.width * scale
val lightBoxH = lightBox.height * scale
for (y in lightBoxY.div(TILE_SIZE).floorInt()
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
for (x in lightBoxX.div(TILE_SIZE).floorInt()
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
// put lanterns to the area the luminantBox is occupying
lightBoxCopy.forEach { (lightBox, colour) ->
val lightBoxX = it.hitbox.startX + (lightBox.startX * scale)
val lightBoxY = it.hitbox.startY + (lightBox.startY * scale)
val lightBoxW = lightBox.width * scale
val lightBoxH = lightBox.height * scale
for (y in lightBoxY.div(TILE_SIZE).floorInt()
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
for (x in lightBoxX.div(TILE_SIZE).floorInt()
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
val oldLight = lanternMap[LandUtil.getBlockAddr(world, x, y)] ?: Cvec(0) // if two or more luminous actors share the same block, mix the light
val actorLight = colour
val oldLight = lanternMap[LandUtil.getBlockAddr(world, x, y)] ?: Cvec(0) // if two or more luminous actors share the same block, mix the light
val actorLight = colour
lanternMap[LandUtil.getBlockAddr(world, x, y)] = oldLight.maxAndAssign(actorLight)
}
lanternMap[LandUtil.getBlockAddr(world, x, y)] = oldLight.maxAndAssign(actorLight)
}
}
}
// put shades to the area the luminantBox is occupying
shadeBoxCopy.forEach { (shadeBox, colour) ->
val lightBoxX = it.hitbox.startX + (shadeBox.startX * scale)
val lightBoxY = it.hitbox.startY + (shadeBox.startY * scale)
val lightBoxW = shadeBox.width * scale
val lightBoxH = shadeBox.height * scale
for (y in lightBoxY.div(TILE_SIZE).floorInt()
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
for (x in lightBoxX.div(TILE_SIZE).floorInt()
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
// put shades to the area the luminantBox is occupying
shadeBoxCopy.forEach { (shadeBox, colour) ->
val lightBoxX = it.hitbox.startX + (shadeBox.startX * scale)
val lightBoxY = it.hitbox.startY + (shadeBox.startY * scale)
val lightBoxW = shadeBox.width * scale
val lightBoxH = shadeBox.height * scale
for (y in lightBoxY.div(TILE_SIZE).floorInt()
..lightBoxY.plus(lightBoxH).div(TILE_SIZE).floorInt()) {
for (x in lightBoxX.div(TILE_SIZE).floorInt()
..lightBoxX.plus(lightBoxW).div(TILE_SIZE).floorInt()) {
val oldLight = shadowMap[LandUtil.getBlockAddr(world, x, y)] ?: Cvec(0) // if two or more luminous actors share the same block, mix the light
val actorLight = colour
val oldLight = shadowMap[LandUtil.getBlockAddr(world, x, y)] ?: Cvec(0) // if two or more luminous actors share the same block, mix the light
val actorLight = colour
shadowMap[LandUtil.getBlockAddr(world, x, y)] = oldLight.maxAndAssign(actorLight)
}
shadowMap[LandUtil.getBlockAddr(world, x, y)] = oldLight.maxAndAssign(actorLight)
}
}
}