mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
renaming some files
This commit is contained in:
@@ -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.
|
||||
*
|
||||
@@ -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<Float>()
|
||||
val terrainDamages = HashArray<Float>()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<BlockLayerI16> {
|
||||
override fun write(json: Json, obj: BlockLayerI16, knownType: Class<*>?) {
|
||||
it.setSerializer(BlockLayerGenericI16::class.java, object : Json.Serializer<BlockLayerGenericI16> {
|
||||
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
|
||||
|
||||
@@ -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<BlockLayerI16>
|
||||
@Transient internal lateinit var blockLayer: ArrayList<BlockLayerGenericI16>
|
||||
@Transient internal lateinit var dat: Array<ByteArray>
|
||||
|
||||
@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<BlockLayerI16>()
|
||||
blockLayer = ArrayList<BlockLayerGenericI16>()
|
||||
|
||||
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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user