Better flightlist checks / fix edge cases

This commit is contained in:
loucass003 committed 2026-07-29 04:35:22 +02:00
1 parent 5d0e6011dc
commit 1290b8f930
3 files changed
+49 -14

No files matched your search

@@ -34,6 +34,7 @@ class ResetsBasicBehaviour : ResetsBehaviour {
val feetOnly = !bodyParts.isNullOrEmpty() && bodyParts.all { it in FOOT_PARTS }
when {
feetOnly -> state.copy(feetMountingResetCompleted = true)
bodyParts.isNullOrEmpty() -> state.copy(
mountingResetCompleted = true,
feetMountingResetCompleted = action.resetMountingFeet || state.feetMountingResetCompleted,
@@ -24,19 +24,16 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChangedBy
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import solarxr_protocol.datatypes.BodyPart
import solarxr_protocol.datatypes.TrackerStatus
import solarxr_protocol.rpc.TrackingChecklistNeedCalibration
import solarxr_protocol.rpc.TrackingChecklistPublicNetworks
import solarxr_protocol.rpc.TrackingChecklistSteamVRDisconnected
import solarxr_protocol.rpc.TrackingChecklistStep
import solarxr_protocol.rpc.TrackingChecklistStepId
import solarxr_protocol.rpc.TrackingChecklistStepVisibility
@@ -216,18 +213,34 @@ class FullResetCheckBehaviour(
override fun observe(receiver: TrackingChecklist) {
val scope = receiver.context.scope
server.context.state
.flatMapLatest { state ->
state.trackers.map { (id, tracker) ->
tracker.context.state
.distinctUntilChangedBy { it.status to it.bodyPart }
.filter { isConnectedAssignedImu(it) }
.map { id }
}.merge()
val connected = mutableSetOf<Int>()
trackerStatesFlow(server)
.map { trackers -> trackers.filter { isConnectedAssignedImu(it) }.map { it.id }.toSet() }
.distinctUntilChanged()
.onEach { current ->
needsReset.update { ids -> ids + (current - connected) }
connected.clear()
connected.addAll(current)
}
.onEach { id -> needsReset.update { ids -> ids + id } }
.launchIn(scope)
val bodyParts = mutableMapOf<Int, BodyPart>()
trackerStatesFlow(server)
.map { trackers -> trackers.mapNotNull { tracker -> tracker.bodyPart?.let { tracker.id to it } }.toMap() }
.distinctUntilChanged()
.onEach { current ->
for ((id, bodyPart) in current) {
val previous = bodyParts[id]
if (previous != null && previous != bodyPart) {
needsReset.update { ids -> ids + id }
}
}
bodyParts.clear()
bodyParts.putAll(current)
}
.launchIn(scope)
// Clear everything on a full reset.
resetsManager.context.state
.distinctUntilChangedBy { it.lastFullResetTime }
.drop(1)
@@ -28,14 +28,13 @@ import solarxr_protocol.datatypes.hardware_info.ImuType
import solarxr_protocol.rpc.ResetType
import solarxr_protocol.rpc.TrackingChecklistStep
import solarxr_protocol.rpc.TrackingChecklistStepId
import solarxr_protocol.rpc.TrackingChecklistTrackerReset
import kotlin.test.Test
import kotlin.test.assertEquals
@OptIn(ExperimentalCoroutinesApi::class)
class TrackingChecklistTest {
// Registers every step behaviour together, matching production wiring, so the tests also cover
// that the behaviours coexist without clobbering each other's steps.
private class Harness(scope: TestScope, networkSupported: Boolean = true) {
val server: VRServer = buildTestVrServer(scope.backgroundScope)
val settings: Settings = buildTestSettings(scope.backgroundScope)
@@ -137,6 +136,28 @@ class TrackingChecklistTest {
assertEquals(false, h.step(TrackingChecklistStepId.FULL_RESET).valid)
}
@Test
fun `adding a tracker does not re-flag the existing already-reset trackers`() = runTest {
val h = Harness(this)
h.addTracker(BodyPart.CHEST)
runCurrent()
h.resetsManager.context.dispatch(ResetsActions.EndReset(ResetType.FULL))
runCurrent()
assertEquals(true, h.step(TrackingChecklistStepId.FULL_RESET).valid)
// A newly discovered tracker starts disconnected; adding it must not re-flag the existing one
val added = h.addTracker(BodyPart.HIP, status = TrackerStatus.DISCONNECTED)
runCurrent()
assertEquals(true, h.step(TrackingChecklistStepId.FULL_RESET).valid)
// Only the new tracker gets flagged once it connects
added.context.dispatch(TrackerActions.SetStatus(TrackerStatus.OK))
runCurrent()
assertEquals(false, h.step(TrackingChecklistStepId.FULL_RESET).valid)
val pending = (h.step(TrackingChecklistStepId.FULL_RESET).extraData as TrackingChecklistTrackerReset).trackersId
assertEquals(listOf(added.context.state.value.id.toUShort()), pending)
}
@Test
fun `MOUNTING_CALIBRATION is enabled with an IMU tracker and valid after a mounting reset`() = runTest {
val h = Harness(this)