mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
Generalised BlockLayer
This commit is contained in:
@@ -3,6 +3,8 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.BlockCodex
|
||||
import net.torvald.terrarum.WireCodex
|
||||
import net.torvald.terrarum.gameitems.isBlock
|
||||
import net.torvald.terrarum.gameitems.isWall
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-02-03.
|
||||
@@ -74,19 +76,22 @@ object PlayerBuilderSigrid {
|
||||
fun fillTestInventory(inventory: ActorInventory) {
|
||||
|
||||
App.tileMaker.tags.forEach { (t, _) ->
|
||||
val prop = BlockCodex[t]
|
||||
if (!prop.isActorBlock && !prop.hasTag("AIR") && !prop.hasTag("INTERNAL")) {
|
||||
if (t.isBlock() || t.isWall()) {
|
||||
val prop = BlockCodex[t]
|
||||
if (!prop.isActorBlock && !prop.hasTag("AIR") && !prop.hasTag("INTERNAL")) {
|
||||
|
||||
inventory.add(t, 9995)
|
||||
try {
|
||||
inventory.add(
|
||||
"wall@$t",
|
||||
9995
|
||||
) // this code will try to add nonexisting wall items, do not get surprised with NPEs
|
||||
}
|
||||
catch (e: NullPointerException) { /* tHiS iS fInE */ }
|
||||
catch (e: Throwable) {
|
||||
System.err.println("[PlayerBuilder] $e")
|
||||
inventory.add(t, 9995)
|
||||
try {
|
||||
inventory.add(
|
||||
"wall@$t",
|
||||
9995
|
||||
) // this code will try to add nonexisting wall items, do not get surprised with NPEs
|
||||
}
|
||||
catch (e: NullPointerException) { /* tHiS iS fInE */
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
System.err.println("[PlayerBuilder] $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,19 +4,17 @@ import com.badlogic.gdx.graphics.Pixmap
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.gameworld.BlockLayer
|
||||
import net.torvald.terrarum.gameworld.BlockLayerI16
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.ChunkLoadingLoadScreen
|
||||
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||
import net.torvald.terrarum.modulebasegame.SavegameMigrator
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import net.torvald.terrarum.savegame.*
|
||||
import net.torvald.terrarum.savegame.VDFileID.SAVEGAMEINFO
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import java.io.File
|
||||
import java.io.Reader
|
||||
@@ -145,8 +143,8 @@ object LoadSavegame {
|
||||
val worldDiskSavegameInfo = ByteArray64Reader(worldDisk.getFile(SAVEGAMEINFO)!!.bytes, Common.CHARSET)
|
||||
val world = ReadWorld(worldDiskSavegameInfo, worldDisk.diskFile)
|
||||
|
||||
world.layerTerrain = BlockLayer(world.width, world.height)
|
||||
world.layerWall = BlockLayer(world.width, world.height)
|
||||
world.layerTerrain = BlockLayerI16(world.width, world.height)
|
||||
world.layerWall = BlockLayerI16(world.width, world.height)
|
||||
|
||||
newIngame.world = world // must be set before the loadscreen, otherwise the loadscreen will try to read from the NullWorld which is already destroyed
|
||||
newIngame.worldDisk = VDUtil.readDiskArchive(worldDisk.diskFile, Level.INFO)
|
||||
|
||||
@@ -4,6 +4,8 @@ import net.torvald.terrarum.ItemCodex
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.gameactors.NoSerialise
|
||||
import net.torvald.terrarum.gameworld.BlockLayer
|
||||
import net.torvald.terrarum.gameworld.BlockLayerI16
|
||||
import net.torvald.terrarum.gameworld.BlockLayerI16I8
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
|
||||
@@ -82,9 +84,7 @@ object WriteWorld {
|
||||
val ba = ByteArray64()
|
||||
for (y in cy * LandUtil.CHUNK_H until (cy + 1) * LandUtil.CHUNK_H) {
|
||||
for (x in cx * LandUtil.CHUNK_W until (cx + 1) * LandUtil.CHUNK_W) {
|
||||
val tilenum = layer.unsafeGetTile(x, y)
|
||||
ba.appendByte(tilenum.ushr(8).and(255).toByte())
|
||||
ba.appendByte(tilenum.and(255).toByte())
|
||||
ba.appendBytes(layer.unsafeToBytes(x, y))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,17 +116,19 @@ object ReadWorld {
|
||||
|
||||
fun decodeChunkToLayer(chunk: ByteArray64, targetLayer: BlockLayer, cx: Int, cy: Int) {
|
||||
val bytes = Common.unzip(chunk)
|
||||
if (bytes.size != cw * ch * 2L)
|
||||
if (bytes.size != cw * ch * targetLayer.bytesPerBlock)
|
||||
throw UnsupportedOperationException("Chunk size mismatch: decoded chunk size is ${bytes.size} bytes " +
|
||||
"where ${LandUtil.CHUNK_W * LandUtil.CHUNK_H * 2L} bytes (Int16 of ${LandUtil.CHUNK_W}x${LandUtil.CHUNK_H}) were expected")
|
||||
"where ${LandUtil.CHUNK_W * LandUtil.CHUNK_H * targetLayer.bytesPerBlock} bytes (Int${8 * targetLayer.bytesPerBlock} of ${LandUtil.CHUNK_W}x${LandUtil.CHUNK_H}) were expected")
|
||||
|
||||
for (k in 0 until cw * ch) {
|
||||
val tilenum = bytes[2L*k].toUint().shl(8) or bytes[2L*k + 1].toUint()
|
||||
val offx = k % cw
|
||||
val offy = k / cw
|
||||
val ba = ByteArray(targetLayer.bytesPerBlock.toInt()) {
|
||||
bytes[targetLayer.bytesPerBlock * k + it]
|
||||
}
|
||||
|
||||
// try {
|
||||
targetLayer.unsafeSetTile(cx * cw + offx, cy * ch + offy, tilenum)
|
||||
targetLayer.unsafeSetTile(cx * cw + offx, cy * ch + offy, ba)
|
||||
// }
|
||||
// catch (e: IndexOutOfBoundsException) {
|
||||
// printdbgerr(this, "IndexOutOfBoundsException, cx = $cx, cy = $cy, k = $k, offx = $offx, offy = $offy")
|
||||
|
||||
@@ -111,6 +111,12 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par
|
||||
world.setTileTerrain(x, y, newTile, true)
|
||||
|
||||
world.setTileWall(x, y, newTile, true)
|
||||
|
||||
|
||||
// TODO TEST CODE
|
||||
if (newTile == Block.DIRT) {
|
||||
world.setTileOre(x, y, "ores@basegame:1", 0)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user