From bec47e81e27435aa70b2c16bdd34f4bcabe776fd Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 11 Sep 2022 17:10:01 +0900 Subject: [PATCH] now dropped items can produce light (e.g. dropped torch) --- assets/mods/basegame/blocks/blocks.csv | 12 ++-- .../terrarum/blockproperties/BlockCodex.kt | 2 +- .../terrarum/debuggerapp/CSVEditor.java | 4 +- .../terrarum/gameactors/ActorWithBody.kt | 22 +++++++ .../torvald/terrarum/gameactors/Luminous.kt | 6 +- .../torvald/terrarum/gameitems/GameItem.kt | 10 +++ .../terrarum/itemproperties/ItemCodex.kt | 17 ++--- .../gameactors/ActorHumanoid.kt | 21 +++--- .../modulebasegame/gameactors/DroppedItem.kt | 27 +++++--- .../gameactors/FixtureSwingingDoorBase.kt | 14 ++-- .../gameactors/FixtureTikiTorch.kt | 29 +++------ .../modulebasegame/gameactors/ItemCarrying.kt | 30 +-------- .../gameactors/ProjectileSimple.kt | 19 +++--- .../modulebasegame/gameitems/BlockBase.kt | 3 +- .../terrarum/worlddrawer/LightmapRenderer.kt | 64 +++++++++---------- 15 files changed, 140 insertions(+), 140 deletions(-) diff --git a/assets/mods/basegame/blocks/blocks.csv b/assets/mods/basegame/blocks/blocks.csv index 8309d34cb..b87d8d6cc 100644 --- a/assets/mods/basegame/blocks/blocks.csv +++ b/assets/mods/basegame/blocks/blocks.csv @@ -1,4 +1,4 @@ -"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" +"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" "0";"0";"0";"BLOCK_AIR";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"1";"N/A";"0";"0";"4";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"" "16";"17";"17";"BLOCK_STONE";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"ROCK,NATURAL" "17";"17";"17";"BLOCK_STONE_QUARRIED";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"ROCK" @@ -55,10 +55,10 @@ "162";"162";"162";"BLOCK_PLATFORM_EBONY";"0.0312";"0.0312";"0.0312";"0.0312";"5";"1200";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"PLATFORM" "163";"163";"163";"BLOCK_PLATFORM_BIRCH";"0.0312";"0.0312";"0.0312";"0.0312";"5";"670";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"PLATFORM" "164";"164";"164";"BLOCK_PLATFORM_BLOODROSE";"0.0312";"0.0312";"0.0312";"0.0312";"5";"900";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"PLATFORM" -"176";"176";"192";"BLOCK_TORCH";"0.0312";"0.0312";"0.0312";"0.0312";"1";"800";"FXTR";"0";"0";"N/A";"1";"0";"16";"1.0000";"0.6372";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT" -"177";"177";"193";"BLOCK_TORCH_FROST";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1100";"FXTR";"0";"0";"N/A";"1";"0";"16";"0.3048";"0.4848";"1.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT" -"192";"176";"192";"BLOCK_TORCH";"0.0312";"0.0312";"0.0312";"0.0312";"1";"800";"FXTR";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT,UNLIT" -"193";"177";"193";"BLOCK_TORCH_FROST";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1100";"FXTR";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT,UNLIT" +"176";"176";"176";"BLOCK_TORCH";"0.0312";"0.0312";"0.0312";"0.0312";"1";"800";"FXTR";"0";"0";"N/A";"1";"0";"16";"1.0000";"0.6372";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT" +"177";"177";"177";"BLOCK_TORCH_FROST";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1100";"FXTR";"0";"0";"N/A";"1";"0";"16";"0.3048";"0.4848";"1.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT" +"192";"176";"176";"BLOCK_TORCH";"0.0312";"0.0312";"0.0312";"0.0312";"1";"800";"FXTR";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT,UNLIT" +"193";"177";"177";"BLOCK_TORCH_FROST";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1100";"FXTR";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT,UNLIT" "208";"208";"208";"BLOCK_ILLUMINATOR_WHITE";"0.0312";"0.0312";"0.0312";"0.0312";"1";"2500";"GLAS";"1";"1";"N/A";"0";"0";"16";"0.9270";"0.9414";"0.8519";"0.0000";"N/A";"N/A";"0.0";"LIGHT" "209";"209";"209";"BLOCK_ILLUMINATOR_YELLOW";"0.0312";"0.0312";"0.0312";"0.0312";"1";"2500";"GLAS";"1";"1";"N/A";"0";"0";"16";"1.0000";"0.8408";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT" "210";"210";"210";"BLOCK_ILLUMINATOR_ORANGE";"0.0312";"0.0312";"0.0312";"0.0312";"1";"2500";"GLAS";"1";"1";"N/A";"0";"0";"16";"1.0000";"0.5294";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT" @@ -123,7 +123,7 @@ # # id: Block ID. ID equal to or greater than 4096 is for fluids, mainly for lighting calculation. # 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 # # Drop and World can point to the item from other modules (usually 'basegame') # To achieve that, specify the full ID, e.g. basegame:32 diff --git a/src/net/torvald/terrarum/blockproperties/BlockCodex.kt b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt index 98dfe7741..e50a8bca8 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockCodex.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt @@ -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") diff --git a/src/net/torvald/terrarum/debuggerapp/CSVEditor.java b/src/net/torvald/terrarum/debuggerapp/CSVEditor.java index a426527ce..de373d3f2 100644 --- a/src/net/torvald/terrarum/debuggerapp/CSVEditor.java +++ b/src/net/torvald/terrarum/debuggerapp/CSVEditor.java @@ -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.0–1.0+ shdg=Shade Green (light absorption). Valid range 0.0–1.0+ diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index ae3cfa4d0..9f134df92 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -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 = emptyList() + + /** + * Arguments: + * + * Hitbox(x-offset, y-offset, width, height) + * (Use ArrayList for normal circumstances) + * + * NOTE: MUST NOT SERIALISE (use `@Transient`) + */ + open var shadeBoxList: List = emptyList() + // end of Luminous + protected constructor() : super() constructor(renderOrder: RenderOrder, physProp: PhysProperties, id: ActorID? = null) : super(renderOrder, id) { diff --git a/src/net/torvald/terrarum/gameactors/Luminous.kt b/src/net/torvald/terrarum/gameactors/Luminous.kt index f6e6763ab..532d39737 100644 --- a/src/net/torvald/terrarum/gameactors/Luminous.kt +++ b/src/net/torvald/terrarum/gameactors/Luminous.kt @@ -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 -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/src/net/torvald/terrarum/gameitems/GameItem.kt b/src/net/torvald/terrarum/gameitems/GameItem.kt index 7193fdccd..4cd2c764e 100644 --- a/src/net/torvald/terrarum/gameitems/GameItem.kt +++ b/src/net/torvald/terrarum/gameitems/GameItem.kt @@ -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@") diff --git a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt index 2c0399540..0bf1cc6dc 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt @@ -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( diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt index f587045c4..5be2646d2 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorHumanoid.kt @@ -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 - 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 - 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 = 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 = 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) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt index bd6cf00c8..7d7a67e10 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt @@ -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 diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt index b36c30773..d8f231361 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt @@ -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 = ArrayList() - @Transient override val shadeBoxList: ArrayList = 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 } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt index bfb0a140b..f77fac44b 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt @@ -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 = ArrayList(1) - @Transient override val shadeBoxList: ArrayList = 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 diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ItemCarrying.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ItemCarrying.kt index 4afefccf4..14489d481 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ItemCarrying.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ItemCarrying.kt @@ -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 - get() = throw UnsupportedOperationException() - override val shadeBoxList: List - get() = throw UnsupportedOperationException() - init { } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt index 8c6c200aa..20f832dac 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ProjectileSimple.kt @@ -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() - @Transient override val shadeBoxList = ArrayList() + @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 diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt index 28484bf78..17b159475 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt @@ -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) diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt index 67604e43d..f40a093a5 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt @@ -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) } } }