diff --git a/server/core/src/main/java/dev/slimevr/solarxr/tracker-assignment.kt b/server/core/src/main/java/dev/slimevr/solarxr/tracker-assignment.kt index cf2dd28ed..a313698e0 100644 --- a/server/core/src/main/java/dev/slimevr/solarxr/tracker-assignment.kt +++ b/server/core/src/main/java/dev/slimevr/solarxr/tracker-assignment.kt @@ -1,11 +1,14 @@ package dev.slimevr.solarxr import dev.slimevr.VRServer +import dev.slimevr.skeleton.bodyPartMap +import dev.slimevr.tracker.Tracker import dev.slimevr.tracker.TrackerActions import dev.slimevr.util.isActive import io.github.axisangles.ktmath.Quaternion import solarxr_protocol.datatypes.BodyPart import solarxr_protocol.rpc.AssignTrackerRequest +import solarxr_protocol.rpc.ResetTrackerAssignments class AssignTrackerBehaviour( private val server: VRServer, @@ -46,5 +49,33 @@ class AssignTrackerBehaviour( ) } }.launchIn(receiver.context.scope) + + receiver.rpcDispatcher.on { + val trackers = server.context.state.value.trackers.values + val intendedBodyParts = bodyPartMap() + + // First unassign all trackers so that we don't have conflicts. + trackers.forEach { tracker -> + val intendedBodyPart = tracker.context.state.value.intendedBodyPart + intendedBodyParts.putIfAbsent(intendedBodyPart, tracker) + + tracker.context.dispatch( + TrackerActions.Update { + copy(bodyPart = null) + }, + ) + } + + // Then re-assign trackers with intended body parts, using the map to ensure + // we don't try to assign two trackers to the same body part if there were + // multiple with the same intended body part. + intendedBodyParts.forEach { (bodyPart, tracker) -> + tracker.context.dispatch( + TrackerActions.Update { + copy(bodyPart = bodyPart) + }, + ) + } + }.launchIn(receiver.context.scope) } } diff --git a/solarxr-protocol b/solarxr-protocol index e2aa0f7af..a62e289a0 160000 --- a/solarxr-protocol +++ b/solarxr-protocol @@ -1 +1 @@ -Subproject commit e2aa0f7af31565ae99414a9d942ef147ec4bf8a5 +Subproject commit a62e289a03f105502510e9f65141fa4618021328