diff --git a/gui/src/hooks/reset.ts b/gui/src/hooks/reset.ts index 35b665c32..ccbbf82e0 100644 --- a/gui/src/hooks/reset.ts +++ b/gui/src/hooks/reset.ts @@ -48,6 +48,17 @@ export function useReset( const req = new ResetRequestT(); req.resetType = options.type; req.bodyParts = parts; + switch (options.type) { + case ResetType.Yaw: + req.delay = 0; + break; + case ResetType.Full: + req.delay = 3; + break; + case ResetType.Mounting: + req.delay = 3; + break; + } sendRPCPacket(RpcMessage.ResetRequest, req); Sentry.metrics.count('reset_click', 1, { diff --git a/server/core/src/main/java/dev/slimevr/config/resets.kt b/server/core/src/main/java/dev/slimevr/config/resets.kt index 695982235..0459b94d2 100644 --- a/server/core/src/main/java/dev/slimevr/config/resets.kt +++ b/server/core/src/main/java/dev/slimevr/config/resets.kt @@ -1,32 +1,7 @@ package dev.slimevr.config import kotlinx.serialization.Serializable - -enum class ArmsResetModes(val id: Int) { - /** Upper arm going back and forearm going forward */ - BACK(0), - - /** Arms going forward */ - FORWARD(1), - - /** Arms going up to the sides into a T-pose */ - T_POSE_UP(2), - - /** Arms going down to the sides from a T-pose */ - T_POSE_DOWN(3), - ; - - companion object { - val values = entries.toTypedArray() - - fun fromId(id: Int): ArmsResetModes? { - for (filter in values) { - if (filter.id == id) return filter - } - return null - } - } -} +import solarxr_protocol.rpc.ArmsMountingResetMode enum class MountingMethods(val id: Int) { MANUAL(0), @@ -50,7 +25,7 @@ data class ResetsConfig( /** Always reset mounting for feet */ val resetMountingFeet: Boolean = false, /** Reset mode used for the arms */ - val mode: ArmsResetModes = ArmsResetModes.BACK, + val armsResetMode: ArmsMountingResetMode = ArmsMountingResetMode.BACK, /** Yaw reset smoothing time in seconds */ val yawResetSmoothTime: Float = 0.0f, /** Save automatic mounting reset calibration */ @@ -58,7 +33,4 @@ data class ResetsConfig( /** Reset the HMD's pitch upon full reset */ val resetHmdPitch: Boolean = false, val lastMountingMethod: MountingMethods = MountingMethods.AUTOMATIC, - val yawResetDelay: Float = 0.0f, - val fullResetDelay: Float = 3.0f, - val mountingResetDelay: Float = 3.0f, ) diff --git a/server/core/src/main/java/dev/slimevr/resets/behaviours.kt b/server/core/src/main/java/dev/slimevr/resets/behaviours.kt index 759d80d3d..515c12fe4 100644 --- a/server/core/src/main/java/dev/slimevr/resets/behaviours.kt +++ b/server/core/src/main/java/dev/slimevr/resets/behaviours.kt @@ -1,5 +1,6 @@ package dev.slimevr.resets +import dev.slimevr.config.MountingMethods import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.delay import kotlinx.coroutines.flow.distinctUntilChangedBy @@ -25,6 +26,8 @@ class ResetsBasicBehaviour : ResetsBehaviour { is ResetsActions.EndReset -> { if (action.resetType == ResetType.Full) { state.copy(canDoYawReset = true, canDoMountingReset = true, lastFullResetTime = System.nanoTime()) + } else if (action.resetType == ResetType.Mounting) { + state.copy(config = state.config.copy(lastMountingMethod = MountingMethods.AUTOMATIC)) } else { state.copy() } diff --git a/server/core/src/main/java/dev/slimevr/resets/module.kt b/server/core/src/main/java/dev/slimevr/resets/module.kt index 958700ea0..14f0e6fa6 100644 --- a/server/core/src/main/java/dev/slimevr/resets/module.kt +++ b/server/core/src/main/java/dev/slimevr/resets/module.kt @@ -1,7 +1,6 @@ package dev.slimevr.resets import dev.slimevr.AppLogger -import dev.slimevr.Phase1ContextProvider import dev.slimevr.VRServer import dev.slimevr.config.ResetsConfig import dev.slimevr.context.Behaviour @@ -47,21 +46,10 @@ class ResetsManager(val context: ResetsContext, val server: VRServer) { * If delay is null, the default delay from config will be used. * If bodyParts is null, resets all trackers. */ - suspend fun scheduleReset(resetSourceName: String, resetType: ResetType, delay: Float? = null, bodyParts: List? = null) { + suspend fun scheduleReset(resetSourceName: String, resetType: ResetType, delay: Float = 0f, bodyParts: List? = null) { resetJob.cancelAndJoin() resetJob = context.scope.safeLaunch { - val config = context.state.value.config - val delayMs = if (delay != null) { - (delay * 1000).toInt() // Use provided delay - } else { - when (resetType) { // Fall back to config - ResetType.Yaw -> (config.yawResetDelay * 1000).toInt() - - ResetType.Full -> (config.fullResetDelay * 1000).toInt() - - ResetType.Mounting -> (config.mountingResetDelay * 1000).toInt() - } - } + val delayMs = (delay * 1000).toInt() val fullSeconds = delayMs / 1000 val remainder = delayMs % 1000 @@ -82,7 +70,7 @@ class ResetsManager(val context: ResetsContext, val server: VRServer) { } delay((remainder).toLong()) - executeTrackerResets(resetType, bodyParts, config) + executeTrackerResets(resetType, bodyParts, context.state.value.config) context.dispatch(ResetsActions.EndReset(resetType)) diff --git a/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt b/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt index dc8d95ed1..537530814 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/behaviours.kt @@ -112,7 +112,7 @@ class YouSpinMeRightRoundBehaviour(val inputHz: Float = 1f) : SkeletonBehaviour } class ComputedSkeletonBehaviour( - val hz: Float = 100f, + val hz: Float = 100f, // TODO behaviours like smoothing will behave different based on hz val processors: List = emptyList(), ) : SkeletonBehaviour { override fun observe(receiver: Skeleton) { diff --git a/server/core/src/main/java/dev/slimevr/solarxr/module.kt b/server/core/src/main/java/dev/slimevr/solarxr/module.kt index 5ae692579..5c9832f66 100644 --- a/server/core/src/main/java/dev/slimevr/solarxr/module.kt +++ b/server/core/src/main/java/dev/slimevr/solarxr/module.kt @@ -72,6 +72,7 @@ class SolarXRBridge( appContext.vrcConfigManager?.let { vrc -> add(VrcBehaviour(vrc, appContext.server, userHeight = { appContext.skeleton.context.state.value.userHeight })) } + add(ResetsBehaviour(appContext.config.settings)) add(TapDetectionBehaviour(appContext.config.settings)) add(VrcOscBehaviour(appContext.vrcOscManager)) add(VmcBehaviour(appContext.vmcManager)) diff --git a/server/core/src/main/java/dev/slimevr/solarxr/resets.kt b/server/core/src/main/java/dev/slimevr/solarxr/resets.kt new file mode 100644 index 000000000..a86fb4f34 --- /dev/null +++ b/server/core/src/main/java/dev/slimevr/solarxr/resets.kt @@ -0,0 +1,38 @@ +package dev.slimevr.solarxr + +import dev.slimevr.config.ResetsConfig +import dev.slimevr.config.Settings +import dev.slimevr.config.SettingsActions +import dev.slimevr.config.TapDetectionConfig +import solarxr_protocol.rpc.ChangeSettingsRequest +import solarxr_protocol.rpc.ResetsSettings +import solarxr_protocol.rpc.TapDetectionSettings + +class ResetsBehaviour( + private val settings: Settings, +) : SolarXRBridgeBehaviour { + override fun observe(receiver: SolarXRBridge) { + receiver.rpcDispatcher.on { req -> + val resetsSettings = req.resetsSettings ?: return@on + + val oldConfig = settings.context.state.value.data.resetsConfig + val newConfig = oldConfig.copy( + resetMountingFeet = resetsSettings.resetMountingFeet == true, + armsResetMode = resetsSettings.armsMountingResetMode ?: oldConfig.armsResetMode, + yawResetSmoothTime = resetsSettings.yawResetSmoothTime ?: oldConfig.yawResetSmoothTime, + saveMountingReset = resetsSettings.saveMountingReset == true, + resetHmdPitch = resetsSettings.resetHmdPitch == true, + ) + + settings.context.dispatch(SettingsActions.Update { copy(resetsConfig = newConfig) }) + } + } +} + +fun buildResetsSettings(config: ResetsConfig): ResetsSettings = ResetsSettings( + resetMountingFeet = config.resetMountingFeet, + armsMountingResetMode = config.armsResetMode, + yawResetSmoothTime = config.yawResetSmoothTime, + saveMountingReset = config.saveMountingReset, + resetHmdPitch = config.resetHmdPitch, +) diff --git a/server/core/src/main/java/dev/slimevr/solarxr/sessioncalibration.kt b/server/core/src/main/java/dev/slimevr/solarxr/sessioncalibration.kt index 23f42c844..52a17a64f 100644 --- a/server/core/src/main/java/dev/slimevr/solarxr/sessioncalibration.kt +++ b/server/core/src/main/java/dev/slimevr/solarxr/sessioncalibration.kt @@ -13,7 +13,7 @@ class SessionCalibrationBehaviour( ) : SolarXRBridgeBehaviour { override fun observe(receiver: SolarXRBridge) { receiver.rpcDispatcher.on { req -> - resetsManager.scheduleReset("SolarXRBridge", req.resetType ?: ResetType.Yaw, req.delay, req.bodyParts) + resetsManager.scheduleReset("SolarXRBridge", req.resetType ?: ResetType.Yaw, req.delay ?: 0f, req.bodyParts) } } } diff --git a/server/core/src/main/java/dev/slimevr/solarxr/settings.kt b/server/core/src/main/java/dev/slimevr/solarxr/settings.kt index 9061e6406..e6a3b4261 100644 --- a/server/core/src/main/java/dev/slimevr/solarxr/settings.kt +++ b/server/core/src/main/java/dev/slimevr/solarxr/settings.kt @@ -18,6 +18,7 @@ class SettingsBehaviour( receiver.rpcDispatcher.on { receiver.sendRpc( SettingsResponse( + resetsSettings = buildResetsSettings(settings.context.state.value.data.resetsConfig), tapDetectionSettings = buildTapDetectionSettings(settings.context.state.value.data.tapDetectionConfig), vmcOsc = buildVmcOscSettings(vmcManager.context.state.value.config), ), diff --git a/server/core/src/main/java/dev/slimevr/solarxr/tapdetection.kt b/server/core/src/main/java/dev/slimevr/solarxr/tapdetection.kt index 0e1b0746e..74a77999e 100644 --- a/server/core/src/main/java/dev/slimevr/solarxr/tapdetection.kt +++ b/server/core/src/main/java/dev/slimevr/solarxr/tapdetection.kt @@ -14,7 +14,7 @@ class TapDetectionBehaviour( val tapDetectionSettings = req.tapDetectionSettings ?: return@on val oldConfig = settings.context.state.value.data.tapDetectionConfig - val newConfig = TapDetectionConfig( + val newConfig = oldConfig.copy( yawResetDelay = tapDetectionSettings.yawResetDelay ?: oldConfig.yawResetDelay, fullResetDelay = tapDetectionSettings.fullResetDelay ?: oldConfig.fullResetDelay, mountingResetDelay = tapDetectionSettings.mountingResetDelay ?: oldConfig.mountingResetDelay,