Remove return value from axis functions in API

This commit is contained in:
Henrik Rydgård 2022-12-31 21:44:52 +01:00
parent a3a949f5e6
commit 07114c6aaf
18 changed files with 52 additions and 72 deletions

@ -65,7 +65,7 @@ void NativeUpdate();
// time is not yet implemented. finger can be from 0 to 7, inclusive.
void NativeTouch(const TouchInput &touch);
bool NativeKey(const KeyInput &key);
bool NativeAxis(const AxisInput &axis);
void NativeAxis(const AxisInput &axis);
// Called when it's time to render. If the device can keep up, this
// will also be called sixty times per second. Main thread.

@ -92,7 +92,7 @@ void ScreenManager::touch(const TouchInput &touch) {
bool ScreenManager::key(const KeyInput &key) {
std::lock_guard<std::recursive_mutex> guard(inputLock_);
bool result = false;
// Send key up to every screen layer.
// Send key up to every screen layer, to avoid stuck keys.
if (key.flags & KEY_UP) {
for (auto &layer : stack_) {
result = layer.screen->key(key);
@ -103,7 +103,7 @@ bool ScreenManager::key(const KeyInput &key) {
return result;
}
bool ScreenManager::axis(const AxisInput &axis) {
void ScreenManager::axis(const AxisInput &axis) {
std::lock_guard<std::recursive_mutex> guard(inputLock_);
// Ignore duplicate values to prevent axis values overwriting each other.
@ -112,20 +112,18 @@ bool ScreenManager::axis(const AxisInput &axis) {
// PSP games can't see higher resolution than this.
int value = 128 + ceilf(axis.value * 127.5f + 127.5f);
if (lastAxis_[key] == value) {
return false;
return;
}
lastAxis_[key] = value;
bool result = false;
// Send center axis to every screen layer.
if (axis.value == 0) {
for (auto &layer : stack_) {
result = layer.screen->axis(axis);
layer.screen->axis(axis);
}
} else if (!stack_.empty()) {
result = stack_.back().screen->axis(axis);
stack_.back().screen->axis(axis);
}
return result;
}
void ScreenManager::deviceLost() {

@ -57,7 +57,7 @@ public:
virtual void dialogFinished(const Screen *dialog, DialogResult result) {}
virtual void touch(const TouchInput &touch) {}
virtual bool key(const KeyInput &key) { return false; }
virtual bool axis(const AxisInput &touch) { return false; }
virtual void axis(const AxisInput &touch) {}
virtual void sendMessage(const char *msg, const char *value) {}
virtual void deviceLost() {}
virtual void deviceRestored() {}
@ -134,7 +134,7 @@ public:
// Instant touch, separate from the update() mechanism.
void touch(const TouchInput &touch);
bool key(const KeyInput &key);
bool axis(const AxisInput &touch);
void axis(const AxisInput &touch);
// Generic facility for gross hacks :P
void sendMessage(const char *msg, const char *value);

@ -199,12 +199,10 @@ void UIDialogScreen::sendMessage(const char *msg, const char *value) {
}
}
bool UIScreen::axis(const AxisInput &axis) {
void UIScreen::axis(const AxisInput &axis) {
if (root_) {
UI::AxisEvent(axis, root_);
return true;
}
return false;
}
UI::EventReturn UIScreen::OnBack(UI::EventParams &e) {

@ -27,7 +27,7 @@ public:
void touch(const TouchInput &touch) override;
bool key(const KeyInput &touch) override;
bool axis(const AxisInput &touch) override;
void axis(const AxisInput &touch) override;
TouchInput transformTouch(const TouchInput &touch) override;

@ -46,7 +46,7 @@ static bool vrFlatGame = false;
static float vrMatrix[VR_MATRIX_COUNT][16];
static bool vrMirroring[VR_MIRRORING_COUNT];
static bool (*NativeAxis)(const AxisInput &axis);
static void (*NativeAxis)(const AxisInput &axis);
static bool (*NativeKey)(const KeyInput &key);
static void (*NativeTouch)(const TouchInput &touch);
@ -189,7 +189,7 @@ void GetVRResolutionPerEye(int* width, int* height) {
}
}
void SetVRCallbacks(bool(*axis)(const AxisInput &axis), bool(*key)(const KeyInput &key), void (*touch)(const TouchInput &touch)) {
void SetVRCallbacks(void (*axis)(const AxisInput &axis), bool(*key)(const KeyInput &key), void (*touch)(const TouchInput &touch)) {
NativeAxis = axis;
NativeKey = key;
NativeTouch = touch;

@ -29,7 +29,7 @@ bool IsVREnabled();
void InitVROnAndroid(void* vm, void* activity, const char* system, int version, const char* name);
void EnterVR(bool firstStart, void* vulkanContext);
void GetVRResolutionPerEye(int* width, int* height);
void SetVRCallbacks(bool(*axis)(const AxisInput &axis), bool(*key)(const KeyInput &key), void(*touch)(const TouchInput &touch));
void SetVRCallbacks(void(*axis)(const AxisInput &axis), bool(*key)(const KeyInput &key), void(*touch)(const TouchInput &touch));
// VR input integration
void SetVRAppMode(VRAppMode mode);

@ -117,20 +117,16 @@ bool ControlMapper::Key(const KeyInput &key, bool *pauseTrigger) {
return pspKeys.size() > 0;
}
bool ControlMapper::Axis(const AxisInput &axis) {
void ControlMapper::Axis(const AxisInput &axis) {
if (axis.value > 0) {
processAxis(axis, 1);
return true;
} else if (axis.value < 0) {
processAxis(axis, -1);
return true;
} else if (axis.value == 0) {
// Both directions! Prevents sticking for digital input devices that are axises (like HAT)
processAxis(axis, 1);
processAxis(axis, -1);
return true;
}
return false;
}
void ControlMapper::Update() {

@ -17,7 +17,7 @@ public:
bool Key(const KeyInput &key, bool *pauseTrigger);
void pspKey(int deviceId, int pspKeyCode, int flags);
bool Axis(const AxisInput &axis);
void Axis(const AxisInput &axis);
// Required callbacks
void SetCallbacks(

@ -407,11 +407,11 @@ static bool IgnoreAxisForMapping(int axis) {
}
bool KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
void KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
if (mapped_ || time_now_d() < delayUntil_)
return false;
return;
if (IgnoreAxisForMapping(axis.axisId))
return false;
return;
if (axis.value > AXIS_BIND_THRESHOLD) {
mapped_ = true;
@ -428,14 +428,13 @@ bool KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
if (callback_)
callback_(kdf);
}
return true;
}
bool KeyMappingNewMouseKeyDialog::axis(const AxisInput &axis) {
void KeyMappingNewMouseKeyDialog::axis(const AxisInput &axis) {
if (mapped_)
return false;
return;
if (IgnoreAxisForMapping(axis.axisId))
return false;
return;
if (axis.value > AXIS_BIND_THRESHOLD) {
mapped_ = true;
@ -452,7 +451,6 @@ bool KeyMappingNewMouseKeyDialog::axis(const AxisInput &axis) {
if (callback_)
callback_(kdf);
}
return true;
}
enum class StickHistoryViewType {
@ -619,12 +617,12 @@ bool AnalogSetupScreen::key(const KeyInput &key) {
return retval;
}
bool AnalogSetupScreen::axis(const AxisInput &axis) {
void AnalogSetupScreen::axis(const AxisInput &axis) {
// We DON'T call UIScreen::Axis here! Otherwise it'll try to move the UI focus around.
// UIScreen::axis(axis);
// Instead we just send the input directly to the mapper, that we'll visualize.
return mapper_.Axis(axis);
mapper_.Axis(axis);
}
void AnalogSetupScreen::CreateViews() {
@ -778,13 +776,12 @@ bool TouchTestScreen::key(const KeyInput &key) {
return true;
}
bool TouchTestScreen::axis(const AxisInput &axis) {
void TouchTestScreen::axis(const AxisInput &axis) {
// This is mainly to catch axis events that would otherwise get translated
// into arrow keys, since seeing keyboard arrow key events appear when using
// a controller would be confusing for the user.
if (IgnoreAxisForMapping(axis.axisId))
return false;
return;
const float AXIS_LOG_THRESHOLD = AXIS_BIND_THRESHOLD * 0.5f;
if (axis.value > AXIS_LOG_THRESHOLD || axis.value < -AXIS_LOG_THRESHOLD) {
@ -797,7 +794,6 @@ bool TouchTestScreen::axis(const AxisInput &axis) {
lastKeyEvent_->SetText(buf);
}
}
return true;
}
void TouchTestScreen::render() {

@ -62,7 +62,7 @@ public:
const char *tag() const override { return "KeyMappingNewKey"; }
bool key(const KeyInput &key) override;
bool axis(const AxisInput &axis) override;
void axis(const AxisInput &axis) override;
void SetDelay(float t);
@ -88,7 +88,7 @@ public:
const char *tag() const override { return "KeyMappingNewMouseKey"; }
bool key(const KeyInput &key) override;
bool axis(const AxisInput &axis) override;
void axis(const AxisInput &axis) override;
protected:
void CreatePopupContents(UI::ViewGroup *parent) override;
@ -110,7 +110,7 @@ public:
AnalogSetupScreen(const Path &gamePath);
bool key(const KeyInput &key) override;
bool axis(const AxisInput &axis) override;
void axis(const AxisInput &axis) override;
void update() override;
@ -144,7 +144,7 @@ public:
void render() override;
bool key(const KeyInput &key) override;
bool axis(const AxisInput &axis) override;
void axis(const AxisInput &axis) override;
const char *tag() const override { return "TouchTest"; }

@ -788,7 +788,7 @@ bool EmuScreen::key(const KeyInput &key) {
return controlMapper_.Key(key, &pauseTrigger_);
}
bool EmuScreen::axis(const AxisInput &axis) {
void EmuScreen::axis(const AxisInput &axis) {
Core_NotifyActivity();
return controlMapper_.Axis(axis);

@ -52,7 +52,7 @@ public:
void touch(const TouchInput &touch) override;
bool key(const KeyInput &key) override;
bool axis(const AxisInput &axis) override;
void axis(const AxisInput &axis) override;
private:
void CreateViews() override;

@ -1353,15 +1353,15 @@ bool NativeKey(const KeyInput &key) {
return retval;
}
bool NativeAxis(const AxisInput &axis) {
void NativeAxis(const AxisInput &axis) {
// VR actions
if (IsVREnabled() && !UpdateVRAxis(axis)) {
return false;
return;
}
if (!screenManager) {
// Too early.
return false;
return;
}
using namespace TiltEventProcessor;
@ -1369,11 +1369,8 @@ bool 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.
if (screenManager) {
return screenManager->axis(axis);
} else {
return false;
}
screenManager->axis(axis);
return;
}
// create the base coordinate tilt system from the calibration data.
@ -1404,7 +1401,7 @@ bool NativeAxis(const AxisInput &axis) {
if (fabs(axis.value) < 0.8f && g_Config.iTiltOrientation == 2) // Auto tilt switch
verticalTilt = false;
else
return false; // Tilt on Z instead
return; // Tilt on Z instead
}
if (portrait) {
currentTilt.x_ = axis.value;
@ -1426,7 +1423,7 @@ bool NativeAxis(const AxisInput &axis) {
if (fabs(axis.value) < 0.8f && g_Config.iTiltOrientation == 2) // Auto tilt switch
verticalTilt = true;
else
return false; // Tilt on X instead
return; // Tilt on X instead
}
if (portrait) {
currentTilt.x_ = -axis.value;
@ -1442,13 +1439,12 @@ bool NativeAxis(const AxisInput &axis) {
//Don't know how to handle these. Someone should figure it out.
//Does the Ouya even have an accelerometer / gyro? I can't find any reference to these
//in the Ouya docs...
return false;
return;
default:
// Don't take over completely!
if (!screenManager)
return false;
return screenManager->axis(axis);
screenManager->axis(axis);
return;
}
//figure out the sensitivity of the tilt. (sensitivity is originally 0 - 100)
@ -1463,7 +1459,6 @@ bool NativeAxis(const AxisInput &axis) {
Tilt trueTilt = GenTilt(baseTilt, currentTilt, g_Config.bInvertTiltX, g_Config.bInvertTiltY, g_Config.fDeadzoneRadius, xSensitivity, ySensitivity);
TranslateTiltToInput(trueTilt);
return true;
}
void NativeMessageReceived(const char *message, const char *value) {

@ -58,7 +58,7 @@ void TiltAnalogSettingsScreen::CreateViews() {
settings->Add(new Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
}
bool TiltAnalogSettingsScreen::axis(const AxisInput &axis) {
void TiltAnalogSettingsScreen::axis(const AxisInput &axis) {
if (axis.deviceId == DEVICE_ID_ACCELEROMETER) {
// Historically, we've had X and Y swapped, likely due to portrait vs landscape.
// TODO: We may want to configure this based on screen orientation.
@ -69,7 +69,6 @@ bool TiltAnalogSettingsScreen::axis(const AxisInput &axis) {
currentTiltX_ = axis.value;
}
}
return false;
}
UI::EventReturn TiltAnalogSettingsScreen::OnCalibrate(UI::EventParams &e) {

@ -25,7 +25,7 @@ public:
TiltAnalogSettingsScreen() {}
void CreateViews() override;
bool axis(const AxisInput &axis) override;
void axis(const AxisInput &axis) override;
const char *tag() const override { return "TiltAnalogSettings"; }

@ -1147,17 +1147,17 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_keyUp(JNIEnv *, jclass, jin
return NativeKey(keyInput);
}
extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_joystickAxis(
extern "C" void Java_org_ppsspp_ppsspp_NativeApp_joystickAxis(
JNIEnv *env, jclass, jint deviceId, jint axisId, jfloat value) {
if (!renderer_inited)
return false;
return;
AxisInput axis;
axis.axisId = axisId;
axis.deviceId = deviceId;
axis.value = value;
return NativeAxis(axis);
NativeAxis(axis);
}
extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_mouseWheelEvent(
@ -1169,9 +1169,9 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_mouseWheelEvent(
return true;
}
extern "C" jboolean JNICALL Java_org_ppsspp_ppsspp_NativeApp_accelerometer(JNIEnv *, jclass, float x, float y, float z) {
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_accelerometer(JNIEnv *, jclass, float x, float y, float z) {
if (!renderer_inited)
return false;
return;
AxisInput axis;
axis.deviceId = DEVICE_ID_ACCELEROMETER;
@ -1179,17 +1179,15 @@ extern "C" jboolean JNICALL Java_org_ppsspp_ppsspp_NativeApp_accelerometer(JNIEn
axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_X;
axis.value = x;
bool retvalX = NativeAxis(axis);
NativeAxis(axis);
axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Y;
axis.value = y;
bool retvalY = NativeAxis(axis);
NativeAxis(axis);
axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Z;
axis.value = z;
bool retvalZ = NativeAxis(axis);
return retvalX || retvalY || retvalZ;
NativeAxis(axis);
}
extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendMessage(JNIEnv *env, jclass, jstring message, jstring param) {

@ -48,7 +48,7 @@ public class NativeApp {
// Sensor/input data. These are asynchronous, beware!
public static native void touch(float x, float y, int data, int pointerId);
public static native boolean accelerometer(float x, float y, float z);
public static native void accelerometer(float x, float y, float z);
public static native void sendMessage(String msg, String arg);
public static native void sendInputBox(String seqID, boolean result, String value);