mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
faster block tiling hash
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.random.XXHash32
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
/**
|
||||
@@ -118,7 +119,7 @@ class Point2i() {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = XXHash32.hashGeoCoord(x, y)
|
||||
override fun hashCode(): Int = getHashCoord(x, y)
|
||||
override fun equals(other: Any?) = if (other is Point2i)
|
||||
this.x == other.x && this.y == other.y
|
||||
else
|
||||
@@ -130,4 +131,20 @@ class Point2i() {
|
||||
operator fun component2() = y
|
||||
|
||||
fun toVector() = Vector2(this.x.toDouble(), this.y.toDouble())
|
||||
|
||||
companion object {
|
||||
private fun tavGrainSynthesisRNG(frame: Int, band: Int, x: Int, y: Int): Int {
|
||||
var hash = frame * 0x9e3779b9.toInt() xor band * 0x7f4a7c15 xor (y shl 16) xor x
|
||||
hash = hash xor (hash shr 16)
|
||||
hash = hash * 0x7feb352d
|
||||
hash = hash xor (hash shr 15)
|
||||
hash = hash * 0x846ca68b.toInt()
|
||||
hash = hash xor (hash shr 16)
|
||||
return hash
|
||||
}
|
||||
|
||||
private fun getHashCoord(x: Int, y: Int): Int {
|
||||
return tavGrainSynthesisRNG(31, 65003, x, y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,14 +59,14 @@ class BlockProp : TaggedProp {
|
||||
fun getLumCol(x: Int, y: Int) = if (dynamicLuminosityFunction == 0) {
|
||||
baseLumCol
|
||||
} else {
|
||||
val offset = XXHash32.hashGeoCoord(x, y).fmod(BlockCodex.DYNAMIC_RANDOM_CASES)
|
||||
val offset = getHashCoord(x, y, BlockCodex.DYNAMIC_RANDOM_CASES)
|
||||
BlockCodex[BlockCodex.tileToVirtual[id]!![offset]]._lumCol
|
||||
}
|
||||
|
||||
fun getLumCol(x: Int, y: Int, channel: Int): Float = if (dynamicLuminosityFunction == 0) {
|
||||
baseLumCol.lane(channel)
|
||||
} else {
|
||||
val offset = XXHash32.hashGeoCoord(x, y).fmod(BlockCodex.DYNAMIC_RANDOM_CASES)
|
||||
val offset = getHashCoord(x, y, BlockCodex.DYNAMIC_RANDOM_CASES)
|
||||
BlockCodex[BlockCodex.tileToVirtual[id]!![offset]]._lumCol.lane(channel)
|
||||
}
|
||||
|
||||
@@ -112,4 +112,20 @@ class BlockProp : TaggedProp {
|
||||
val isSolidForTileCnx: Boolean
|
||||
get() = if (tags.contains("DORENDER") || !isActorBlock) isSolid else false
|
||||
|
||||
|
||||
companion object {
|
||||
private fun tavGrainSynthesisRNG(frame: Int, band: Int, x: Int, y: Int): Int {
|
||||
var hash = frame * 0x9e3779b9.toInt() xor band * 0x7f4a7c15 xor (y shl 16) xor x
|
||||
hash = hash xor (hash shr 16)
|
||||
hash = hash * 0x7feb352d
|
||||
hash = hash xor (hash shr 15)
|
||||
hash = hash * 0x846ca68b.toInt()
|
||||
hash = hash xor (hash shr 16)
|
||||
return hash
|
||||
}
|
||||
|
||||
private fun getHashCoord(x: Int, y: Int, mod: Int): Int {
|
||||
return tavGrainSynthesisRNG(31, 65003, x, y) fmod mod
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import com.badlogic.gdx.math.Matrix4
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.random.XXHash64
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.measureDebugTime
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
@@ -21,8 +20,6 @@ import net.torvald.terrarum.gameworld.FLUID_MIN_MASS
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.modulebasegame.worldgenerator.shake
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import net.torvald.terrarum.serialise.toBig64
|
||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.Companion.WALL_OVERLAY_COLOUR
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import net.torvald.unsafe.UnsafeLong2D
|
||||
@@ -410,13 +407,28 @@ internal object BlocksDrawer {
|
||||
|
||||
}
|
||||
|
||||
private fun tavGrainSynthesisRNG(frame: Int, band: Int, x: Int, y: Int): Int {
|
||||
var hash = frame * 0x9e3779b9.toInt() xor band * 0x7f4a7c15 xor (y shl 16) xor x
|
||||
hash = hash xor (hash shr 16)
|
||||
hash = hash * 0x7feb352d
|
||||
hash = hash xor (hash shr 15)
|
||||
hash = hash * 0x846ca68b.toInt()
|
||||
hash = hash xor (hash shr 16)
|
||||
return hash
|
||||
}
|
||||
|
||||
private fun getHashCoord(x: Int, y: Int, mod: Long, layer: Int, tileNumber: Int): Int {
|
||||
|
||||
private fun getHashCoord(x: Int, y: Int, mod: Int, layer: Int, tileNumber: Int): Int {
|
||||
val (x, y) = world.coerceXY(x, y)
|
||||
return (XXHash64.hash(
|
||||
/*return (XXHash64.hash(
|
||||
LandUtil.getBlockAddr(world, x, y).toBig64(),
|
||||
world.generatorSeed shake tileNumber.toLong() shake layer.toLong()
|
||||
) fmod mod).toInt()
|
||||
) fmod mod).toInt()*/
|
||||
return tavGrainSynthesisRNG(
|
||||
world.worldIndex.leastSignificantBits.toInt(),
|
||||
(world.generatorSeed shake tileNumber.toLong() shake layer.toLong()).toInt(),
|
||||
x, y
|
||||
) fmod mod
|
||||
}
|
||||
|
||||
private var for_y_start = 0
|
||||
|
||||
Reference in New Issue
Block a user