things are not quite working yet but here's more descriptive error message for ya

This commit is contained in:
minjaesong
2021-08-25 20:55:21 +09:00
parent 9a8bd8d6ec
commit 29c5599746
7 changed files with 39 additions and 62 deletions

View File

@@ -989,7 +989,7 @@ public class AppLoader implements ApplicationListener {
return true;
}
catch (java.nio.file.NoSuchFileException e) {
// write default config to game dir. Call this method again to read config from it.
// write default config to game dir. Call th.is method again to read config from it.
try {
createConfigJson();
}

View File

@@ -8,6 +8,7 @@ import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.BlockMarkerActor
import net.torvald.terrarum.gameitem.ItemID
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.ui.ConsoleWindow
@@ -41,8 +42,8 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
set(value) {
printdbg(this, "Ingame instance ${this.hashCode()}, accepting new world ${value.layerTerrain}; called from")
printStackTrace(this)
field = value
IngameRenderer.setRenderedWorld(value)
}
/** how many different planets/stages/etc. are thenre. Whole stages must be manually managed by YOU. */
var gameworldIndices = ArrayList<Int>()

View File

@@ -35,37 +35,6 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable {
data.forEachIndexed { index, byte -> UnsafeHelper.unsafe.putByte(ptr.ptr + index, byte) }
}
/**
* Returns an iterator over blocks of type `Int`.
*
* @return an Iterator.
*/
fun blocksIterator(): Iterator<Int> {
return object : Iterator<Int> {
private var iteratorCount = 0
override fun hasNext(): Boolean {
return iteratorCount < width * height
}
override fun next(): Int {
val y = iteratorCount / width
val x = iteratorCount % width
// advance counter
iteratorCount += 1
val offset = BYTES_PER_BLOCK * (y * width + x)
val lsb = ptr[offset]
val msb = ptr[offset + 1]
return lsb.toUint() + msb.toUint().shl(8)
}
}
}
/**
* Returns an iterator over stored bytes.
*
@@ -73,17 +42,13 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable {
*/
fun bytesIterator(): Iterator<Byte> {
return object : Iterator<Byte> {
private var iteratorCount = 0L
override fun hasNext(): Boolean {
return iteratorCount < width * height
return iteratorCount < width * height * BYTES_PER_BLOCK
}
override fun next(): Byte {
iteratorCount += 1
return ptr[iteratorCount]
return ptr[iteratorCount - 1]
}
}
}

View File

@@ -222,8 +222,8 @@ class GameWorld : Disposable {
return tileNumberToNameMap[layerWall.unsafeGetTile(x, y)]!!
}
catch (e: NullPointerException) {
System.err.println("NPE for wall ${layerWall.unsafeGetTile(x, y)} in ($x, $y)")
throw e
val msg = "No tile name mapping for wall ${layerWall.unsafeGetTile(x, y)} in ($x, $y)"
throw NoSuchElementException(msg)
}
}
@@ -237,8 +237,8 @@ class GameWorld : Disposable {
return tileNumberToNameMap[layerTerrain.unsafeGetTile(x, y)]!!
}
catch (e: NullPointerException) {
System.err.println("NPE for terrain ${layerTerrain.unsafeGetTile(x, y)} in ($x, $y)")
throw e
val msg = "No tile name mapping for terrain ${layerTerrain.unsafeGetTile(x, y)} in ($x, $y)"
throw NoSuchElementException(msg)
}
}

View File

@@ -153,11 +153,12 @@ object IngameRenderer : Disposable {
fun setRenderedWorld(world: GameWorld) {
try {
if (this.world != world) {
printdbg(this, "World change detected -- " +
"old world: ${this.world.hashCode()}, " +
"new world: ${world.hashCode()}")
// printdbg(this, "World change detected -- " +
// "old world: ${this.world.hashCode()}, " +
// "new world: ${world.hashCode()}")
// change worlds from internal methods
this.world = world
LightmapRenderer.internalSetWorld(world)
BlocksDrawer.world = world
FeaturesDrawer.world = world
@@ -165,8 +166,6 @@ object IngameRenderer : Disposable {
}
catch (e: UninitializedPropertyAccessException) {
// new init, do nothing
}
finally {
this.world = world
}
}

View File

@@ -1,6 +1,8 @@
package net.torvald.terrarum.serialise
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import java.io.InputStream
import java.io.Reader
@@ -22,7 +24,6 @@ open class ReadWorld(val ingame: TerrarumIngame) {
world.postLoad()
ingame.world = world
//ingame.actorNowPlaying?.setPosition(3.0, 3.0)
}
}

View File

@@ -4,6 +4,7 @@ import com.badlogic.gdx.utils.Json
import com.badlogic.gdx.utils.JsonReader
import com.badlogic.gdx.utils.JsonValue
import com.badlogic.gdx.utils.JsonWriter
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.gameworld.BlockLayer
import net.torvald.terrarum.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -43,7 +44,7 @@ open class WriteWorld(val ingame: TerrarumIngame) {
companion object {
/** dispose of the `offendingObject` after rejection! */
class BlockLayerHashMismatchError(val offendingObject: BlockLayer) : Error()
class BlockLayerHashMismatchError(val oldHash: String, val newHash: String, val offendingObject: BlockLayer) : 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()
@@ -80,12 +81,18 @@ open class WriteWorld(val ingame: TerrarumIngame) {
//return strToBlockLayer(json.fromJson(type, jsonData.toJson(JsonWriter.OutputType.minimal)) as LayerInfo)
// full manual
return strToBlockLayer(LayerInfo(
jsonData.getString("h"),
jsonData.getString("b"),
jsonData.getInt("x"),
jsonData.getInt("y")
))
try {
return strToBlockLayer(LayerInfo(
jsonData.getString("h"),
jsonData.getString("b"),
jsonData.getInt("x"),
jsonData.getInt("y")
))
}
catch (e: BlockLayerHashMismatchError) {
EchoError(e.message ?: "")
return e.offendingObject
}
}
})
// WorldTime
@@ -112,10 +119,13 @@ open class WriteWorld(val ingame: TerrarumIngame) {
val zo = GZIPOutputStream(bo)
// zip
b.bytesIterator().forEachRemaining {
/*b.bytesIterator().forEachRemaining {
zo.write(it.toInt())
}
zo.flush(); zo.close()
zo.flush(); zo.close()*/
b.bytesIterator().forEachRemaining {
bo.write(it.toInt())
}
// enascii
val ba = bo.toByteArray64()
@@ -155,18 +165,19 @@ open class WriteWorld(val ingame: TerrarumIngame) {
}; Ascii85.decode(buf[0], buf[1], buf[2], buf[3], buf[4]).forEach { unasciidBytes.add(it) }
// unzip
val zi = GZIPInputStream(ByteArray64InputStream(unasciidBytes))
/*val zi = GZIPInputStream(ByteArray64InputStream(unasciidBytes))
while (true) {
val byte = zi.read()
if (byte == -1) break
unzipdBytes.add(byte.toByte())
}
zi.close()
zi.close()*/
// write to blocklayer and the digester
digester.reset()
var writeCursor = 0L
unzipdBytes.forEach {
// unzipdBytes.forEach {
unasciidBytes.forEach {
if (writeCursor < layer.ptr.size) {
layer.ptr[writeCursor] = it
digester.update(it)
@@ -178,7 +189,7 @@ open class WriteWorld(val ingame: TerrarumIngame) {
val hash = StringBuilder().let { sb -> digester.digest().forEach { sb.append(it.tostr()) }; sb.toString() }
if (hash != layerInfo.h) {
throw BlockLayerHashMismatchError(layer)
throw BlockLayerHashMismatchError(layerInfo.h, hash, layer)
}
return layer