mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-30 13:52:47 -08:00
PacketDropSimulatorInputProcessor
This commit is contained in:
1 parent
06a54e106e
commit
a0f6bbfd92
3 files changed
+42
-1
No files matched your search
@@ -75,6 +75,8 @@ class LocalizerResetBehaviour(val settings: Settings) : SkeletonBehaviour {
|
||||
*/
|
||||
class YouSpinMeRightRoundBehaviour(val inputHz: Int = 100, val speed: Float = 1f, val randomPacketLoss: Float = 0f, val constantPacketLoss: Float = 0f, val sendPosition: Boolean = false) : SkeletonBehaviour {
|
||||
override fun observe(receiver: Skeleton) {
|
||||
println("YouSpinMeRightRoundBehaviour sending fake bone data for simulation.")
|
||||
|
||||
receiver.context.scope.launch {
|
||||
val interval = (millisecondsInSecond / inputHz.toFloat()).toLong().milliseconds
|
||||
val startTime = timeSource.markNow()
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package dev.slimevr.skeleton.inputprocessors
|
||||
|
||||
import dev.slimevr.skeleton.BodyPartMap
|
||||
import dev.slimevr.skeleton.BoneInput
|
||||
import dev.slimevr.skeleton.InputSkeleton
|
||||
import dev.slimevr.skeleton.SkeletonInputProcessor
|
||||
import dev.slimevr.skeleton.bodyPartMap
|
||||
import kotlin.random.Random
|
||||
import kotlin.time.ComparableTimeMark
|
||||
|
||||
/**
|
||||
* Used for simulating packet drop, leave commented for production.
|
||||
*/
|
||||
class PacketDropSimulatorInputProcessor(val randomPacketDrop: Float) : SkeletonInputProcessor {
|
||||
init {
|
||||
println("PacketDropSimulatorInputProcessor simulating ${randomPacketDrop * 100}% packet drop.")
|
||||
}
|
||||
|
||||
val lastBone: BodyPartMap<BoneInput> = bodyPartMap()
|
||||
val lastPoseTime: BodyPartMap<ComparableTimeMark> = bodyPartMap()
|
||||
override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) {
|
||||
mutableInputSkeleton.forEach { (part, input) ->
|
||||
val isNewData = lastPoseTime[part] != mutableInputSkeleton[part]?.poseTime
|
||||
lastPoseTime[part] = mutableInputSkeleton[part]?.poseTime
|
||||
if (isNewData) {
|
||||
val dropPacket = Random.nextFloat() < randomPacketDrop
|
||||
if (!dropPacket) {
|
||||
lastBone[part] = input
|
||||
} else if (lastBone[part] != null) {
|
||||
mutableInputSkeleton[part] = lastBone[part]
|
||||
}
|
||||
} else if (lastBone[part] != null) {
|
||||
mutableInputSkeleton[part] = lastBone[part]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import dev.slimevr.skeleton.inputprocessors.FilteringInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.FingersInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.HeadPositionFallbackInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.NeckInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.PacketDropSimulatorInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.SpineInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.ToesInputProcessor
|
||||
import dev.slimevr.skeleton.targetprocessors.FloorClipTargetProcessor
|
||||
@@ -262,12 +263,13 @@ class Skeleton(
|
||||
ProportionsBehaviour(ctx.config.userConfig),
|
||||
HeightLogBehaviour(),
|
||||
LocalizerResetBehaviour(settings),
|
||||
// YouSpinMeRightRoundBehaviour(inputHz = 100, speed = 1f, randomPacketLoss = 0f, constantPacketLoss = 0f, sendPosition = true),
|
||||
// YouSpinMeRightRoundBehaviour(inputHz = 100, speed = 1f, randomPacketLoss = 0.9f, constantPacketLoss = 0f, sendPosition = false),
|
||||
ComputedSkeletonBehaviour(
|
||||
hz = hz,
|
||||
waiter = waiter,
|
||||
// Run before FK on the inputs
|
||||
inputProcessors = listOf(
|
||||
// PacketDropSimulatorInputProcessor(0.85f),
|
||||
FilteringInputProcessor(settings),
|
||||
HeadPositionFallbackInputProcessor(),
|
||||
FallbackInputProcessor(),
|
||||
|
||||
Reference in new issue
Block a user