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))
private bool UpdateFrame() { if (!IsActive) { return(true); } if (IsStopped) { return(false); } HotkeyButtons currentHotkeyButtons = 0; ControllerKeys currentButton = 0; JoystickPosition leftJoystick; JoystickPosition rightJoystick; KeyboardInput? hidKeyboard = null; int leftJoystickDx = 0; int leftJoystickDy = 0; int rightJoystickDx = 0; int rightJoystickDy = 0; // OpenTK always captures keyboard events, even if out of focus, so check if window is focused. if (IsFocused) { KeyboardState keyboard = OpenTK.Input.Keyboard.GetState(); Gtk.Application.Invoke(delegate { HandleScreenState(keyboard); }); // Normal Input currentHotkeyButtons = KeyboardControls.GetHotkeyButtons(ConfigurationState.Instance.Hid.KeyboardControls, keyboard); currentButton = KeyboardControls.GetButtons(ConfigurationState.Instance.Hid.KeyboardControls, keyboard); if (ConfigurationState.Instance.Hid.EnableKeyboard) { hidKeyboard = KeyboardControls.GetKeysDown(ConfigurationState.Instance.Hid.KeyboardControls, keyboard); } (leftJoystickDx, leftJoystickDy) = KeyboardControls.GetLeftStick(ConfigurationState.Instance.Hid.KeyboardControls, keyboard); (rightJoystickDx, rightJoystickDy) = KeyboardControls.GetRightStick(ConfigurationState.Instance.Hid.KeyboardControls, keyboard); } if (!hidKeyboard.HasValue) { hidKeyboard = new KeyboardInput { Modifier = 0, Keys = new int[0x8] }; } currentButton |= _primaryController.GetButtons(); // Keyboard has priority stick-wise if (leftJoystickDx == 0 && leftJoystickDy == 0) { (leftJoystickDx, leftJoystickDy) = _primaryController.GetLeftStick(); } if (rightJoystickDx == 0 && rightJoystickDy == 0) { (rightJoystickDx, rightJoystickDy) = _primaryController.GetRightStick(); } leftJoystick = new JoystickPosition { Dx = leftJoystickDx, Dy = leftJoystickDy }; rightJoystick = new JoystickPosition { Dx = rightJoystickDx, Dy = rightJoystickDy }; currentButton |= _device.Hid.UpdateStickButtons(leftJoystick, rightJoystick); bool hasTouch = false; // Get screen touch position from left mouse click // OpenTK always captures mouse events, even if out of focus, so check if window is focused. if (IsFocused && _mousePressed) { int screenWidth = AllocatedWidth; int screenHeight = AllocatedHeight; if (AllocatedWidth > (AllocatedHeight * SwitchPanelWidth) / SwitchPanelHeight) { screenWidth = (AllocatedHeight * SwitchPanelWidth) / SwitchPanelHeight; } else { screenHeight = (AllocatedWidth * SwitchPanelHeight) / SwitchPanelWidth; } int startX = (AllocatedWidth - screenWidth) >> 1; int startY = (AllocatedHeight - screenHeight) >> 1; int endX = startX + screenWidth; int endY = startY + screenHeight; if (_mouseX >= startX && _mouseY >= startY && _mouseX < endX && _mouseY < endY) { int screenMouseX = (int)_mouseX - startX; int screenMouseY = (int)_mouseY - startY; int mX = (screenMouseX * SwitchPanelWidth) / screenWidth; int mY = (screenMouseY * SwitchPanelHeight) / screenHeight; TouchPoint currentPoint = new TouchPoint { X = (uint)mX, // can be -ve? Y = (uint)mY, // Placeholder values till more data is acquired DiameterX = 10, DiameterY = 10, Angle = 90 }; hasTouch = true; _device.Hid.Touchscreen.Update(currentPoint); } } if (!hasTouch) { _device.Hid.Touchscreen.Update(); } if (ConfigurationState.Instance.Hid.EnableKeyboard && hidKeyboard.HasValue) { _device.Hid.Keyboard.Update(hidKeyboard.Value); } _device.Hid.DebugPad.Update(); _device.Hid.Npads.SetGamepadsInput(new GamepadInput { PlayerId = HidControllerID.Auto, Buttons = currentButton, LStick = leftJoystick, RStick = rightJoystick }); // Toggle vsync if (currentHotkeyButtons.HasFlag(HotkeyButtons.ToggleVSync) && !_prevHotkeyButtons.HasFlag(HotkeyButtons.ToggleVSync)) { _device.EnableDeviceVsync = !_device.EnableDeviceVsync; } _prevHotkeyButtons = currentHotkeyButtons; return(true); }
private bool UpdateFrame() { if (!IsActive) { return(true); } if (IsStopped) { return(false); } if (IsFocused) { Gtk.Application.Invoke(delegate { KeyboardState keyboard = OpenTK.Input.Keyboard.GetState(); HandleScreenState(keyboard); if (keyboard.IsKeyDown(OpenTK.Input.Key.Delete)) { if (!ParentWindow.State.HasFlag(Gdk.WindowState.Fullscreen)) { Ptc.Continue(); } } }); } List <GamepadInput> gamepadInputs = new List <GamepadInput>(); foreach (InputConfig inputConfig in ConfigurationState.Instance.Hid.InputConfig.Value.ToArray()) { ControllerKeys currentButton = 0; JoystickPosition leftJoystick = new JoystickPosition(); JoystickPosition rightJoystick = new JoystickPosition(); KeyboardInput? hidKeyboard = null; int leftJoystickDx = 0; int leftJoystickDy = 0; int rightJoystickDx = 0; int rightJoystickDy = 0; if (inputConfig is KeyboardConfig keyboardConfig) { if (IsFocused) { // Keyboard Input KeyboardController keyboardController = new KeyboardController(keyboardConfig); currentButton = keyboardController.GetButtons(); (leftJoystickDx, leftJoystickDy) = keyboardController.GetLeftStick(); (rightJoystickDx, rightJoystickDy) = keyboardController.GetRightStick(); leftJoystick = new JoystickPosition { Dx = leftJoystickDx, Dy = leftJoystickDy }; rightJoystick = new JoystickPosition { Dx = rightJoystickDx, Dy = rightJoystickDy }; if (ConfigurationState.Instance.Hid.EnableKeyboard) { hidKeyboard = keyboardController.GetKeysDown(); } if (!hidKeyboard.HasValue) { hidKeyboard = new KeyboardInput { Modifier = 0, Keys = new int[0x8] }; } if (ConfigurationState.Instance.Hid.EnableKeyboard) { _device.Hid.Keyboard.Update(hidKeyboard.Value); } } } else if (inputConfig is Common.Configuration.Hid.ControllerConfig controllerConfig) { // Controller Input JoystickController joystickController = new JoystickController(controllerConfig); currentButton |= joystickController.GetButtons(); (leftJoystickDx, leftJoystickDy) = joystickController.GetLeftStick(); (rightJoystickDx, rightJoystickDy) = joystickController.GetRightStick(); leftJoystick = new JoystickPosition { Dx = controllerConfig.LeftJoycon.InvertStickX ? -leftJoystickDx : leftJoystickDx, Dy = controllerConfig.LeftJoycon.InvertStickY ? -leftJoystickDy : leftJoystickDy }; rightJoystick = new JoystickPosition { Dx = controllerConfig.RightJoycon.InvertStickX ? -rightJoystickDx : rightJoystickDx, Dy = controllerConfig.RightJoycon.InvertStickY ? -rightJoystickDy : rightJoystickDy }; } currentButton |= _device.Hid.UpdateStickButtons(leftJoystick, rightJoystick); gamepadInputs.Add(new GamepadInput { PlayerId = (HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex, Buttons = currentButton, LStick = leftJoystick, RStick = rightJoystick }); } _device.Hid.Npads.SetGamepadsInput(gamepadInputs.ToArray()); // Hotkeys HotkeyButtons currentHotkeyButtons = KeyboardController.GetHotkeyButtons(OpenTK.Input.Keyboard.GetState()); if (currentHotkeyButtons.HasFlag(HotkeyButtons.ToggleVSync) && !_prevHotkeyButtons.HasFlag(HotkeyButtons.ToggleVSync)) { _device.EnableDeviceVsync = !_device.EnableDeviceVsync; } _prevHotkeyButtons = currentHotkeyButtons; //Touchscreen bool hasTouch = false; // Get screen touch position from left mouse click // OpenTK always captures mouse events, even if out of focus, so check if window is focused. if (IsFocused && _mousePressed) { int screenWidth = AllocatedWidth; int screenHeight = AllocatedHeight; if (AllocatedWidth > (AllocatedHeight * SwitchPanelWidth) / SwitchPanelHeight) { screenWidth = (AllocatedHeight * SwitchPanelWidth) / SwitchPanelHeight; } else { screenHeight = (AllocatedWidth * SwitchPanelHeight) / SwitchPanelWidth; } int startX = (AllocatedWidth - screenWidth) >> 1; int startY = (AllocatedHeight - screenHeight) >> 1; int endX = startX + screenWidth; int endY = startY + screenHeight; if (_mouseX >= startX && _mouseY >= startY && _mouseX < endX && _mouseY < endY) { int screenMouseX = (int)_mouseX - startX; int screenMouseY = (int)_mouseY - startY; int mX = (screenMouseX * SwitchPanelWidth) / screenWidth; int mY = (screenMouseY * SwitchPanelHeight) / screenHeight; TouchPoint currentPoint = new TouchPoint { X = (uint)mX, Y = (uint)mY, // Placeholder values till more data is acquired DiameterX = 10, DiameterY = 10, Angle = 90 }; hasTouch = true; _device.Hid.Touchscreen.Update(currentPoint); } } if (!hasTouch) { _device.Hid.Touchscreen.Update(); } _device.Hid.DebugPad.Update(); return(true); }
private bool UpdateFrame() { if (!_isActive) { return(true); } if (_isStopped) { return(false); } if (_isFocused) { Gtk.Application.Invoke(delegate { KeyboardState keyboard = OpenTK.Input.Keyboard.GetState(); HandleScreenState(keyboard); if (keyboard.IsKeyDown(OpenTK.Input.Key.Delete)) { if (!ParentWindow.State.HasFlag(Gdk.WindowState.Fullscreen)) { Ptc.Continue(); } } }); } List <GamepadInput> gamepadInputs = new List <GamepadInput>(NpadDevices.MaxControllers); List <SixAxisInput> motionInputs = new List <SixAxisInput>(NpadDevices.MaxControllers); MotionDevice motionDevice = new MotionDevice(_dsuClient); foreach (InputConfig inputConfig in ConfigurationState.Instance.Hid.InputConfig.Value) { ControllerKeys currentButton = 0; JoystickPosition leftJoystick = new JoystickPosition(); JoystickPosition rightJoystick = new JoystickPosition(); KeyboardInput? hidKeyboard = null; int leftJoystickDx = 0; int leftJoystickDy = 0; int rightJoystickDx = 0; int rightJoystickDy = 0; if (inputConfig.EnableMotion) { motionDevice.RegisterController(inputConfig.PlayerIndex); } if (inputConfig is KeyboardConfig keyboardConfig) { if (_isFocused) { // Keyboard Input KeyboardController keyboardController = new KeyboardController(keyboardConfig); currentButton = keyboardController.GetButtons(); (leftJoystickDx, leftJoystickDy) = keyboardController.GetLeftStick(); (rightJoystickDx, rightJoystickDy) = keyboardController.GetRightStick(); leftJoystick = new JoystickPosition { Dx = leftJoystickDx, Dy = leftJoystickDy }; rightJoystick = new JoystickPosition { Dx = rightJoystickDx, Dy = rightJoystickDy }; if (ConfigurationState.Instance.Hid.EnableKeyboard) { hidKeyboard = keyboardController.GetKeysDown(); } if (!hidKeyboard.HasValue) { hidKeyboard = new KeyboardInput { Modifier = 0, Keys = new int[0x8] }; } if (ConfigurationState.Instance.Hid.EnableKeyboard) { _device.Hid.Keyboard.Update(hidKeyboard.Value); } } } else if (inputConfig is Common.Configuration.Hid.ControllerConfig controllerConfig) { // Controller Input JoystickController joystickController = new JoystickController(controllerConfig); currentButton |= joystickController.GetButtons(); (leftJoystickDx, leftJoystickDy) = joystickController.GetLeftStick(); (rightJoystickDx, rightJoystickDy) = joystickController.GetRightStick(); leftJoystick = new JoystickPosition { Dx = controllerConfig.LeftJoycon.InvertStickX ? -leftJoystickDx : leftJoystickDx, Dy = controllerConfig.LeftJoycon.InvertStickY ? -leftJoystickDy : leftJoystickDy }; rightJoystick = new JoystickPosition { Dx = controllerConfig.RightJoycon.InvertStickX ? -rightJoystickDx : rightJoystickDx, Dy = controllerConfig.RightJoycon.InvertStickY ? -rightJoystickDy : rightJoystickDy }; } currentButton |= _device.Hid.UpdateStickButtons(leftJoystick, rightJoystick); motionDevice.Poll(inputConfig, inputConfig.Slot); SixAxisInput sixAxisInput = new SixAxisInput() { PlayerId = (HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex, Accelerometer = motionDevice.Accelerometer, Gyroscope = motionDevice.Gyroscope, Rotation = motionDevice.Rotation, Orientation = motionDevice.Orientation }; motionInputs.Add(sixAxisInput); gamepadInputs.Add(new GamepadInput { PlayerId = (HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex, Buttons = currentButton, LStick = leftJoystick, RStick = rightJoystick }); if (inputConfig.ControllerType == Common.Configuration.Hid.ControllerType.JoyconPair) { if (!inputConfig.MirrorInput) { motionDevice.Poll(inputConfig, inputConfig.AltSlot); sixAxisInput = new SixAxisInput() { PlayerId = (HLE.HOS.Services.Hid.PlayerIndex)inputConfig.PlayerIndex, Accelerometer = motionDevice.Accelerometer, Gyroscope = motionDevice.Gyroscope, Rotation = motionDevice.Rotation, Orientation = motionDevice.Orientation }; } motionInputs.Add(sixAxisInput); } } _device.Hid.Npads.Update(gamepadInputs); _device.Hid.Npads.UpdateSixAxis(motionInputs); _device.TamperMachine.UpdateInput(gamepadInputs); if (_isFocused) { // Hotkeys HotkeyButtons currentHotkeyButtons = KeyboardController.GetHotkeyButtons(OpenTK.Input.Keyboard.GetState()); if (currentHotkeyButtons.HasFlag(HotkeyButtons.ToggleVSync) && !_prevHotkeyButtons.HasFlag(HotkeyButtons.ToggleVSync)) { _device.EnableDeviceVsync = !_device.EnableDeviceVsync; Logger.Info?.Print(LogClass.Application, $"Vsync toggled to: {_device.EnableDeviceVsync}"); } _prevHotkeyButtons = currentHotkeyButtons; } //Touchscreen bool hasTouch = false; // Get screen touch position from left mouse click // OpenTK always captures mouse events, even if out of focus, so check if window is focused. if (_isFocused && _mousePressed) { float aspectWidth = SwitchPanelHeight * ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat(); int screenWidth = AllocatedWidth; int screenHeight = AllocatedHeight; if (AllocatedWidth > AllocatedHeight * aspectWidth / SwitchPanelHeight) { screenWidth = (int)(AllocatedHeight * aspectWidth) / SwitchPanelHeight; } else { screenHeight = (AllocatedWidth * SwitchPanelHeight) / (int)aspectWidth; } int startX = (AllocatedWidth - screenWidth) >> 1; int startY = (AllocatedHeight - screenHeight) >> 1; int endX = startX + screenWidth; int endY = startY + screenHeight; if (_mouseX >= startX && _mouseY >= startY && _mouseX < endX && _mouseY < endY) { int screenMouseX = (int)_mouseX - startX; int screenMouseY = (int)_mouseY - startY; int mX = (screenMouseX * (int)aspectWidth) / screenWidth; int mY = (screenMouseY * SwitchPanelHeight) / screenHeight; TouchPoint currentPoint = new TouchPoint { X = (uint)mX, Y = (uint)mY, // Placeholder values till more data is acquired DiameterX = 10, DiameterY = 10, Angle = 90 }; hasTouch = true; _device.Hid.Touchscreen.Update(currentPoint); } } if (!hasTouch) { _device.Hid.Touchscreen.Update(); } _device.Hid.DebugPad.Update(); return(true); }
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); } }