Same goes to karst/worm caves

This commit is contained in:
DBotThePony 2024-04-21 22:30:14 +07:00
parent fbbab1c82d
commit 82c2d1315e
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 8 additions and 6 deletions
src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.kstarbound.world.terrain
import com.github.benmanes.caffeine.cache.Caffeine
import com.github.benmanes.caffeine.cache.Scheduler
import ru.dbotthepony.kommons.arrays.Double2DArray
import ru.dbotthepony.kommons.arrays.Float2DArray
import ru.dbotthepony.kstarbound.math.vector.Vector2i
import ru.dbotthepony.kstarbound.Starbound
import ru.dbotthepony.kstarbound.defs.PerlinNoiseParameters
@ -67,7 +68,7 @@ class KarstCaveTerrainSelector(data: Data, parameters: TerrainSelectorParameters
private inner class Sector(val sector: Vector2i) {
private var maxValue = 0.0
private val values = Double2DArray.allocate(data.sectorSize, data.sectorSize)
private val values = Float2DArray.allocate(data.sectorSize, data.sectorSize)
init {
for (y in sector.y - data.bufferHeight until sector.y + data.sectorSize + data.bufferHeight) {
@ -118,11 +119,11 @@ class KarstCaveTerrainSelector(data: Data, parameters: TerrainSelectorParameters
operator fun get(x: Int, y: Int): Double {
val get = values[x - sector.x, y - sector.y]
return if (get > 0.0) get else -maxValue
return if (get > 0.0) get.toDouble() else -maxValue
}
private operator fun set(x: Int, y: Int, value: Double) {
values[x - sector.x, y - sector.y] = value
values[x - sector.x, y - sector.y] = value.toFloat()
}
}

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.kstarbound.world.terrain
import com.github.benmanes.caffeine.cache.Caffeine
import com.github.benmanes.caffeine.cache.Scheduler
import ru.dbotthepony.kommons.arrays.Double2DArray
import ru.dbotthepony.kommons.arrays.Float2DArray
import ru.dbotthepony.kommons.math.linearInterpolation
import ru.dbotthepony.kstarbound.math.vector.Vector2d
import ru.dbotthepony.kstarbound.math.vector.Vector2i
@ -49,7 +50,7 @@ class WormCaveTerrainSelector(data: Data, parameters: TerrainSelectorParameters)
)
private inner class Sector(val sector: Vector2i) {
private val values = Double2DArray.allocate(data.sectorSize, data.sectorSize)
private val values = Float2DArray.allocate(data.sectorSize, data.sectorSize)
private var maxValue = data.wormSizeRange.y / 2.0
init {
@ -172,11 +173,11 @@ class WormCaveTerrainSelector(data: Data, parameters: TerrainSelectorParameters)
operator fun get(x: Int, y: Int): Double {
val get = values[x - sector.x, y - sector.y]
return if (get > 0.0) get else -maxValue
return if (get > 0.0) get.toDouble() else -maxValue
}
private operator fun set(x: Int, y: Int, value: Double) {
values[x - sector.x, y - sector.y] = value
values[x - sector.x, y - sector.y] = value.toFloat()
}
}