Same goes to karst/worm caves
This commit is contained in:
parent
fbbab1c82d
commit
82c2d1315e
@ -3,6 +3,7 @@ package ru.dbotthepony.kstarbound.world.terrain
|
|||||||
import com.github.benmanes.caffeine.cache.Caffeine
|
import com.github.benmanes.caffeine.cache.Caffeine
|
||||||
import com.github.benmanes.caffeine.cache.Scheduler
|
import com.github.benmanes.caffeine.cache.Scheduler
|
||||||
import ru.dbotthepony.kommons.arrays.Double2DArray
|
import ru.dbotthepony.kommons.arrays.Double2DArray
|
||||||
|
import ru.dbotthepony.kommons.arrays.Float2DArray
|
||||||
import ru.dbotthepony.kstarbound.math.vector.Vector2i
|
import ru.dbotthepony.kstarbound.math.vector.Vector2i
|
||||||
import ru.dbotthepony.kstarbound.Starbound
|
import ru.dbotthepony.kstarbound.Starbound
|
||||||
import ru.dbotthepony.kstarbound.defs.PerlinNoiseParameters
|
import ru.dbotthepony.kstarbound.defs.PerlinNoiseParameters
|
||||||
@ -67,7 +68,7 @@ class KarstCaveTerrainSelector(data: Data, parameters: TerrainSelectorParameters
|
|||||||
|
|
||||||
private inner class Sector(val sector: Vector2i) {
|
private inner class Sector(val sector: Vector2i) {
|
||||||
private var maxValue = 0.0
|
private var maxValue = 0.0
|
||||||
private val values = Double2DArray.allocate(data.sectorSize, data.sectorSize)
|
private val values = Float2DArray.allocate(data.sectorSize, data.sectorSize)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
for (y in sector.y - data.bufferHeight until sector.y + data.sectorSize + data.bufferHeight) {
|
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 {
|
operator fun get(x: Int, y: Int): Double {
|
||||||
val get = values[x - sector.x, y - sector.y]
|
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) {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.kstarbound.world.terrain
|
|||||||
import com.github.benmanes.caffeine.cache.Caffeine
|
import com.github.benmanes.caffeine.cache.Caffeine
|
||||||
import com.github.benmanes.caffeine.cache.Scheduler
|
import com.github.benmanes.caffeine.cache.Scheduler
|
||||||
import ru.dbotthepony.kommons.arrays.Double2DArray
|
import ru.dbotthepony.kommons.arrays.Double2DArray
|
||||||
|
import ru.dbotthepony.kommons.arrays.Float2DArray
|
||||||
import ru.dbotthepony.kommons.math.linearInterpolation
|
import ru.dbotthepony.kommons.math.linearInterpolation
|
||||||
import ru.dbotthepony.kstarbound.math.vector.Vector2d
|
import ru.dbotthepony.kstarbound.math.vector.Vector2d
|
||||||
import ru.dbotthepony.kstarbound.math.vector.Vector2i
|
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 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
|
private var maxValue = data.wormSizeRange.y / 2.0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -172,11 +173,11 @@ class WormCaveTerrainSelector(data: Data, parameters: TerrainSelectorParameters)
|
|||||||
|
|
||||||
operator fun get(x: Int, y: Int): Double {
|
operator fun get(x: Int, y: Int): Double {
|
||||||
val get = values[x - sector.x, y - sector.y]
|
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) {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user