diff --git a/android/app-android.cpp b/android/app-android.cpp index 10e18c9d17..3c4b080794 100644 --- a/android/app-android.cpp +++ b/android/app-android.cpp @@ -382,7 +382,7 @@ extern "C" jint Java_com_henrikrydgard_libnative_NativeApp_audioRender(JNIEnv* e return 0; } -extern "C" void JNICALL Java_com_henrikrydgard_libnative_NativeApp_touch +extern "C" jboolean JNICALL Java_com_henrikrydgard_libnative_NativeApp_touch (JNIEnv *, jclass, float x, float y, int code, int pointerId) { float scaledX = x * dp_xscale; float scaledY = y * dp_yscale; @@ -398,33 +398,34 @@ extern "C" void JNICALL Java_com_henrikrydgard_libnative_NativeApp_touch input_state.pointer_down[pointerId] = false; } - NativeTouch(touch); + bool retval = NativeTouch(touch); { lock_guard guard(input_state.lock); if (pointerId >= MAX_POINTERS) { ELOG("Too many pointers: %i", pointerId); - return; // We ignore 8+ pointers entirely. + return false; // We ignore 8+ pointers entirely. } input_state.pointer_x[pointerId] = scaledX; input_state.pointer_y[pointerId] = scaledY; input_state.mouse_valid = true; } + return retval; } -extern "C" void Java_com_henrikrydgard_libnative_NativeApp_keyDown(JNIEnv *, jclass, jint deviceId, jint key) { +extern "C" jboolean Java_com_henrikrydgard_libnative_NativeApp_keyDown(JNIEnv *, jclass, jint deviceId, jint key) { KeyInput keyInput; keyInput.deviceId = deviceId; keyInput.keyCode = key; keyInput.flags = KEY_DOWN; - NativeKey(keyInput); + return NativeKey(keyInput); } -extern "C" void Java_com_henrikrydgard_libnative_NativeApp_keyUp(JNIEnv *, jclass, jint deviceId, jint key) { +extern "C" jboolean Java_com_henrikrydgard_libnative_NativeApp_keyUp(JNIEnv *, jclass, jint deviceId, jint key) { KeyInput keyInput; keyInput.deviceId = deviceId; keyInput.keyCode = key; keyInput.flags = KEY_UP; - NativeKey(keyInput); + return NativeKey(keyInput); } extern "C" void Java_com_henrikrydgard_libnative_NativeApp_beginJoystickEvent( @@ -432,10 +433,10 @@ extern "C" void Java_com_henrikrydgard_libnative_NativeApp_beginJoystickEvent( // mutex lock? } -extern "C" void Java_com_henrikrydgard_libnative_NativeApp_joystickAxis( +extern "C" jboolean Java_com_henrikrydgard_libnative_NativeApp_joystickAxis( JNIEnv *env, jclass, jint deviceId, jint axisId, jfloat value) { if (!renderer_inited) - return; + return false; switch (axisId) { case JOYSTICK_AXIS_X: left_joystick_x_async = value; @@ -461,7 +462,7 @@ extern "C" void Java_com_henrikrydgard_libnative_NativeApp_joystickAxis( axis.axisId = axisId; axis.deviceId = deviceId; axis.value = value; - NativeAxis(axis); + return NativeAxis(axis); } extern "C" void Java_com_henrikrydgard_libnative_NativeApp_endJoystickEvent( @@ -470,14 +471,15 @@ extern "C" void Java_com_henrikrydgard_libnative_NativeApp_endJoystickEvent( } -extern "C" void Java_com_henrikrydgard_libnative_NativeApp_mouseWheelEvent( +extern "C" jboolean Java_com_henrikrydgard_libnative_NativeApp_mouseWheelEvent( JNIEnv *env, jclass, jint stick, jfloat x, jfloat y) { - // TODO + // TODO: Support mousewheel for android + return true; } -extern "C" void JNICALL Java_com_henrikrydgard_libnative_NativeApp_accelerometer(JNIEnv *, jclass, float x, float y, float z) { +extern "C" jboolean JNICALL Java_com_henrikrydgard_libnative_NativeApp_accelerometer(JNIEnv *, jclass, float x, float y, float z) { if (!renderer_inited) - return; + return false; // Theoretically this needs locking but I doubt it matters. Worst case, the X // from one "sensor frame" will be used together with Y from the next. // Should look into quantization though, for compressed movement storage. @@ -492,15 +494,16 @@ extern "C" void JNICALL Java_com_henrikrydgard_libnative_NativeApp_accelerometer axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_X; axis.value = x; - NativeAxis(axis); + bool retval = NativeAxis(axis); axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Y; axis.value = y; - NativeAxis(axis); + retval = retval || NativeAxis(axis); axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Z; axis.value = z; - NativeAxis(axis); + retval = retval || NativeAxis(axis); + return retval; } extern "C" void Java_com_henrikrydgard_libnative_NativeApp_sendMessage(JNIEnv *env, jclass, jstring message, jstring param) { diff --git a/android/src/com/henrikrydgard/libnative/NativeApp.java b/android/src/com/henrikrydgard/libnative/NativeApp.java index 070d74ee3d..03eb8fa96f 100644 --- a/android/src/com/henrikrydgard/libnative/NativeApp.java +++ b/android/src/com/henrikrydgard/libnative/NativeApp.java @@ -22,22 +22,22 @@ public class NativeApp { // There's not really any reason to ever call shutdown as we can recover from a killed activity. public static native void shutdown(); - public static native void keyDown(int deviceId, int key); - public static native void keyUp(int deviceId, int key); + public static native boolean keyDown(int deviceId, int key); + public static native boolean keyUp(int deviceId, int key); public static native void beginJoystickEvent(); public static native void joystickAxis(int deviceId, int axis, float value); public static native void endJoystickEvent(); - public static native void mouseWheelEvent(float x, float y); + public static native boolean mouseWheelEvent(float x, float y); // will only be called between init() and shutdown() public static native int audioRender(short[] buffer); // Sensor/input data. These are asynchronous, beware! - public static native void touch(float x, float y, int data, int pointerId); + public static native boolean touch(float x, float y, int data, int pointerId); - public static native void accelerometer(float x, float y, float z); + public static native boolean accelerometer(float x, float y, float z); public static native void sendMessage(String msg, String arg); diff --git a/base/NativeApp.h b/base/NativeApp.h index 571364f42b..cf3815a0bf 100644 --- a/base/NativeApp.h +++ b/base/NativeApp.h @@ -57,9 +57,9 @@ void NativeUpdate(InputState &input); // Useful for triggering audio events, saving a few ms. // If you don't care about touch latency, just do a no-op implementation of this. // time is not yet implemented. finger can be from 0 to 7, inclusive. -void NativeTouch(const TouchInput &touch); -void NativeKey(const KeyInput &key); -void NativeAxis(const AxisInput &axis); +bool NativeTouch(const TouchInput &touch); +bool NativeKey(const KeyInput &key); +bool 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.