new cobblestone texture, layer transition dithering with buffer layer

This commit is contained in:
minjaesong
2021-02-28 11:30:10 +09:00
parent 6cf8553ac2
commit 37c6ffd062
10 changed files with 70 additions and 25 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -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;

View File

@@ -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)
}

View File

@@ -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)
}
}

View File

@@ -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]

View File

@@ -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<Double>, world: GameWorld) {
private fun draw(x: Int, noises: List<Joise>, 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)
}
}

View File

@@ -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]}" +

View File

@@ -4,7 +4,7 @@ Following code is an example savegame JSON files.
```
{
savename: "Test World 1",
genver: <generator version in integer>,
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: <creation time in real-world unix time>,
lastplay_t: <creation time in real-world unix time>,
creation_t: <creation time in real-world unix time>,
thumb: <RFC-1924-encoded gzipped thumbnail image in TGA>,
thumb: <Ascii85-encoded gzipped thumbnail image in TGA>,
blocks: <BlockCodex serialised>,
items: <ItemCodex serialised>,
@@ -37,42 +37,42 @@ File is named as `"world"+world_index+".json"`
height: 2048,
spawnx: 4096,
spawny: 248,
genver: <generator version in integer>,
genver: 4, /* generator version in integer */
time_t: <in-game TIME_T of this world>,
terr: {
s: 33554432,
h: "a441b15fe9a3cf56661190a0b93b9dec7d04127288cc87250967cf3b52894d11",
b: <RFC-1924-encoded gzipped terrain layerdata>
b: <Ascii85-encoded gzipped terrain layerdata>
},
wall: {
s: 33554432,
h: <SHA-256 hash of 'b'>,
b: <RFC-1924-encoded gzipped wall layerdata>
b: <Ascii85-encoded gzipped wall layerdata>
},
tdmg: {
s: 8795,
h: <SHA-256 hash of 'b'>,
b: <RFC-1924-encoded gzipped terrain damage in JSON>
b: <Ascii85-encoded gzipped terrain damage in JSON>
},
wdmg: {
s: 2,
h: <SHA-256 hash of 'b'>,
b: <RFC-1924-encoded gzipped wall damage in JSON>
b: <Ascii85-encoded gzipped wall damage in JSON>
},
flui: {
s: 15734
h: <SHA-256 hash of 'b'>,
b: <RFC-1924-encoded gzipped fluids in JSON>
b: <Ascii85-encoded gzipped fluids in JSON>
},
wire: {
s: 2,
h: <SHA-256 hash of 'b'>,
b: <RFC-1924-encoded gzipped wiring nodes in JSON>
b: <Ascii85-encoded gzipped wiring nodes in JSON>
},
tmap: {
s: 4316,
h: <SHA-256 hash of 'b'>,
b: <RFC-1924-encoded gzipped tilenumber-to-tilename map in JSON>
b: <Ascii85-encoded gzipped tilenumber-to-tilename map in JSON>
}
}
```

Binary file not shown.