forked from SlimeVR/SlimeVR-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pause tracking keybind & protobuf command (SlimeVR#867)
- Loading branch information
1 parent
25bd050
commit eefe7ef
Showing
12 changed files
with
179 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
server/core/src/main/java/dev/slimevr/protocol/rpc/trackingpause/RPCTrackingPause.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dev.slimevr.protocol.rpc.trackingpause | ||
|
||
import com.google.flatbuffers.FlatBufferBuilder | ||
import dev.slimevr.protocol.GenericConnection | ||
import dev.slimevr.protocol.ProtocolAPI | ||
import dev.slimevr.protocol.rpc.RPCHandler | ||
import dev.slimevr.trackingpause.TrackingPauseListener | ||
import solarxr_protocol.rpc.RpcMessage | ||
import solarxr_protocol.rpc.RpcMessageHeader | ||
import solarxr_protocol.rpc.TrackingPauseStateResponse | ||
import java.nio.ByteBuffer | ||
|
||
class RPCTrackingPause(private val rpcHandler: RPCHandler, private val api: ProtocolAPI) : TrackingPauseListener { | ||
|
||
private val currentPauseState | ||
get() = api.server.humanPoseManager.skeleton.getPauseTracking() | ||
|
||
init { | ||
rpcHandler.registerPacketListener( | ||
RpcMessage.TrackingPauseStateRequest, | ||
::onTrackingPauseStateRequest | ||
) | ||
|
||
// HumanPoseManager might not be immediately available, so queue the server | ||
// to register the listener once it's fully initialized | ||
api.server.queueTask { | ||
api.server.humanPoseManager.trackingPauseHandler.addListener(this) | ||
} | ||
} | ||
|
||
private fun getPauseStateResponse(trackingPaused: Boolean): ByteBuffer { | ||
val fbb = FlatBufferBuilder(32) | ||
val state = TrackingPauseStateResponse.createTrackingPauseStateResponse(fbb, trackingPaused) | ||
val outbound = rpcHandler.createRPCMessage(fbb, RpcMessage.TrackingPauseStateResponse, state) | ||
fbb.finish(outbound) | ||
return fbb.dataBuffer() | ||
} | ||
|
||
private fun onTrackingPauseStateRequest(conn: GenericConnection, messageHeader: RpcMessageHeader) { | ||
conn.send(getPauseStateResponse(currentPauseState)) | ||
} | ||
|
||
override fun onTrackingPause(trackingPaused: Boolean) { | ||
val pauseState = getPauseStateResponse(trackingPaused) | ||
forAllListeners { it.send(pauseState) } | ||
} | ||
|
||
private fun forAllListeners(action: (GenericConnection) -> Unit) { | ||
api.apiServers.forEach { | ||
it.apiConnections.forEach(action) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
server/core/src/main/java/dev/slimevr/trackingpause/TrackingPauseHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.slimevr.trackingpause | ||
|
||
import java.util.concurrent.CopyOnWriteArrayList | ||
|
||
class TrackingPauseHandler { | ||
private val listeners: MutableList<TrackingPauseListener> = CopyOnWriteArrayList() | ||
|
||
fun sendTrackingPauseState(trackingPaused: Boolean) { | ||
listeners.forEach { it.onTrackingPause(trackingPaused) } | ||
} | ||
|
||
fun addListener(listener: TrackingPauseListener) { | ||
listeners.add(listener) | ||
} | ||
|
||
fun removeListener(listener: TrackingPauseListener) { | ||
listeners.removeIf { it == listener } | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
server/core/src/main/java/dev/slimevr/trackingpause/TrackingPauseListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package dev.slimevr.trackingpause | ||
|
||
interface TrackingPauseListener { | ||
fun onTrackingPause(trackingPaused: Boolean) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule solarxr-protocol
updated
31 files