Skip to content

Commit

Permalink
Merge pull request #16501 from ThirteenAG/master
Browse files Browse the repository at this point in the history
Input (inc. mouse and keyboard) api for plugins
  • Loading branch information
hrydgard committed Feb 1, 2023
2 parents 2ed88a8 + bf2cabb commit 6c86537
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Common/Input/KeyCodes.h
Expand Up @@ -275,6 +275,8 @@ typedef enum _keycode_t {
NKCODE_EXT_ROTATION_DOWN = 1112,
NKCODE_EXT_ROTATION_LEFT = 1113,
NKCODE_EXT_ROTATION_RIGHT = 1114,

NKCODE_MAX
} keycode_t;

enum AndroidJoystickAxis {
Expand Down Expand Up @@ -330,5 +332,6 @@ enum AndroidJoystickAxis {
JOYSTICK_AXIS_ACCELEROMETER_Y = 41,
JOYSTICK_AXIS_ACCELEROMETER_Z = 42,

// The numbers must NOT be changed, only additions are allowed
JOYSTICK_AXIS_MAX = 44
};
2 changes: 2 additions & 0 deletions Core/HLE/Plugins.cpp
Expand Up @@ -29,6 +29,8 @@
#include "Core/HLE/sceKernelModule.h"

namespace HLEPlugins {
float PluginDataAxis[JOYSTICK_AXIS_MAX];
std::map<int, uint8_t> PluginDataKeys;

static bool anyEnabled = false;
static std::vector<std::string> prxPlugins;
Expand Down
4 changes: 4 additions & 0 deletions Core/HLE/Plugins.h
Expand Up @@ -17,6 +17,8 @@

#pragma once

#include "Input/KeyCodes.h"

class PointerWrap;

namespace HLEPlugins {
Expand All @@ -31,4 +33,6 @@ void DoState(PointerWrap &p);

bool HasEnabled();

extern float PluginDataAxis[JOYSTICK_AXIS_MAX];
extern std::map<int, uint8_t> PluginDataKeys;
};
21 changes: 14 additions & 7 deletions Core/HLE/sceIo.cpp
Expand Up @@ -71,7 +71,10 @@ extern "C" {
// For headless screenshots.
#include "Core/HLE/sceDisplay.h"
// For EMULATOR_DEVCTL__GET_SCALE
#include <System/Display.h>
#include "System/Display.h"
// For EMULATOR_DEVCTL__GET_AXIS/VKEY
#include "Core/HLE/Plugins.h"
#include "Input/KeyCodes.h"

static const int ERROR_ERRNO_IO_ERROR = 0x80010005;
static const int ERROR_MEMSTICK_DEVCTL_BAD_PARAMS = 0x80220081;
Expand Down Expand Up @@ -1997,8 +2000,8 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
EMULATOR_DEVCTL__TOGGLE_FASTFORWARD = 0x30,
EMULATOR_DEVCTL__GET_ASPECT_RATIO,
EMULATOR_DEVCTL__GET_SCALE,
EMULATOR_DEVCTL__GET_LTRIGGER,
EMULATOR_DEVCTL__GET_RTRIGGER
EMULATOR_DEVCTL__GET_AXIS,
EMULATOR_DEVCTL__GET_VKEY,
};

switch (cmd) {
Expand Down Expand Up @@ -2067,11 +2070,15 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
Memory::Write_Float(scale, outPtr);
}
return 0;
case EMULATOR_DEVCTL__GET_LTRIGGER:
//To-do
case EMULATOR_DEVCTL__GET_AXIS:
if (Memory::IsValidAddress(outPtr) && (argAddr >= 0 && argAddr < JOYSTICK_AXIS_MAX)) {
Memory::Write_Float(HLEPlugins::PluginDataAxis[argAddr], outPtr);
}
return 0;
case EMULATOR_DEVCTL__GET_RTRIGGER:
//To-do
case EMULATOR_DEVCTL__GET_VKEY:
if (Memory::IsValidAddress(outPtr) && (argAddr >= 0 && argAddr < NKCODE_MAX)) {
Memory::Write_U8(HLEPlugins::PluginDataKeys[argAddr], outPtr);
}
return 0;
}

Expand Down
7 changes: 7 additions & 0 deletions UI/NativeApp.cpp
Expand Up @@ -145,6 +145,8 @@
#include "UI/DarwinMemoryStickManager.h"
#endif

#include <Core/HLE/Plugins.h>

ScreenManager *screenManager;
std::string config_filename;

Expand Down Expand Up @@ -1341,7 +1343,10 @@ bool NativeKey(const KeyInput &key) {
#endif
bool retval = false;
if (screenManager)
{
HLEPlugins::PluginDataKeys[key.keyCode] = (key.flags & KEY_DOWN) ? 1 : 0;
retval = screenManager->key(key);
}
return retval;
}

Expand All @@ -1361,6 +1366,7 @@ void NativeAxis(const AxisInput &axis) {
// only handle tilt events if tilt is enabled.
if (g_Config.iTiltInputType == TILT_NULL) {
// if tilt events are disabled, then run it through the usual way.
HLEPlugins::PluginDataAxis[axis.axisId] = axis.value;
screenManager->axis(axis);
return;
}
Expand Down Expand Up @@ -1434,6 +1440,7 @@ void NativeAxis(const AxisInput &axis) {
return;

default:
HLEPlugins::PluginDataAxis[axis.axisId] = axis.value;
// Don't take over completely!
screenManager->axis(axis);
return;
Expand Down
4 changes: 4 additions & 0 deletions Windows/RawInput.cpp
Expand Up @@ -29,6 +29,7 @@
#include "Common/CommonFuncs.h"
#include "Common/SysError.h"
#include "Core/Config.h"
#include "Core/HLE/Plugins.h"

#ifndef HID_USAGE_PAGE_GENERIC
#define HID_USAGE_PAGE_GENERIC ((USHORT) 0x01)
Expand Down Expand Up @@ -320,6 +321,9 @@ namespace WindowsRawInput {
g_mouseDeltaX += raw->data.mouse.lLastX;
g_mouseDeltaY += raw->data.mouse.lLastY;

HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_MOUSE_REL_X] = g_mouseDeltaX;
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_MOUSE_REL_Y] = g_mouseDeltaY;

const int rawInputDownID[5] = {
RI_MOUSE_LEFT_BUTTON_DOWN,
RI_MOUSE_RIGHT_BUTTON_DOWN,
Expand Down
4 changes: 4 additions & 0 deletions Windows/WindowsHost.cpp
Expand Up @@ -71,6 +71,7 @@

#include "Windows/main.h"
#include "UI/OnScreenDisplay.h"
#include <Core/HLE/Plugins.h>

float g_mouseDeltaX = 0;
float g_mouseDeltaY = 0;
Expand Down Expand Up @@ -258,6 +259,9 @@ void WindowsHost::PollControllers() {

g_mouseDeltaX *= g_Config.fMouseSmoothing;
g_mouseDeltaY *= g_Config.fMouseSmoothing;

HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_MOUSE_REL_X] = g_mouseDeltaX;
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_MOUSE_REL_Y] = g_mouseDeltaY;
}

void WindowsHost::BootDone() {
Expand Down

0 comments on commit 6c86537

Please sign in to comment.