From dcabe69bc8d78f329be059e0775978ec202c817e Mon Sep 17 00:00:00 2001 From: loucass003 Date: Mon, 14 Sep 2026 03:43:54 +0200 Subject: [PATCH] Bone Routing from pack --- .../dev/slimevr/bones/compiled-skeleton.kt | 32 ++++++- .../slimevr/bones/resource-pack-compiler.kt | 44 ++++++++- .../java/dev/slimevr/routing/behaviours.kt | 16 ++-- .../main/java/dev/slimevr/routing/routing.kt | 84 +++++----------- .../dev/slimevr/solarxr/driver/outgoing.kt | 15 --- .../dev/slimevr/solarxr/rpc/bone-routing.kt | 28 +++--- .../src/main/java/dev/slimevr/vmc/mapping.kt | 3 - .../java/dev/slimevr/vrcosc/output-encoder.kt | 3 - .../slimevr/bones/ResourcePackCompilerTest.kt | 95 +++++++++++++++++- .../slimevr/routing/AutomaticRoutesTest.kt | 26 ++--- .../dev/slimevr/routing/CandidateBonesTest.kt | 38 ++++---- .../dev/slimevr/routing/ManualRoutesTest.kt | 96 +++++++++---------- 12 files changed, 293 insertions(+), 187 deletions(-) diff --git a/server/core/src/main/java/dev/slimevr/bones/compiled-skeleton.kt b/server/core/src/main/java/dev/slimevr/bones/compiled-skeleton.kt index dd3adbf9e..de3bc802a 100644 --- a/server/core/src/main/java/dev/slimevr/bones/compiled-skeleton.kt +++ b/server/core/src/main/java/dev/slimevr/bones/compiled-skeleton.kt @@ -4,6 +4,7 @@ import dev.slimevr.resourcepacks.FixedProportionDefault import dev.slimevr.resourcepacks.HeightRatioProportionDefault import dev.slimevr.resourcepacks.ProportionDefault import io.github.axisangles.ktmath.Vector3 +import solarxr_protocol.rpc.RoutingOutput import solarxr_protocol.rpc.SkeletonBone private fun resolveDefault(default: ProportionDefault, height: Float): Float = when (default) { @@ -49,8 +50,8 @@ data class CompiledOffset(val base: Vector3, val terms: List class BoneOffsets(val tail: BoneMap, val head: BoneMap) /** - * The compiled bone registry, proportion catalog, and per-bone offset, constraint, and - * rotation-fallback rule produced by [compileResourcePacks]. [copyRotationFallbacks] (bone to + * The compiled bone registry, proportion catalog, per-bone offset, constraint, rotation-fallback + * rule, and routing fact produced by [compileResourcePacks]. [copyRotationFallbacks] (bone to * source) and [firstActiveRotationFallbacks] (bone to source list) are each in * ancestor-before-descendant order on their own; every core bone's `copy` source that itself needs * resolving first is its own parent, and a `firstActive` bone's only source that ever needs @@ -66,7 +67,34 @@ class CompiledSkeleton( val constraints: BoneMap, val copyRotationFallbacks: List>, val firstActiveRotationFallbacks: List>>, + private val driverOutputs: BoneSet, + private val vmcOutputs: BoneSet, + private val vrchatOutputs: BoneSet, + private val vrchatRequired: BoneSet, + val overridableBones: BoneSet, + private val candidateSources: BoneMap>, ) { + /** Bones [output] can receive, from each bone's `outputs.driver`/`outputs.vmc`/`outputs.vrchat`. */ + fun acceptedBones(output: RoutingOutput): Set = when (output) { + RoutingOutput.DRIVER -> driverOutputs + RoutingOutput.VMC -> vmcOutputs + RoutingOutput.VRC_OSC -> vrchatOutputs + } + + /** + * Bones [output] that are required and cannot be disabled + */ + fun requiredBones(output: RoutingOutput): Set = when (output) { + RoutingOutput.DRIVER -> emptySet() + RoutingOutput.VMC -> vmcOutputs + RoutingOutput.VRC_OSC -> vrchatRequired + } + + /** Bones with a `candidateSources` list, each naming the bones that make it a routing candidate. */ + val candidateBones: Set get() = candidateSources.keys + + fun candidateSourcesOf(boneId: BoneId): List = candidateSources[boneId] ?: emptyList() + /** Every proportion's default value at [height], keyed by proportion key. */ fun defaultProportionValues(height: Float = REFERENCE_HEIGHT): Map { val result = mutableMapOf() diff --git a/server/core/src/main/java/dev/slimevr/bones/resource-pack-compiler.kt b/server/core/src/main/java/dev/slimevr/bones/resource-pack-compiler.kt index 85511f847..e3a2b1afa 100644 --- a/server/core/src/main/java/dev/slimevr/bones/resource-pack-compiler.kt +++ b/server/core/src/main/java/dev/slimevr/bones/resource-pack-compiler.kt @@ -146,6 +146,12 @@ fun compileResourcePacks(catalog: ResourcePackCatalog): CompiledSkeleton { val constraints = BoneMap.of(registry) val copyFallbacksByBoneId = mutableMapOf>() val firstActiveFallbacksByBoneId = mutableMapOf>() + val driverOutputs = BoneSet.of(registry) + val vmcOutputs = BoneSet.of(registry) + val vrchatOutputs = BoneSet.of(registry) + val vrchatRequired = BoneSet.of(registry) + val overridableBones = BoneSet.of(registry) + val candidateSources = BoneMap.of>(registry) for (contribution in allContributions) { val definition = contribution.resource.value val boneId = registry[definition.key] ?: continue @@ -157,6 +163,16 @@ fun compileResourcePacks(catalog: ResourcePackCatalog): CompiledSkeleton { is CopyRotationFallback -> copyFallbacksByBoneId[boneId] = contribution to fallback is FirstActiveRotationFallback -> firstActiveFallbacksByBoneId[boneId] = contribution to fallback } + definition.outputs?.driver?.let { driverOutputs.add(boneId) } + definition.outputs?.vmc?.let { vmcOutputs.add(boneId) } + definition.outputs?.vrchat?.let { + vrchatOutputs.add(boneId) + if (it.required == true) vrchatRequired.add(boneId) + } + if (definition.overridable == true) overridableBones.add(boneId) + definition.candidateSources?.let { sources -> + candidateSources[boneId] = sources.map { resolveBoneKey(it, contribution, "candidateSources", registry, diagnostics) } + } } val hierarchyOrder = registry.hierarchyFrom(registry.root).map { it.second } val copyRotationFallbacks = hierarchyOrder.mapNotNull { boneId -> @@ -169,7 +185,10 @@ fun compileResourcePacks(catalog: ResourcePackCatalog): CompiledSkeleton { } if (diagnostics.isNotEmpty()) throw ResourcePackCompilationException(diagnostics) - return CompiledSkeleton(registry, proportions, tailOffsets, headOffsets, constraints, copyRotationFallbacks, firstActiveRotationFallbacks) + return CompiledSkeleton( + registry, proportions, tailOffsets, headOffsets, constraints, copyRotationFallbacks, firstActiveRotationFallbacks, + driverOutputs, vmcOutputs, vrchatOutputs, vrchatRequired, overridableBones, candidateSources, + ) } private fun compileConstraint(constraint: PackConstraint): Constraint = when (constraint) { @@ -193,6 +212,20 @@ private fun compileConstraint(constraint: PackConstraint): Constraint = when (co ) } +/** Resolves a bone key referenced from [contribution], reporting [context] on an unknown key. */ +private fun resolveBoneKey( + key: String, + contribution: BoneContribution, + context: String, + registry: BoneRegistry, + diagnostics: MutableList, +): BoneId { + val boneId = registry[key] + if (boneId != null) return boneId + diagnostics += ResourcePackCompilationDiagnostic(contribution.pack.manifest.value.id, contribution.resource.path, "Unknown bone '$key' in $context") + return BoneId(0u) +} + /** Resolves one rotation-fallback source key (or the `"parent"` shorthand) to a [BoneId]. */ private fun resolveFallbackBone( key: String, @@ -201,10 +234,11 @@ private fun resolveFallbackBone( diagnostics: MutableList, ): BoneId { val target = if (key == "parent") contribution.resource.value.parent else key - val boneId = target?.let { registry[it] } - if (boneId != null) return boneId - diagnostics += ResourcePackCompilationDiagnostic(contribution.pack.manifest.value.id, contribution.resource.path, "Unknown bone '$key' in rotationFallback") - return BoneId(0u) + if (target == null) { + diagnostics += ResourcePackCompilationDiagnostic(contribution.pack.manifest.value.id, contribution.resource.path, "Unknown bone '$key' in rotationFallback") + return BoneId(0u) + } + return resolveBoneKey(target, contribution, "rotationFallback", registry, diagnostics) } private fun compileOffset( diff --git a/server/core/src/main/java/dev/slimevr/routing/behaviours.kt b/server/core/src/main/java/dev/slimevr/routing/behaviours.kt index c0c9f3392..1e3182b56 100644 --- a/server/core/src/main/java/dev/slimevr/routing/behaviours.kt +++ b/server/core/src/main/java/dev/slimevr/routing/behaviours.kt @@ -16,7 +16,7 @@ class BoneRoutingBasicBehaviour(private val appContext: AppContextProvider) : Bo override fun observe(receiver: BoneRoutingManager) { val server = appContext.server val settings = appContext.config.settings - val registry = appContext.bones.current + val definition = appContext.skeleton.definition combine( settings.context.state.map { it.data.boneRoutingConfig }.distinctUntilChanged(), @@ -27,7 +27,7 @@ class BoneRoutingBasicBehaviour(private val appContext: AppContextProvider) : Bo if (!config.automatic) { receiver.context.dispatch( BoneRoutingActions.SetRoutes( - effectiveRoutes(manualRoutesAsBoneIds(config.manualRoutes, registry), outputStates, registry), + effectiveRoutes(manualRoutesAsBoneIds(config.manualRoutes, definition), outputStates, definition), ), ) } @@ -47,19 +47,19 @@ class BoneRoutingBasicBehaviour(private val appContext: AppContextProvider) : Bo trackers.map { tracker -> tracker.context.state.distinctUntilChanged { a, b -> a.boneId == b.boneId && a.status == b.status } }, - ) { states -> trackedBodyParts(states.asList(), registry) } + ) { states -> trackedBoneIds(states.asList()) } .distinctUntilChanged() } - .map { fineBodyParts -> Triple(config, outputStates, fineBodyParts) } + .map { boneIds -> Triple(config, outputStates, boneIds) } } - .onEach { (config, outputStates, fineBodyParts) -> - val candidates = determineCandidateBones(fineBodyParts) + .onEach { (config, outputStates, boneIds) -> + val candidates = determineCandidateBones(boneIds, definition) receiver.context.dispatch( BoneRoutingActions.SetRoutes( effectiveRoutes( - computeAutomaticRoutes(candidates, outputStates, registry) + overrideRoutes(config, registry), + computeAutomaticRoutes(candidates, outputStates, definition) + overrideRoutes(config, definition), outputStates, - registry, + definition, ), ), ) diff --git a/server/core/src/main/java/dev/slimevr/routing/routing.kt b/server/core/src/main/java/dev/slimevr/routing/routing.kt index 32df71472..9a871b2b8 100644 --- a/server/core/src/main/java/dev/slimevr/routing/routing.kt +++ b/server/core/src/main/java/dev/slimevr/routing/routing.kt @@ -3,13 +3,10 @@ package dev.slimevr.routing import dev.slimevr.AppContextProvider import dev.slimevr.bones.BodyPart import dev.slimevr.bones.BoneId -import dev.slimevr.bones.BoneRegistry +import dev.slimevr.bones.CompiledSkeleton import dev.slimevr.config.BoneRoutingConfig -import dev.slimevr.solarxr.driver.DRIVER_SUPPORTED_BONES import dev.slimevr.tracker.TrackerState import dev.slimevr.util.isActive -import dev.slimevr.vmc.VMC_SUPPORTED_BONES -import dev.slimevr.vrcosc.VRC_OSC_SUPPORTED_BONES import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine @@ -30,11 +27,7 @@ private val ALL_ACTIVE: OutputStates = RoutingOutput.entries.associateWith { Rou private val PRIORITY_CHAIN = listOf(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC) -fun acceptedBones(output: RoutingOutput): Set = when (output) { - RoutingOutput.DRIVER -> DRIVER_SUPPORTED_BONES - RoutingOutput.VRC_OSC -> VRC_OSC_SUPPORTED_BONES - RoutingOutput.VMC -> VMC_SUPPORTED_BONES -} +fun acceptedBones(output: RoutingOutput, definition: CompiledSkeleton): Set = definition.acceptedBones(output) fun conflictingOutputs(output: RoutingOutput): Set = when (output) { in PRIORITY_CHAIN -> PRIORITY_CHAIN.toSet() - output @@ -42,32 +35,19 @@ fun conflictingOutputs(output: RoutingOutput): Set = when (output } /** Bones an output needs to work at all, so the user cannot turn them off. */ -fun requiredBones(output: RoutingOutput): Set = when (output) { - RoutingOutput.DRIVER, RoutingOutput.VRC_OSC -> emptySet() - RoutingOutput.VMC -> VMC_SUPPORTED_BONES -} +fun requiredBones(output: RoutingOutput, definition: CompiledSkeleton): Set = definition.requiredBones(output) /** * Bones automatic never routes on its own. Sending a hand to the driver takes over the * real controllers, so it stays the user's call whatever the mode. */ -val OVERRIDABLE_BONES: Set = setOf(BodyPart.LEFT_HAND, BodyPart.RIGHT_HAND) +fun overridableBones(output: RoutingOutput, definition: CompiledSkeleton): Set = definition.overridableBones intersect acceptedBones(output, definition) subtract requiredBones(output, definition) -fun overridableBones(output: RoutingOutput): Set = OVERRIDABLE_BONES intersect acceptedBones(output) subtract requiredBones(output) +fun manualRoutesAsBoneIds(manualRoutes: Map>?, definition: CompiledSkeleton): Routes = manualRoutes.orEmpty().mapNotNull { (key, outputs) -> definition.registry[key]?.let { it to outputs } }.toMap() -/** Resolves a static [BodyPart] set to the [BoneId]s a specific registry gives them. */ -private fun BoneRegistry.idsOf(bodyParts: Set): Set = bodyParts.mapNotNullTo(mutableSetOf()) { this[it] } +fun Routes.toManualRoutesConfig(definition: CompiledSkeleton): Map> = mapNotNull { (boneId, outputs) -> definition.registry.keyOf(boneId)?.let { it to outputs } }.toMap() -private fun BoneRegistry.acceptedIds(output: RoutingOutput): Set = idsOf(acceptedBones(output)) -private fun BoneRegistry.requiredIds(output: RoutingOutput): Set = idsOf(requiredBones(output)) - -fun manualRoutesAsBoneIds(manualRoutes: Map>?, registry: BoneRegistry): Routes = manualRoutes.orEmpty().mapNotNull { (key, outputs) -> registry[key]?.let { it to outputs } }.toMap() -fun Routes.toManualRoutesConfig(registry: BoneRegistry): Map> = mapNotNull { (boneId, outputs) -> registry.keyOf(boneId)?.let { it to outputs } }.toMap() - -fun overrideRoutes(config: BoneRoutingConfig, registry: BoneRegistry): Routes { - val overridableIds = registry.idsOf(OVERRIDABLE_BONES) - return manualRoutesAsBoneIds(config.manualRoutes, registry).filterKeys { it in overridableIds } -} +fun overrideRoutes(config: BoneRoutingConfig, definition: CompiledSkeleton): Routes = manualRoutesAsBoneIds(config.manualRoutes, definition).filterKeys { it in definition.overridableBones } fun isActive(states: OutputStates, output: RoutingOutput): Boolean = states[output] == RoutingOutputState.ACTIVE @@ -121,24 +101,24 @@ fun intendedRoutesFlow(appContext: AppContextProvider): Flow = combine( appContext.config.settings.context.state.map { it.data.boneRoutingConfig }.distinctUntilChanged(), appContext.boneRouting.context.state.map { it.routes }, ) { config, sent -> - val registry = appContext.bones.current - val requested = if (config.automatic) sent else manualRoutesAsBoneIds(config.manualRoutes, registry) - effectiveRoutes(requested + overrideRoutes(config, registry), ALL_ACTIVE, registry) + val definition = appContext.skeleton.definition + val requested = if (config.automatic) sent else manualRoutesAsBoneIds(config.manualRoutes, definition) + effectiveRoutes(requested + overrideRoutes(config, definition), ALL_ACTIVE, definition) }.distinctUntilChanged() /** * What actually gets sent: the requested routes plus whatever each output requires, * minus anything an output cannot accept or cannot currently send. */ -fun effectiveRoutes(routes: Routes, outputStates: OutputStates, registry: BoneRegistry): Routes { +fun effectiveRoutes(routes: Routes, outputStates: OutputStates, definition: CompiledSkeleton): Routes { val result = mutableMapOf>() for ((bone, outputs) in routes) { - val kept = outputs.filterTo(mutableSetOf()) { isActive(outputStates, it) && bone in registry.acceptedIds(it) } + val kept = outputs.filterTo(mutableSetOf()) { isActive(outputStates, it) && bone in acceptedBones(it, definition) } if (kept.isNotEmpty()) result[bone] = kept } for (output in RoutingOutput.entries) { if (!isActive(outputStates, output)) continue - for (bone in registry.requiredIds(output)) { + for (bone in requiredBones(output, definition)) { result[bone] = result[bone].orEmpty() + output } } @@ -149,59 +129,47 @@ fun applyRoutingChange( config: BoneRoutingConfig, automatic: Boolean, routes: Routes, - registry: BoneRegistry, + definition: CompiledSkeleton, ): BoneRoutingConfig { // Switching modes only flips the switch: each mode keeps the picks left in it. if (automatic != config.automatic) return config.copy(automatic = automatic) val requested = routes - .mapValues { (bone, outputs) -> outputs.filterTo(mutableSetOf()) { bone in registry.acceptedIds(it) && bone !in registry.requiredIds(it) } } + .mapValues { (bone, outputs) -> outputs.filterTo(mutableSetOf()) { bone in acceptedBones(it, definition) && bone !in requiredBones(it, definition) } } .filterValues { it.isNotEmpty() } - val overridableIds = registry.idsOf(OVERRIDABLE_BONES) + val overridableIds = definition.overridableBones return config.copy( manualRoutes = if (automatic) { // Automatic owns every other bone, so only the overrides come from the request. ( - manualRoutesAsBoneIds(config.manualRoutes, registry).filterKeys { it !in overridableIds } + + manualRoutesAsBoneIds(config.manualRoutes, definition).filterKeys { it !in overridableIds } + requested.filterKeys { it in overridableIds } - ).toManualRoutesConfig(registry) + ).toManualRoutesConfig(definition) } else { - requested.toManualRoutesConfig(registry) + requested.toManualRoutesConfig(definition) }, ) } -private val candidateToFineBodyParts = mapOf( - BodyPart.UPPER_CHEST to setOf(BodyPart.UPPER_CHEST, BodyPart.LOWER_CHEST), - BodyPart.LEFT_UPPER_ARM to setOf(BodyPart.LEFT_UPPER_ARM, BodyPart.LEFT_LOWER_ARM), - BodyPart.RIGHT_UPPER_ARM to setOf(BodyPart.RIGHT_UPPER_ARM, BodyPart.RIGHT_LOWER_ARM), - BodyPart.HIP to setOf(BodyPart.HIP, BodyPart.LOWER_WAIST, BodyPart.UPPER_WAIST, BodyPart.LOWER_CHEST, BodyPart.UPPER_CHEST), - BodyPart.LEFT_UPPER_LEG to setOf(BodyPart.LEFT_UPPER_LEG), - BodyPart.RIGHT_UPPER_LEG to setOf(BodyPart.RIGHT_UPPER_LEG), - BodyPart.LEFT_FOOT to setOf(BodyPart.LEFT_FOOT, BodyPart.LEFT_LOWER_LEG, BodyPart.LEFT_UPPER_LEG), - BodyPart.RIGHT_FOOT to setOf(BodyPart.RIGHT_FOOT, BodyPart.RIGHT_LOWER_LEG, BodyPart.RIGHT_UPPER_LEG), -) - -/** Tracker body parts that count as present. Loopback trackers never enable an output. */ -fun trackedBodyParts(trackers: Collection, registry: BoneRegistry): Set = trackers +/** Tracker bones that count as present. Loopback trackers never enable an output. */ +fun trackedBoneIds(trackers: Collection): Set = trackers .filter { it.status.isActive() && it.origin != DeviceOrigin.DRIVER && it.origin != DeviceOrigin.VRC && it.origin != DeviceOrigin.VMC } - .map { it.boneId?.let { id -> registry.bodyPartOf(id) } } + .map { it.boneId } .toSet() -fun determineCandidateBones(fineBodyParts: Set): Set = candidateToFineBodyParts - .filterValues { it.any { bp -> bp in fineBodyParts } } - .keys +fun determineCandidateBones(trackedBoneIds: Set, definition: CompiledSkeleton): Set = definition.candidateBones + .filterTo(mutableSetOf()) { candidate -> definition.candidateSourcesOf(candidate).any { it in trackedBoneIds } } /** Hands each bone to the best output that is on and can take it, so nothing is sent twice. */ -fun computeAutomaticRoutes(candidateBones: Set, outputStates: OutputStates, registry: BoneRegistry): Routes { +fun computeAutomaticRoutes(candidateBones: Set, outputStates: OutputStates, definition: CompiledSkeleton): Routes { val chain = PRIORITY_CHAIN.filter { isActive(outputStates, it) } return candidateBones - .mapNotNull { bone -> chain.firstOrNull { bone in acceptedBones(it) }?.let { output -> registry[bone]?.let { it to setOf(output) } } } + .mapNotNull { bone -> chain.firstOrNull { bone in acceptedBones(it, definition) }?.let { output -> bone to setOf(output) } } .toMap() } diff --git a/server/core/src/main/java/dev/slimevr/solarxr/driver/outgoing.kt b/server/core/src/main/java/dev/slimevr/solarxr/driver/outgoing.kt index c4dce3fa2..8a38c2366 100644 --- a/server/core/src/main/java/dev/slimevr/solarxr/driver/outgoing.kt +++ b/server/core/src/main/java/dev/slimevr/solarxr/driver/outgoing.kt @@ -23,21 +23,6 @@ import solarxr_protocol.datatypes.DeviceOrigin import solarxr_protocol.driver_protocol.BoneBatteryUpdate import solarxr_protocol.driver_protocol.SkeletonUpdate -val DRIVER_SUPPORTED_BONES = setOf( - BodyPart.UPPER_CHEST, - BodyPart.LEFT_UPPER_ARM, - BodyPart.RIGHT_UPPER_ARM, - BodyPart.HIP, - BodyPart.LEFT_UPPER_LEG, - BodyPart.RIGHT_UPPER_LEG, - BodyPart.LEFT_FOOT, - BodyPart.RIGHT_FOOT, - BodyPart.LEFT_SHOULDER, - BodyPart.RIGHT_SHOULDER, - BodyPart.LEFT_HAND, - BodyPart.RIGHT_HAND, -) - class DriverOutgoingTrackersBehaviour( private val appContext: AppContextProvider, ) : SolarXRBridgeBehaviour { diff --git a/server/core/src/main/java/dev/slimevr/solarxr/rpc/bone-routing.kt b/server/core/src/main/java/dev/slimevr/solarxr/rpc/bone-routing.kt index 34703b7ce..456104eb9 100644 --- a/server/core/src/main/java/dev/slimevr/solarxr/rpc/bone-routing.kt +++ b/server/core/src/main/java/dev/slimevr/solarxr/rpc/bone-routing.kt @@ -2,7 +2,7 @@ package dev.slimevr.solarxr.rpc import dev.slimevr.AppContextProvider import dev.slimevr.bones.BoneId -import dev.slimevr.bones.BoneRegistry +import dev.slimevr.bones.CompiledSkeleton import dev.slimevr.config.SettingsActions import dev.slimevr.routing.OutputStates import dev.slimevr.routing.Routes @@ -30,26 +30,21 @@ import solarxr_protocol.rpc.RoutingOutput import solarxr_protocol.rpc.RoutingOutputState import solarxr_protocol.rpc.RoutingOutputStatus -// Every bone any output can take gets a row, so the GUI can draw the whole table -// from the response alone. -private val ROUTABLE_BONES = RoutingOutput.entries.flatMapTo(mutableSetOf()) { acceptedBones(it) } - private fun buildResponse( automatic: Boolean, routes: Routes, outputStates: OutputStates, - registry: BoneRegistry, + routableBones: Set, + definition: CompiledSkeleton, ) = BoneRoutingSettingsResponse( automatic = automatic, - routes = ROUTABLE_BONES.mapNotNull { bone -> registry[bone] }.map { boneId -> - BoneRoute(boneId = boneId.value, outputs = routes[boneId].orEmpty().toList()) - }, + routes = routableBones.map { boneId -> BoneRoute(boneId = boneId.value, outputs = routes[boneId].orEmpty().toList()) }, outputs = RoutingOutput.entries.map { output -> RoutingOutputStatus( output = output, - accepts = acceptedBones(output).mapNotNull { registry[it]?.value }, - requires = requiredBones(output).mapNotNull { registry[it]?.value }, - overridable = overridableBones(output).mapNotNull { registry[it]?.value }, + accepts = acceptedBones(output, definition).map { it.value }, + requires = requiredBones(output, definition).map { it.value }, + overridable = overridableBones(output, definition).map { it.value }, conflicts = conflictingOutputs(output).toList(), state = outputStates[output] ?: RoutingOutputState.UNSUPPORTED, ) @@ -62,12 +57,15 @@ class BoneRoutingBehaviour( private val settings = appContext.config.settings override fun observe(receiver: SolarXRBridge) { - val registry = appContext.bones.current + val definition = appContext.skeleton.definition + // Every bone any output can take gets a row, so the GUI can draw the whole table + // from the response alone. + val routableBones = RoutingOutput.entries.flatMapTo(mutableSetOf()) { acceptedBones(it, definition) } val responses = combine( settings.context.state.map { it.data.boneRoutingConfig.automatic }.distinctUntilChanged(), intendedRoutesFlow(appContext), outputStatesFlow(appContext), - ) { automatic, routes, outputStates -> buildResponse(automatic, routes, outputStates, registry) } + ) { automatic, routes, outputStates -> buildResponse(automatic, routes, outputStates, routableBones, definition) } .distinctUntilChanged() receiver.rpcDispatcher.on { @@ -95,7 +93,7 @@ class BoneRoutingBehaviour( config = boneRoutingConfig, automatic = req.automatic, routes = requested, - registry = registry, + definition = definition, ), ) }, diff --git a/server/core/src/main/java/dev/slimevr/vmc/mapping.kt b/server/core/src/main/java/dev/slimevr/vmc/mapping.kt index 549365601..632309a9a 100644 --- a/server/core/src/main/java/dev/slimevr/vmc/mapping.kt +++ b/server/core/src/main/java/dev/slimevr/vmc/mapping.kt @@ -73,9 +73,6 @@ val BODY_PART_TO_UNITY_BONE: BodyPartMap> = BodyPartMap( ), ) -// Bones VMC can accept. Used by the routing module. -val VMC_SUPPORTED_BONES: Set = BODY_PART_TO_UNITY_BONE.keys - // HIP-rooted hierarchy. VMC/Unity expects this; our skeleton is HEAD-rooted. // TODO Test with a model that has UPPER_CHEST // and figure out how to deal with it (check if present in VRM?) diff --git a/server/core/src/main/java/dev/slimevr/vrcosc/output-encoder.kt b/server/core/src/main/java/dev/slimevr/vrcosc/output-encoder.kt index b960ca53b..db9a905bc 100644 --- a/server/core/src/main/java/dev/slimevr/vrcosc/output-encoder.kt +++ b/server/core/src/main/java/dev/slimevr/vrcosc/output-encoder.kt @@ -23,9 +23,6 @@ private val trackerIdsByBodyPart = mapOf( BodyPart.RIGHT_UPPER_ARM to 8, ) -/** Bones VRChat OSC can accept. Used by the routing module. */ -val VRC_OSC_SUPPORTED_BONES: Set = trackerIdsByBodyPart.keys - internal fun buildOutgoingBundle( bones: ComputedSkeleton, routedBones: Set, diff --git a/server/core/src/test/java/dev/slimevr/bones/ResourcePackCompilerTest.kt b/server/core/src/test/java/dev/slimevr/bones/ResourcePackCompilerTest.kt index 89fbf7b7f..1883e0365 100644 --- a/server/core/src/test/java/dev/slimevr/bones/ResourcePackCompilerTest.kt +++ b/server/core/src/test/java/dev/slimevr/bones/ResourcePackCompilerTest.kt @@ -7,7 +7,7 @@ import dev.slimevr.resourcepacks.ResourcePackCatalog import dev.slimevr.resourcepacks.ResourcePackParser import io.github.axisangles.ktmath.Vector3 import kotlinx.coroutines.test.runTest -import solarxr_protocol.datatypes.BodyPart +import solarxr_protocol.rpc.RoutingOutput import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -183,6 +183,99 @@ class ResourcePackCompilerTest { assertTrue(error.diagnostics.any { "Unknown bone" in it.message && "rotationFallback" in it.message }) } + @Test + fun `bundled core pack's driver and VMC accepted sets match the retired hardcoded tables`() = runTest { + val core = ResourcePackParser().parse(ClasspathResourcePackSource.core(javaClass.classLoader)) + val definition = compileResourcePacks(catalog(core)) + val registry = definition.registry + + val driverBones = setOf( + BodyPart.UPPER_CHEST, BodyPart.LEFT_UPPER_ARM, BodyPart.RIGHT_UPPER_ARM, BodyPart.HIP, + BodyPart.LEFT_UPPER_LEG, BodyPart.RIGHT_UPPER_LEG, BodyPart.LEFT_FOOT, BodyPart.RIGHT_FOOT, + BodyPart.LEFT_SHOULDER, BodyPart.RIGHT_SHOULDER, BodyPart.LEFT_HAND, BodyPart.RIGHT_HAND, + ).map { registry[it.key]!! }.toSet() + assertEquals(driverBones, definition.acceptedBones(RoutingOutput.DRIVER)) + + assertEquals(60, definition.acceptedBones(RoutingOutput.VMC).size) + assertEquals(definition.acceptedBones(RoutingOutput.VMC), definition.requiredBones(RoutingOutput.VMC)) + } + + @Test + fun `bundled core pack's VRChat accepted and required sets grow past the retired hardcoded table`() = runTest { + val core = ResourcePackParser().parse(ClasspathResourcePackSource.core(javaClass.classLoader)) + val definition = compileResourcePacks(catalog(core)) + val registry = definition.registry + + val oldEight = setOf( + BodyPart.HIP, + BodyPart.LEFT_FOOT, + BodyPart.RIGHT_FOOT, + BodyPart.LEFT_UPPER_LEG, + BodyPart.RIGHT_UPPER_LEG, + BodyPart.UPPER_CHEST, + BodyPart.LEFT_UPPER_ARM, + BodyPart.RIGHT_UPPER_ARM, + ).map { registry[it.key]!! }.toSet() + val accepted = definition.acceptedBones(RoutingOutput.VRC_OSC) + assertEquals(19, accepted.size) + assertTrue(accepted.containsAll(oldEight)) + + assertEquals(setOf(registry[BodyPart.HEAD.key]!!), definition.requiredBones(RoutingOutput.VRC_OSC)) + } + + @Test + fun `bundled core pack's overridable bones match the retired hardcoded set`() = runTest { + val core = ResourcePackParser().parse(ClasspathResourcePackSource.core(javaClass.classLoader)) + val definition = compileResourcePacks(catalog(core)) + val registry = definition.registry + assertEquals(setOf(registry[BodyPart.LEFT_HAND.key]!!, registry[BodyPart.RIGHT_HAND.key]!!), definition.overridableBones) + } + + @Test + fun `bundled core pack's candidate bones include the retired table plus every toe`() = runTest { + val core = ResourcePackParser().parse(ClasspathResourcePackSource.core(javaClass.classLoader)) + val definition = compileResourcePacks(catalog(core)) + val registry = definition.registry + + val oldEight = setOf( + BodyPart.UPPER_CHEST, + BodyPart.LEFT_UPPER_ARM, + BodyPart.RIGHT_UPPER_ARM, + BodyPart.HIP, + BodyPart.LEFT_UPPER_LEG, + BodyPart.RIGHT_UPPER_LEG, + BodyPart.LEFT_FOOT, + BodyPart.RIGHT_FOOT, + ).map { registry[it.key]!! }.toSet() + val toes = setOf( + BodyPart.LEFT_BIG_TOE, BodyPart.LEFT_INDEX_TOE, BodyPart.LEFT_MIDDLE_TOE, BodyPart.LEFT_RING_TOE, BodyPart.LEFT_LITTLE_TOE, + BodyPart.RIGHT_BIG_TOE, BodyPart.RIGHT_INDEX_TOE, BodyPart.RIGHT_MIDDLE_TOE, BodyPart.RIGHT_RING_TOE, BodyPart.RIGHT_LITTLE_TOE, + ).map { registry[it.key]!! }.toSet() + assertEquals(oldEight + toes, definition.candidateBones) + + val hip = registry[BodyPart.HIP.key]!! + assertEquals( + setOf(BodyPart.HIP, BodyPart.LOWER_WAIST, BodyPart.UPPER_WAIST, BodyPart.LOWER_CHEST, BodyPart.UPPER_CHEST).map { registry[it.key]!! }.toSet(), + definition.candidateSourcesOf(hip).toSet(), + ) + } + + @Test + fun `compiler reports an unknown bone named in candidateSources`() = runTest { + val core = ResourcePackParser().parse(ClasspathResourcePackSource.core(javaClass.classLoader)) + val user = ResourcePackParser().parse( + InMemoryResourcePackSource( + mapOf( + "manifest.json" to manifest("example:extra"), + "data/bones/extra.json" to """{"key":"example:extra","nameKey":"example:bone.extra","parent":"slimevr:head","candidateSources":["example:missing"]}""", + "assets/lang/en.json" to """{"example:bone.extra":"Extra bone"}""", + ), + ), + ) + val error = assertFailsWith { compileResourcePacks(catalog(core, user)) } + assertTrue(error.diagnostics.any { "Unknown bone" in it.message && "candidateSources" in it.message }) + } + @Test fun `compiler includes user-pack bones after the core registry`() = runTest { val core = ResourcePackParser().parse(ClasspathResourcePackSource.core(javaClass.classLoader)) diff --git a/server/core/src/test/java/dev/slimevr/routing/AutomaticRoutesTest.kt b/server/core/src/test/java/dev/slimevr/routing/AutomaticRoutesTest.kt index bf02c36d2..035dc4484 100644 --- a/server/core/src/test/java/dev/slimevr/routing/AutomaticRoutesTest.kt +++ b/server/core/src/test/java/dev/slimevr/routing/AutomaticRoutesTest.kt @@ -1,10 +1,9 @@ package dev.slimevr.routing import dev.slimevr.bones.BodyPart -import dev.slimevr.bones.BoneRegistry -import dev.slimevr.solarxr.driver.DRIVER_SUPPORTED_BONES -import dev.slimevr.vmc.VMC_SUPPORTED_BONES -import dev.slimevr.vrcosc.VRC_OSC_SUPPORTED_BONES +import dev.slimevr.bones.BoneId +import dev.slimevr.bones.boneId +import dev.slimevr.testCompiledSkeleton import solarxr_protocol.rpc.RoutingOutput import solarxr_protocol.rpc.RoutingOutputState import kotlin.test.Test @@ -18,28 +17,31 @@ private fun active(vararg outputs: RoutingOutput): OutputStates = RoutingOutput. private val NONE_ACTIVE = active() +private val DRIVER_SUPPORTED_BONES = testCompiledSkeleton.acceptedBones(RoutingOutput.DRIVER) +private val VMC_SUPPORTED_BONES = testCompiledSkeleton.acceptedBones(RoutingOutput.VMC) +private val VRC_OSC_SUPPORTED_BONES = testCompiledSkeleton.acceptedBones(RoutingOutput.VRC_OSC) + /** * Bones a typical full body setup produces. Deliberately includes lower legs, which * no output can take, so the tests also cover candidates being dropped. */ -private val COMMON_CANDIDATES = setOf( +private val COMMON_CANDIDATES: Set = setOf( BodyPart.HIP, BodyPart.UPPER_CHEST, - BodyPart.UPPER_CHEST, BodyPart.LEFT_UPPER_LEG, BodyPart.RIGHT_UPPER_LEG, BodyPart.LEFT_LOWER_LEG, BodyPart.RIGHT_LOWER_LEG, -) +).mapTo(mutableSetOf()) { it.boneId } class AutomaticRoutesTest { - private val registry = BoneRegistry.standard() + private val definition = testCompiledSkeleton - private fun routedTo(routes: Routes, output: RoutingOutput): Set = routes.filterValues { output in it }.keys.mapNotNullTo(mutableSetOf(), registry::bodyPartOf) + private fun routedTo(routes: Routes, output: RoutingOutput): Set = routes.filterValues { output in it }.keys - private fun computeAutomaticRoutes(candidateBones: Set, outputStates: OutputStates): Routes = computeAutomaticRoutes(candidateBones, outputStates, registry) + private fun computeAutomaticRoutes(candidateBones: Set, outputStates: OutputStates): Routes = computeAutomaticRoutes(candidateBones, outputStates, definition) - private fun effectiveRoutes(routes: Routes, outputStates: OutputStates): Routes = effectiveRoutes(routes, outputStates, registry) + private fun effectiveRoutes(routes: Routes, outputStates: OutputStates): Routes = effectiveRoutes(routes, outputStates, definition) @Test fun `the driver alone takes every bone it supports`() { @@ -78,7 +80,7 @@ class AutomaticRoutesTest { fun `a bone neither can take goes nowhere`() { // NECK is VMC only. val routes = computeAutomaticRoutes( - setOf(BodyPart.NECK), + setOf(BodyPart.NECK.boneId), active(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC), ) diff --git a/server/core/src/test/java/dev/slimevr/routing/CandidateBonesTest.kt b/server/core/src/test/java/dev/slimevr/routing/CandidateBonesTest.kt index 49bf77984..c946f79e5 100644 --- a/server/core/src/test/java/dev/slimevr/routing/CandidateBonesTest.kt +++ b/server/core/src/test/java/dev/slimevr/routing/CandidateBonesTest.kt @@ -1,27 +1,30 @@ package dev.slimevr.routing import dev.slimevr.bones.BodyPart +import dev.slimevr.bones.BoneId +import dev.slimevr.bones.boneId +import dev.slimevr.testCompiledSkeleton import kotlin.test.Test import kotlin.test.assertEquals class CandidateBonesTest { @Test - fun `Candidate bones are automatically determined based off body parts`() { + fun `Candidate bones are automatically determined based off tracked bones`() { data class TestCase( val name: String, - val fineBodyParts: Set, + val trackedBoneIds: Set, val expected: Set, ) val testCases = listOf( TestCase( name = "no body part", - fineBodyParts = emptySet(), + trackedBoneIds = emptySet(), expected = emptySet(), ), TestCase( name = "upper chest enables upper chest and hip", - fineBodyParts = setOf(BodyPart.UPPER_CHEST), + trackedBoneIds = setOf(BodyPart.UPPER_CHEST), expected = setOf( BodyPart.UPPER_CHEST, BodyPart.HIP, @@ -29,7 +32,7 @@ class CandidateBonesTest { ), TestCase( name = "lower chest enables upper chest and hip", - fineBodyParts = setOf(BodyPart.LOWER_CHEST), + trackedBoneIds = setOf(BodyPart.LOWER_CHEST), expected = setOf( BodyPart.UPPER_CHEST, BodyPart.HIP, @@ -37,49 +40,49 @@ class CandidateBonesTest { ), TestCase( name = "lower waist enables hip", - fineBodyParts = setOf(BodyPart.LOWER_WAIST), + trackedBoneIds = setOf(BodyPart.LOWER_WAIST), expected = setOf( BodyPart.HIP, ), ), TestCase( name = "hip enables hip", - fineBodyParts = setOf(BodyPart.HIP), + trackedBoneIds = setOf(BodyPart.HIP), expected = setOf( BodyPart.HIP, ), ), TestCase( name = "left lower arm enables left upper arm", - fineBodyParts = setOf(BodyPart.LEFT_LOWER_ARM), + trackedBoneIds = setOf(BodyPart.LEFT_LOWER_ARM), expected = setOf( BodyPart.LEFT_UPPER_ARM, ), ), TestCase( name = "right lower arm enables right upper arm", - fineBodyParts = setOf(BodyPart.RIGHT_LOWER_ARM), + trackedBoneIds = setOf(BodyPart.RIGHT_LOWER_ARM), expected = setOf( BodyPart.RIGHT_UPPER_ARM, ), ), TestCase( name = "left lower leg enables left foot", - fineBodyParts = setOf(BodyPart.LEFT_LOWER_LEG), + trackedBoneIds = setOf(BodyPart.LEFT_LOWER_LEG), expected = setOf( BodyPart.LEFT_FOOT, ), ), TestCase( name = "right lower leg enables right foot", - fineBodyParts = setOf(BodyPart.RIGHT_LOWER_LEG), + trackedBoneIds = setOf(BodyPart.RIGHT_LOWER_LEG), expected = setOf( BodyPart.RIGHT_FOOT, ), ), TestCase( name = "multiple automatic trackers", - fineBodyParts = setOf( + trackedBoneIds = setOf( BodyPart.LEFT_UPPER_ARM, BodyPart.RIGHT_FOOT, BodyPart.HIP, @@ -92,7 +95,7 @@ class CandidateBonesTest { ), TestCase( name = "worn hand trackers still enable nothing, hands are overridden by hand", - fineBodyParts = setOf( + trackedBoneIds = setOf( BodyPart.LEFT_HAND, BodyPart.RIGHT_HAND, ), @@ -100,7 +103,7 @@ class CandidateBonesTest { ), TestCase( name = "hands alongside automatic trackers leave the automatic ones untouched", - fineBodyParts = setOf( + trackedBoneIds = setOf( BodyPart.LEFT_FOOT, BodyPart.RIGHT_HAND, ), @@ -111,11 +114,12 @@ class CandidateBonesTest { ) testCases.forEach { case -> - val result = determineCandidateBones(case.fineBodyParts) + val trackedBoneIds: Set = case.trackedBoneIds.mapTo(mutableSetOf()) { it?.boneId } + val result = determineCandidateBones(trackedBoneIds, testCompiledSkeleton) assertEquals( - expected = case.expected, - actual = result.toSet(), + expected = case.expected.mapTo(mutableSetOf()) { it.boneId }, + actual = result, message = case.name, ) } diff --git a/server/core/src/test/java/dev/slimevr/routing/ManualRoutesTest.kt b/server/core/src/test/java/dev/slimevr/routing/ManualRoutesTest.kt index d97f7bc16..9b97b2237 100644 --- a/server/core/src/test/java/dev/slimevr/routing/ManualRoutesTest.kt +++ b/server/core/src/test/java/dev/slimevr/routing/ManualRoutesTest.kt @@ -1,16 +1,16 @@ package dev.slimevr.routing import dev.slimevr.bones.BodyPart -import dev.slimevr.bones.BoneRegistry import dev.slimevr.bones.boneId import dev.slimevr.config.BoneRoutingConfig +import dev.slimevr.testCompiledSkeleton import solarxr_protocol.rpc.RoutingOutput import solarxr_protocol.rpc.RoutingOutputState import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNull -private val registry = BoneRegistry.standard() +private val definition = testCompiledSkeleton private fun active(vararg outputs: RoutingOutput): OutputStates = RoutingOutput.entries.associateWith { if (it in outputs) RoutingOutputState.ACTIVE else RoutingOutputState.INACTIVE @@ -21,7 +21,7 @@ private val ALL_ON = active(*RoutingOutput.entries.toTypedArray()) private fun routesOf(vararg pairs: Pair>): Routes = pairs.associate { (bodyPart, outputs) -> bodyPart.boneId to outputs } -private fun manualRoutesOf(manualRoutes: Map>?): Routes = manualRoutesAsBoneIds(manualRoutes, registry) +private fun manualRoutesOf(manualRoutes: Map>?): Routes = manualRoutesAsBoneIds(manualRoutes, definition) private val AUTO_ROUTES = routesOf( BodyPart.HIP to setOf(RoutingOutput.DRIVER), @@ -37,7 +37,7 @@ class ManualRoutesTest { BodyPart.HIP to setOf(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC), ) - val sanitized = effectiveRoutes(routes, active(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC), registry) + val sanitized = effectiveRoutes(routes, active(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC), definition) assertEquals( setOf(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC), @@ -49,7 +49,7 @@ class ManualRoutesTest { fun `an unavailable output is dropped even when explicitly routed`() { val routes = routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC)) - val sanitized = effectiveRoutes(routes, active(RoutingOutput.VRC_OSC), registry) + val sanitized = effectiveRoutes(routes, active(RoutingOutput.VRC_OSC), definition) assertEquals(setOf(RoutingOutput.VRC_OSC), sanitized[BodyPart.HIP.boneId]) } @@ -58,7 +58,7 @@ class ManualRoutesTest { fun `an output that cannot take the bone is dropped`() { val routes = routesOf(BodyPart.NECK to setOf(RoutingOutput.VRC_OSC, RoutingOutput.VMC)) - val sanitized = effectiveRoutes(routes, active(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC), registry) + val sanitized = effectiveRoutes(routes, active(RoutingOutput.DRIVER, RoutingOutput.VRC_OSC, RoutingOutput.VMC), definition) assertEquals(setOf(RoutingOutput.VMC), sanitized[BodyPart.NECK.boneId]) } @@ -67,7 +67,7 @@ class ManualRoutesTest { fun `a bone left with no output is not kept`() { val routes = routesOf(BodyPart.HIP to setOf(RoutingOutput.VRC_OSC)) - assertEquals(emptyMap(), effectiveRoutes(routes, NONE_ACTIVE, registry)) + assertEquals(emptyMap(), effectiveRoutes(routes, NONE_ACTIVE, definition)) } } @@ -84,7 +84,7 @@ class RoutingChangeTest { fun `switching to manual the first time starts from an empty table`() { val config = BoneRoutingConfig(automatic = true, manualRoutes = null) - val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES, registry = registry) + val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES, definition = definition) assertEquals(false, next.automatic) assertEquals(emptyMap(), next.manualRoutes.orEmpty()) @@ -93,28 +93,28 @@ class RoutingChangeTest { @Test fun `switching to manual again keeps the table the user built`() { val built = routesOf(BodyPart.HIP to setOf(RoutingOutput.VRC_OSC)) - val config = BoneRoutingConfig(automatic = true, manualRoutes = built.toManualRoutesConfig(registry)) + val config = BoneRoutingConfig(automatic = true, manualRoutes = built.toManualRoutesConfig(definition)) - val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES, registry = registry) + val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES, definition = definition) assertEquals(built, manualRoutesOf(next.manualRoutes)) } @Test fun `editing while manual stores the new table`() { - val config = BoneRoutingConfig(automatic = false, manualRoutes = HAND_TABLE.toManualRoutesConfig(registry)) + val config = BoneRoutingConfig(automatic = false, manualRoutes = HAND_TABLE.toManualRoutesConfig(definition)) val edited = routesOf(BodyPart.HIP to setOf(RoutingOutput.VRC_OSC)) - val next = applyRoutingChange(config, automatic = false, routes = edited, registry = registry) + val next = applyRoutingChange(config, automatic = false, routes = edited, definition = definition) assertEquals(edited, manualRoutesOf(next.manualRoutes)) } @Test fun `switching back to automatic keeps the manual table`() { - val config = BoneRoutingConfig(automatic = false, manualRoutes = HAND_TABLE.toManualRoutesConfig(registry)) + val config = BoneRoutingConfig(automatic = false, manualRoutes = HAND_TABLE.toManualRoutesConfig(definition)) - val next = applyRoutingChange(config, automatic = true, routes = emptyMap(), registry = registry) + val next = applyRoutingChange(config, automatic = true, routes = emptyMap(), definition = definition) assertEquals(true, next.automatic) assertEquals(HAND_TABLE, manualRoutesOf(next.manualRoutes)) @@ -124,7 +124,7 @@ class RoutingChangeTest { fun `staying automatic never creates a manual table`() { val config = BoneRoutingConfig(automatic = true, manualRoutes = null) - val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES, registry = registry) + val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES, definition = definition) assertEquals(emptyMap(), next.manualRoutes) } @@ -134,10 +134,10 @@ class RoutingChangeTest { var config = BoneRoutingConfig(automatic = true, manualRoutes = null) val built = AUTO_ROUTES + HAND_TABLE - config = applyRoutingChange(config, automatic = false, routes = emptyMap(), registry = registry) - config = applyRoutingChange(config, automatic = false, routes = built, registry = registry) - config = applyRoutingChange(config, automatic = true, routes = emptyMap(), registry = registry) - config = applyRoutingChange(config, automatic = false, routes = emptyMap(), registry = registry) + config = applyRoutingChange(config, automatic = false, routes = emptyMap(), definition = definition) + config = applyRoutingChange(config, automatic = false, routes = built, definition = definition) + config = applyRoutingChange(config, automatic = true, routes = emptyMap(), definition = definition) + config = applyRoutingChange(config, automatic = false, routes = emptyMap(), definition = definition) assertEquals(built, manualRoutesOf(config.manualRoutes)) } @@ -150,7 +150,7 @@ class ForcedRoutesTest { BoneRoutingConfig(automatic = false, manualRoutes = emptyMap()), automatic = false, routes = routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER, RoutingOutput.VMC)), - registry = registry, + definition = definition, ) assertEquals(routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)), manualRoutesOf(config.manualRoutes)) @@ -162,7 +162,7 @@ class ForcedRoutesTest { BoneRoutingConfig(automatic = false, manualRoutes = emptyMap()), automatic = false, routes = routesOf(BodyPart.NECK to setOf(RoutingOutput.VMC)), - registry = registry, + definition = definition, ) assertEquals(emptyMap(), config.manualRoutes) @@ -172,13 +172,13 @@ class ForcedRoutesTest { fun `required bones come back when the routes are resolved`() { val config = BoneRoutingConfig( automatic = false, - manualRoutes = routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)).toManualRoutesConfig(registry), + manualRoutes = routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)).toManualRoutesConfig(definition), ) val resolved = effectiveRoutes( manualRoutesOf(config.manualRoutes), active(RoutingOutput.DRIVER, RoutingOutput.VMC), - registry, + definition, ) assertEquals(setOf(RoutingOutput.DRIVER, RoutingOutput.VMC), resolved[BodyPart.HIP.boneId]) @@ -189,14 +189,14 @@ class ForcedRoutesTest { fun `an inactive output does not force anything`() { val config = BoneRoutingConfig(automatic = false, manualRoutes = emptyMap()) - val resolved = effectiveRoutes(manualRoutesOf(config.manualRoutes), active(RoutingOutput.DRIVER), registry) + val resolved = effectiveRoutes(manualRoutesOf(config.manualRoutes), active(RoutingOutput.DRIVER), definition) assertEquals(emptyMap(), resolved) } @Test fun `the page shows required bones ticked whatever is stored`() { - val shown = effectiveRoutes(emptyMap(), ALL_ON, registry) + val shown = effectiveRoutes(emptyMap(), ALL_ON, definition) assertEquals(setOf(RoutingOutput.VMC), shown[BodyPart.NECK.boneId]) } @@ -205,8 +205,8 @@ class ForcedRoutesTest { fun `automatic gets required bones through the same step as manual`() { val states = active(RoutingOutput.DRIVER, RoutingOutput.VMC) - val automatic = effectiveRoutes(computeAutomaticRoutes(setOf(BodyPart.HIP), states, registry), states, registry) - val manual = effectiveRoutes(routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)), states, registry) + val automatic = effectiveRoutes(computeAutomaticRoutes(setOf(BodyPart.HIP.boneId), states, definition), states, definition) + val manual = effectiveRoutes(routesOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)), states, definition) assertEquals(automatic[BodyPart.NECK.boneId], manual[BodyPart.NECK.boneId]) assertEquals(automatic[BodyPart.HIP.boneId], manual[BodyPart.HIP.boneId]) @@ -214,44 +214,44 @@ class ForcedRoutesTest { @Test fun `everything VMC accepts it also requires`() { - assertEquals(acceptedBones(RoutingOutput.VMC), requiredBones(RoutingOutput.VMC)) - assertEquals(emptySet(), requiredBones(RoutingOutput.DRIVER)) + assertEquals(acceptedBones(RoutingOutput.VMC, definition), requiredBones(RoutingOutput.VMC, definition)) + assertEquals(emptySet(), requiredBones(RoutingOutput.DRIVER, definition)) } } class OverrideRoutesTest { @Test fun `hands are the user's call on the driver only`() { - assertEquals(OVERRIDABLE_BONES, overridableBones(RoutingOutput.DRIVER)) + assertEquals(setOf(BodyPart.LEFT_HAND.boneId, BodyPart.RIGHT_HAND.boneId), overridableBones(RoutingOutput.DRIVER, definition)) // Never accepted there. - assertEquals(emptySet(), overridableBones(RoutingOutput.VRC_OSC)) + assertEquals(emptySet(), overridableBones(RoutingOutput.VRC_OSC, definition)) // Accepted, but required, so it is always on. - assertEquals(emptySet(), overridableBones(RoutingOutput.VMC)) + assertEquals(emptySet(), overridableBones(RoutingOutput.VMC, definition)) } @Test fun `automatic routes no hands on its own`() { - val candidates = determineCandidateBones(setOf(BodyPart.LEFT_HAND, BodyPart.HIP)) + val candidates = determineCandidateBones(setOf(BodyPart.LEFT_HAND.boneId, BodyPart.HIP.boneId), definition) - val routes = computeAutomaticRoutes(candidates, ALL_ON, registry) + val routes = computeAutomaticRoutes(candidates, ALL_ON, definition) assertNull(routes[BodyPart.LEFT_HAND.boneId]) } @Test fun `an override routes the hand while automatic`() { - val config = BoneRoutingConfig(automatic = true, manualRoutes = HAND_TABLE.toManualRoutesConfig(registry)) + val config = BoneRoutingConfig(automatic = true, manualRoutes = HAND_TABLE.toManualRoutesConfig(definition)) - val routes = computeAutomaticRoutes(determineCandidateBones(emptySet()), ALL_ON, registry) + overrideRoutes(config, registry) + val routes = computeAutomaticRoutes(determineCandidateBones(emptySet(), definition), ALL_ON, definition) + overrideRoutes(config, definition) assertEquals(setOf(RoutingOutput.DRIVER), routes[BodyPart.LEFT_HAND.boneId]) } @Test fun `only the overridable bones of a stored table count as overrides`() { - val config = BoneRoutingConfig(automatic = true, manualRoutes = (AUTO_ROUTES + HAND_TABLE).toManualRoutesConfig(registry)) + val config = BoneRoutingConfig(automatic = true, manualRoutes = (AUTO_ROUTES + HAND_TABLE).toManualRoutesConfig(definition)) - assertEquals(HAND_TABLE, overrideRoutes(config, registry)) + assertEquals(HAND_TABLE, overrideRoutes(config, definition)) } @Test @@ -262,7 +262,7 @@ class OverrideRoutesTest { config, automatic = true, routes = routesOf(BodyPart.LEFT_HAND to setOf(RoutingOutput.VMC)), - registry = registry, + definition = definition, ) assertEquals(emptyMap(), next.manualRoutes) @@ -272,7 +272,7 @@ class OverrideRoutesTest { fun `editing while automatic stores the override and nothing else`() { val config = BoneRoutingConfig(automatic = true, manualRoutes = null) - val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES + HAND_TABLE, registry = registry) + val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES + HAND_TABLE, definition = definition) assertEquals(HAND_TABLE, manualRoutesOf(next.manualRoutes)) } @@ -280,18 +280,18 @@ class OverrideRoutesTest { @Test fun `editing while automatic leaves a stored manual table alone`() { val stored = routesOf(BodyPart.HIP to setOf(RoutingOutput.VRC_OSC)) - val config = BoneRoutingConfig(automatic = true, manualRoutes = stored.toManualRoutesConfig(registry)) + val config = BoneRoutingConfig(automatic = true, manualRoutes = stored.toManualRoutesConfig(definition)) - val next = applyRoutingChange(config, automatic = true, routes = HAND_TABLE, registry = registry) + val next = applyRoutingChange(config, automatic = true, routes = HAND_TABLE, definition = definition) assertEquals(stored + HAND_TABLE, manualRoutesOf(next.manualRoutes)) } @Test fun `dropping the hand from the request clears the override`() { - val config = BoneRoutingConfig(automatic = true, manualRoutes = HAND_TABLE.toManualRoutesConfig(registry)) + val config = BoneRoutingConfig(automatic = true, manualRoutes = HAND_TABLE.toManualRoutesConfig(definition)) - val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES, registry = registry) + val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES, definition = definition) assertEquals(emptyMap(), next.manualRoutes) } @@ -300,10 +300,10 @@ class OverrideRoutesTest { fun `the override survives a round trip through manual`() { var config = BoneRoutingConfig(automatic = true, manualRoutes = null) - config = applyRoutingChange(config, automatic = true, routes = HAND_TABLE, registry = registry) - config = applyRoutingChange(config, automatic = false, routes = emptyMap(), registry = registry) - config = applyRoutingChange(config, automatic = true, routes = emptyMap(), registry = registry) + config = applyRoutingChange(config, automatic = true, routes = HAND_TABLE, definition = definition) + config = applyRoutingChange(config, automatic = false, routes = emptyMap(), definition = definition) + config = applyRoutingChange(config, automatic = true, routes = emptyMap(), definition = definition) - assertEquals(setOf(RoutingOutput.DRIVER), overrideRoutes(config, registry)[BodyPart.LEFT_HAND.boneId]) + assertEquals(setOf(RoutingOutput.DRIVER), overrideRoutes(config, definition)[BodyPart.LEFT_HAND.boneId]) } }