proper refresh rate selection

This commit is contained in:
qimiko committed 2024-05-31 05:38:39 -07:00
1 parent efaeeba5ec
commit 75596fefd2
2 files changed
+15 -7

No files matched your search

@@ -363,7 +363,13 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
} }
glSurfaceView.initView() glSurfaceView.initView()
glSurfaceView.setCocos2dxRenderer(Cocos2dxRenderer())
val renderer = Cocos2dxRenderer(glSurfaceView)
glSurfaceView.setCocos2dxRenderer(renderer)
if (forceRefreshRate) {
renderer.setFrameRate = true
}
editText.inputType = 145 editText.inputType = 145
glSurfaceView.cocos2dxEditText = editText glSurfaceView.cocos2dxEditText = editText
@@ -417,10 +423,6 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
mIsRunning = true mIsRunning = true
// Cocos2dxHelper.onResume() // Cocos2dxHelper.onResume()
mGLSurfaceView?.onResume() mGLSurfaceView?.onResume()
if (forceRefreshRate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
mGLSurfaceView?.updateRefreshRate()
}
} }
private fun pauseGame() { private fun pauseGame() {
@@ -1,11 +1,12 @@
package org.cocos2dx.lib package org.cocos2dx.lib
import android.opengl.GLSurfaceView import android.opengl.GLSurfaceView
import android.os.Build
import javax.microedition.khronos.egl.EGLConfig import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10 import javax.microedition.khronos.opengles.GL10
@Suppress("unused", "KotlinJniMissingFunction") @Suppress("unused", "KotlinJniMissingFunction")
class Cocos2dxRenderer : GLSurfaceView.Renderer { class Cocos2dxRenderer(private var handler: Cocos2dxGLSurfaceView) : GLSurfaceView.Renderer {
companion object { companion object {
@JvmStatic @JvmStatic
fun setAnimationInterval(@Suppress("UNUSED_PARAMETER") animationInterval: Double) { fun setAnimationInterval(@Suppress("UNUSED_PARAMETER") animationInterval: Double) {
@@ -60,6 +61,7 @@ class Cocos2dxRenderer : GLSurfaceView.Renderer {
private var screenWidth = 0 private var screenWidth = 0
private var screenHeight = 0 private var screenHeight = 0
var sendResizeEvents = false var sendResizeEvents = false
var setFrameRate = false
fun setScreenWidthAndHeight(surfaceWidth: Int, surfaceHeight: Int) { fun setScreenWidthAndHeight(surfaceWidth: Int, surfaceHeight: Int) {
screenWidth = surfaceWidth screenWidth = surfaceWidth
@@ -71,7 +73,11 @@ class Cocos2dxRenderer : GLSurfaceView.Renderer {
lastTickInNanoSeconds = System.nanoTime() lastTickInNanoSeconds = System.nanoTime()
} }
override fun onSurfaceChanged(gl10: GL10?, width: Int, height: Int) {} override fun onSurfaceChanged(gl10: GL10?, width: Int, height: Int) {
if (setFrameRate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
handler.updateRefreshRate()
}
}
override fun onDrawFrame(gl: GL10?) { override fun onDrawFrame(gl: GL10?) {
nativeRender() nativeRender()