mirror of
https://github.com/Bixilon/Minosoft.git
synced 2026-12-05 07:48:20 +00:00
biome sampling: check if source supports it
This commit is contained in:
5 files changed
+36
-7
No files matched your search
@@ -19,7 +19,7 @@ import de.bixilon.minosoft.data.world.chunk.ChunkSize
|
||||
import de.bixilon.minosoft.data.world.positions.InChunkPosition
|
||||
|
||||
class XZBiomeArray(private val biomes: Array<Biome?>) : BiomeSource {
|
||||
override val flags = IntInlineEnumSet<BiomeSourceFlags>() + BiomeSourceFlags.VERTICAL
|
||||
override val flags = IntInlineEnumSet<BiomeSourceFlags>() + BiomeSourceFlags.HORIZONTAL
|
||||
|
||||
init {
|
||||
assert(biomes.size == ChunkSize.SECTION_WIDTH_X * ChunkSize.SECTION_WIDTH_Z) { "Biome array size does not match the xz block count!" }
|
||||
|
||||
@@ -33,6 +33,7 @@ class SampledColor {
|
||||
}
|
||||
|
||||
fun toColor(): RGBColor {
|
||||
assert(count >= 0 && count < (1 shl 24))
|
||||
if (count == 0) {
|
||||
return Colors.WHITE_RGB
|
||||
}
|
||||
@@ -40,6 +41,7 @@ class SampledColor {
|
||||
}
|
||||
|
||||
fun toNullColor(): RGBColor? {
|
||||
assert(count >= 0 && count < (1 shl 24))
|
||||
if (count == 0) return null
|
||||
|
||||
return RGBColor(this.red / count, this.green / count, this.blue / count)
|
||||
|
||||
+1
@@ -18,6 +18,7 @@ import kotlin.math.exp
|
||||
// who would have though that the computer vision course at university would help me someday...
|
||||
object GaussianKernel {
|
||||
const val MAX_RADIUS = 15
|
||||
val SINGLE = listOf(GaussianSample(0, 0, 0, 1)).pack()
|
||||
private val cache2D: Array<GaussianSampleList?> = arrayOfNulls(MAX_RADIUS)
|
||||
private val cache3D: Array<GaussianSampleList?> = arrayOfNulls(MAX_RADIUS)
|
||||
|
||||
|
||||
+19
-5
@@ -16,24 +16,38 @@ package de.bixilon.minosoft.gui.rendering.tint.sampler.gaussian
|
||||
import de.bixilon.minosoft.data.registries.biomes.Biome
|
||||
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||
import de.bixilon.minosoft.data.world.biome.source.BiomeSourceFlags
|
||||
import de.bixilon.minosoft.data.world.chunk.chunk.Chunk
|
||||
import de.bixilon.minosoft.data.world.positions.BlockPosition
|
||||
import de.bixilon.minosoft.gui.rendering.tint.TintProvider
|
||||
import de.bixilon.minosoft.gui.rendering.tint.sampler.RadiusColorSampler
|
||||
|
||||
class GaussianTintSampler(radius: Int = 5) : RadiusColorSampler(radius) {
|
||||
private val kernel = GaussianKernel.get2D(radius)
|
||||
private var kernel: GaussianSampleList? = null
|
||||
|
||||
private fun getKernel(chunk: Chunk): GaussianSampleList? {
|
||||
kernel?.let { return it }
|
||||
val source = chunk.biomeSource ?: return null
|
||||
|
||||
val kernel = when {
|
||||
BiomeSourceFlags.HORIZONTAL !in source.flags -> GaussianKernel.SINGLE
|
||||
BiomeSourceFlags.VERTICAL in source.flags -> GaussianKernel.get3D(radius)
|
||||
else -> GaussianKernel.get2D(radius)
|
||||
}
|
||||
this.kernel = kernel
|
||||
|
||||
return kernel
|
||||
}
|
||||
|
||||
// TODO: check if biome source actually supports 3d biomes
|
||||
override fun sampleFluid(chunk: Chunk, position: BlockPosition, provider: TintProvider) {
|
||||
kernel.iterate { x, y, z, weight -> sampleFluid(chunk, position, BlockPosition(x, y, z), weight, provider) }
|
||||
getKernel(chunk)?.iterate { x, y, z, weight -> sampleFluid(chunk, position, BlockPosition(x, y, z), weight, provider) }
|
||||
}
|
||||
|
||||
override fun sampleBlock(chunk: Chunk, state: BlockState, position: BlockPosition, provider: TintProvider) {
|
||||
kernel.iterate { x, y, z, weight -> sampleBlock(chunk, state, position, BlockPosition(x, y, z), weight, provider) }
|
||||
getKernel(chunk)?.iterate { x, y, z, weight -> sampleBlock(chunk, state, position, BlockPosition(x, y, z), weight, provider) }
|
||||
}
|
||||
|
||||
override fun sampleCustomColor(chunk: Chunk, position: BlockPosition, sampler: (Biome) -> RGBColor?) {
|
||||
kernel.iterate { x, y, z, weight -> sampleCustom(chunk, position, BlockPosition(x, y, z), weight, sampler) }
|
||||
getKernel(chunk)?.iterate { x, y, z, weight -> sampleCustom(chunk, position, BlockPosition(x, y, z), weight, sampler) }
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.tint.sampler.simple
|
||||
import de.bixilon.minosoft.data.registries.biomes.Biome
|
||||
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||
import de.bixilon.minosoft.data.world.biome.source.BiomeSourceFlags
|
||||
import de.bixilon.minosoft.data.world.chunk.chunk.Chunk
|
||||
import de.bixilon.minosoft.data.world.positions.BlockPosition
|
||||
import de.bixilon.minosoft.gui.rendering.tint.TintProvider
|
||||
@@ -23,10 +24,19 @@ import de.bixilon.minosoft.gui.rendering.tint.sampler.RadiusColorSampler
|
||||
|
||||
class SimpleTintSampler(radius: Int = 5) : RadiusColorSampler(radius) {
|
||||
|
||||
// TODO: check if biome source actually supports 3d biomes
|
||||
private fun getRadius(chunk: Chunk): Int {
|
||||
val source = chunk.biomeSource ?: return 0
|
||||
|
||||
if (BiomeSourceFlags.HORIZONTAL !in source.flags) return 0
|
||||
|
||||
return this.radius
|
||||
}
|
||||
|
||||
// TODO: support 3d sampling
|
||||
override fun sampleFluid(chunk: Chunk, position: BlockPosition, provider: TintProvider) {
|
||||
sampleFluid(chunk, position, BlockPosition(0, 0, 0), 100, provider)
|
||||
|
||||
val radius = getRadius(chunk)
|
||||
val diameter = radius * radius
|
||||
|
||||
var offset = 1
|
||||
@@ -53,6 +63,7 @@ class SimpleTintSampler(radius: Int = 5) : RadiusColorSampler(radius) {
|
||||
override fun sampleBlock(chunk: Chunk, state: BlockState, position: BlockPosition, provider: TintProvider) {
|
||||
sampleBlock(chunk, state, position, BlockPosition(0, 0, 0), 100, provider)
|
||||
|
||||
val radius = getRadius(chunk)
|
||||
val diameter = radius * radius
|
||||
|
||||
var offset = 1
|
||||
@@ -78,6 +89,7 @@ class SimpleTintSampler(radius: Int = 5) : RadiusColorSampler(radius) {
|
||||
override fun sampleCustomColor(chunk: Chunk, position: BlockPosition, sampler: (Biome) -> RGBColor?) {
|
||||
sampleCustom(chunk, position, BlockPosition(0, 0, 0), 100, sampler)
|
||||
|
||||
val radius = getRadius(chunk)
|
||||
val diameter = radius * radius
|
||||
|
||||
var offset = 1
|
||||
|
||||
Reference in new issue
Block a user