From 995d02d966b19be00109de028c9427ec441ebd19 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 8 Aug 2021 21:38:38 +0900 Subject: [PATCH] signal emitter is now a fixture --- assets/mods/basegame/blocks/blocks.csv | 2 +- assets/mods/basegame/items/itemid.csv | 1 + .../fixtures/signal_source.tga} | 0 .../terrarum/gameworld/WorldSimulator.kt | 24 ++++- .../modulebasegame/gameactors/FixtureBase.kt | 11 +-- .../gameactors/FixtureLogicSignalEmitter.kt | 31 +++++++ .../gameactors/PlayerBuilderSigrid.kt | 1 + .../gameitems/ItemLogicSignalEmitter.kt | 48 ++++++++++ .../worlddrawer/LightCalculatorContext.kt | 24 ----- .../terrarum/worlddrawer/LightmapRenderer.kt | 93 ------------------- 10 files changed, 109 insertions(+), 126 deletions(-) rename assets/mods/basegame/{blocks/5000.tga => sprites/fixtures/signal_source.tga} (100%) create mode 100644 src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt create mode 100644 src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalEmitter.kt delete mode 100644 src/net/torvald/terrarum/worlddrawer/LightCalculatorContext.kt diff --git a/assets/mods/basegame/blocks/blocks.csv b/assets/mods/basegame/blocks/blocks.csv index f1d30bc21..6eef08fdb 100644 --- a/assets/mods/basegame/blocks/blocks.csv +++ b/assets/mods/basegame/blocks/blocks.csv @@ -111,7 +111,7 @@ "65536";"0";"BLOCK_WATER";"0.1016";"0.0744";"0.0508";"0.0826";"100";"1000";"WATR";"0";"0";"0";"0";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"005599A6";"16";"0.0" "65537";"0";"BLOCK_LAVA";"0.9696";"0.9696";"0.9696";"0.9696";"100";"2600";"ROCK";"0";"0";"0";"0";"0";"0";"16";"0.7664";"0.2032";"0.0000";"0.0000";"FF4600E6";"32";"0.0" "-1";"0";"BLOCK_NULL";"4.0000";"4.0000";"4.0000";"4.0000";"-1";"2600";"NULL";"0";"0";"1";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0" -"5000";"5000";"BLOCK_SIGNAL_POWER_SOURCE";"0.1252";"0.1252";"0.1252";"0.1252";"24";"1400";"NULL";"0";"0";"0";"N/A";"0";"4";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" +#"5000";"5000";"BLOCK_SIGNAL_POWER_SOURCE";"0.1252";"0.1252";"0.1252";"0.1252";"24";"1400";"NULL";"0";"0";"0";"N/A";"0";"4";"16";"0.0";"0.0";"0.0";"0.0";"N/A";"N/A";"0.0" ## Notes ## diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index a6704e8b8..338f5fd09 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -5,3 +5,4 @@ "5";"net.torvald.terrarum.modulebasegame.gameitems.TikiTorchTester" "6";"net.torvald.terrarum.modulebasegame.gameitems.ItemStorageChest" "7";"net.torvald.terrarum.modulebasegame.gameitems.WireGraphDebugger" +"8";"net.torvald.terrarum.modulebasegame.gameitems.ItemLogicSignalEmitter" diff --git a/assets/mods/basegame/blocks/5000.tga b/assets/mods/basegame/sprites/fixtures/signal_source.tga similarity index 100% rename from assets/mods/basegame/blocks/5000.tga rename to assets/mods/basegame/sprites/fixtures/signal_source.tga diff --git a/src/net/torvald/terrarum/gameworld/WorldSimulator.kt b/src/net/torvald/terrarum/gameworld/WorldSimulator.kt index 5826e7063..2adbb7491 100644 --- a/src/net/torvald/terrarum/gameworld/WorldSimulator.kt +++ b/src/net/torvald/terrarum/gameworld/WorldSimulator.kt @@ -10,6 +10,8 @@ import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gameitem.ItemID import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid +import net.torvald.terrarum.worlddrawer.BlocksDrawer +import net.torvald.terrarum.worlddrawer.WorldCamera import org.khelekore.prtree.* import kotlin.math.roundToInt @@ -447,8 +449,28 @@ object WorldSimulator { } - private fun simulateWires(delta: Float) { + private val wiresimOverscan = 60 + /*private fun wiresimGetSourceBlocks(): List { + val ret = ArrayList() + + val for_y_start = (WorldCamera.y.toFloat() / TILE_SIZE).floorInt() + val for_y_end = for_y_start + BlocksDrawer.tilesInVertical - 1 + + val for_x_start = (WorldCamera.x.toFloat() / TILE_SIZE).floorInt() + val for_x_end = for_x_start + BlocksDrawer.tilesInHorizontal - 1 + + for (y in for_y_start - wiresimOverscan..for_y_end + wiresimOverscan) { + for (x in for_x_start - wiresimOverscan..for_x_end + wiresimOverscan) { + + } + } + + return ret + }*/ + + private fun simulateWires(delta: Float) { + //val sourceBlocks = wiresimGetSourceBlocks() } private enum class WireConStatus { THRU, END, BRANCH } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index e938f6aea..69743d656 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -12,6 +12,7 @@ import net.torvald.terrarum.gameactors.PhysProperties import net.torvald.terrarum.gameitem.ItemID import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.ui.UICanvas +import org.dyn4j.geometry.Vector2 /** * Created by minjaesong on 2016-06-17. @@ -29,6 +30,9 @@ open class FixtureBase( var blockBox: BlockBox = blockBox0 protected set // something like TapestryObject will want to redefine this + open val wireEmitterType = "" + open val wireEmission = Vector2() + open val wireConsumption = Vector2() /** * Block-wise position of this fixture when it's placed on the world. Null if it's not on the world @@ -103,13 +107,6 @@ open class FixtureBase( } - /** - * Update code that runs once for every frame - */ - open fun updateSelf() { - - } - /** * Removes this instance of the fixture from the world */ diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt new file mode 100644 index 000000000..fc6601f8f --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureLogicSignalEmitter.kt @@ -0,0 +1,31 @@ +package net.torvald.terrarum.modulebasegame.gameactors + +import net.torvald.terrarum.CommonResourcePool +import net.torvald.terrarum.ModMgr +import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE +import net.torvald.terrarum.gameactors.AVKey +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack +import org.dyn4j.geometry.Vector2 + +class FixtureLogicSignalEmitter(nameFun: () -> String) : FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1, 1), nameFun = nameFun) { + + override val wireEmitterType = "digital_bit" + override val wireEmission = Vector2(1.0, 0.0) + + init { + density = 1400.0 + setHitboxDimension(TILE_SIZE, TILE_SIZE, 0, -1) + + makeNewSprite(TextureRegionPack(CommonResourcePool.getAsTextureRegion("basegame-sprites-fixtures-signal_source.tga").texture, TILE_SIZE, TILE_SIZE)) + sprite!!.setRowsAndFrames(1, 1) + + actorValue[AVKey.BASEMASS] = MASS + } + + override fun dispose() { } + + companion object { + const val MASS = 1.0 + } +} + diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt index 264ab8da8..05eb44e32 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt @@ -96,6 +96,7 @@ object PlayerBuilderSigrid { inventory.add("item@basegame:5", 385930603) // test tiki torch inventory.add("item@basegame:6", 95) // storage chest inventory.add("item@basegame:7", 1) // wire debugger + inventory.add("item@basegame:8", 9995) // power source WireCodex.getAll().forEach { try { diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalEmitter.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalEmitter.kt new file mode 100644 index 000000000..10478112d --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemLogicSignalEmitter.kt @@ -0,0 +1,48 @@ +package net.torvald.terrarum.modulebasegame.gameitems + +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.terrarum.CommonResourcePool +import net.torvald.terrarum.ModMgr +import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.gameitem.GameItem +import net.torvald.terrarum.gameitem.ItemID +import net.torvald.terrarum.itemproperties.Material +import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.modulebasegame.gameactors.FixtureLogicSignalEmitter + +class ItemLogicSignalEmitter(originalID: ItemID) : GameItem(originalID) { + + override var dynamicID: ItemID = originalID + override val originalName = "ITEM_TIKI_TORCH" + override var baseMass = FixtureLogicSignalEmitter.MASS + override var stackable = true + override var inventoryCategory = Category.FIXTURE + override val isUnique = false + override val isDynamic = false + override val material = Material() + override val itemImage: TextureRegion + get() = CommonResourcePool.getAsTextureRegion("basegame-sprites-fixtures-signal_source.tga") + override var baseToolSize: Double? = baseMass + + init { + CommonResourcePool.addToLoadingList("basegame-sprites-fixtures-signal_source.tga") { + val t = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "sprites/fixtures/signal_source.tga"))) + t.flip(false, true) + /*return*/t + } + CommonResourcePool.loadAll() + + equipPosition = EquipPosition.HAND_GRIP + } + + override fun startPrimaryUse(delta: Float): Boolean { + val item = FixtureLogicSignalEmitter { Lang[originalName] } + + return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY) + // return true when placed, false when cannot be placed + } + + + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/worlddrawer/LightCalculatorContext.kt b/src/net/torvald/terrarum/worlddrawer/LightCalculatorContext.kt deleted file mode 100644 index ecb74c57a..000000000 --- a/src/net/torvald/terrarum/worlddrawer/LightCalculatorContext.kt +++ /dev/null @@ -1,24 +0,0 @@ -package net.torvald.terrarum.worlddrawer - -import net.torvald.gdx.graphics.Cvec -import net.torvald.gdx.graphics.UnsafeCvecArray -import net.torvald.terrarum.blockproperties.Block.AIR -import net.torvald.terrarum.blockproperties.BlockCodex -import net.torvald.terrarum.blockproperties.Fluid -import net.torvald.terrarum.gameworld.BlockAddress -import net.torvald.terrarum.gameworld.GameWorld -import net.torvald.terrarum.modulebasegame.ui.abs -import net.torvald.terrarum.realestate.LandUtil -import kotlin.system.exitProcess - -/** - * Created by minjaesong on 2020-03-04 - */ - -internal class LightCalculatorContext( - private val world: GameWorld, - private val lightmap: UnsafeCvecArray, - private val lanternMap: HashMap -) { - // No longer in use because of the much efficient light updating method -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt index c2648b67f..ac0a49ca3 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt @@ -211,46 +211,9 @@ object LightmapRenderer { } } - // YE OLDE LIGHT UPDATER - // O((5*9)n where n is a size of the map. - // Because of inevitable overlaps on the area, it only works with MAX blend - /*fun or1() { - // Round 1 - for (y in for_y_start - overscan_open..for_y_end) { - for (x in for_x_start - overscan_open..for_x_end) { - calculateAndAssign(lightmap, x, y) - } - } - } - fun or2() { - // Round 2 - for (y in for_y_end + overscan_open downTo for_y_start) { - for (x in for_x_start - overscan_open..for_x_end) { - calculateAndAssign(lightmap, x, y) - } - } - } - fun or3() { - // Round 3 - for (y in for_y_end + overscan_open downTo for_y_start) { - for (x in for_x_end + overscan_open downTo for_x_start) { - calculateAndAssign(lightmap, x, y) - } - } - } - fun or4() { - // Round 4 - for (y in for_y_start - overscan_open..for_y_end) { - for (x in for_x_end + overscan_open downTo for_x_start) { - calculateAndAssign(lightmap, x, y) - } - } - }*/ - // 'NEWLIGHT2' LIGHT SWIPER // O((8*2)n) where n is a size of the map. fun r1() { - // TODO test non-parallel swipeDiag = false for (line in 1 until LIGHTMAP_HEIGHT - 1) { swipeLight( @@ -261,7 +224,6 @@ object LightmapRenderer { } } fun r2() { - // TODO test non-parallel swipeDiag = false for (line in 1 until LIGHTMAP_WIDTH - 1) { swipeLight( @@ -272,7 +234,6 @@ object LightmapRenderer { } } fun r3() { - // TODO test non-parallel swipeDiag = true /* construct indices such that: 56789ABC @@ -310,7 +271,6 @@ object LightmapRenderer { } } fun r4() { - // TODO test non-parallel swipeDiag = true /* 1 w-2 @@ -612,59 +572,6 @@ object LightmapRenderer { } } - /** Another YE OLDE light simulator - * Calculates the light simulation, using main lightmap as one of the input. - */ - /*private fun calculateAndAssign(lightmap: UnsafeCvecArray, worldX: Int, worldY: Int) { - - //if (inNoopMask(worldX, worldY)) return - - // O(9n) == O(n) where n is a size of the map - - //getLightsAndShades(worldX, worldY) - - val x = worldX.convX() - val y = worldY.convY() - - // calculate ambient - /* + * + 0 4 1 - * * @ * 6 @ 7 - * + * + 2 5 3 - * sample ambient for eight points and apply attenuation for those - * maxblend eight values and use it - */ - - - // TODO getLightsAndShades is replaced with precalculate; change following codes accordingly! - _ambientAccumulator.r = _mapLightLevelThis.getR(x, y) - _ambientAccumulator.g = _mapLightLevelThis.getG(x, y) - _ambientAccumulator.b = _mapLightLevelThis.getB(x, y) - _ambientAccumulator.a = _mapLightLevelThis.getA(x, y) - - _thisTileOpacity.r = _mapThisTileOpacity.getR(x, y) - _thisTileOpacity.g = _mapThisTileOpacity.getG(x, y) - _thisTileOpacity.b = _mapThisTileOpacity.getB(x, y) - _thisTileOpacity.a = _mapThisTileOpacity.getA(x, y) - - _thisTileOpacity2.r = _mapThisTileOpacity2.getR(x, y) - _thisTileOpacity2.g = _mapThisTileOpacity2.getG(x, y) - _thisTileOpacity2.b = _mapThisTileOpacity2.getB(x, y) - _thisTileOpacity2.a = _mapThisTileOpacity2.getA(x, y) - - // will "overwrite" what's there in the lightmap if it's the first pass - // takes about 2 ms on 6700K - /* + */_ambientAccumulator.maxAndAssign(darkenColoured(x - 1, y - 1, _thisTileOpacity2)) - /* + */_ambientAccumulator.maxAndAssign(darkenColoured(x + 1, y - 1, _thisTileOpacity2)) - /* + */_ambientAccumulator.maxAndAssign(darkenColoured(x - 1, y + 1, _thisTileOpacity2)) - /* + */_ambientAccumulator.maxAndAssign(darkenColoured(x + 1, y + 1, _thisTileOpacity2)) - /* * */_ambientAccumulator.maxAndAssign(darkenColoured(x, y - 1, _thisTileOpacity)) - /* * */_ambientAccumulator.maxAndAssign(darkenColoured(x, y + 1, _thisTileOpacity)) - /* * */_ambientAccumulator.maxAndAssign(darkenColoured(x - 1, y, _thisTileOpacity)) - /* * */_ambientAccumulator.maxAndAssign(darkenColoured(x + 1, y, _thisTileOpacity)) - - lightmap.setVec(x, y, _ambientAccumulator) - }*/ - private fun isSolid(x: Int, y: Int): Float? { // ...so that they wouldn't appear too dark if (!inBounds(x, y)) return null