mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 10:04:05 +09:00
things are not quite working yet but here's more descriptive error message for ya
This commit is contained in:
@@ -989,7 +989,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (java.nio.file.NoSuchFileException e) {
|
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 {
|
try {
|
||||||
createConfigJson();
|
createConfigJson();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import net.torvald.terrarum.gameactors.Actor
|
|||||||
import net.torvald.terrarum.gameactors.BlockMarkerActor
|
import net.torvald.terrarum.gameactors.BlockMarkerActor
|
||||||
import net.torvald.terrarum.gameitem.ItemID
|
import net.torvald.terrarum.gameitem.ItemID
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
|
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||||
import net.torvald.terrarum.realestate.LandUtil
|
import net.torvald.terrarum.realestate.LandUtil
|
||||||
import net.torvald.terrarum.ui.ConsoleWindow
|
import net.torvald.terrarum.ui.ConsoleWindow
|
||||||
@@ -41,8 +42,8 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
|||||||
set(value) {
|
set(value) {
|
||||||
printdbg(this, "Ingame instance ${this.hashCode()}, accepting new world ${value.layerTerrain}; called from")
|
printdbg(this, "Ingame instance ${this.hashCode()}, accepting new world ${value.layerTerrain}; called from")
|
||||||
printStackTrace(this)
|
printStackTrace(this)
|
||||||
|
|
||||||
field = value
|
field = value
|
||||||
|
IngameRenderer.setRenderedWorld(value)
|
||||||
}
|
}
|
||||||
/** how many different planets/stages/etc. are thenre. Whole stages must be manually managed by YOU. */
|
/** how many different planets/stages/etc. are thenre. Whole stages must be manually managed by YOU. */
|
||||||
var gameworldIndices = ArrayList<Int>()
|
var gameworldIndices = ArrayList<Int>()
|
||||||
|
|||||||
@@ -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) }
|
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.
|
* Returns an iterator over stored bytes.
|
||||||
*
|
*
|
||||||
@@ -73,17 +42,13 @@ open class BlockLayer(val width: Int, val height: Int) : Disposable {
|
|||||||
*/
|
*/
|
||||||
fun bytesIterator(): Iterator<Byte> {
|
fun bytesIterator(): Iterator<Byte> {
|
||||||
return object : Iterator<Byte> {
|
return object : Iterator<Byte> {
|
||||||
|
|
||||||
private var iteratorCount = 0L
|
private var iteratorCount = 0L
|
||||||
|
|
||||||
override fun hasNext(): Boolean {
|
override fun hasNext(): Boolean {
|
||||||
return iteratorCount < width * height
|
return iteratorCount < width * height * BYTES_PER_BLOCK
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun next(): Byte {
|
override fun next(): Byte {
|
||||||
iteratorCount += 1
|
iteratorCount += 1
|
||||||
|
return ptr[iteratorCount - 1]
|
||||||
return ptr[iteratorCount]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,8 +222,8 @@ class GameWorld : Disposable {
|
|||||||
return tileNumberToNameMap[layerWall.unsafeGetTile(x, y)]!!
|
return tileNumberToNameMap[layerWall.unsafeGetTile(x, y)]!!
|
||||||
}
|
}
|
||||||
catch (e: NullPointerException) {
|
catch (e: NullPointerException) {
|
||||||
System.err.println("NPE for wall ${layerWall.unsafeGetTile(x, y)} in ($x, $y)")
|
val msg = "No tile name mapping for wall ${layerWall.unsafeGetTile(x, y)} in ($x, $y)"
|
||||||
throw e
|
throw NoSuchElementException(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,8 +237,8 @@ class GameWorld : Disposable {
|
|||||||
return tileNumberToNameMap[layerTerrain.unsafeGetTile(x, y)]!!
|
return tileNumberToNameMap[layerTerrain.unsafeGetTile(x, y)]!!
|
||||||
}
|
}
|
||||||
catch (e: NullPointerException) {
|
catch (e: NullPointerException) {
|
||||||
System.err.println("NPE for terrain ${layerTerrain.unsafeGetTile(x, y)} in ($x, $y)")
|
val msg = "No tile name mapping for terrain ${layerTerrain.unsafeGetTile(x, y)} in ($x, $y)"
|
||||||
throw e
|
throw NoSuchElementException(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,11 +153,12 @@ object IngameRenderer : Disposable {
|
|||||||
fun setRenderedWorld(world: GameWorld) {
|
fun setRenderedWorld(world: GameWorld) {
|
||||||
try {
|
try {
|
||||||
if (this.world != world) {
|
if (this.world != world) {
|
||||||
printdbg(this, "World change detected -- " +
|
// printdbg(this, "World change detected -- " +
|
||||||
"old world: ${this.world.hashCode()}, " +
|
// "old world: ${this.world.hashCode()}, " +
|
||||||
"new world: ${world.hashCode()}")
|
// "new world: ${world.hashCode()}")
|
||||||
|
|
||||||
// change worlds from internal methods
|
// change worlds from internal methods
|
||||||
|
this.world = world
|
||||||
LightmapRenderer.internalSetWorld(world)
|
LightmapRenderer.internalSetWorld(world)
|
||||||
BlocksDrawer.world = world
|
BlocksDrawer.world = world
|
||||||
FeaturesDrawer.world = world
|
FeaturesDrawer.world = world
|
||||||
@@ -165,8 +166,6 @@ object IngameRenderer : Disposable {
|
|||||||
}
|
}
|
||||||
catch (e: UninitializedPropertyAccessException) {
|
catch (e: UninitializedPropertyAccessException) {
|
||||||
// new init, do nothing
|
// new init, do nothing
|
||||||
}
|
|
||||||
finally {
|
|
||||||
this.world = world
|
this.world = world
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package net.torvald.terrarum.serialise
|
package net.torvald.terrarum.serialise
|
||||||
|
|
||||||
|
import net.torvald.terrarum.console.Echo
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
|
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.io.Reader
|
import java.io.Reader
|
||||||
@@ -22,7 +24,6 @@ open class ReadWorld(val ingame: TerrarumIngame) {
|
|||||||
world.postLoad()
|
world.postLoad()
|
||||||
|
|
||||||
ingame.world = world
|
ingame.world = world
|
||||||
//ingame.actorNowPlaying?.setPosition(3.0, 3.0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.utils.Json
|
|||||||
import com.badlogic.gdx.utils.JsonReader
|
import com.badlogic.gdx.utils.JsonReader
|
||||||
import com.badlogic.gdx.utils.JsonValue
|
import com.badlogic.gdx.utils.JsonValue
|
||||||
import com.badlogic.gdx.utils.JsonWriter
|
import com.badlogic.gdx.utils.JsonWriter
|
||||||
|
import net.torvald.terrarum.console.EchoError
|
||||||
import net.torvald.terrarum.gameworld.BlockLayer
|
import net.torvald.terrarum.gameworld.BlockLayer
|
||||||
import net.torvald.terrarum.gameworld.WorldTime
|
import net.torvald.terrarum.gameworld.WorldTime
|
||||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||||
@@ -43,7 +44,7 @@ open class WriteWorld(val ingame: TerrarumIngame) {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/** dispose of the `offendingObject` after rejection! */
|
/** 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 fun Byte.tostr() = this.toInt().and(255).toString(16).padStart(2,'0')
|
||||||
private val digester = DigestUtils.getSha256Digest()
|
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)
|
//return strToBlockLayer(json.fromJson(type, jsonData.toJson(JsonWriter.OutputType.minimal)) as LayerInfo)
|
||||||
|
|
||||||
// full manual
|
// full manual
|
||||||
return strToBlockLayer(LayerInfo(
|
try {
|
||||||
jsonData.getString("h"),
|
return strToBlockLayer(LayerInfo(
|
||||||
jsonData.getString("b"),
|
jsonData.getString("h"),
|
||||||
jsonData.getInt("x"),
|
jsonData.getString("b"),
|
||||||
jsonData.getInt("y")
|
jsonData.getInt("x"),
|
||||||
))
|
jsonData.getInt("y")
|
||||||
|
))
|
||||||
|
}
|
||||||
|
catch (e: BlockLayerHashMismatchError) {
|
||||||
|
EchoError(e.message ?: "")
|
||||||
|
return e.offendingObject
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// WorldTime
|
// WorldTime
|
||||||
@@ -112,10 +119,13 @@ open class WriteWorld(val ingame: TerrarumIngame) {
|
|||||||
val zo = GZIPOutputStream(bo)
|
val zo = GZIPOutputStream(bo)
|
||||||
|
|
||||||
// zip
|
// zip
|
||||||
b.bytesIterator().forEachRemaining {
|
/*b.bytesIterator().forEachRemaining {
|
||||||
zo.write(it.toInt())
|
zo.write(it.toInt())
|
||||||
}
|
}
|
||||||
zo.flush(); zo.close()
|
zo.flush(); zo.close()*/
|
||||||
|
b.bytesIterator().forEachRemaining {
|
||||||
|
bo.write(it.toInt())
|
||||||
|
}
|
||||||
|
|
||||||
// enascii
|
// enascii
|
||||||
val ba = bo.toByteArray64()
|
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) }
|
}; Ascii85.decode(buf[0], buf[1], buf[2], buf[3], buf[4]).forEach { unasciidBytes.add(it) }
|
||||||
|
|
||||||
// unzip
|
// unzip
|
||||||
val zi = GZIPInputStream(ByteArray64InputStream(unasciidBytes))
|
/*val zi = GZIPInputStream(ByteArray64InputStream(unasciidBytes))
|
||||||
while (true) {
|
while (true) {
|
||||||
val byte = zi.read()
|
val byte = zi.read()
|
||||||
if (byte == -1) break
|
if (byte == -1) break
|
||||||
unzipdBytes.add(byte.toByte())
|
unzipdBytes.add(byte.toByte())
|
||||||
}
|
}
|
||||||
zi.close()
|
zi.close()*/
|
||||||
|
|
||||||
// write to blocklayer and the digester
|
// write to blocklayer and the digester
|
||||||
digester.reset()
|
digester.reset()
|
||||||
var writeCursor = 0L
|
var writeCursor = 0L
|
||||||
unzipdBytes.forEach {
|
// unzipdBytes.forEach {
|
||||||
|
unasciidBytes.forEach {
|
||||||
if (writeCursor < layer.ptr.size) {
|
if (writeCursor < layer.ptr.size) {
|
||||||
layer.ptr[writeCursor] = it
|
layer.ptr[writeCursor] = it
|
||||||
digester.update(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() }
|
val hash = StringBuilder().let { sb -> digester.digest().forEach { sb.append(it.tostr()) }; sb.toString() }
|
||||||
|
|
||||||
if (hash != layerInfo.h) {
|
if (hash != layerInfo.h) {
|
||||||
throw BlockLayerHashMismatchError(layer)
|
throw BlockLayerHashMismatchError(layerInfo.h, hash, layer)
|
||||||
}
|
}
|
||||||
|
|
||||||
return layer
|
return layer
|
||||||
|
|||||||
Reference in New Issue
Block a user