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

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