Skip to content

Commit

Permalink
this is dumb
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 24, 2025
1 parent 91c06bd commit 986e33c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL

val forceRefreshRate = preferenceUtils.getBoolean(PreferenceUtils.Key.FORCE_HRR)
if (forceRefreshRate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
var chosenDisplay = display.supportedModes?.maxByOrNull { it.refreshRate }
val chosenDisplay = display.supportedModes?.maxByOrNull { it.refreshRate }
if (chosenDisplay != null) {
var chosenRefreshRate = chosenDisplay.refreshRate
println("Forcing a refresh rate of $chosenRefreshRate (display ${chosenDisplay.modeId})")
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/org/cocos2dx/lib/Cocos2dxGLSurfaceView.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cocos2dx.lib

import android.app.Activity
import android.content.Context
import android.opengl.GLSurfaceView
import android.os.Build
Expand Down Expand Up @@ -120,7 +121,19 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {

@RequiresApi(Build.VERSION_CODES.R)
fun updateRefreshRate(refreshRate: Float) {
holder.surface.setFrameRate(refreshRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT)
var chosenRefreshRate = refreshRate

val chosenDisplay = display.supportedModes?.maxByOrNull { it.refreshRate }
if (chosenDisplay != null && chosenDisplay.refreshRate > refreshRate) {
println("updateRefreshRate found a higher refresh rate (${chosenDisplay.modeId}: ${chosenDisplay.refreshRate} > $refreshRate)")
chosenRefreshRate = chosenDisplay.refreshRate
}

holder.surface.setFrameRate(chosenRefreshRate, Surface.FRAME_RATE_COMPATIBILITY_DEFAULT)

if (isAttachedToWindow) {
(context as Activity).window.attributes.preferredRefreshRate = chosenRefreshRate
}
}

override fun onPause() {
Expand Down

0 comments on commit 986e33c

Please sign in to comment.