implement internal callbacks

This commit is contained in:
Chloe committed 2025-06-22 14:45:04 -07:00
1 parent 7d75825d01
commit 0b92f4a318
3 files changed
+25 -30

No files matched your search

@@ -588,6 +588,10 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
mGLSurfaceView?.sendTimestampEvents = true mGLSurfaceView?.sendTimestampEvents = true
true true
} }
GeodeUtils.CAPABILITY_INTERNAL_CALLBACKS -> {
mGLSurfaceView?.sendInternalTimestampEvents = true
true
}
else -> false else -> false
} }
} }
@@ -542,6 +542,7 @@ object GeodeUtils {
const val CAPABILITY_EXTENDED_INPUT = "extended_input" const val CAPABILITY_EXTENDED_INPUT = "extended_input"
const val CAPABILITY_TIMESTAMP_INPUT = "timestamp_inputs" const val CAPABILITY_TIMESTAMP_INPUT = "timestamp_inputs"
const val CAPABILITY_INTERNAL_CALLBACKS = "internal_callbacks_v1"
private var capabilityListener: WeakReference<CapabilityListener?> = WeakReference(null) private var capabilityListener: WeakReference<CapabilityListener?> = WeakReference(null)
@@ -582,4 +583,5 @@ object GeodeUtils {
* @see reportPlatformCapability * @see reportPlatformCapability
*/ */
external fun setNextInputTimestamp(timestamp: Long) external fun setNextInputTimestamp(timestamp: Long)
external fun setNextInputTimestampInternal(timestamp: Long)
} }
@@ -56,6 +56,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
} }
var sendTimestampEvents = false var sendTimestampEvents = false
var sendInternalTimestampEvents = false
var manualBackEvents = false var manualBackEvents = false
var cocos2dxEditText: AppCompatEditText? = null var cocos2dxEditText: AppCompatEditText? = null
@@ -150,6 +151,14 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
queueEvent { cocos2dxRenderer.handleOnResume() } queueEvent { cocos2dxRenderer.handleOnResume() }
} }
private fun sendNextEventTimestamp(timestamp: Long) {
if (sendTimestampEvents)
GeodeUtils.setNextInputTimestamp(timestamp)
if (sendInternalTimestampEvents)
GeodeUtils.setNextInputTimestampInternal(timestamp)
}
override fun onTouchEvent(motionEvent: MotionEvent): Boolean { override fun onTouchEvent(motionEvent: MotionEvent): Boolean {
val pointerNumber = motionEvent.pointerCount val pointerNumber = motionEvent.pointerCount
val ids = IntArray(pointerNumber) val ids = IntArray(pointerNumber)
@@ -169,9 +178,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
val xDown = xs[0] val xDown = xs[0]
val f = ys[0] val f = ys[0]
queueEvent { queueEvent {
if (sendTimestampEvents) sendNextEventTimestamp(timestamp)
GeodeUtils.setNextInputTimestamp(timestamp)
cocos2dxRenderer.handleActionDown(idDown, xDown, f) cocos2dxRenderer.handleActionDown(idDown, xDown, f)
} }
true true
@@ -181,27 +188,21 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
val f2 = xs[0] val f2 = xs[0]
val f3 = ys[0] val f3 = ys[0]
queueEvent { queueEvent {
if (sendTimestampEvents) sendNextEventTimestamp(timestamp)
GeodeUtils.setNextInputTimestamp(timestamp)
cocos2dxRenderer.handleActionUp(idUp, f2, f3) cocos2dxRenderer.handleActionUp(idUp, f2, f3)
} }
true true
} }
MotionEvent.ACTION_MOVE -> { MotionEvent.ACTION_MOVE -> {
queueEvent { queueEvent {
if (sendTimestampEvents) sendNextEventTimestamp(timestamp)
GeodeUtils.setNextInputTimestamp(timestamp)
cocos2dxRenderer.handleActionMove(ids, xs, ys) cocos2dxRenderer.handleActionMove(ids, xs, ys)
} }
true true
} }
MotionEvent.ACTION_CANCEL -> { MotionEvent.ACTION_CANCEL -> {
queueEvent { queueEvent {
if (sendTimestampEvents) sendNextEventTimestamp(timestamp)
GeodeUtils.setNextInputTimestamp(timestamp)
cocos2dxRenderer.handleActionCancel(ids, xs, ys) cocos2dxRenderer.handleActionCancel(ids, xs, ys)
} }
true true
@@ -212,9 +213,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
val xPointerDown = motionEvent.getX(indexPointerDown) val xPointerDown = motionEvent.getX(indexPointerDown)
val y = motionEvent.getY(indexPointerDown) val y = motionEvent.getY(indexPointerDown)
queueEvent { queueEvent {
if (sendTimestampEvents) sendNextEventTimestamp(timestamp)
GeodeUtils.setNextInputTimestamp(timestamp)
cocos2dxRenderer.handleActionDown(idPointerDown, xPointerDown, y) cocos2dxRenderer.handleActionDown(idPointerDown, xPointerDown, y)
} }
true true
@@ -225,9 +224,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
val xPointerUp = motionEvent.getX(indexPointUp) val xPointerUp = motionEvent.getX(indexPointUp)
val y2 = motionEvent.getY(indexPointUp) val y2 = motionEvent.getY(indexPointUp)
queueEvent { queueEvent {
if (sendTimestampEvents) sendNextEventTimestamp(timestamp)
GeodeUtils.setNextInputTimestamp(timestamp)
cocos2dxRenderer.handleActionUp(idPointerUp, xPointerUp, y2) cocos2dxRenderer.handleActionUp(idPointerUp, xPointerUp, y2)
} }
true true
@@ -276,9 +273,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
} else { } else {
val currentTime = System.nanoTime() val currentTime = System.nanoTime()
queueEvent { queueEvent {
if (sendTimestampEvents) sendNextEventTimestamp(currentTime)
GeodeUtils.setNextInputTimestamp(currentTime)
GeodeUtils.nativeKeyDown(KeyEvent.KEYCODE_BACK, 0, false) GeodeUtils.nativeKeyDown(KeyEvent.KEYCODE_BACK, 0, false)
} }
} }
@@ -300,9 +295,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
} }
queueEvent { queueEvent {
if (sendTimestampEvents) sendNextEventTimestamp(event.eventTime * MS_TO_NS)
GeodeUtils.setNextInputTimestamp(event.eventTime * MS_TO_NS)
GeodeUtils.nativeKeyDown(keyCode, event.modifiers, event.repeatCount != 0) GeodeUtils.nativeKeyDown(keyCode, event.modifiers, event.repeatCount != 0)
} }
true true
@@ -325,9 +318,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
} }
queueEvent { queueEvent {
if (sendTimestampEvents) sendNextEventTimestamp(event.eventTime * MS_TO_NS)
GeodeUtils.setNextInputTimestamp(event.eventTime * MS_TO_NS)
GeodeUtils.nativeKeyUp(keyCode, event.modifiers) GeodeUtils.nativeKeyUp(keyCode, event.modifiers)
} }
@@ -348,9 +339,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
event.eventTimeNanos else event.eventTime * MS_TO_NS event.eventTimeNanos else event.eventTime * MS_TO_NS
queueEvent { queueEvent {
if (sendTimestampEvents) sendNextEventTimestamp(timestamp)
GeodeUtils.setNextInputTimestamp(timestamp)
GeodeUtils.nativeActionScroll(scrollX, scrollY) GeodeUtils.nativeActionScroll(scrollX, scrollY)
} }