add timestamp for fallback inputs

This commit is contained in:
Chloe committed 2026-01-29 15:49:00 -07:00
1 parent e786599e73
commit 426a1a1ade
2 files changed
+24 -18

No files matched your search

@@ -23,6 +23,7 @@ import kotlin.math.abs
private const val HANDLER_OPEN_IME_KEYBOARD = 2 private const val HANDLER_OPEN_IME_KEYBOARD = 2
private const val HANDLER_CLOSE_IME_KEYBOARD = 3 private const val HANDLER_CLOSE_IME_KEYBOARD = 3
private const val MS_TO_NS = 1_000_000 private const val MS_TO_NS = 1_000_000
private const val SEC_TO_NS = 1_000_000_000.0
class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) { class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
companion object { companion object {
@@ -167,6 +168,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
val ys = FloatArray(pointerNumber) val ys = FloatArray(pointerNumber)
val timestamp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) val timestamp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
motionEvent.eventTimeNanos else motionEvent.eventTime * MS_TO_NS motionEvent.eventTimeNanos else motionEvent.eventTime * MS_TO_NS
val timestampSec = timestamp / SEC_TO_NS
for (i in 0 until pointerNumber) { for (i in 0 until pointerNumber) {
ids[i] = motionEvent.getPointerId(i) ids[i] = motionEvent.getPointerId(i)
@@ -188,7 +190,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
GeodeUtils.TOUCH_TYPE_BEGIN, ids.sliceArray(0..0), xs.sliceArray(0..0), ys.sliceArray(0..0) GeodeUtils.TOUCH_TYPE_BEGIN, ids.sliceArray(0..0), xs.sliceArray(0..0), ys.sliceArray(0..0)
) )
else else
cocos2dxRenderer.handleActionDown(idDown, xDown, f) cocos2dxRenderer.handleActionDown(idDown, xDown, f, timestampSec)
} }
true true
} }
@@ -205,7 +207,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
GeodeUtils.TOUCH_TYPE_END, ids.sliceArray(0..0), xs.sliceArray(0..0), ys.sliceArray(0..0) GeodeUtils.TOUCH_TYPE_END, ids.sliceArray(0..0), xs.sliceArray(0..0), ys.sliceArray(0..0)
) )
else else
cocos2dxRenderer.handleActionUp(idUp, f2, f3) cocos2dxRenderer.handleActionUp(idUp, f2, f3, timestampSec)
} }
true true
} }
@@ -219,7 +221,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
GeodeUtils.TOUCH_TYPE_MOVE, ids, xs, ys GeodeUtils.TOUCH_TYPE_MOVE, ids, xs, ys
) )
else else
cocos2dxRenderer.handleActionMove(ids, xs, ys) cocos2dxRenderer.handleActionMove(ids, xs, ys, timestampSec)
} }
true true
} }
@@ -233,7 +235,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
GeodeUtils.TOUCH_TYPE_CANCEL, ids, xs, ys GeodeUtils.TOUCH_TYPE_CANCEL, ids, xs, ys
) )
else else
cocos2dxRenderer.handleActionCancel(ids, xs, ys) cocos2dxRenderer.handleActionCancel(ids, xs, ys, timestampSec)
} }
true true
} }
@@ -251,7 +253,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
GeodeUtils.TOUCH_TYPE_BEGIN, intArrayOf(idPointerDown), floatArrayOf(xPointerDown), floatArrayOf(y) GeodeUtils.TOUCH_TYPE_BEGIN, intArrayOf(idPointerDown), floatArrayOf(xPointerDown), floatArrayOf(y)
) )
else else
cocos2dxRenderer.handleActionDown(idPointerDown, xPointerDown, y) cocos2dxRenderer.handleActionDown(idPointerDown, xPointerDown, y, timestampSec)
} }
true true
} }
@@ -269,7 +271,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
GeodeUtils.TOUCH_TYPE_END, intArrayOf(idPointerUp), floatArrayOf(xPointerUp), floatArrayOf(y2) GeodeUtils.TOUCH_TYPE_END, intArrayOf(idPointerUp), floatArrayOf(xPointerUp), floatArrayOf(y2)
) )
else else
cocos2dxRenderer.handleActionUp(idPointerUp, xPointerUp, y2) cocos2dxRenderer.handleActionUp(idPointerUp, xPointerUp, y2, timestampSec)
} }
true true
} }
@@ -40,21 +40,25 @@ class Cocos2dxRenderer(private var handler: Cocos2dxGLSurfaceView) : GLSurfaceVi
@JvmStatic @JvmStatic
private external fun nativeTextClosed() private external fun nativeTextClosed()
// timestamp was added in 2.208, but the jni method has no required type signature.
// it doesn't hurt to unconditionally send one
@JvmStatic @JvmStatic
private external fun nativeTouchesBegin(id: Int, x: Float, y: Float) private external fun nativeTouchesBegin(id: Int, x: Float, y: Float, timestamp: Double)
@JvmStatic @JvmStatic
private external fun nativeTouchesCancel( private external fun nativeTouchesCancel(
ids: IntArray, ids: IntArray,
xs: FloatArray, xs: FloatArray,
ys: FloatArray ys: FloatArray,
timestamp: Double,
) )
@JvmStatic @JvmStatic
private external fun nativeTouchesEnd(id: Int, x: Float, y: Float) private external fun nativeTouchesEnd(id: Int, x: Float, y: Float, timestamp: Double)
@JvmStatic @JvmStatic
private external fun nativeTouchesMove(ids: IntArray, xs: FloatArray, ys: FloatArray) private external fun nativeTouchesMove(ids: IntArray, xs: FloatArray, ys: FloatArray, timestamp: Double)
@JvmStatic @JvmStatic
private external fun nativeInit(width: Int, height: Int) private external fun nativeInit(width: Int, height: Int)
@@ -109,20 +113,20 @@ class Cocos2dxRenderer(private var handler: Cocos2dxGLSurfaceView) : GLSurfaceVi
} }
} }
fun handleActionDown(id: Int, x: Float, y: Float) { fun handleActionDown(id: Int, x: Float, y: Float, timestamp: Double) {
nativeTouchesBegin(id, x, y) nativeTouchesBegin(id, x, y, timestamp)
} }
fun handleActionUp(id: Int, x: Float, y: Float) { fun handleActionUp(id: Int, x: Float, y: Float, timestamp: Double) {
nativeTouchesEnd(id, x, y) nativeTouchesEnd(id, x, y, timestamp)
} }
fun handleActionCancel(ids: IntArray, xs: FloatArray, ys: FloatArray) { fun handleActionCancel(ids: IntArray, xs: FloatArray, ys: FloatArray, timestamp: Double) {
nativeTouchesCancel(ids, xs, ys) nativeTouchesCancel(ids, xs, ys, timestamp)
} }
fun handleActionMove(ids: IntArray, xs: FloatArray, ys: FloatArray) { fun handleActionMove(ids: IntArray, xs: FloatArray, ys: FloatArray, timestamp: Double) {
nativeTouchesMove(ids, xs, ys) nativeTouchesMove(ids, xs, ys, timestamp)
} }
fun handleKeyDown(keyCode: Int) { fun handleKeyDown(keyCode: Int) {