lightsource randomiser hash will be same even when x < 0

This commit is contained in:
minjaesong
2020-02-24 14:46:37 +09:00
parent 0d8d6ca9fa
commit ad903952cc
4 changed files with 16 additions and 8 deletions

View File

@@ -57,11 +57,12 @@ class BlockProp {
//var lumColB = 0f // memoised value of dynamic luminosity
//var lumColA = 0f // memoised value of dynamic luminosity
internal val _lumCol = Cvec(0)
// X- and Y-value must be treated properly beforehand! (use GameWorld.coerceXY())
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)
BlockCodex[BlockCodex.dynamicToVirtualMap[id]!! - offset.fmod(BlockCodex.DYNAMIC_RANDOM_CASES)]._lumCol
val offset = XXHash32.hash(((x and 0xFFFF).shl(16) or (y and 0xFFFF)).toLittle(), 10000).fmod(BlockCodex.DYNAMIC_RANDOM_CASES)
BlockCodex[BlockCodex.dynamicToVirtualMap[id]!! - offset]._lumCol
}
/**

View File

@@ -170,7 +170,7 @@ open class GameWorld : Disposable {
//val wireArray: ByteArray
// get() = layerWire.data
private fun coerceXY(x: Int, y: Int) = (x fmod width) to (y.coerceIn(0, height - 1))
fun coerceXY(x: Int, y: Int) = (x fmod width) to (y.coerceIn(0, height - 1))
fun getTileFromWall(rawX: Int, rawY: Int): Int {
val (x, y) = coerceXY(rawX, rawY)
@@ -182,6 +182,9 @@ open class GameWorld : Disposable {
return layerTerrain.unsafeGetTile(x, y)
}
fun getTileFromWallRaw(coercedX: Int, coercedY: Int) = layerWall.unsafeGetTile(coercedX, coercedY)
fun getTileFromTerrainRaw(coercedX: Int, coercedY: Int) = layerTerrain.unsafeGetTile(coercedX, coercedY)
/**
* Set the tile of wall as specified, with damage value of zero.
* @param x

View File

@@ -10,9 +10,11 @@ import net.torvald.terrarum.gameworld.fmod
* Created by minjaesong on 2016-03-27.
*/
object LandUtil {
fun getBlockAddr(world: GameWorld, x: Int, y: Int): BlockAddress =
// coercing and fmod-ing follows ROUNDWORLD rule. See: GameWorld.coerceXY()
(world.width * y.coerceIn(0, world.height - 1)).toLong() + x.fmod(world.width)
fun getBlockAddr(world: GameWorld, x: Int, y: Int): BlockAddress {
// coercing and fmod-ing follows ROUNDWORLD rule. See: GameWorld.coerceXY()
val (x, y) = world.coerceXY(x, y)
return (world.width.toLong() * y) + x
}
fun resolveBlockAddr(world: GameWorld, t: BlockAddress): Pair<Int, Int> =
Pair((t % world.width).toInt(), (t / world.width).toInt())

View File

@@ -674,10 +674,12 @@ object LightmapRenderer {
* - sunlight
*/
private fun getLightsAndShades(x: Int, y: Int) {
val (x, y) = world.coerceXY(x, y)
lightLevelThis.set(colourNull)
thisTerrain = world.getTileFromTerrain(x, y)
thisTerrain = world.getTileFromTerrainRaw(x, y)
thisFluid = world.getFluid(x, y)
thisWall = world.getTileFromWall(x, y)
thisWall = world.getTileFromWallRaw(x, y)
// regarding the issue #26
try {