public bool TryGetData(int player, int slot, out MotionInput input) { lock (_motionData) { if (_motionData.ContainsKey(player)) { input = _motionData[player][slot]; return(true); } } input = null; return(false); }
#pragma warning disable CS1998 public void HandleResponse(byte[] data, int clientId) #pragma warning restore CS1998 { ResetRetryTimer(clientId); MessageType type = (MessageType)BitConverter.ToUInt32(data.AsSpan().Slice(16, 4)); data = data.AsSpan().Slice(16).ToArray(); using MemoryStream mem = new MemoryStream(data); using BinaryReader reader = new BinaryReader(mem); switch (type) { case MessageType.Protocol: break; case MessageType.Info: ControllerInfoResponse contollerInfo = reader.ReadStruct <ControllerInfoResponse>(); break; case MessageType.Data: ControllerDataResponse inputData = reader.ReadStruct <ControllerDataResponse>(); Vector3 accelerometer = new Vector3() { X = -inputData.AccelerometerX, Y = inputData.AccelerometerZ, Z = -inputData.AccelerometerY }; Vector3 gyroscrope = new Vector3() { X = inputData.GyroscopePitch, Y = inputData.GyroscopeRoll, Z = -inputData.GyroscopeYaw }; ulong timestamp = inputData.MotionTimestamp; InputConfig config = ConfigurationState.Instance.Hid.InputConfig.Value.Find(x => x.PlayerIndex == (PlayerIndex)clientId); lock (_motionData) { int slot = inputData.Shared.Slot; if (_motionData.ContainsKey(clientId)) { if (_motionData[clientId].ContainsKey(slot)) { var previousData = _motionData[clientId][slot]; previousData.Update(accelerometer, gyroscrope, timestamp, config.Sensitivity, (float)config.GyroDeadzone); } else { MotionInput input = new MotionInput(); input.Update(accelerometer, gyroscrope, timestamp, config.Sensitivity, (float)config.GyroDeadzone); _motionData[clientId].Add(slot, input); } } else { MotionInput input = new MotionInput(); input.Update(accelerometer, gyroscrope, timestamp, config.Sensitivity, (float)config.GyroDeadzone); _motionData.Add(clientId, new Dictionary <int, MotionInput>() { { slot, input } }); } } break; } }