diff --git a/assets/mods/basegame/blocks/17 - Copy.tga b/assets/mods/basegame/blocks/17 - Copy.tga new file mode 100644 index 000000000..dcb4e5d7c --- /dev/null +++ b/assets/mods/basegame/blocks/17 - Copy.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d46b345f560b3df8aea1da1ad0dd47c2a8ff8d8ecba8d1c860a0778180753339 +size 50220 diff --git a/assets/mods/basegame/blocks/17.tga b/assets/mods/basegame/blocks/17.tga index dcb4e5d7c..19f044082 100644 --- a/assets/mods/basegame/blocks/17.tga +++ b/assets/mods/basegame/blocks/17.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d46b345f560b3df8aea1da1ad0dd47c2a8ff8d8ecba8d1c860a0778180753339 -size 50220 +oid sha256:7eab05a2b3d98f1ecec41dc6ca506696506c81ced888b6b4495d703d061e473a +size 50194 diff --git a/src/net/torvald/random/XXHash32.java b/src/net/torvald/random/XXHash32.java index d1bf7963f..16da0b289 100644 --- a/src/net/torvald/random/XXHash32.java +++ b/src/net/torvald/random/XXHash32.java @@ -17,6 +17,11 @@ public class XXHash32 { static final int PRIME4 = 0x27D4EB2F; static final int PRIME5 = 0x165667B1; + public static int hashGeoCoord(int x, int y) { + int p = ((x & 65535) << 16) | (y & 65535); + return hash(new byte[]{(byte) p, (byte)(p >>> 8), (byte)(p >>> 16), (byte)(p >>> 24)}, 10000); + } + public static int hash(byte[] data, int seed) { int end = data.length; int offset = 0; diff --git a/src/net/torvald/terrarum/blockproperties/BlockProp.kt b/src/net/torvald/terrarum/blockproperties/BlockProp.kt index 9f94bc9ff..3caccab94 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockProp.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockProp.kt @@ -62,14 +62,14 @@ class BlockProp { fun getLumCol(x: Int, y: Int) = if (dynamicLuminosityFunction == 0) { baseLumCol } else { - val offset = XXHash32.hash(((x and 0xFFFF).shl(16) or (y and 0xFFFF)).toLittle(), 10000).fmod(BlockCodex.DYNAMIC_RANDOM_CASES) + val offset = XXHash32.hashGeoCoord(x, y).fmod(BlockCodex.DYNAMIC_RANDOM_CASES) BlockCodex[BlockCodex.tileToVirtual[id]!![offset]]._lumCol } fun getLumCol(x: Int, y: Int, channel: Int): Float = if (dynamicLuminosityFunction == 0) { baseLumCol.getElem(channel) } else { - val offset = XXHash32.hash(((x and 0xFFFF).shl(16) or (y and 0xFFFF)).toLittle(), 10000).fmod(BlockCodex.DYNAMIC_RANDOM_CASES) + val offset = XXHash32.hashGeoCoord(x, y).fmod(BlockCodex.DYNAMIC_RANDOM_CASES) BlockCodex[BlockCodex.tileToVirtual[id]!![offset]]._lumCol.getElem(channel) } diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index 55fb376c2..d7619095e 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -384,7 +384,7 @@ open class GameWorld : Disposable { // advance counter iteratorCount += 1 - return getTileFromTerrain(x, y)!! + return getTileFromTerrain(x, y) } } @@ -404,7 +404,7 @@ open class GameWorld : Disposable { // advance counter iteratorCount += 1 - return getTileFromWall(x, y)!! + return getTileFromWall(x, y) } } diff --git a/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt b/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt index 83be6c6bb..d0875b247 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/ExportMap.kt @@ -33,8 +33,7 @@ internal object ExportMap : ConsoleCommand { var mapDataPointer = 0 for (tile in world.terrainIterator()) { - val tileNumber = CreateTileAtlas.tileIDtoItemSheetNumber(tile) - val colArray = CreateTileAtlas.terrainTileColourMap.get(tileNumber)!!.toByteArray() + val colArray = CreateTileAtlas.terrainTileColourMap.get(tile)!!.toByteArray() for (i in 0..2) { mapData[mapDataPointer + i] = colArray[i] diff --git a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Terragen.kt b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Terragen.kt index 9196ec96c..2e21cfaa1 100644 --- a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Terragen.kt +++ b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Terragen.kt @@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.worldgenerator import com.sudoplay.joise.Joise import com.sudoplay.joise.module.* +import net.torvald.random.XXHash32 import net.torvald.terrarum.AppLoader import net.torvald.terrarum.AppLoader.printdbg import net.torvald.terrarum.blockproperties.Block @@ -23,6 +24,8 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par private val YHEIGHT_MAGIC = 2800.0 / 3.0 private val YHEIGHT_DIVISOR = 2.0 / 7.0 + private val dirtStoneDitherSize = 3 // actual dither size will be double of this value + override fun getDone() { ThreadExecutor.renew() (0 until world.width).sliceEvenly(genSlices).mapIndexed { i, xs -> @@ -55,6 +58,8 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par //private fun draw(x: Int, y: Int, width: Int, height: Int, noiseValue: List, world: GameWorld) { private fun draw(x: Int, noises: List, st: Double, soff: Double) { + var dirtStoneTransition = 0 + for (y in 0 until world.height) { val sx = sin(st) * soff + soff // plus sampleOffset to make only val sz = cos(st) * soff + soff // positive points are to be sampled @@ -65,12 +70,42 @@ class Terragen(world: GameWorld, seed: Long, params: Any) : Gen(world, seed, par val terr = noiseValue[0].tiered(.0, .5, .88) val cave = if (noiseValue[1] < 0.5) 0 else 1 + // mark off the position where the transition occurred + if (dirtStoneTransition == 0 && terr == 2) { + dirtStoneTransition = y + } + val wallBlock = groundDepthBlock[terr] - val terrBlock = if (cave == 0) Block.AIR else wallBlock //wallBlock * cave // AIR is always zero, this is the standard + val terrBlock = if (cave == 0) Block.AIR else wallBlock world.setTileTerrain(x, y, terrBlock, true) world.setTileWall(x, y, wallBlock, true) } + + // dither shits + /* + # + # - dirt-to-cobble transition, height = dirtStoneDitherSize + # + % + % - cobble-to-rock transition, height = dirtStoneDitherSize + % + */ + for (pos in 0 until dirtStoneDitherSize * 2) { + val y = dirtStoneTransition - dirtStoneDitherSize + pos + + val hash = XXHash32.hashGeoCoord(x, y).and(0x7FFFFFFF) / 2147483647.0 + val newTile = if (pos < dirtStoneDitherSize) + if (hash < pos.toDouble() / dirtStoneDitherSize) Block.STONE_QUARRIED else Block.DIRT + else + if (hash >= (pos.toDouble() - dirtStoneDitherSize) / dirtStoneDitherSize) Block.STONE_QUARRIED else Block.STONE + + if (world.getTileFromTerrain(x, y) != Block.AIR) { + world.setTileTerrain(x, y, newTile, true) + } + // wall is dithered no mater what; do not put if-statement here + world.setTileWall(x, y, newTile, true) + } } diff --git a/src/net/torvald/terrarum/serialise/Ascii85.kt b/src/net/torvald/terrarum/serialise/Ascii85.kt index 79badf5c1..ba2075340 100644 --- a/src/net/torvald/terrarum/serialise/Ascii85.kt +++ b/src/net/torvald/terrarum/serialise/Ascii85.kt @@ -12,9 +12,9 @@ object Ascii85 { private val INVERSE_TABLE = LongArray(127) /** Int of `-1` */ - val PAD_BYTE = -1 + const val PAD_BYTE = -1 /** Null-character (`\0`) */ - val PAD_CHAR = 0.toChar() + const val PAD_CHAR = 0.toChar() private val INTERNAL_PAD_BYTE = 0 private val INTERNAL_PAD_CHAR = CHAR_TABLE.last() @@ -51,13 +51,13 @@ object Ascii85 { (b3.toLong().and(255) shl 8) or b4.toLong().and(255) val c1 = (sum / 52200625L).toInt() - sum = sum - (c1 * 52200625L) + sum -= (c1 * 52200625L) val c2 = (sum / 614125L).toInt() - sum = sum - (c2 * 614125L) + sum -= (c2 * 614125L) val c3 = (sum / 7225L).toInt() - sum = sum - (c3 * 7225L) + sum -= (c3 * 7225L) val c4 = (sum / 85L).toInt() - sum = sum % 85L + sum %= 85L return ("${CHAR_TABLE[c1]}" + "${CHAR_TABLE[c2]}" + diff --git a/work_files/DataFormats/just-json-it-saveformat.md b/work_files/DataFormats/just-json-it-saveformat.md index 878bb122b..db1be0c5c 100644 --- a/work_files/DataFormats/just-json-it-saveformat.md +++ b/work_files/DataFormats/just-json-it-saveformat.md @@ -4,7 +4,7 @@ Following code is an example savegame JSON files. ``` { savename: "Test World 1", - genver: , + genver: 4, /* generator version in integer */ terrseed: "84088805e145b555", randseed: "19b25856e1c150ca834cffc8b59b23ad", weatseed: "e5e72beb4e3c6926d3dc9e3e2ef7833b", @@ -12,7 +12,7 @@ Following code is an example savegame JSON files. creation_t: , lastplay_t: , creation_t: , - thumb: , + thumb: , blocks: , items: , @@ -37,42 +37,42 @@ File is named as `"world"+world_index+".json"` height: 2048, spawnx: 4096, spawny: 248, - genver: , + genver: 4, /* generator version in integer */ time_t: , terr: { s: 33554432, h: "a441b15fe9a3cf56661190a0b93b9dec7d04127288cc87250967cf3b52894d11", - b: + b: }, wall: { s: 33554432, h: , - b: + b: }, tdmg: { s: 8795, h: , - b: + b: }, wdmg: { s: 2, h: , - b: + b: }, flui: { s: 15734 h: , - b: + b: }, wire: { s: 2, h: , - b: + b: }, tmap: { s: 4316, h: , - b: + b: } } ``` diff --git a/work_files/graphics/terrain/cobble.kra b/work_files/graphics/terrain/cobble.kra new file mode 100644 index 000000000..dbe1c2a3f --- /dev/null +++ b/work_files/graphics/terrain/cobble.kra @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1753cb64b0613f6651345f5f0a46cde745d15c0687fe2bdb915ce093e2e6ecac +size 76497