From 0c2b8947dda876f4f2f51dd44dcdd4e4fc1adb50 Mon Sep 17 00:00:00 2001 From: loucass003 Date: Wed, 5 Aug 2026 14:02:01 +0200 Subject: [PATCH] Overrides on hands in auto --- .../settings/pages/BoneRoutingSettings.tsx | 25 ++- .../main/java/dev/slimevr/config/settings.kt | 3 +- .../java/dev/slimevr/routing/behaviours.kt | 7 +- .../main/java/dev/slimevr/routing/routing.kt | 61 ++++---- .../java/dev/slimevr/solarxr/bone-routing.kt | 5 +- .../slimevr/trackingchecklist/behaviours.kt | 5 +- .../dev/slimevr/trackingchecklist/module.kt | 2 +- .../dev/slimevr/routing/CandidateBonesTest.kt | 59 +------ .../dev/slimevr/routing/ManualRoutesTest.kt | 146 +++++++++++++----- .../TrackingChecklistTest.kt | 13 +- 10 files changed, 173 insertions(+), 153 deletions(-) diff --git a/gui/app/src/components/settings/pages/BoneRoutingSettings.tsx b/gui/app/src/components/settings/pages/BoneRoutingSettings.tsx index 3de0c18d8..c7daaacbc 100644 --- a/gui/app/src/components/settings/pages/BoneRoutingSettings.tsx +++ b/gui/app/src/components/settings/pages/BoneRoutingSettings.tsx @@ -141,6 +141,7 @@ type BoneTables = { routes: RouteMap; accepts: Map>; requires: Map>; + overridable: Map>; duplicated: Map>; }; @@ -153,6 +154,9 @@ function cellState(row: BoneRow, output: RoutingOutput, tables: BoneTables) { required: accepted.length > 0 && accepted.every((bone) => tables.requires.get(output)?.has(bone)), + overridable: + accepted.length > 0 && + accepted.every((bone) => tables.overridable.get(output)?.has(bone)), routed: row.bones.some((bone) => tables.routes.get(bone)?.has(output)), duplicate: row.bones.some((bone) => tables.duplicated.get(bone)?.has(output) @@ -245,6 +249,7 @@ function RouteCell({ automatic, accepted, required, + overridable, unavailable, routed, duplicate, @@ -255,6 +260,7 @@ function RouteCell({ automatic: boolean; accepted: boolean; required: boolean; + overridable: boolean; unavailable: boolean; routed: boolean; duplicate: boolean; @@ -272,7 +278,7 @@ function RouteCell({ return cell(
); } - if (automatic) { + if (automatic && !overridable) { return routed ? cell(, 'fill-accent-background-20') : cell(
); @@ -346,6 +352,17 @@ export function BoneRoutingSettings() { [outputs] ); + const overridable = useMemo( + () => + new Map( + outputs.map((status) => [ + status.output, + new Set(status.overridable ?? []), + ]) + ), + [outputs] + ); + const conflicts = useMemo( () => new Map( @@ -387,8 +404,8 @@ export function BoneRoutingSettings() { }, [routes, conflicts]); const tables = useMemo( - () => ({ routes, accepts, requires, duplicated }), - [routes, accepts, requires, duplicated] + () => ({ routes, accepts, requires, overridable, duplicated }), + [routes, accepts, requires, overridable, duplicated] ); const duplicatedNames = useMemo(() => { @@ -479,7 +496,7 @@ export function BoneRoutingSettings() { const setMode = (nextAutomatic: boolean) => { setAutomatic(nextAutomatic); - submit(nextAutomatic, routes); + submit(nextAutomatic, new Map()); }; const toggleGroup = (id: string) => { diff --git a/server/core/src/main/java/dev/slimevr/config/settings.kt b/server/core/src/main/java/dev/slimevr/config/settings.kt index 1f3b82814..68c3ee61f 100644 --- a/server/core/src/main/java/dev/slimevr/config/settings.kt +++ b/server/core/src/main/java/dev/slimevr/config/settings.kt @@ -48,7 +48,8 @@ data class BoneRoutingConfig( /** Generate the routes from the connected trackers and the output priority. */ val automatic: Boolean = true, /** - * Explicit routes, ignored while [automatic]. Do not read directly, use BoneRoutingManager. + * Explicit routes. Ignored while [automatic], apart from the overridable bones, which + * the user owns in either mode. Do not read directly, use BoneRoutingManager. */ val manualRoutes: Map>? = null, ) 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 87c921bb1..b280b370d 100644 --- a/server/core/src/main/java/dev/slimevr/routing/behaviours.kt +++ b/server/core/src/main/java/dev/slimevr/routing/behaviours.kt @@ -54,10 +54,13 @@ class BoneRoutingBasicBehaviour(private val appContext: AppContextProvider) : Bo .map { fineBodyParts -> Triple(config, outputStates, fineBodyParts) } } .onEach { (config, outputStates, fineBodyParts) -> - val candidates = determineCandidateBones(config, fineBodyParts) + val candidates = determineCandidateBones(fineBodyParts) receiver.context.dispatch( BoneRoutingActions.SetRoutes( - effectiveRoutes(computeAutomaticRoutes(candidates, outputStates), outputStates), + effectiveRoutes( + computeAutomaticRoutes(candidates, outputStates) + overrideRoutes(config), + outputStates, + ), ), ) } 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 580a8cca2..015ca6ce2 100644 --- a/server/core/src/main/java/dev/slimevr/routing/routing.kt +++ b/server/core/src/main/java/dev/slimevr/routing/routing.kt @@ -42,6 +42,17 @@ fun requiredBones(output: RoutingOutput): Set = when (output) { RoutingOutput.VMC -> VMC_SUPPORTED_BONES } +/** + * 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): Set = + OVERRIDABLE_BONES intersect acceptedBones(output) subtract requiredBones(output) + +fun overrideRoutes(config: BoneRoutingConfig): Routes = config.manualRoutes.orEmpty().filterKeys { it in OVERRIDABLE_BONES } + fun isActive(states: OutputStates, output: RoutingOutput): Boolean = states[output] == RoutingOutputState.ACTIVE fun platformSupports(appContext: AppContextProvider, output: RoutingOutput): Boolean = when (output) { @@ -89,7 +100,8 @@ 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 -> - effectiveRoutes(if (config.automatic) sent else config.manualRoutes.orEmpty(), ALL_ACTIVE) + val requested = if (config.automatic) sent else config.manualRoutes.orEmpty() + effectiveRoutes(requested + overrideRoutes(config), ALL_ACTIVE) }.distinctUntilChanged() /** @@ -113,41 +125,27 @@ fun effectiveRoutes(routes: Routes, outputStates: OutputStates): Routes { return result } -/** - * The table a first switch to manual starts from: what automatic would route if every - * output this platform has were switched on. An output that is merely off still gets its - * bones, so switching it on later actually sends something. - * - * TODO: maybe this is bad, or annoying logic. we could default to just empty routes when switching to manual - */ -fun seedManualRoutes(appContext: AppContextProvider): Routes { - val config = appContext.config.settings.context.state.value.data.boneRoutingConfig - val trackers = appContext.server.context.state.value.trackers.values.map { it.context.state.value } - val allEnabled = RoutingOutput.entries.associateWith { - if (platformSupports(appContext, it)) RoutingOutputState.ACTIVE else RoutingOutputState.UNSUPPORTED - } - - return computeAutomaticRoutes(determineCandidateBones(config, trackedBodyParts(trackers)), allEnabled) -} - fun applyRoutingChange( config: BoneRoutingConfig, automatic: Boolean, routes: Routes, - seed: Routes, ): BoneRoutingConfig { - fun sanitized(source: Routes): Routes = source + // 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 acceptedBones(it) && bone !in requiredBones(it) } } .filterValues { it.isNotEmpty() } return config.copy( - automatic = automatic, - manualRoutes = when { - automatic -> config.manualRoutes - config.automatic -> config.manualRoutes ?: sanitized(seed) - else -> sanitized(routes) + manualRoutes = if (automatic) { + // Automatic owns every other bone, so only the overrides come from the request. + config.manualRoutes.orEmpty().filterKeys { it !in OVERRIDABLE_BONES } + + requested.filterKeys { it in OVERRIDABLE_BONES } + } else { + requested }, ) } @@ -173,16 +171,9 @@ fun trackedBodyParts(trackers: Collection): Set = track .map { it.bodyPart } .toSet() -fun determineCandidateBones(config: BoneRoutingConfig, fineBodyParts: Set): Set { - val candidates = candidateToFineBodyParts - .filterValues { it.any { bp -> bp in fineBodyParts } } - .keys - // Hands aren't toggled automatically - val handBones = config.manualRoutes.orEmpty().keys.filter { - it == BodyPart.LEFT_HAND || it == BodyPart.RIGHT_HAND - } - return candidates + handBones -} +fun determineCandidateBones(fineBodyParts: Set): Set = candidateToFineBodyParts + .filterValues { it.any { bp -> bp in fineBodyParts } } + .keys /** 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): Routes { diff --git a/server/core/src/main/java/dev/slimevr/solarxr/bone-routing.kt b/server/core/src/main/java/dev/slimevr/solarxr/bone-routing.kt index 3f50e7ade..4f0b0669a 100644 --- a/server/core/src/main/java/dev/slimevr/solarxr/bone-routing.kt +++ b/server/core/src/main/java/dev/slimevr/solarxr/bone-routing.kt @@ -9,8 +9,8 @@ import dev.slimevr.routing.applyRoutingChange import dev.slimevr.routing.conflictingOutputs import dev.slimevr.routing.intendedRoutesFlow import dev.slimevr.routing.outputStatesFlow +import dev.slimevr.routing.overridableBones import dev.slimevr.routing.requiredBones -import dev.slimevr.routing.seedManualRoutes import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.drop @@ -43,6 +43,7 @@ private fun buildResponse( output = output, accepts = acceptedBones(output).toList(), requires = requiredBones(output).toList(), + overridable = overridableBones(output).toList(), conflicts = conflictingOutputs(output).toList(), state = outputStates[output], ) @@ -79,7 +80,6 @@ class BoneRoutingBehaviour( bone to outputs } .toMap() - val seed = seedManualRoutes(appContext) settings.context.dispatch( SettingsActions.Update { @@ -88,7 +88,6 @@ class BoneRoutingBehaviour( config = boneRoutingConfig, automatic = req.automatic == true, routes = requested, - seed = seed, ), ) }, diff --git a/server/core/src/main/java/dev/slimevr/trackingchecklist/behaviours.kt b/server/core/src/main/java/dev/slimevr/trackingchecklist/behaviours.kt index bec57d7d0..93252453d 100644 --- a/server/core/src/main/java/dev/slimevr/trackingchecklist/behaviours.kt +++ b/server/core/src/main/java/dev/slimevr/trackingchecklist/behaviours.kt @@ -148,7 +148,6 @@ class TrackerErrorCheckBehaviour(private val server: VRServer) : TrackingCheckli class SteamVRHandsCheckBehaviour( private val server: VRServer, - private val settings: Settings, private val boneRouting: BoneRoutingManager, ) : TrackingChecklistBehaviourType { private val HAND_BONES = setOf(BodyPart.LEFT_HAND, BodyPart.RIGHT_HAND) @@ -157,7 +156,6 @@ class SteamVRHandsCheckBehaviour( trackers: List, routes: Routes, driverConnected: Boolean, - automatic: Boolean, ): TrackingChecklistStep { // The skeleton computes a hand bone from the arm chain, so routing one sends a hand // tracker to SteamVR whether or not the user wears anything on that hand. @@ -172,7 +170,7 @@ class SteamVRHandsCheckBehaviour( return TrackingChecklistStep( valid = !handsSentToDriver || (!hasControllers && hasHandTrackers), - enabled = driverConnected && !automatic, + enabled = driverConnected, ignorable = true, visibility = TrackingChecklistStepVisibility.WHEN_INVALID, ) @@ -183,7 +181,6 @@ class SteamVRHandsCheckBehaviour( trackerStatesFlow(server), boneRouting.context.state.map { state -> state.routes }, server.context.state.map { state -> state.drivers.isNotEmpty() }.distinctUntilChanged(), - settings.context.state.map { state -> state.data.boneRoutingConfig.automatic }.distinctUntilChanged(), ::computeStep, ) .distinctUntilChanged() diff --git a/server/core/src/main/java/dev/slimevr/trackingchecklist/module.kt b/server/core/src/main/java/dev/slimevr/trackingchecklist/module.kt index 7fb96dd15..74521a78e 100644 --- a/server/core/src/main/java/dev/slimevr/trackingchecklist/module.kt +++ b/server/core/src/main/java/dev/slimevr/trackingchecklist/module.kt @@ -35,7 +35,7 @@ class TrackingChecklist( add(FullResetCheckBehaviour(appContext.server, appContext.resetsManager)) add(MountingCalibrationCheckBehaviour(appContext.server, appContext.resetsManager, appContext.config.settings)) add(TrackerErrorCheckBehaviour(appContext.server)) - add(SteamVRHandsCheckBehaviour(appContext.server, appContext.config.settings, appContext.boneRouting)) + add(SteamVRHandsCheckBehaviour(appContext.server, appContext.boneRouting)) add(FeetMountingCalibrationCheckBehaviour(appContext.server, appContext.resetsManager, appContext.config.settings)) // TODO: STAY_ALIGNED_CONFIGURED 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 34d0e922f..eda1aec5a 100644 --- a/server/core/src/test/java/dev/slimevr/routing/CandidateBonesTest.kt +++ b/server/core/src/test/java/dev/slimevr/routing/CandidateBonesTest.kt @@ -1,8 +1,6 @@ package dev.slimevr.routing -import dev.slimevr.config.BoneRoutingConfig import solarxr_protocol.datatypes.BodyPart -import solarxr_protocol.rpc.RoutingOutput import kotlin.test.Test import kotlin.test.assertEquals @@ -12,7 +10,6 @@ class CandidateBonesTest { data class TestCase( val name: String, val fineBodyParts: Set, - val configuredTrackers: List, val expected: Set, ) @@ -20,13 +17,11 @@ class CandidateBonesTest { TestCase( name = "no body part", fineBodyParts = emptySet(), - configuredTrackers = emptyList(), expected = emptySet(), ), TestCase( name = "upper chest enables upper chest and hip", fineBodyParts = setOf(BodyPart.UPPER_CHEST), - configuredTrackers = emptyList(), expected = setOf( BodyPart.UPPER_CHEST, BodyPart.HIP, @@ -35,7 +30,6 @@ class CandidateBonesTest { TestCase( name = "chest enables upper chest and hip", fineBodyParts = setOf(BodyPart.CHEST), - configuredTrackers = emptyList(), expected = setOf( BodyPart.UPPER_CHEST, BodyPart.HIP, @@ -44,7 +38,6 @@ class CandidateBonesTest { TestCase( name = "waist enables hip", fineBodyParts = setOf(BodyPart.WAIST), - configuredTrackers = emptyList(), expected = setOf( BodyPart.HIP, ), @@ -52,7 +45,6 @@ class CandidateBonesTest { TestCase( name = "hip enables hip", fineBodyParts = setOf(BodyPart.HIP), - configuredTrackers = emptyList(), expected = setOf( BodyPart.HIP, ), @@ -60,7 +52,6 @@ class CandidateBonesTest { TestCase( name = "left lower arm enables left upper arm", fineBodyParts = setOf(BodyPart.LEFT_LOWER_ARM), - configuredTrackers = emptyList(), expected = setOf( BodyPart.LEFT_UPPER_ARM, ), @@ -68,7 +59,6 @@ class CandidateBonesTest { TestCase( name = "right lower arm enables right upper arm", fineBodyParts = setOf(BodyPart.RIGHT_LOWER_ARM), - configuredTrackers = emptyList(), expected = setOf( BodyPart.RIGHT_UPPER_ARM, ), @@ -76,7 +66,6 @@ class CandidateBonesTest { TestCase( name = "left lower leg enables left foot", fineBodyParts = setOf(BodyPart.LEFT_LOWER_LEG), - configuredTrackers = emptyList(), expected = setOf( BodyPart.LEFT_FOOT, ), @@ -84,7 +73,6 @@ class CandidateBonesTest { TestCase( name = "right lower leg enables right foot", fineBodyParts = setOf(BodyPart.RIGHT_LOWER_LEG), - configuredTrackers = emptyList(), expected = setOf( BodyPart.RIGHT_FOOT, ), @@ -96,7 +84,6 @@ class CandidateBonesTest { BodyPart.RIGHT_FOOT, BodyPart.HIP, ), - configuredTrackers = emptyList(), expected = setOf( BodyPart.LEFT_UPPER_ARM, BodyPart.RIGHT_FOOT, @@ -104,51 +91,27 @@ class CandidateBonesTest { ), ), TestCase( - name = "hands are always included from config", - fineBodyParts = emptySet(), - configuredTrackers = listOf( - BodyPart.LEFT_HAND, - BodyPart.RIGHT_HAND, - ), - expected = setOf( + name = "worn hand trackers still enable nothing, hands are overridden by hand", + fineBodyParts = setOf( BodyPart.LEFT_HAND, BodyPart.RIGHT_HAND, ), + expected = emptySet(), ), TestCase( - name = "non-hand manual trackers are ignored", - fineBodyParts = emptySet(), - configuredTrackers = listOf( - BodyPart.CHEST, - BodyPart.WAIST, - BodyPart.LEFT_HAND, - ), - expected = setOf( - BodyPart.LEFT_HAND, - ), - ), - TestCase( - name = "automatic trackers combined with hands", + name = "hands alongside automatic trackers leave the automatic ones untouched", fineBodyParts = setOf( BodyPart.LEFT_FOOT, - ), - configuredTrackers = listOf( BodyPart.RIGHT_HAND, ), expected = setOf( BodyPart.LEFT_FOOT, - BodyPart.RIGHT_HAND, ), ), ) testCases.forEach { case -> - val result = determineCandidateBones( - config = BoneRoutingConfig( - manualRoutes = case.configuredTrackers.associateWith { setOf(RoutingOutput.DRIVER) }, - ), - fineBodyParts = case.fineBodyParts, - ) + val result = determineCandidateBones(case.fineBodyParts) assertEquals( expected = case.expected, @@ -157,16 +120,4 @@ class CandidateBonesTest { ) } } - - @Test - fun `hands stay routable manually while never auto enabling`() { - val candidates = determineCandidateBones( - config = BoneRoutingConfig( - manualRoutes = mapOf(BodyPart.LEFT_HAND to setOf(RoutingOutput.DRIVER)), - ), - fineBodyParts = emptySet(), - ) - - assertEquals(setOf(BodyPart.LEFT_HAND), candidates) - } } 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 ca5eac3f6..508187be1 100644 --- a/server/core/src/test/java/dev/slimevr/routing/ManualRoutesTest.kt +++ b/server/core/src/test/java/dev/slimevr/routing/ManualRoutesTest.kt @@ -75,31 +75,23 @@ class RoutingChangeTest { } @Test - fun `switching to manual the first time seeds from the automatic routes`() { + 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 = emptyMap(), seed = AUTO_ROUTES) + val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES) assertEquals(false, next.automatic) - assertEquals(AUTO_ROUTES, next.manualRoutes.orEmpty()) + assertEquals(emptyMap(), next.manualRoutes.orEmpty()) } @Test fun `switching to manual again keeps the table the user built`() { - val config = BoneRoutingConfig(automatic = true, manualRoutes = HAND_TABLE) + val built = routesOf(BodyPart.HIP to setOf(RoutingOutput.VRC_OSC)) + val config = BoneRoutingConfig(automatic = true, manualRoutes = built) - val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES, seed = AUTO_ROUTES) + val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES) - assertEquals(HAND_TABLE, next.manualRoutes) - } - - @Test - fun `switching to manual again keeps an empty table the user cleared`() { - val config = BoneRoutingConfig(automatic = true, manualRoutes = emptyMap()) - - val next = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES, seed = AUTO_ROUTES) - - assertEquals(emptyMap(), next.manualRoutes) + assertEquals(built, next.manualRoutes) } @Test @@ -107,7 +99,7 @@ class RoutingChangeTest { val config = BoneRoutingConfig(automatic = false, manualRoutes = HAND_TABLE) val edited = mapOf(BodyPart.HIP to setOf(RoutingOutput.VRC_OSC)) - val next = applyRoutingChange(config, automatic = false, routes = edited, seed = AUTO_ROUTES) + val next = applyRoutingChange(config, automatic = false, routes = edited) assertEquals(edited, next.manualRoutes) } @@ -116,7 +108,7 @@ class RoutingChangeTest { fun `switching back to automatic keeps the manual table`() { val config = BoneRoutingConfig(automatic = false, manualRoutes = HAND_TABLE) - val next = applyRoutingChange(config, automatic = true, routes = emptyMap(), seed = AUTO_ROUTES) + val next = applyRoutingChange(config, automatic = true, routes = emptyMap()) assertEquals(true, next.automatic) assertEquals(HAND_TABLE, next.manualRoutes) @@ -126,36 +118,22 @@ 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, seed = AUTO_ROUTES) + val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES) - assertNull(next.manualRoutes) + assertEquals(emptyMap(), next.manualRoutes) } @Test fun `a full round trip through automatic does not lose the manual table`() { var config = BoneRoutingConfig(automatic = true, manualRoutes = null) + val built = AUTO_ROUTES + HAND_TABLE - config = applyRoutingChange(config, automatic = false, routes = emptyMap(), seed = AUTO_ROUTES) - config = applyRoutingChange(config, automatic = false, routes = HAND_TABLE, seed = AUTO_ROUTES) - config = applyRoutingChange(config, automatic = true, routes = HAND_TABLE, seed = AUTO_ROUTES) - config = applyRoutingChange(config, automatic = false, routes = AUTO_ROUTES, seed = AUTO_ROUTES) + config = applyRoutingChange(config, automatic = false, routes = emptyMap()) + config = applyRoutingChange(config, automatic = false, routes = built) + config = applyRoutingChange(config, automatic = true, routes = emptyMap()) + config = applyRoutingChange(config, automatic = false, routes = emptyMap()) - assertEquals(HAND_TABLE, config.manualRoutes) - } - - @Test - fun `the seed carries outputs that are merely off`() { - val allOn = RoutingOutput.entries.associateWith { RoutingOutputState.ACTIVE } - val seed = computeAutomaticRoutes(setOf(BodyPart.HIP), allOn) - - val config = applyRoutingChange( - BoneRoutingConfig(automatic = true, manualRoutes = null), - automatic = false, - routes = emptyMap(), - seed = seed, - ) - - assertEquals(setOf(RoutingOutput.DRIVER), config.manualRoutes.orEmpty()[BodyPart.HIP]) + assertEquals(built, config.manualRoutes) } } @@ -166,7 +144,6 @@ class ForcedRoutesTest { BoneRoutingConfig(automatic = false, manualRoutes = emptyMap()), automatic = false, routes = mapOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER, RoutingOutput.VMC)), - seed = AUTO_ROUTES, ) assertEquals(mapOf(BodyPart.HIP to setOf(RoutingOutput.DRIVER)), config.manualRoutes) @@ -178,7 +155,6 @@ class ForcedRoutesTest { BoneRoutingConfig(automatic = false, manualRoutes = emptyMap()), automatic = false, routes = mapOf(BodyPart.NECK to setOf(RoutingOutput.VMC)), - seed = AUTO_ROUTES, ) assertEquals(emptyMap(), config.manualRoutes) @@ -233,3 +209,91 @@ class ForcedRoutesTest { assertEquals(emptySet(), requiredBones(RoutingOutput.DRIVER)) } } + +class OverrideRoutesTest { + @Test + fun `hands are the user's call on the driver only`() { + assertEquals(OVERRIDABLE_BONES, overridableBones(RoutingOutput.DRIVER)) + // Never accepted there. + assertEquals(emptySet(), overridableBones(RoutingOutput.VRC_OSC)) + // Accepted, but required, so it is always on. + assertEquals(emptySet(), overridableBones(RoutingOutput.VMC)) + } + + @Test + fun `automatic routes no hands on its own`() { + val candidates = determineCandidateBones(setOf(BodyPart.LEFT_HAND, BodyPart.HIP)) + + val routes = computeAutomaticRoutes(candidates, ALL_ON) + + assertNull(routes[BodyPart.LEFT_HAND]) + } + + @Test + fun `an override routes the hand while automatic`() { + val config = BoneRoutingConfig(automatic = true, manualRoutes = HAND_TABLE) + + val routes = computeAutomaticRoutes(determineCandidateBones(emptySet()), ALL_ON) + overrideRoutes(config) + + assertEquals(setOf(RoutingOutput.DRIVER), routes[BodyPart.LEFT_HAND]) + } + + @Test + fun `only the overridable bones of a stored table count as overrides`() { + val config = BoneRoutingConfig(automatic = true, manualRoutes = AUTO_ROUTES + HAND_TABLE) + + assertEquals(HAND_TABLE, overrideRoutes(config)) + } + + @Test + fun `an output that requires the hand cannot be overridden`() { + val config = BoneRoutingConfig(automatic = true, manualRoutes = null) + + val next = applyRoutingChange( + config, + automatic = true, + routes = mapOf(BodyPart.LEFT_HAND to setOf(RoutingOutput.VMC)), + ) + + assertEquals(emptyMap(), next.manualRoutes) + } + + @Test + 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) + + assertEquals(HAND_TABLE, next.manualRoutes) + } + + @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) + + val next = applyRoutingChange(config, automatic = true, routes = HAND_TABLE) + + assertEquals(stored + HAND_TABLE, next.manualRoutes) + } + + @Test + fun `dropping the hand from the request clears the override`() { + val config = BoneRoutingConfig(automatic = true, manualRoutes = HAND_TABLE) + + val next = applyRoutingChange(config, automatic = true, routes = AUTO_ROUTES) + + assertEquals(emptyMap(), next.manualRoutes) + } + + @Test + fun `the override survives a round trip through manual`() { + var config = BoneRoutingConfig(automatic = true, manualRoutes = null) + + config = applyRoutingChange(config, automatic = true, routes = HAND_TABLE) + config = applyRoutingChange(config, automatic = false, routes = emptyMap()) + config = applyRoutingChange(config, automatic = true, routes = emptyMap()) + + assertEquals(setOf(RoutingOutput.DRIVER), overrideRoutes(config)[BodyPart.LEFT_HAND]) + } +} diff --git a/server/core/src/test/java/dev/slimevr/trackingchecklist/TrackingChecklistTest.kt b/server/core/src/test/java/dev/slimevr/trackingchecklist/TrackingChecklistTest.kt index 6ed45689f..7682ef9b5 100644 --- a/server/core/src/test/java/dev/slimevr/trackingchecklist/TrackingChecklistTest.kt +++ b/server/core/src/test/java/dev/slimevr/trackingchecklist/TrackingChecklistTest.kt @@ -63,7 +63,7 @@ class TrackingChecklistTest { MountingCalibrationCheckBehaviour(server, resetsManager, settings), FeetMountingCalibrationCheckBehaviour(server, resetsManager, settings), NetworkProfileCheckBehaviour(networkProfileManager), - SteamVRHandsCheckBehaviour(server, settings, boneRouting), + SteamVRHandsCheckBehaviour(server, boneRouting), ), ) checklist.context.observeAll(checklist) @@ -296,7 +296,6 @@ class TrackingChecklistTest { @Test fun `STEAMVR_HANDS_ENABLED is disabled without a driver`() = runTest { val h = Harness(this) - h.setAutomatic(false) h.routeToDriver(BodyPart.LEFT_HAND, BodyPart.RIGHT_HAND) runCurrent() @@ -320,7 +319,6 @@ class TrackingChecklistTest { @Test fun `STEAMVR_HANDS_ENABLED flags hands sent to the driver with no hand tracker worn`() = runTest { val h = Harness(this) - h.setAutomatic(false) h.connectDriver() h.routeToDriver(BodyPart.LEFT_HAND, BodyPart.RIGHT_HAND) runCurrent() @@ -333,7 +331,6 @@ class TrackingChecklistTest { @Test fun `STEAMVR_HANDS_ENABLED accepts hand trackers when no controller is held`() = runTest { val h = Harness(this) - h.setAutomatic(false) h.connectDriver() h.addTracker(BodyPart.LEFT_HAND, origin = DeviceOrigin.UDP) h.routeToDriver(BodyPart.LEFT_HAND, BodyPart.RIGHT_HAND) @@ -345,7 +342,6 @@ class TrackingChecklistTest { @Test fun `STEAMVR_HANDS_ENABLED ignores hands that are not routed to the driver`() = runTest { val h = Harness(this) - h.setAutomatic(false) h.connectDriver() h.addTracker(BodyPart.LEFT_HAND, origin = DeviceOrigin.UDP) h.addTracker(BodyPart.LEFT_HAND, origin = DeviceOrigin.DRIVER) @@ -355,7 +351,7 @@ class TrackingChecklistTest { } @Test - fun `STEAMVR_HANDS_ENABLED is disabled in automatic mode`() = runTest { + fun `STEAMVR_HANDS_ENABLED flags hands in automatic mode too`() = runTest { val h = Harness(this) h.setAutomatic(true) h.connectDriver() @@ -364,7 +360,8 @@ class TrackingChecklistTest { h.routeToDriver(BodyPart.LEFT_HAND, BodyPart.RIGHT_HAND) runCurrent() - // Automatic owns the routes, so there is nothing the user could undo. - assertEquals(false, h.step(TrackingChecklistStepId.STEAMVR_HANDS_ENABLED).enabled) + // Hands are the user's call in either mode, so there is always something to undo. + assertEquals(true, h.step(TrackingChecklistStepId.STEAMVR_HANDS_ENABLED).enabled) + assertEquals(false, h.step(TrackingChecklistStepId.STEAMVR_HANDS_ENABLED).valid) } }