mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-02 06:42:36 -08:00
Resets settings + delay from GUI
This commit is contained in:
1 parent
98ccc7c667
commit
22999975ad
10 files changed
+62
-48
No files matched your search
@@ -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,
|
||||
)
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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<BodyPart>? = null) {
|
||||
suspend fun scheduleReset(resetSourceName: String, resetType: ResetType, delay: Float = 0f, bodyParts: List<BodyPart>? = 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))
|
||||
|
||||
|
||||
@@ -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<SkeletonProcessor> = emptyList(),
|
||||
) : SkeletonBehaviour {
|
||||
override fun observe(receiver: Skeleton) {
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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<ChangeSettingsRequest> { 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,
|
||||
)
|
||||
@@ -13,7 +13,7 @@ class SessionCalibrationBehaviour(
|
||||
) : SolarXRBridgeBehaviour {
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.rpcDispatcher.on<ResetRequest> { req ->
|
||||
resetsManager.scheduleReset("SolarXRBridge", req.resetType ?: ResetType.Yaw, req.delay, req.bodyParts)
|
||||
resetsManager.scheduleReset("SolarXRBridge", req.resetType ?: ResetType.Yaw, req.delay ?: 0f, req.bodyParts)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ class SettingsBehaviour(
|
||||
receiver.rpcDispatcher.on<SettingsRequest> {
|
||||
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),
|
||||
),
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user