Skip to content

Commit

Permalink
Pass in accelerometer readings using NativeAccelerometer instead of N…
Browse files Browse the repository at this point in the history
…ativeAxis
  • Loading branch information
hrydgard committed Sep 27, 2023
1 parent 3b004e7 commit c28dc9e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Common/Input/InputState.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum InputDeviceID {
DEVICE_ID_XINPUT_1 = 21,
DEVICE_ID_XINPUT_2 = 22,
DEVICE_ID_XINPUT_3 = 23,
DEVICE_ID_ACCELEROMETER = 30,
DEVICE_ID_ACCELEROMETER = 30, // no longer used
DEVICE_ID_XR_HMD = 39,
DEVICE_ID_XR_CONTROLLER_LEFT = 40,
DEVICE_ID_XR_CONTROLLER_RIGHT = 41,
Expand Down
2 changes: 1 addition & 1 deletion Common/Input/KeyCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ enum InputAxis {
JOYSTICK_AXIS_MOUSE_REL_X = 26,
JOYSTICK_AXIS_MOUSE_REL_Y = 27,

// Mobile device accelerometer/gyro
// Mobile device accelerometer/gyro. NOTE: These are no longer passed around internally, only used for the plugin API.
JOYSTICK_AXIS_ACCELEROMETER_X = 40,
JOYSTICK_AXIS_ACCELEROMETER_Y = 41,
JOYSTICK_AXIS_ACCELEROMETER_Z = 42,
Expand Down
1 change: 1 addition & 0 deletions Common/System/NativeApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ bool NativeIsRestarting();
void NativeTouch(const TouchInput &touch);
bool NativeKey(const KeyInput &key);
void NativeAxis(const AxisInput *axis, size_t count);
void NativeAccelerometer(float tiltX, float tiltY, float tiltZ);

// Called when it's process a frame, including rendering. If the device can keep up, this
// will be called sixty times per second. Main thread.
Expand Down
13 changes: 1 addition & 12 deletions Qt/QtMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,18 +731,7 @@ void MainUI::updateAccelerometer() {
// TODO: Toggle it depending on whether it is enabled
QAccelerometerReading *reading = acc->reading();
if (reading) {
AxisInput axis[3];
for (int i = 0; i < 3; i++) {
axis[i].deviceId = DEVICE_ID_ACCELEROMETER;
}

axis[0].axisId = JOYSTICK_AXIS_ACCELEROMETER_X;
axis[0].value = reading->x();
axis[1].axisId = JOYSTICK_AXIS_ACCELEROMETER_Y;
axis[1].value = reading->y();
axis[2].axisId = JOYSTICK_AXIS_ACCELEROMETER_Z;
axis[2].value = reading->z();
NativeAxis(axis, 3);
NativeAccelerometer(reading->x(), reading->y(), reading->z());
}
#endif
}
Expand Down
18 changes: 6 additions & 12 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,22 +1336,12 @@ static void ProcessOneAxisEvent(const AxisInput &axis) {
}

void NativeAxis(const AxisInput *axes, size_t count) {
// figure out what the current tilt orientation is by checking the axis event
// This is static, since we need to remember where we last were (in terms of orientation)
static float tiltX;
static float tiltY;
static float tiltZ;

for (size_t i = 0; i < count; i++) {
ProcessOneAxisEvent(axes[i]);
switch (axes[i].axisId) {
case JOYSTICK_AXIS_ACCELEROMETER_X: tiltX = axes[i].value; break;
case JOYSTICK_AXIS_ACCELEROMETER_Y: tiltY = axes[i].value; break;
case JOYSTICK_AXIS_ACCELEROMETER_Z: tiltZ = axes[i].value; break;
default: break;
}
}
}

void NativeAccelerometer(float tiltX, float tiltY, float tiltZ) {
if (g_Config.iTiltInputType == TILT_NULL) {
// if tilt events are disabled, don't do anything special.
return;
Expand All @@ -1377,6 +1367,10 @@ void NativeAxis(const AxisInput *axes, size_t count) {
TiltEventProcessor::ProcessTilt(landscape, tiltBaseAngleY, tiltX, tiltY, tiltZ,
g_Config.bInvertTiltX, g_Config.bInvertTiltY,
xSensitivity, ySensitivity);

HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_ACCELEROMETER_X] = tiltX;
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_ACCELEROMETER_Y] = tiltY;
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_ACCELEROMETER_Z] = tiltZ;
}

void System_PostUIMessage(const std::string &message, const std::string &value) {
Expand Down
13 changes: 1 addition & 12 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1240,18 +1240,7 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_mouseWheelEvent(
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_accelerometer(JNIEnv *, jclass, float x, float y, float z) {
if (!renderer_inited)
return;

AxisInput axis[3];
for (int i = 0; i < 3; i++) {
axis[i].deviceId = DEVICE_ID_ACCELEROMETER;
}
axis[0].axisId = JOYSTICK_AXIS_ACCELEROMETER_X;
axis[0].value = x;
axis[1].axisId = JOYSTICK_AXIS_ACCELEROMETER_Y;
axis[1].value = y;
axis[2].axisId = JOYSTICK_AXIS_ACCELEROMETER_Z;
axis[2].value = z;
NativeAxis(axis, 3);
NativeAccelerometer(x, y, z);
}

extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendMessageFromJava(JNIEnv *env, jclass, jstring message, jstring param) {
Expand Down

0 comments on commit c28dc9e

Please sign in to comment.