From 3de4018d759255f7e020c52b78a620f9a0d8dd98 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 22 Oct 2024 11:41:29 +0900 Subject: [PATCH] renaming some files --- ...ayerI16F16.kt => BlockLayerFluidI16F16.kt} | 0 ...ockLayerI16.kt => BlockLayerGenericI16.kt} | 26 ++++++++++++------- .../torvald/terrarum/gameworld/GameWorld.kt | 18 ++++++------- .../terrarum/modulebasegame/BuildingMaker.kt | 6 ++--- .../modulebasegame/ExplosionManager.kt | 13 ++++------ .../modulebasegame/serialise/LoadSavegame.kt | 10 +++---- src/net/torvald/terrarum/serialise/Common.kt | 16 ++++++------ .../terrarum/serialise/PointOfInterest.kt | 8 +++--- .../terrarum/serialise/ReadSimpleWorld.kt | 4 +-- 9 files changed, 53 insertions(+), 48 deletions(-) rename src/net/torvald/terrarum/gameworld/{BlockLayerI16F16.kt => BlockLayerFluidI16F16.kt} (100%) rename src/net/torvald/terrarum/gameworld/{BlockLayerI16.kt => BlockLayerGenericI16.kt} (82%) diff --git a/src/net/torvald/terrarum/gameworld/BlockLayerI16F16.kt b/src/net/torvald/terrarum/gameworld/BlockLayerFluidI16F16.kt similarity index 100% rename from src/net/torvald/terrarum/gameworld/BlockLayerI16F16.kt rename to src/net/torvald/terrarum/gameworld/BlockLayerFluidI16F16.kt diff --git a/src/net/torvald/terrarum/gameworld/BlockLayerI16.kt b/src/net/torvald/terrarum/gameworld/BlockLayerGenericI16.kt similarity index 82% rename from src/net/torvald/terrarum/gameworld/BlockLayerI16.kt rename to src/net/torvald/terrarum/gameworld/BlockLayerGenericI16.kt index f97f1f4d6..94d4cf62c 100644 --- a/src/net/torvald/terrarum/gameworld/BlockLayerI16.kt +++ b/src/net/torvald/terrarum/gameworld/BlockLayerGenericI16.kt @@ -2,6 +2,9 @@ package net.torvald.terrarum.gameworld import com.badlogic.gdx.utils.Disposable import net.torvald.terrarum.App.printdbg +import net.torvald.terrarum.gameworld.GameWorld.Companion.TERRAIN +import net.torvald.terrarum.gameworld.GameWorld.Companion.WALL +import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.archivers.ClusteredFormatDOM import net.torvald.terrarum.serialise.toUint import net.torvald.unsafe.UnsafeHelper import net.torvald.unsafe.UnsafePtr @@ -18,7 +21,20 @@ import net.torvald.unsafe.UnsafePtr * * Note to self: refrain from using shorts--just do away with two bytes: different system have different endianness */ -open class BlockLayerI16(override val width: Int, override val height: Int) : BlockLayer { +class BlockLayerI16( + override val width: Int, + override val height: Int, + disk: ClusteredFormatDOM, + layerNum: Int, + world: GameWorld +): BlockLayer() { + + override val chunkPool = ChunkPool(disk, layerNum, BYTES_PER_BLOCK, world, when (layerNum) { + TERRAIN -> ChunkPool.getRenameFunTerrain(world) + WALL -> ChunkPool.getRenameFunTerrain(world) + else -> throw IllegalArgumentException("Unknown layer number for I16: $layerNum") + }) + override val bytesPerBlock = BYTES_PER_BLOCK // for some reason, all the efforts of saving the memory space were futile. @@ -33,14 +49,6 @@ open class BlockLayerI16(override val width: Int, override val height: Int) : Bl ptr.fillWith(-1) } - /** - * @param data Byte array representation of the layer - */ - constructor(width: Int, height: Int, data: ByteArray) : this(width, height) { - TODO() - data.forEachIndexed { index, byte -> UnsafeHelper.unsafe.putByte(ptr.ptr + index, byte) } - } - /** * Returns an iterator over stored bytes. * diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index 662f72223..32f8f2c85 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -42,8 +42,8 @@ class PhysicalStatus() { * Special version of GameWorld where everything, including layer data, are saved in a single JSON file (i.e. not chunked) */ class SimpleGameWorld(width: Int, height: Int) : GameWorld(width, height) { - override lateinit var layerWall: BlockLayerI16 - override lateinit var layerTerrain: BlockLayerI16 + override lateinit var layerWall: BlockLayerGenericI16 + override lateinit var layerTerrain: BlockLayerGenericI16 constructor() : this(0, 0) override fun dispose() { layerWall.dispose() @@ -89,10 +89,10 @@ open class GameWorld( } //layers - @Transient open lateinit var layerWall: BlockLayerI16 - @Transient open lateinit var layerTerrain: BlockLayerI16 + @Transient open lateinit var layerWall: BlockLayerGenericI16 + @Transient open lateinit var layerTerrain: BlockLayerGenericI16 @Transient open lateinit var layerOres: BlockLayerOresI16I8 // damage to the block follows `terrainDamages` - @Transient open lateinit var layerFluids: BlockLayerI16F16 + @Transient open lateinit var layerFluids: BlockLayerFluidI16F16 val wallDamages = HashArray() val terrainDamages = HashArray() @@ -230,10 +230,10 @@ open class GameWorld( this.spawnX = width / 2 this.spawnY = 150 - layerTerrain = BlockLayerI16(width, height) - layerWall = BlockLayerI16(width, height) + layerTerrain = BlockLayerGenericI16(width, height) + layerWall = BlockLayerGenericI16(width, height) layerOres = BlockLayerOresI16I8(width, height) - layerFluids = BlockLayerI16F16(width, height) + layerFluids = BlockLayerFluidI16F16(width, height) chunkFlags = Array(height / CHUNK_H) { ByteArray(width / CHUNK_W) } // temperature layer: 2x2 is one cell @@ -544,7 +544,7 @@ open class GameWorld( fun setTileOnLayerUnsafe(layer: Int, x: Int, y: Int, tile: Int) { (getLayer(layer) ?: throw IllegalArgumentException("Unknown layer index: $layer")).let { - if (it !is BlockLayerI16) throw IllegalArgumentException("Block layers other than BlockLayer16 is not supported yet)") + if (it !is BlockLayerGenericI16) throw IllegalArgumentException("Block layers other than BlockLayer16 is not supported yet)") it.unsafeSetTile(x, y, tile) } } diff --git a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt index fd5c7d051..c96bca310 100644 --- a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt +++ b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt @@ -14,7 +14,7 @@ import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.gameparticles.ParticleBase -import net.torvald.terrarum.gameworld.BlockLayerI16 +import net.torvald.terrarum.gameworld.BlockLayerGenericI16 import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid import net.torvald.terrarum.gameworld.WorldTime @@ -877,8 +877,8 @@ class YamlCommandToolExportTest : YamlInvokable { ui.world.tileNameToNumberMap ) val layer = POILayer(name) - val terr = BlockLayerI16(poi.w, poi.h) - val wall = BlockLayerI16(poi.w, poi.h) + val terr = BlockLayerGenericI16(poi.w, poi.h) + val wall = BlockLayerGenericI16(poi.w, poi.h) layer.blockLayer = arrayListOf(terr, wall) poi.layers.add(layer) diff --git a/src/net/torvald/terrarum/modulebasegame/ExplosionManager.kt b/src/net/torvald/terrarum/modulebasegame/ExplosionManager.kt index 81ed12325..96aefcfdf 100644 --- a/src/net/torvald/terrarum/modulebasegame/ExplosionManager.kt +++ b/src/net/torvald/terrarum/modulebasegame/ExplosionManager.kt @@ -1,14 +1,11 @@ package net.torvald.terrarum.modulebasegame -import com.badlogic.gdx.utils.Queue import net.torvald.terrarum.BlockCodex import net.torvald.terrarum.ItemCodex import net.torvald.terrarum.OreCodex -import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.ceilToInt -import net.torvald.terrarum.gameworld.BlockLayerI16 +import net.torvald.terrarum.gameworld.BlockLayerGenericI16 import net.torvald.terrarum.gameworld.GameWorld -import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.gameworld.getOffset import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore import net.torvald.unsafe.UnsafeHelper @@ -37,7 +34,7 @@ object ExplosionManager { val lineMax = world.height - ty + CALC_RADIUS // create a copy of the tilemap - val tilemap = BlockLayerI16(CALC_WIDTH, CALC_WIDTH) + val tilemap = BlockLayerGenericI16(CALC_WIDTH, CALC_WIDTH) val breakmap = UnsafeFloatArray(CALC_WIDTH, CALC_WIDTH) // fill in the tilemap copy @@ -72,7 +69,7 @@ object ExplosionManager { }.start() } - private fun memcpyFromWorldTiles(CALC_RADIUS: Int, CALC_WIDTH: Int, world: GameWorld, xStart: Int, yStart: Int, yOff: Int, out: BlockLayerI16) { + private fun memcpyFromWorldTiles(CALC_RADIUS: Int, CALC_WIDTH: Int, world: GameWorld, xStart: Int, yStart: Int, yOff: Int, out: BlockLayerGenericI16) { // if the bounding box must wrap around if (xStart > world.width - CALC_RADIUS) { val lenLeft = world.width - xStart @@ -104,7 +101,7 @@ object ExplosionManager { } } - private fun memcpyToWorldTiles(CALC_RADIUS: Int, CALC_WIDTH: Int, world: GameWorld, xStart: Int, yStart: Int, yOff: Int, out: BlockLayerI16) { + private fun memcpyToWorldTiles(CALC_RADIUS: Int, CALC_WIDTH: Int, world: GameWorld, xStart: Int, yStart: Int, yOff: Int, out: BlockLayerGenericI16) { // if the bounding box must wrap around if (xStart > world.width - CALC_RADIUS) { val lenLeft = world.width - xStart @@ -158,7 +155,7 @@ object ExplosionManager { CALC_RADIUS: Int, CALC_WIDTH: Int, world: GameWorld, breakmap: UnsafeFloatArray, - tilemap: BlockLayerI16, + tilemap: BlockLayerGenericI16, tx: Int, ty: Int, power: Float, dropProbNonOre: Float, diff --git a/src/net/torvald/terrarum/modulebasegame/serialise/LoadSavegame.kt b/src/net/torvald/terrarum/modulebasegame/serialise/LoadSavegame.kt index e28d3b1ce..8fe71f930 100644 --- a/src/net/torvald/terrarum/modulebasegame/serialise/LoadSavegame.kt +++ b/src/net/torvald/terrarum/modulebasegame/serialise/LoadSavegame.kt @@ -2,8 +2,8 @@ package net.torvald.terrarum.modulebasegame.serialise import net.torvald.terrarum.* import net.torvald.terrarum.console.Echo -import net.torvald.terrarum.gameworld.BlockLayerI16 -import net.torvald.terrarum.gameworld.BlockLayerI16F16 +import net.torvald.terrarum.gameworld.BlockLayerGenericI16 +import net.torvald.terrarum.gameworld.BlockLayerFluidI16F16 import net.torvald.terrarum.gameworld.BlockLayerOresI16I8 import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.langpack.Lang @@ -61,10 +61,10 @@ object LoadSavegame { val world = ReadWorld(worldDiskSavegameInfo, worldDisk.diskFile) - world.layerTerrain = BlockLayerI16(world.width, world.height) - world.layerWall = BlockLayerI16(world.width, world.height) + world.layerTerrain = BlockLayerGenericI16(world.width, world.height) + world.layerWall = BlockLayerGenericI16(world.width, world.height) world.layerOres = BlockLayerOresI16I8(world.width, world.height) - world.layerFluids = BlockLayerI16F16(world.width, world.height) + world.layerFluids = BlockLayerFluidI16F16(world.width, world.height) world.chunkFlags = Array(world.height / LandUtil.CHUNK_H) { ByteArray(world.width / LandUtil.CHUNK_W) } newIngame.world = world // must be set before the loadscreen, otherwise the loadscreen will try to read from the NullWorld which is already destroyed diff --git a/src/net/torvald/terrarum/serialise/Common.kt b/src/net/torvald/terrarum/serialise/Common.kt index 8328f318f..b1c8c44eb 100644 --- a/src/net/torvald/terrarum/serialise/Common.kt +++ b/src/net/torvald/terrarum/serialise/Common.kt @@ -10,7 +10,7 @@ import io.airlift.compress.zstd.ZstdOutputStream import net.torvald.random.HQRNG import net.torvald.terrarum.* import net.torvald.terrarum.console.EchoError -import net.torvald.terrarum.gameworld.BlockLayerI16 +import net.torvald.terrarum.gameworld.BlockLayerGenericI16 import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.WorldTime import net.torvald.terrarum.savegame.ByteArray64 @@ -41,7 +41,7 @@ object Common { val CHARSET = Charsets.UTF_8 /** dispose of the `offendingObject` after rejection! */ - class BlockLayerHashMismatchError(val oldHash: String, val newHash: String, val offendingObject: BlockLayerI16) : Error("Old Hash $oldHash != New Hash $newHash") + class BlockLayerHashMismatchError(val oldHash: String, val newHash: String, val offendingObject: BlockLayerGenericI16) : Error("Old Hash $oldHash != New Hash $newHash") private fun Byte.tostr() = this.toInt().and(255).toString(16).padStart(2,'0') private val digester = DigestUtils.getSha256Digest() @@ -74,8 +74,8 @@ object Common { } }) // BlockLayer - it.setSerializer(BlockLayerI16::class.java, object : Json.Serializer { - override fun write(json: Json, obj: BlockLayerI16, knownType: Class<*>?) { + it.setSerializer(BlockLayerGenericI16::class.java, object : Json.Serializer { + override fun write(json: Json, obj: BlockLayerGenericI16, knownType: Class<*>?) { digester.reset() obj.bytesIterator().forEachRemaining { digester.update(it) } val hash = StringBuilder().let { sb -> digester.digest().forEach { sb.append(it.tostr()) }; sb.toString() } @@ -85,7 +85,7 @@ object Common { json.writeValue(layer) } - override fun read(json: Json, jsonData: JsonValue, type: Class<*>): BlockLayerI16 { + override fun read(json: Json, jsonData: JsonValue, type: Class<*>): BlockLayerGenericI16 { // full manual try { return strToBlockLayer(LayerInfo( @@ -435,12 +435,12 @@ object Common { * @param b a BlockLayer * @return Bytes in [b] which are GZip'd then Ascii85-encoded */ - private fun blockLayerToStr(b: BlockLayerI16): String { + private fun blockLayerToStr(b: BlockLayerGenericI16): String { return bytesToZipdStr(b.bytesIterator()) } - private fun strToBlockLayer(layerInfo: LayerInfo): BlockLayerI16 { - val layer = BlockLayerI16(layerInfo.x, layerInfo.y) + private fun strToBlockLayer(layerInfo: LayerInfo): BlockLayerGenericI16 { + val layer = BlockLayerGenericI16(layerInfo.x, layerInfo.y) val unzipdBytes = strToBytes(StringReader(layerInfo.b)) // write to blocklayer and the digester diff --git a/src/net/torvald/terrarum/serialise/PointOfInterest.kt b/src/net/torvald/terrarum/serialise/PointOfInterest.kt index 928091583..39fd65f56 100644 --- a/src/net/torvald/terrarum/serialise/PointOfInterest.kt +++ b/src/net/torvald/terrarum/serialise/PointOfInterest.kt @@ -5,7 +5,7 @@ import com.badlogic.gdx.utils.JsonValue import net.torvald.terrarum.TerrarumAppConfiguration import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.gameitems.ItemID -import net.torvald.terrarum.gameworld.BlockLayerI16 +import net.torvald.terrarum.gameworld.BlockLayerGenericI16 import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld.Companion.TERRAIN import net.torvald.terrarum.gameworld.GameWorld.Companion.WALL @@ -128,7 +128,7 @@ class POILayer( constructor() : this("undefined") @Transient var name = name - @Transient internal lateinit var blockLayer: ArrayList + @Transient internal lateinit var blockLayer: ArrayList @Transient internal lateinit var dat: Array @Deprecated("Used for debug print", ReplaceWith("name")) @Transient internal var id = "" @@ -179,10 +179,10 @@ class POILayer( if (::blockLayer.isInitialized) { blockLayer.forEach { it.dispose() } } - blockLayer = ArrayList() + blockLayer = ArrayList() dat.forEachIndexed { layerIndex, layer -> - val currentBlockLayer = BlockLayerI16(width, height).also { + val currentBlockLayer = BlockLayerGenericI16(width, height).also { blockLayer.add(it) } for (w in 0 until layer.size / byteLength) { diff --git a/src/net/torvald/terrarum/serialise/ReadSimpleWorld.kt b/src/net/torvald/terrarum/serialise/ReadSimpleWorld.kt index 91e527095..15c83f464 100644 --- a/src/net/torvald/terrarum/serialise/ReadSimpleWorld.kt +++ b/src/net/torvald/terrarum/serialise/ReadSimpleWorld.kt @@ -4,7 +4,7 @@ import net.torvald.terrarum.App import net.torvald.terrarum.IngameInstance import net.torvald.terrarum.ItemCodex import net.torvald.terrarum.gameactors.Actor -import net.torvald.terrarum.gameworld.BlockLayerI16F16 +import net.torvald.terrarum.gameworld.BlockLayerFluidI16F16 import net.torvald.terrarum.gameworld.BlockLayerOresI16I8 import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.SimpleGameWorld @@ -26,7 +26,7 @@ object ReadSimpleWorld { world.tileNameToNumberMap[s] = l.toInt() } world.layerOres = BlockLayerOresI16I8(world.width, world.height) - world.layerFluids = BlockLayerI16F16(world.width, world.height) + world.layerFluids = BlockLayerFluidI16F16(world.width, world.height) ItemCodex.loadFromSave(origin, world.dynamicToStaticTable, world.dynamicItemInventory) }