mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-06 08:42:32 -08:00
Migrate old server configs to rewrite
This commit is contained in:
1 parent
6b65058bb3
commit
caf8435636
14 files changed
+684
-19
No files matched your search
@@ -2,18 +2,22 @@ package dev.slimevr.config
|
||||
|
||||
import dev.slimevr.context.Behaviour
|
||||
import dev.slimevr.context.Context
|
||||
import dev.slimevr.tracker.driverTrackerHardwareId
|
||||
import dev.slimevr.tracker.hidTrackerHardwareId
|
||||
import dev.slimevr.tracker.udpTrackerHardwareId
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.decodeFromJsonElement
|
||||
import kotlinx.serialization.json.intOrNull
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
|
||||
private const val DEVICES_CONFIG_VERSION = 1
|
||||
private const val DEVICES_CONFIG_VERSION = 2
|
||||
const val DEVICES_CONFIG_PATH = "devices.json"
|
||||
|
||||
@Serializable
|
||||
@@ -88,9 +92,32 @@ class DevicesConfig(
|
||||
|
||||
private fun migrateDevicesConfig(json: JsonObject): JsonObject {
|
||||
val version = json["version"]?.jsonPrimitive?.intOrNull ?: 0
|
||||
return when {
|
||||
else -> json
|
||||
if (version >= DEVICES_CONFIG_VERSION) return json
|
||||
val migrated = (version + 1..DEVICES_CONFIG_VERSION).fold(json) { current, to -> migrateDevicesConfigTo(to, current) }
|
||||
return JsonObject(migrated + ("version" to JsonPrimitive(DEVICES_CONFIG_VERSION)))
|
||||
}
|
||||
|
||||
/** Brings a devices config up to version [to] from the one before. */
|
||||
private fun migrateDevicesConfigTo(to: Int, json: JsonObject): JsonObject = when (to) {
|
||||
1 -> json
|
||||
2 -> migrateDevicesConfigV2(json)
|
||||
else -> error("No devices config migration to version $to")
|
||||
}
|
||||
|
||||
/** Version 1 keyed trackers by their bare hardware id, version 2 prefixes it with the tracker origin. */
|
||||
private fun migrateDevicesConfigV2(json: JsonObject): JsonObject {
|
||||
val udpTrackerId = Regex("((?:[0-9A-F]{2}:){5}[0-9A-F]{2}|\\d{1,3}(?:\\.\\d{1,3}){3}):(\\d{1,9})")
|
||||
val hidTrackerId = Regex("[0-9A-F]{12}|[0-9A-F]{16}")
|
||||
|
||||
fun prefixed(id: String): String {
|
||||
if (id.startsWith("vmc:") || id.startsWith("vrcosc:")) return id
|
||||
udpTrackerId.matchEntire(id)?.let { return udpTrackerHardwareId(it.groupValues[1], it.groupValues[2].toInt()) }
|
||||
if (hidTrackerId.matches(id)) return hidTrackerHardwareId(id)
|
||||
return driverTrackerHardwareId(id)
|
||||
}
|
||||
|
||||
val trackers = json["trackers"] as? JsonObject ?: return json
|
||||
return JsonObject(json + ("trackers" to JsonObject(trackers.mapKeys { (id, _) -> prefixed(id) })))
|
||||
}
|
||||
|
||||
private fun parseAndMigrateDevicesConfig(raw: String): DevicesConfigState {
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import dev.slimevr.logging.AppLogger
|
||||
import dev.slimevr.tracker.hidTrackerHardwareId
|
||||
import dev.slimevr.tracker.udpTrackerHardwareId
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import it.krzeminski.snakeyaml.engine.kmp.api.Load
|
||||
import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.buildJsonObject
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.rpc.ArmsMountingResetMode
|
||||
import solarxr_protocol.rpc.StayAlignedRelaxedPose
|
||||
|
||||
/** Config file of the previous server, in the same folder as the current config. */
|
||||
const val LEGACY_CONFIG_PATH = "vrconfig.yml"
|
||||
private const val MIN_LEGACY_CONFIG_VERSION = 14
|
||||
|
||||
private val UDP_TRACKER_NAME = Regex("udp://((?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2})/(\\d{1,9})")
|
||||
private val HID_TRACKER_NAME = Regex("([0-9A-Fa-f]{12})/0")
|
||||
|
||||
private val LEGACY_POSE_KEYS = listOf(
|
||||
StayAlignedRelaxedPose.STANDING to "standingRelaxedPose",
|
||||
StayAlignedRelaxedPose.SITTING to "sittingRelaxedPose",
|
||||
StayAlignedRelaxedPose.FLAT to "flatRelaxedPose",
|
||||
)
|
||||
|
||||
data class LegacyConfigMigration(
|
||||
val settings: SettingsConfigState,
|
||||
val user: UserConfigData,
|
||||
val devices: DevicesConfigState,
|
||||
)
|
||||
|
||||
suspend fun importLegacyConfig(storage: ConfigStorage) {
|
||||
if (storage.exists(GLOBAL_CONFIG_PATH)) return
|
||||
val raw = storage.read(LEGACY_CONFIG_PATH) ?: return
|
||||
|
||||
val migration = try {
|
||||
migrateLegacyConfig(raw)
|
||||
} catch (e: Exception) {
|
||||
AppLogger.config.error(e, "Failed to read ${storage.displayPath(LEGACY_CONFIG_PATH)}")
|
||||
return
|
||||
}
|
||||
if (migration == null) {
|
||||
AppLogger.config.info("Skipped ${storage.displayPath(LEGACY_CONFIG_PATH)}, only version $MIN_LEGACY_CONFIG_VERSION and newer are imported")
|
||||
return
|
||||
}
|
||||
|
||||
val defaults = GlobalConfigState()
|
||||
storage.write(
|
||||
configPath(SETTINGS_PROFILE_DIR, profileFileName(defaults.selectedSettingsProfile)),
|
||||
jsonConfig.encodeToString(migration.settings),
|
||||
overwrite = false,
|
||||
)
|
||||
storage.write(
|
||||
configPath(USER_PROFILE_DIR, profileFileName(defaults.selectedUserProfile)),
|
||||
jsonConfig.encodeToString(migration.user),
|
||||
overwrite = false,
|
||||
)
|
||||
storage.write(DEVICES_CONFIG_PATH, jsonConfig.encodeToString(migration.devices), overwrite = false)
|
||||
AppLogger.config.info("Imported ${storage.displayPath(LEGACY_CONFIG_PATH)}")
|
||||
}
|
||||
|
||||
fun migrateLegacyConfig(yaml: String): LegacyConfigMigration? {
|
||||
// Configs saved before the GUI trimmed the VRM hold its whole glTF JSON, which can go past the 3 MB default
|
||||
val loadSettings = LoadSettings.builder().setCodePointLimit(Int.MAX_VALUE).build()
|
||||
val root = Load(loadSettings).loadOne(yaml) as? Map<*, *> ?: return null
|
||||
val version = intOf(root["modelVersion"]) ?: return null
|
||||
if (version < MIN_LEGACY_CONFIG_VERSION) return null
|
||||
|
||||
return LegacyConfigMigration(
|
||||
settings = settingsOf(root),
|
||||
user = userOf(root),
|
||||
devices = devicesOf(root),
|
||||
)
|
||||
}
|
||||
|
||||
private fun settingsOf(root: Map<*, *>): SettingsConfigState {
|
||||
val defaults = SettingsConfigState()
|
||||
val server = section(root, "server")
|
||||
val skeleton = section(root, "skeleton")
|
||||
val toggles = section(skeleton, "toggles")
|
||||
val values = section(skeleton, "values")
|
||||
val resets = section(root, "resetsConfig")
|
||||
val tap = section(root, "tapDetection")
|
||||
val vmc = section(root, "vmc")
|
||||
val hid = section(root, "hidConfig")
|
||||
val stayAligned = section(root, "stayAlignedConfig")
|
||||
|
||||
val defaultToggles = defaults.skeletonConfig.toggles
|
||||
val defaultRatios = defaults.skeletonConfig.ratios
|
||||
val defaultResets = defaults.resetsConfig
|
||||
val defaultTap = defaults.tapDetectionConfig
|
||||
val defaultVmc = defaults.vmcConfig
|
||||
|
||||
return defaults.copy(
|
||||
trackersConfig = defaults.trackersConfig.copy(
|
||||
globalMagEnabled = boolOf(server["useMagnetometerOnAllTrackers"]) ?: defaults.trackersConfig.globalMagEnabled,
|
||||
),
|
||||
hidConfig = defaults.hidConfig.copy(
|
||||
trackersOverHid = boolOf(hid["trackersOverHID"]) ?: defaults.hidConfig.trackersOverHid,
|
||||
),
|
||||
skeletonConfig = defaults.skeletonConfig.copy(
|
||||
toggles = defaultToggles.copy(
|
||||
floorClip = boolOf(toggles["floorClip"]) ?: defaultToggles.floorClip,
|
||||
skatingCorrection = boolOf(toggles["skatingCorrection"]) ?: defaultToggles.skatingCorrection,
|
||||
toeSnap = boolOf(toggles["toeSnap"]) ?: defaultToggles.toeSnap,
|
||||
footPlant = boolOf(toggles["footPlant"]) ?: defaultToggles.footPlant,
|
||||
mocapMode = boolOf(toggles["selfLocalization"]) ?: defaultToggles.mocapMode,
|
||||
enforceConstraints = boolOf(toggles["enforceConstraints"]) ?: defaultToggles.enforceConstraints,
|
||||
),
|
||||
ratios = defaultRatios.copy(
|
||||
interpolateUpperLegsTwistWithLowerLegs = floatOf(values["kneeTrackerAnkleAveraging"])
|
||||
?: defaultRatios.interpolateUpperLegsTwistWithLowerLegs,
|
||||
),
|
||||
),
|
||||
resetsConfig = defaultResets.copy(
|
||||
resetMountingFeet = boolOf(resets["resetMountingFeet"]) ?: defaultResets.resetMountingFeet,
|
||||
armsMountingResetMode = armsMountingResetModeOf(resets["mode"]) ?: defaultResets.armsMountingResetMode,
|
||||
yawResetSmoothTime = floatOf(resets["yawResetSmoothTime"]) ?: defaultResets.yawResetSmoothTime,
|
||||
saveMountingReset = boolOf(resets["saveMountingReset"]) ?: defaultResets.saveMountingReset,
|
||||
resetHmdAttitude = boolOf(resets["resetHmdPitch"]) ?: defaultResets.resetHmdAttitude,
|
||||
),
|
||||
tapDetectionConfig = defaultTap.copy(
|
||||
yawResetDelay = floatOf(tap["yawResetDelay"]) ?: defaultTap.yawResetDelay,
|
||||
fullResetDelay = floatOf(tap["fullResetDelay"]) ?: defaultTap.fullResetDelay,
|
||||
mountingResetDelay = floatOf(tap["mountingResetDelay"]) ?: defaultTap.mountingResetDelay,
|
||||
yawResetEnabled = boolOf(tap["yawResetEnabled"]) ?: defaultTap.yawResetEnabled,
|
||||
fullResetEnabled = boolOf(tap["fullResetEnabled"]) ?: defaultTap.fullResetEnabled,
|
||||
mountingResetEnabled = boolOf(tap["mountingResetEnabled"]) ?: defaultTap.mountingResetEnabled,
|
||||
yawResetBodyPart = stringOf(tap["yawResetTracker"])?.let(::bodyPartOf) ?: defaultTap.yawResetBodyPart,
|
||||
fullResetBodyPart = stringOf(tap["fullResetTracker"])?.let(::bodyPartOf) ?: defaultTap.fullResetBodyPart,
|
||||
mountingResetBodyPart = stringOf(tap["mountingResetTracker"])?.let(::bodyPartOf) ?: defaultTap.mountingResetBodyPart,
|
||||
yawResetTaps = intOf(tap["yawResetTaps"]) ?: defaultTap.yawResetTaps,
|
||||
fullResetTaps = intOf(tap["fullResetTaps"]) ?: defaultTap.fullResetTaps,
|
||||
mountingResetTaps = intOf(tap["mountingResetTaps"]) ?: defaultTap.mountingResetTaps,
|
||||
numberTrackersOverThreshold = intOf(tap["numberTrackersOverThreshold"]) ?: defaultTap.numberTrackersOverThreshold,
|
||||
),
|
||||
vmcConfig = defaultVmc.copy(
|
||||
enabled = boolOf(vmc["enabled"]) ?: defaultVmc.enabled,
|
||||
portIn = intOf(vmc["portIn"]) ?: defaultVmc.portIn,
|
||||
portOut = intOf(vmc["portOut"]) ?: defaultVmc.portOut,
|
||||
address = stringOf(vmc["address"]) ?: defaultVmc.address,
|
||||
mirrorTracking = boolOf(vmc["mirrorTracking"]) ?: defaultVmc.mirrorTracking,
|
||||
anchorAtHips = boolOf(vmc["anchorHip"]) ?: defaultVmc.anchorAtHips,
|
||||
vrmJson = vrmJsonOf(vmc["vrmJson"]) ?: defaultVmc.vrmJson,
|
||||
),
|
||||
stayAlignedConfig = defaults.stayAlignedConfig.copy(
|
||||
enabled = boolOf(stayAligned["enabled"]) ?: defaults.stayAlignedConfig.enabled,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
private fun userOf(root: Map<*, *>): UserConfigData {
|
||||
val skeleton = section(root, "skeleton")
|
||||
val stayAligned = section(root, "stayAlignedConfig")
|
||||
|
||||
val poses = LEGACY_POSE_KEYS.mapNotNull { (pose, key) ->
|
||||
val old = section(stayAligned, key)
|
||||
if (boolOf(old["enabled"]) != true) return@mapNotNull null
|
||||
pose to StayAlignedPoseConfig(
|
||||
recorded = true,
|
||||
enabled = true,
|
||||
upperLegAngleInDeg = floatOf(old["upperLegAngleInDeg"]) ?: 0f,
|
||||
lowerLegAngleInDeg = floatOf(old["lowerLegAngleInDeg"]) ?: 0f,
|
||||
footAngleInDeg = floatOf(old["footAngleInDeg"]) ?: 0f,
|
||||
)
|
||||
}.toMap()
|
||||
|
||||
val user = UserConfigData(stayAlignedPoses = poses)
|
||||
val height = (floatOf(skeleton["hmdHeight"]) ?: 0f) - (floatOf(skeleton["floorHeight"]) ?: 0f)
|
||||
if (height < MIN_USER_HEIGHT) return user
|
||||
// Proportions are not imported, they are the defaults for the imported height
|
||||
return withDefaultProportions(user.copy(userHeight = height))
|
||||
}
|
||||
|
||||
private fun devicesOf(root: Map<*, *>): DevicesConfigState {
|
||||
val oldTrackers = section(root, "trackers")
|
||||
val trackers = oldTrackers.entries.mapNotNull { (name, old) ->
|
||||
val hardwareId = (name as? String)?.let(::hardwareIdOf) ?: return@mapNotNull null
|
||||
val config = old as? Map<*, *> ?: return@mapNotNull null
|
||||
hardwareId to TrackerConfig(
|
||||
bodyPart = stringOf(config["designation"])?.let { bodyPartOf(it.removePrefix("body:").uppercase()) },
|
||||
customName = stringOf(config["customName"])?.takeIf { it.isNotBlank() },
|
||||
mountingOrientation = quaternionOf(config["mountingOrientation"]) ?: Quaternion.IDENTITY,
|
||||
)
|
||||
}.toMap()
|
||||
|
||||
val knownDevices = (root["knownDevices"] as? List<*>).orEmpty().mapNotNull { stringOf(it)?.uppercase() }.toSet()
|
||||
|
||||
return DevicesConfigState(allowedUdpDevices = knownDevices, trackers = trackers)
|
||||
}
|
||||
|
||||
private fun hardwareIdOf(trackerName: String): String? {
|
||||
UDP_TRACKER_NAME.matchEntire(trackerName)?.let { return udpTrackerHardwareId(it.groupValues[1].uppercase(), it.groupValues[2].toInt()) }
|
||||
HID_TRACKER_NAME.matchEntire(trackerName)?.let { return hidTrackerHardwareId(it.groupValues[1].uppercase()) }
|
||||
return null
|
||||
}
|
||||
|
||||
private fun bodyPartOf(trackerPosition: String): BodyPart? = when (trackerPosition) {
|
||||
"CHEST" -> BodyPart.UPPER_CHEST
|
||||
"WAIST" -> BodyPart.LOWER_WAIST
|
||||
else -> BodyPart.entries.firstOrNull { it != BodyPart.NONE && it.name == trackerPosition }
|
||||
}
|
||||
|
||||
/** T-pose down does not exist anymore, both T-poses become the side T-pose. */
|
||||
private fun armsMountingResetModeOf(value: Any?): ArmsMountingResetMode? = when (stringOf(value)) {
|
||||
"BACK" -> ArmsMountingResetMode.BACK
|
||||
"FORWARD" -> ArmsMountingResetMode.FORWARD
|
||||
"TPOSE_UP", "TPOSE_DOWN" -> ArmsMountingResetMode.SIDE
|
||||
else -> null
|
||||
}
|
||||
|
||||
/** Strip older VRM that were too big */
|
||||
private fun vrmJsonOf(value: Any?): String? {
|
||||
val raw = stringOf(value)?.takeIf { it.isNotEmpty() } ?: return null
|
||||
val gltf = try {
|
||||
jsonConfig.parseToJsonElement(raw).jsonObject
|
||||
} catch (_: IllegalArgumentException) {
|
||||
return null
|
||||
}
|
||||
val extensions = gltf["extensions"] as? JsonObject
|
||||
return buildJsonObject {
|
||||
if (extensions != null) {
|
||||
put(
|
||||
"extensions",
|
||||
buildJsonObject {
|
||||
extensions["VRM"]?.let { put("VRM", it) }
|
||||
extensions["VRMC_vrm"]?.let { put("VRMC_vrm", it) }
|
||||
},
|
||||
)
|
||||
}
|
||||
gltf["extensionsUsed"]?.let { put("extensionsUsed", it) }
|
||||
gltf["nodes"]?.let { put("nodes", it) }
|
||||
}.toString()
|
||||
}
|
||||
|
||||
private fun quaternionOf(value: Any?): Quaternion? {
|
||||
val map = value as? Map<*, *> ?: return null
|
||||
return Quaternion(
|
||||
floatOf(map["w"]) ?: return null,
|
||||
floatOf(map["x"]) ?: return null,
|
||||
floatOf(map["y"]) ?: return null,
|
||||
floatOf(map["z"]) ?: return null,
|
||||
)
|
||||
}
|
||||
|
||||
private fun section(map: Map<*, *>, key: String): Map<*, *> = map[key] as? Map<*, *> ?: emptyMap<Any?, Any?>()
|
||||
|
||||
private fun stringOf(value: Any?): String? = value as? String
|
||||
|
||||
private fun boolOf(value: Any?): Boolean? = when (value) {
|
||||
is Boolean -> value
|
||||
is String -> value.toBooleanStrictOrNull()
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun floatOf(value: Any?): Float? = when (value) {
|
||||
is Number -> value.toFloat()
|
||||
is String -> value.toFloatOrNull()
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun intOf(value: Any?): Int? = when (value) {
|
||||
is Number -> value.toInt()
|
||||
is String -> value.toIntOrNull()
|
||||
else -> null
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import solarxr_protocol.rpc.ProfileKind
|
||||
import solarxr_protocol.rpc.ProfileOperationStatus
|
||||
import java.util.UUID
|
||||
|
||||
const val GLOBAL_CONFIG_PATH = "global.json"
|
||||
private const val GLOBAL_CONFIG_VERSION = 1
|
||||
private const val CURRENT_CONSENT_VERSION = 2
|
||||
|
||||
@@ -67,7 +68,7 @@ class GlobalConfig(
|
||||
|
||||
companion object {
|
||||
suspend fun create(scope: CoroutineScope, storage: ConfigStorage): GlobalConfig {
|
||||
val initialState = loadFileWithBackup(storage, "global.json", GlobalConfigState()) {
|
||||
val initialState = loadFileWithBackup(storage, GLOBAL_CONFIG_PATH, GlobalConfigState()) {
|
||||
parseAndMigrateGlobalConfig(it)
|
||||
}.let(::withSafeProfileNames)
|
||||
val context = Context.create(
|
||||
@@ -79,12 +80,12 @@ class GlobalConfig(
|
||||
val globalConfig = GlobalConfig(context)
|
||||
globalConfig.startObserving()
|
||||
// Persists defaults filled on load (the generated userId), autosave skips the initial state
|
||||
storage.write("global.json", jsonConfig.encodeToString(initialState))
|
||||
storage.write(GLOBAL_CONFIG_PATH, jsonConfig.encodeToString(initialState))
|
||||
launchAutosave(
|
||||
scope = scope,
|
||||
state = context.state,
|
||||
storage = storage,
|
||||
toPath = { "global.json" },
|
||||
toPath = { GLOBAL_CONFIG_PATH },
|
||||
serialize = { jsonConfig.encodeToString(it) },
|
||||
)
|
||||
return globalConfig
|
||||
@@ -280,6 +281,7 @@ class AppConfig(
|
||||
|
||||
companion object {
|
||||
suspend fun create(scope: CoroutineScope, storage: ConfigStorage): AppConfig {
|
||||
importLegacyConfig(storage)
|
||||
val globalConfig = GlobalConfig.create(scope, storage)
|
||||
|
||||
val userConfig = UserConfig.create(scope, storage, globalConfig.context.state.value.selectedUserProfile)
|
||||
|
||||
@@ -16,6 +16,9 @@ import solarxr_protocol.rpc.StayAlignedRelaxedPose
|
||||
private const val USER_CONFIG_VERSION = 1
|
||||
private const val DEFAULT_USER_HEIGHT = 1.6f
|
||||
|
||||
/** Lowest eye height accepted as the user height. */
|
||||
const val MIN_USER_HEIGHT = 0.9f
|
||||
|
||||
/** A relaxed pose of the user, used by Stay Aligned to correct moving trackers. */
|
||||
@Serializable
|
||||
data class StayAlignedPoseConfig(
|
||||
|
||||
@@ -7,6 +7,7 @@ import dev.slimevr.hid.HIDReceiverActions
|
||||
import dev.slimevr.logging.AppLogger
|
||||
import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.TrackerActions
|
||||
import dev.slimevr.tracker.hidTrackerHardwareId
|
||||
import solarxr_protocol.datatypes.DeviceOrigin
|
||||
import solarxr_protocol.datatypes.TrackerStatus
|
||||
import solarxr_protocol.datatypes.hardware_info.ImuType
|
||||
@@ -53,10 +54,11 @@ internal suspend fun registerHidDevice(
|
||||
/** Creates or finds the [Tracker] for an already-registered HID device and links it to [hidId]. */
|
||||
internal fun ensureHidTracker(receiver: HIDReceiver, hidId: Int, deviceId: Int, imuType: ImuType? = null): Tracker? {
|
||||
val deviceState = receiver.appContext.server.getDevice(deviceId)?.context?.state?.value ?: return null
|
||||
val hardwareId = hidTrackerHardwareId(deviceState.address)
|
||||
|
||||
val tracker = receiver.getTracker(hidId)
|
||||
?: receiver.appContext.server.context.state.value.trackers.values
|
||||
.find { it.context.state.value.hardwareId == deviceState.address && it.context.state.value.origin == DeviceOrigin.HID }
|
||||
.find { it.context.state.value.hardwareId == hardwareId && it.context.state.value.origin == DeviceOrigin.HID }
|
||||
?: run {
|
||||
val trackerId = receiver.appContext.server.nextHandle()
|
||||
val newTracker = Tracker.create(
|
||||
@@ -64,7 +66,7 @@ internal fun ensureHidTracker(receiver: HIDReceiver, hidId: Int, deviceId: Int,
|
||||
id = trackerId,
|
||||
deviceId = deviceState.id,
|
||||
imuType = imuType,
|
||||
hardwareId = deviceState.address,
|
||||
hardwareId = hardwareId,
|
||||
origin = DeviceOrigin.HID,
|
||||
appContext = receiver.appContext,
|
||||
)
|
||||
|
||||
@@ -11,6 +11,7 @@ import dev.slimevr.solarxr.toQuaternion
|
||||
import dev.slimevr.solarxr.toVector3
|
||||
import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.TrackerActions
|
||||
import dev.slimevr.tracker.driverTrackerHardwareId
|
||||
import dev.slimevr.util.inFloatingSeconds
|
||||
import dev.slimevr.util.timeSource
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
@@ -100,9 +101,10 @@ class DriverIncomingTrackersBehaviour(
|
||||
return@onDriverMessage
|
||||
}
|
||||
val hardwareId = req.hardwareIdentifier
|
||||
val trackerHardwareId = driverTrackerHardwareId(hardwareId)
|
||||
|
||||
val existing = server.context.state.value.trackers.values
|
||||
.find { it.context.state.value.hardwareId == hardwareId }
|
||||
.find { it.context.state.value.hardwareId == trackerHardwareId }
|
||||
if (existing != null) {
|
||||
val trackerState = existing.context.state.value
|
||||
// Tracker is in use by another driver right now
|
||||
@@ -149,7 +151,7 @@ class DriverIncomingTrackersBehaviour(
|
||||
intendedBodyPart = req.bodyPart,
|
||||
intendedBoneOffset = offset?.boneOffset,
|
||||
deviceId = deviceId,
|
||||
hardwareId = hardwareId,
|
||||
hardwareId = trackerHardwareId,
|
||||
origin = DeviceOrigin.DRIVER,
|
||||
driverName = driverName,
|
||||
appContext = appContext,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.slimevr.solarxr.rpc
|
||||
|
||||
import dev.slimevr.config.MIN_USER_HEIGHT
|
||||
import dev.slimevr.config.UserConfig
|
||||
import dev.slimevr.config.UserConfigActions
|
||||
import dev.slimevr.config.withDefaultProportions
|
||||
@@ -29,8 +30,6 @@ import solarxr_protocol.rpc.SkeletonProportionsRequest
|
||||
import solarxr_protocol.rpc.SkeletonProportionsResetAllRequest
|
||||
import solarxr_protocol.rpc.SkeletonProportionsResponse
|
||||
|
||||
private const val MIN_HEIGHT = 0.9f
|
||||
|
||||
class SkeletonProportionsBehaviour(
|
||||
private val userConfig: UserConfig,
|
||||
private val skeleton: Skeleton,
|
||||
@@ -70,7 +69,7 @@ class SkeletonProportionsBehaviour(
|
||||
val headHeight = req.headHeight ?: return@on
|
||||
val floorHeight = req.floorHeight ?: 0f
|
||||
val height = headHeight - floorHeight
|
||||
if (height >= MIN_HEIGHT) {
|
||||
if (height >= MIN_USER_HEIGHT) {
|
||||
userConfig.context.dispatch(
|
||||
UserConfigActions.Update { withUserHeight(this, height) },
|
||||
)
|
||||
@@ -80,7 +79,7 @@ class SkeletonProportionsBehaviour(
|
||||
|
||||
receiver.rpcDispatcher.on<SkeletonProportionsResetAllRequest> {
|
||||
val height = userConfig.context.state.value.data.userHeight
|
||||
if (height >= MIN_HEIGHT) {
|
||||
if (height >= MIN_USER_HEIGHT) {
|
||||
userConfig.context.dispatch(UserConfigActions.Update { withDefaultProportions(this) })
|
||||
}
|
||||
}.launchIn(receiver.context.scope)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.slimevr.tracker
|
||||
|
||||
fun udpTrackerHardwareId(deviceHardwareId: String, sensorId: Int): String = "udp:$deviceHardwareId:$sensorId"
|
||||
|
||||
fun hidTrackerHardwareId(address: String): String = "hid:$address"
|
||||
|
||||
fun driverTrackerHardwareId(hardwareIdentifier: String): String = "driver:$hardwareIdentifier"
|
||||
@@ -7,6 +7,7 @@ import dev.slimevr.device.DeviceActions
|
||||
import dev.slimevr.logging.AppLogger
|
||||
import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.TrackerActions
|
||||
import dev.slimevr.tracker.udpTrackerHardwareId
|
||||
import dev.slimevr.util.udpHardwareId
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
@@ -43,7 +44,7 @@ fun getCorrectedAcceleration(acceleration: Vector3, protocolVersion: Int) = if (
|
||||
internal fun assignTracker(receiver: UDPConnection, device: Device, info: SensorInfo): Tracker {
|
||||
val deviceState = device.context.state.value
|
||||
val deviceHardwareId = deviceState.hardwareId ?: udpHardwareId(deviceState.macAddress, deviceState.address)
|
||||
val hardwareId = "$deviceHardwareId:${info.sensorId}"
|
||||
val hardwareId = udpTrackerHardwareId(deviceHardwareId, info.sensorId)
|
||||
|
||||
val existingTracker = receiver.appContext.server.context.state.value.trackers.values
|
||||
.find { t -> t.context.state.value.deviceId == deviceState.id && t.context.state.value.hardwareId == hardwareId }
|
||||
|
||||
Reference in new issue
Block a user