diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-04 17:09:17 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-04 17:09:17 +0200 |
commit | 1c571f991dc99c028b6ee0845a6bf13d09ac12c6 (patch) | |
tree | 8e45f65158db97e5bd2393864cc4fa143e863403 /platform | |
parent | 1634f8214269b6280c3d2481a5463e70764dc198 (diff) | |
parent | f09d0331562a91d930170109d849a7bd0ea3e1b3 (diff) | |
download | redot-engine-1c571f991dc99c028b6ee0845a6bf13d09ac12c6.tar.gz |
Merge pull request #90000 from melquiadess/improve-performance-of-sensor-readings
Android: Improve performance of sensor readings
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/java/lib/src/org/godotengine/godot/Godot.kt | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt index 250680a25b..ce53aeebcb 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt @@ -85,6 +85,9 @@ class Godot(private val context: Context) : SensorEventListener { private val TAG = Godot::class.java.simpleName } + private val windowManager: WindowManager by lazy { + requireActivity().getSystemService(Context.WINDOW_SERVICE) as WindowManager + } private val pluginRegistry: GodotPluginRegistry by lazy { GodotPluginRegistry.getPluginRegistry() } @@ -818,11 +821,8 @@ class Godot(private val context: Context) : SensorEventListener { if (values == null || values.size != 3) { return null } - val display = - (requireActivity().getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay - val displayRotation = display.rotation val rotatedValues = FloatArray(3) - when (displayRotation) { + when (windowManager.defaultDisplay.rotation) { Surface.ROTATION_0 -> { rotatedValues[0] = values[0] rotatedValues[1] = values[1] @@ -851,40 +851,35 @@ class Godot(private val context: Context) : SensorEventListener { if (renderView == null) { return } + + val rotatedValues = getRotatedValues(event.values) + when (event.sensor.type) { Sensor.TYPE_ACCELEROMETER -> { - getRotatedValues(event.values)?.let { rotatedValues -> + rotatedValues?.let { renderView?.queueOnRenderThread { - GodotLib.accelerometer( - -rotatedValues[0], -rotatedValues[1], -rotatedValues[2] - ) + GodotLib.accelerometer(-it[0], -it[1], -it[2]) } } } Sensor.TYPE_GRAVITY -> { - getRotatedValues(event.values)?.let { rotatedValues -> + rotatedValues?.let { renderView?.queueOnRenderThread { - GodotLib.gravity( - -rotatedValues[0], -rotatedValues[1], -rotatedValues[2] - ) + GodotLib.gravity(-it[0], -it[1], -it[2]) } } } Sensor.TYPE_MAGNETIC_FIELD -> { - getRotatedValues(event.values)?.let { rotatedValues -> + rotatedValues?.let { renderView?.queueOnRenderThread { - GodotLib.magnetometer( - -rotatedValues[0], -rotatedValues[1], -rotatedValues[2] - ) + GodotLib.magnetometer(-it[0], -it[1], -it[2]) } } } Sensor.TYPE_GYROSCOPE -> { - getRotatedValues(event.values)?.let { rotatedValues -> + rotatedValues?.let { renderView?.queueOnRenderThread { - GodotLib.gyroscope( - rotatedValues[0], rotatedValues[1], rotatedValues[2] - ) + GodotLib.gyroscope(it[0], it[1], it[2]) } } } |