diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/random/AbstractPerlinNoise.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/random/AbstractPerlinNoise.kt index 0e6054d0..bac7b483 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/random/AbstractPerlinNoise.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/util/random/AbstractPerlinNoise.kt @@ -37,15 +37,15 @@ abstract class AbstractPerlinNoise(val parameters: PerlinNoiseParameters) { protected data class Setup(val b0: Int, val b1: Int, val r0: Double, val r1: Double) protected val p by lazy(LazyThreadSafetyMode.NONE) { IntArray(SCALE * 2 + 2) } - protected val g1 by lazy(LazyThreadSafetyMode.NONE) { DoubleArray(SCALE * 2 + 2) } + protected val g1 by lazy(LazyThreadSafetyMode.NONE) { FloatArray(SCALE * 2 + 2) } // flat arrays for performance - protected val g2_0 by lazy(LazyThreadSafetyMode.NONE) { DoubleArray(SCALE * 2 + 2) } - protected val g2_1 by lazy(LazyThreadSafetyMode.NONE) { DoubleArray(SCALE * 2 + 2) } + protected val g2_0 by lazy(LazyThreadSafetyMode.NONE) { FloatArray(SCALE * 2 + 2) } + protected val g2_1 by lazy(LazyThreadSafetyMode.NONE) { FloatArray(SCALE * 2 + 2) } - protected val g3_0 by lazy(LazyThreadSafetyMode.NONE) { DoubleArray(SCALE * 2 + 2) } - protected val g3_1 by lazy(LazyThreadSafetyMode.NONE) { DoubleArray(SCALE * 2 + 2) } - protected val g3_2 by lazy(LazyThreadSafetyMode.NONE) { DoubleArray(SCALE * 2 + 2) } + protected val g3_0 by lazy(LazyThreadSafetyMode.NONE) { FloatArray(SCALE * 2 + 2) } + protected val g3_1 by lazy(LazyThreadSafetyMode.NONE) { FloatArray(SCALE * 2 + 2) } + protected val g3_2 by lazy(LazyThreadSafetyMode.NONE) { FloatArray(SCALE * 2 + 2) } private var init = false private val initLock = Any() @@ -90,42 +90,42 @@ abstract class AbstractPerlinNoise(val parameters: PerlinNoiseParameters) { val g3_2 = g3_2 p.fill(0) - g1.fill(0.0) - g2_0.fill(0.0) - g2_1.fill(0.0) - g3_0.fill(0.0) - g3_1.fill(0.0) - g3_2.fill(0.0) + g1.fill(0f) + g2_0.fill(0f) + g2_1.fill(0f) + g3_0.fill(0f) + g3_1.fill(0f) + g3_2.fill(0f) val random = random(seed) for (i in 0 until SCALE) { p[i] = i - g1[i] = random.nextInt(-SCALE, SCALE) / SCALE.toDouble() + g1[i] = random.nextInt(-SCALE, SCALE) / SCALE.toFloat() - g2_0[i] = random.nextInt(-SCALE, SCALE) / SCALE.toDouble() - g2_1[i] = random.nextInt(-SCALE, SCALE) / SCALE.toDouble() + g2_0[i] = random.nextInt(-SCALE, SCALE) / SCALE.toFloat() + g2_1[i] = random.nextInt(-SCALE, SCALE) / SCALE.toFloat() - g3_0[i] = random.nextInt(-SCALE, SCALE) / SCALE.toDouble() - g3_1[i] = random.nextInt(-SCALE, SCALE) / SCALE.toDouble() - g3_2[i] = random.nextInt(-SCALE, SCALE) / SCALE.toDouble() + g3_0[i] = random.nextInt(-SCALE, SCALE) / SCALE.toFloat() + g3_1[i] = random.nextInt(-SCALE, SCALE) / SCALE.toFloat() + g3_2[i] = random.nextInt(-SCALE, SCALE) / SCALE.toFloat() val l2 = sqrt(g2_0[i] * g2_0[i] + g2_1[i] * g2_1[i]) val l3 = sqrt(g3_0[i] * g3_0[i] + g3_1[i] * g3_1[i] + g3_2[i] * g3_2[i]) - if (l2 == 0.0) { - g2_0[i] = 1.0 - g2_1[i] = 0.0 + if (l2 == 0f) { + g2_0[i] = 1f + g2_1[i] = 0f } else { g2_0[i] = g2_0[i] / l2 g2_1[i] = g2_1[i] / l2 } - if (l3 == 0.0) { - g3_0[i] = 1.0 - g3_1[i] = 0.0 - g3_2[i] = 0.0 + if (l3 == 0f) { + g3_0[i] = 1f + g3_1[i] = 0f + g3_2[i] = 0f } else { g3_0[i] = g3_0[i] / l3 g3_1[i] = g3_1[i] / l3 @@ -171,12 +171,12 @@ abstract class AbstractPerlinNoise(val parameters: PerlinNoiseParameters) { } @Suppress("NOTHING_TO_INLINE") - protected inline fun at2(x: Double, y: Double, rx: Double, ry: Double): Double { + protected inline fun at2(x: Float, y: Float, rx: Double, ry: Double): Double { return rx * x + ry * y } @Suppress("NOTHING_TO_INLINE") - protected inline fun at3(x: Double, y: Double, z: Double, rx: Double, ry: Double, rz: Double): Double { + protected inline fun at3(x: Float, y: Float, z: Float, rx: Double, ry: Double, rz: Double): Double { return rx * x + ry * y + rz * z }