public void Update() { lock (_lock) { List <GamepadInput> hleInputStates = new List <GamepadInput>(); List <SixAxisInput> hleMotionStates = new List <SixAxisInput>(NpadDevices.MaxControllers); KeyboardInput?hleKeyboardInput = null; foreach (InputConfig inputConfig in _inputConfig) { GamepadInput inputState = default; SixAxisInput motionState = default; NpadController controller = _controllers[(int)inputConfig.PlayerIndex]; // Do we allow input updates and is a controller connected? if (!_blockInputUpdates && controller != null) { DriverConfigurationUpdate(ref controller, inputConfig); controller.UpdateUserConfiguration(inputConfig); controller.Update(); inputState = controller.GetHLEInputState(); inputState.Buttons |= _device.Hid.UpdateStickButtons(inputState.LStick, inputState.RStick); motionState = controller.GetHLEMotionState(); if (_enableKeyboard) { hleKeyboardInput = controller.GetHLEKeyboardInput(); } } else { // Ensure that orientation isn't null motionState.Orientation = new float[9]; } inputState.PlayerId = (Ryujinx.HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex; motionState.PlayerId = (Ryujinx.HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex; hleInputStates.Add(inputState); hleMotionStates.Add(motionState); } _device.Hid.Npads.Update(hleInputStates); _device.Hid.Npads.UpdateSixAxis(hleMotionStates); if (hleKeyboardInput.HasValue) { _device.Hid.Keyboard.Update(hleKeyboardInput.Value); } _device.TamperMachine.UpdateInput(hleInputStates); } }
public void Update(float aspectRatio = 0) { lock (_lock) { List <GamepadInput> hleInputStates = new List <GamepadInput>(); List <SixAxisInput> hleMotionStates = new List <SixAxisInput>(NpadDevices.MaxControllers); KeyboardInput?hleKeyboardInput = null; foreach (InputConfig inputConfig in _inputConfig) { GamepadInput inputState = default; (SixAxisInput, SixAxisInput)motionState = default; NpadController controller = _controllers[(int)inputConfig.PlayerIndex]; Ryujinx.HLE.HOS.Services.Hid.PlayerIndex playerIndex = (Ryujinx.HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex; bool isJoyconPair = false; // Do we allow input updates and is a controller connected? if (!_blockInputUpdates && controller != null) { DriverConfigurationUpdate(ref controller, inputConfig); controller.UpdateUserConfiguration(inputConfig); controller.Update(); controller.UpdateRumble(_device.Hid.Npads.GetRumbleQueue(playerIndex)); inputState = controller.GetHLEInputState(); inputState.Buttons |= _device.Hid.UpdateStickButtons(inputState.LStick, inputState.RStick); isJoyconPair = inputConfig.ControllerType == Common.Configuration.Hid.ControllerType.JoyconPair; var altMotionState = isJoyconPair ? controller.GetHLEMotionState(true) : default; motionState = (controller.GetHLEMotionState(), altMotionState); if (_enableKeyboard) { hleKeyboardInput = controller.GetHLEKeyboardInput(); } } else { // Ensure that orientation isn't null motionState.Item1.Orientation = new float[9]; } inputState.PlayerId = playerIndex; motionState.Item1.PlayerId = playerIndex; hleInputStates.Add(inputState); hleMotionStates.Add(motionState.Item1); if (isJoyconPair && !motionState.Item2.Equals(default))
public void Update(float aspectRatio = 0) { lock (_lock) { List <GamepadInput> hleInputStates = new List <GamepadInput>(); List <SixAxisInput> hleMotionStates = new List <SixAxisInput>(NpadDevices.MaxControllers); KeyboardInput?hleKeyboardInput = null; foreach (InputConfig inputConfig in _inputConfig) { GamepadInput inputState = default; SixAxisInput motionState = default; NpadController controller = _controllers[(int)inputConfig.PlayerIndex]; Ryujinx.HLE.HOS.Services.Hid.PlayerIndex playerIndex = (Ryujinx.HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex; // Do we allow input updates and is a controller connected? if (!_blockInputUpdates && controller != null) { DriverConfigurationUpdate(ref controller, inputConfig); controller.UpdateUserConfiguration(inputConfig); controller.Update(); if (!_device.Hid.Npads.RumbleQueues.TryGetValue(playerIndex, out ConcurrentQueue <(HidVibrationValue, HidVibrationValue)> rumbleQueue)) { rumbleQueue = new ConcurrentQueue <(HidVibrationValue, HidVibrationValue)>(); _device.Hid.Npads.RumbleQueues[playerIndex] = rumbleQueue; } controller.UpdateRumble(rumbleQueue); inputState = controller.GetHLEInputState(); inputState.Buttons |= _device.Hid.UpdateStickButtons(inputState.LStick, inputState.RStick); motionState = controller.GetHLEMotionState(); if (_enableKeyboard) { hleKeyboardInput = controller.GetHLEKeyboardInput(); } } else { // Ensure that orientation isn't null motionState.Orientation = new float[9]; } inputState.PlayerId = playerIndex; motionState.PlayerId = playerIndex; hleInputStates.Add(inputState); hleMotionStates.Add(motionState); } _device.Hid.Npads.Update(hleInputStates); _device.Hid.Npads.UpdateSixAxis(hleMotionStates); if (hleKeyboardInput.HasValue) { _device.Hid.Keyboard.Update(hleKeyboardInput.Value); } if (_enableMouse) { var mouse = _mouseDriver.GetGamepad("0") as IMouse; var mouseInput = IMouse.GetMouseStateSnapshot(mouse); uint buttons = 0; if (mouseInput.IsPressed(MouseButton.Button1)) { buttons |= 1 << 0; } if (mouseInput.IsPressed(MouseButton.Button2)) { buttons |= 1 << 1; } if (mouseInput.IsPressed(MouseButton.Button3)) { buttons |= 1 << 2; } if (mouseInput.IsPressed(MouseButton.Button4)) { buttons |= 1 << 3; } if (mouseInput.IsPressed(MouseButton.Button5)) { buttons |= 1 << 4; } var position = IMouse.GetScreenPosition(mouseInput.Position, mouse.ClientSize, aspectRatio); _device.Hid.Mouse.Update((int)position.X, (int)position.Y, buttons, (int)mouseInput.Scroll.X, (int)mouseInput.Scroll.Y, true); } else { _device.Hid.Mouse.Update(0, 0); } _device.TamperMachine.UpdateInput(hleInputStates); } }