Use world's random in animator
This commit is contained in:
parent
a498c8704b
commit
999f3a8d4f
@ -49,6 +49,7 @@ import ru.dbotthepony.kstarbound.util.random.random
|
||||
import ru.dbotthepony.kstarbound.world.physics.Poly
|
||||
import java.util.*
|
||||
import java.util.function.Consumer
|
||||
import java.util.random.RandomGenerator
|
||||
import kotlin.NoSuchElementException
|
||||
import kotlin.math.atan2
|
||||
import kotlin.math.cos
|
||||
@ -469,15 +470,13 @@ class Animator() {
|
||||
|
||||
val networkGroup = NetworkedGroup()
|
||||
|
||||
private val elements = ArrayList<NetworkedElement>()
|
||||
var processingDirectives by networkedString().also { networkGroup.add(it) }
|
||||
var zoom by networkedFloat(1.0).also { networkGroup.add(it) }
|
||||
var isFlipped by networkedBoolean().also { networkGroup.add(it) }
|
||||
var flippedRelativeCenterLine by networkedFloat().also { networkGroup.add(it) }
|
||||
var animationRate by networkedFloat(1.0).also { networkGroup.add(it); it.interpolator = Interpolator.Linear }
|
||||
|
||||
var processingDirectives by networkedString().also { elements.add(it) }
|
||||
var zoom by networkedFloat(1.0).also { elements.add(it) }
|
||||
var isFlipped by networkedBoolean().also { elements.add(it) }
|
||||
var flippedRelativeCenterLine by networkedFloat().also { elements.add(it) }
|
||||
var animationRate by networkedFloat(1.0).also { elements.add(it); it.interpolator = Interpolator.Linear }
|
||||
|
||||
private val globalTags = NetworkedMap(InternedStringCodec, InternedStringCodec)
|
||||
private val globalTags = NetworkedMap(InternedStringCodec, InternedStringCodec).also { networkGroup.add(it) }
|
||||
private val parts = Object2ObjectAVLTreeMap<String, Part>()
|
||||
private val partTags = HashMap<String, NetworkedMap<String, String>>()
|
||||
|
||||
@ -490,12 +489,6 @@ class Animator() {
|
||||
private val sounds = Object2ObjectAVLTreeMap<String, Sound>()
|
||||
private val effects = Object2ObjectAVLTreeMap<String, Effect>()
|
||||
|
||||
private val random = random()
|
||||
|
||||
init {
|
||||
setupNetworkElements()
|
||||
}
|
||||
|
||||
constructor(config: AnimationDefinition) : this() {
|
||||
for ((k, v) in config.globalTagDefaults) {
|
||||
globalTags[k] = v
|
||||
@ -602,30 +595,6 @@ class Animator() {
|
||||
partTags.computeIfAbsent(k) { NetworkedMap(InternedStringCodec, InternedStringCodec) }
|
||||
}
|
||||
|
||||
setupNetworkElements()
|
||||
}
|
||||
|
||||
// Every part image can have one or more <tag> directives in it, which if set
|
||||
// here will be replaced by the tag value when constructing Drawables. All
|
||||
// Drawables can also have a <frame> tag which will be set to whatever the
|
||||
// current state frame is (1 indexed, so the first frame is 1).
|
||||
fun setGlobalTag(key: String, value: String) {
|
||||
globalTags[key] = value
|
||||
}
|
||||
|
||||
fun setPartTag(partName: String, tagKey: String, tagValue: String) {
|
||||
partTags.computeIfAbsent(partName) {
|
||||
LOGGER.warn("Creating part tags for $it after initialization, this can cause client-server desyncs")
|
||||
NetworkedMap(InternedStringCodec, InternedStringCodec)
|
||||
}.put(tagKey, tagValue)
|
||||
}
|
||||
|
||||
private fun setupNetworkElements() {
|
||||
networkGroup.clear()
|
||||
elements.forEach { networkGroup.add(it) }
|
||||
|
||||
networkGroup.add(globalTags)
|
||||
|
||||
// animated part set
|
||||
for (v in parts.keys) {
|
||||
networkGroup.add(partTags[v] ?: throw RuntimeException("Missing animated part $v!"))
|
||||
@ -634,10 +603,10 @@ class Animator() {
|
||||
stateTypes.entries.stream()
|
||||
.sorted { o1, o2 -> o1.key.compareTo(o2.key) }
|
||||
.map { it.value }
|
||||
.forEach {
|
||||
networkGroup.add(it.stateIndex)
|
||||
networkGroup.add(it.startedEvent)
|
||||
}
|
||||
.forEach {
|
||||
networkGroup.add(it.stateIndex)
|
||||
networkGroup.add(it.startedEvent)
|
||||
}
|
||||
|
||||
for (v in transformationGroups.values) {
|
||||
v.addTo(networkGroup)
|
||||
@ -665,6 +634,22 @@ class Animator() {
|
||||
}
|
||||
}
|
||||
|
||||
// Every part image can have one or more <tag> directives in it, which if set
|
||||
// here will be replaced by the tag value when constructing Drawables. All
|
||||
// Drawables can also have a <frame> tag which will be set to whatever the
|
||||
// current state frame is (1 indexed, so the first frame is 1).
|
||||
fun setGlobalTag(key: String, value: String) {
|
||||
globalTags[key] = value
|
||||
}
|
||||
|
||||
fun setPartTag(partName: String, tagKey: String, tagValue: String) {
|
||||
partTags.computeIfAbsent(partName) {
|
||||
LOGGER.warn("Creating part tags for $it after initialization, this can cause client-server desyncs")
|
||||
NetworkedMap(InternedStringCodec, InternedStringCodec)
|
||||
}.put(tagKey, tagValue)
|
||||
}
|
||||
|
||||
|
||||
fun setActiveState(type: String, state: String, alwaysStart: Boolean = false): Boolean {
|
||||
return stateTypes[type]?.set(state, alwaysStart) ?: return false
|
||||
}
|
||||
@ -944,7 +929,7 @@ class Animator() {
|
||||
|
||||
// TODO: Dynamic target
|
||||
@Suppress("Name_Shadowing")
|
||||
fun tick(delta: Double) {
|
||||
fun tick(delta: Double, random: RandomGenerator) {
|
||||
val delta = delta * animationRate
|
||||
|
||||
for (state in stateTypes.values) {
|
||||
|
@ -572,7 +572,7 @@ open class WorldObject(val config: Registry.Entry<ObjectDefinition>) : TileEntit
|
||||
lastClosestSpaceToDamageSource = null
|
||||
}
|
||||
|
||||
animator.tick(delta)
|
||||
animator.tick(delta, world.random)
|
||||
|
||||
val orientation = orientation
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user