Fixes to dataValue and flickering lights
This commit is contained in:
parent
328cab8127
commit
a41037826c
build.gradle.kts
src/main/kotlin/ru/dbotthepony/kstarbound
@ -82,7 +82,7 @@ dependencies {
|
||||
implementation("com.github.jnr:jnr-ffi:2.2.13")
|
||||
|
||||
implementation("ru.dbotthepony:kbox2d:2.4.1.6")
|
||||
implementation("ru.dbotthepony:kvector:2.6.0")
|
||||
implementation("ru.dbotthepony:kvector:2.6.1")
|
||||
|
||||
implementation("com.github.ben-manes.caffeine:caffeine:3.1.5")
|
||||
}
|
||||
|
@ -788,10 +788,10 @@ class StarboundClient : Closeable {
|
||||
viewportWidth / settings.zoom / PIXELS_IN_STARBOUND_UNIT,
|
||||
viewportHeight / settings.zoom / PIXELS_IN_STARBOUND_UNIT)
|
||||
|
||||
viewportCellX = roundTowardsNegativeInfinity(viewportRectangle.mins.x) - 4
|
||||
viewportCellY = roundTowardsNegativeInfinity(viewportRectangle.mins.y) - 4
|
||||
viewportCellWidth = roundTowardsPositiveInfinity(viewportRectangle.width) + 8
|
||||
viewportCellHeight = roundTowardsPositiveInfinity(viewportRectangle.height) + 8
|
||||
viewportCellX = roundTowardsNegativeInfinity(viewportRectangle.mins.x) - 16
|
||||
viewportCellY = roundTowardsNegativeInfinity(viewportRectangle.mins.y) - 16
|
||||
viewportCellWidth = roundTowardsPositiveInfinity(viewportRectangle.width) + 32
|
||||
viewportCellHeight = roundTowardsPositiveInfinity(viewportRectangle.height) + 32
|
||||
|
||||
if (viewportLighting.width != viewportCellWidth || viewportLighting.height != viewportCellHeight) {
|
||||
viewportLighting = LightCalculator(viewportCells, viewportCellWidth, viewportCellHeight)
|
||||
|
@ -182,10 +182,19 @@ abstract class JsonDriven(val path: String) {
|
||||
value = properties[name]?.let { if (alwaysCopy) it.deepCopy() else it }
|
||||
} else {
|
||||
val itr = defs.iterator()
|
||||
value = merge(properties[name], itr.next()[name])
|
||||
var isCopy = false
|
||||
value = properties[name]
|
||||
|
||||
while ((value == null || value is JsonObject) && itr.hasNext()) {
|
||||
value = mergeNoCopy(value, itr.next()[name])
|
||||
val next = itr.next()[name]
|
||||
|
||||
if (value is JsonObject) {
|
||||
if (next !is JsonObject) continue
|
||||
value = mergeNoCopy(if (isCopy) value else value.deepCopy(), next)
|
||||
isCopy = true
|
||||
} else {
|
||||
value = next
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,27 +217,12 @@ abstract class JsonDriven(val path: String) {
|
||||
|
||||
if (existing == null) {
|
||||
a[k] = v.deepCopy()
|
||||
} else {
|
||||
a[k] = mergeNoCopy(existing, v)!!
|
||||
} else if (existing is JsonObject && v is JsonObject) {
|
||||
a[k] = mergeNoCopy(existing, v)
|
||||
}
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
protected fun mergeNoCopy(a: JsonElement?, b: JsonElement?): JsonElement? {
|
||||
if (a is JsonObject && b is JsonObject) return mergeNoCopy(a, b)
|
||||
return a
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
protected fun merge(a: JsonElement?, b: JsonElement?): JsonElement? {
|
||||
if (a == null && b == null) return null
|
||||
if (a == null) return b!!.deepCopy()
|
||||
if (b == null) return a.deepCopy()
|
||||
|
||||
return mergeNoCopy(a.deepCopy(), b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package ru.dbotthepony.kstarbound.math
|
||||
|
||||
import ru.dbotthepony.kvector.util.linearInterpolation
|
||||
import java.util.random.RandomGenerator
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.sin
|
||||
|
||||
data class PeriodicFunction(
|
||||
val period: Double = 1.0,
|
||||
@ -14,6 +16,12 @@ data class PeriodicFunction(
|
||||
fun interpolate(t: Double, a: Double, b: Double): Double
|
||||
}
|
||||
|
||||
object Sin : Interpolator {
|
||||
override fun interpolate(t: Double, a: Double, b: Double): Double {
|
||||
return linearInterpolation((sin(t * PI - PI / 2.0) + 1.0) / 2.0, a, b)
|
||||
}
|
||||
}
|
||||
|
||||
private var timer = 0.0
|
||||
private var timerMax = 1.0
|
||||
|
||||
@ -31,9 +39,9 @@ data class PeriodicFunction(
|
||||
// we, however, do not, if period time is big enough
|
||||
while (timer <= 0.0) {
|
||||
base = target
|
||||
target = (if (isDescending) min else max) + random.nextDouble(-magnitudeVariance, magnitudeVariance)
|
||||
target = (if (isDescending) min else max) + if (magnitudeVariance == 0.0) 0.0 else random.nextDouble(-magnitudeVariance, magnitudeVariance)
|
||||
isDescending = !isDescending
|
||||
timerMax = (halfPeriod + random.nextDouble(-halfVariance, halfVariance)).coerceAtLeast(0.01)
|
||||
timerMax = (halfPeriod + if (halfVariance == 0.0) 0.0 else random.nextDouble(-halfVariance, halfVariance)).coerceAtLeast(0.01)
|
||||
timer += timerMax
|
||||
|
||||
if (timerMax <= 0.05 && timer <= 0.0) {
|
||||
@ -50,4 +58,8 @@ data class PeriodicFunction(
|
||||
fun value(): Double {
|
||||
return value(::linearInterpolation)
|
||||
}
|
||||
|
||||
fun sinValue(): Double {
|
||||
return value(Sin)
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import ru.dbotthepony.kvector.vector.Vector2d
|
||||
import ru.dbotthepony.kvector.vector.Vector2i
|
||||
import java.lang.ref.ReferenceQueue
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.random.RandomGenerator
|
||||
|
||||
const val CHUNK_SIZE_BITS = 5
|
||||
const val CHUNK_SIZE_MASK = 1 or 2 or 4 or 8 or 16
|
||||
@ -239,6 +240,8 @@ abstract class World<This : World<This, ChunkType>, ChunkType : Chunk<This, Chun
|
||||
|
||||
val chunkMap: ChunkMap = if (size != null) ArrayChunkMap() else HashChunkMap()
|
||||
|
||||
val random: RandomGenerator = RandomGenerator.of("Xoroshiro128PlusPlus")
|
||||
|
||||
/**
|
||||
* Chunks, which have their collision mesh changed
|
||||
*/
|
||||
|
@ -51,7 +51,6 @@ open class WorldObject(
|
||||
//
|
||||
val clientWorld get() = world as ClientWorld
|
||||
val orientations = prototype.value.orientations
|
||||
val validOrientations = orientations.size
|
||||
protected val renderParamLocations = Object2ObjectOpenHashMap<String, () -> String?>()
|
||||
private var frame = 0
|
||||
set(value) {
|
||||
@ -62,6 +61,7 @@ open class WorldObject(
|
||||
}
|
||||
|
||||
private var frameTimer = 0.0
|
||||
val flickerPeriod = prototype.value.flickerPeriod?.copy()
|
||||
|
||||
var isRemoved = false
|
||||
private set
|
||||
@ -138,7 +138,7 @@ open class WorldObject(
|
||||
}
|
||||
|
||||
open fun thinkShared() {
|
||||
|
||||
flickerPeriod?.update(Starbound.TICK_TIME_ADVANCE, world.random)
|
||||
}
|
||||
|
||||
open fun thinkClient() {
|
||||
@ -170,8 +170,15 @@ open class WorldObject(
|
||||
}
|
||||
|
||||
fun addLights(lightCalculator: LightCalculator, xOffset: Int, yOffset: Int) {
|
||||
if ("default" in lightColors) {
|
||||
lightCalculator.addPointLight(pos.x - xOffset, pos.y - yOffset, lightColors["default"]!!)
|
||||
var color = lightColors[color.lowercase]
|
||||
|
||||
if (color != null) {
|
||||
if (flickerPeriod != null) {
|
||||
val sample = flickerPeriod.sinValue().toFloat()
|
||||
color *= sample
|
||||
}
|
||||
|
||||
lightCalculator.addPointLight(pos.x - xOffset, pos.y - yOffset, color)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user