You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-18 14:21:41 +00:00
Android: Fix excessive getRotation calls
This commit is contained in:
@@ -664,6 +664,8 @@ class Godot(private val context: Context) {
|
|||||||
* Configuration change callback
|
* Configuration change callback
|
||||||
*/
|
*/
|
||||||
fun onConfigurationChanged(newConfig: Configuration) {
|
fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
renderView?.inputHandler?.onConfigurationChanged(newConfig)
|
||||||
|
|
||||||
val newDarkMode = newConfig.uiMode.and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
val newDarkMode = newConfig.uiMode.and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
||||||
if (darkMode != newDarkMode) {
|
if (darkMode != newDarkMode) {
|
||||||
darkMode = newDarkMode
|
darkMode = newDarkMode
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import org.godotengine.godot.GodotLib;
|
|||||||
import org.godotengine.godot.GodotRenderView;
|
import org.godotengine.godot.GodotRenderView;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
@@ -86,6 +87,8 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
|
|||||||
|
|
||||||
private int rotaryInputAxis = ROTARY_INPUT_VERTICAL_AXIS;
|
private int rotaryInputAxis = ROTARY_INPUT_VERTICAL_AXIS;
|
||||||
|
|
||||||
|
private int cachedRotation = -1;
|
||||||
|
|
||||||
public GodotInputHandler(Context context, Godot godot) {
|
public GodotInputHandler(Context context, Godot godot) {
|
||||||
this.godot = godot;
|
this.godot = godot;
|
||||||
mInputManager = (InputManager)context.getSystemService(Context.INPUT_SERVICE);
|
mInputManager = (InputManager)context.getSystemService(Context.INPUT_SERVICE);
|
||||||
@@ -741,10 +744,14 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cachedRotation == -1) {
|
||||||
|
updateCachedRotation();
|
||||||
|
}
|
||||||
|
|
||||||
float rotatedValue0 = 0f;
|
float rotatedValue0 = 0f;
|
||||||
float rotatedValue1 = 0f;
|
float rotatedValue1 = 0f;
|
||||||
float rotatedValue2 = 0f;
|
float rotatedValue2 = 0f;
|
||||||
switch (windowManager.getDefaultDisplay().getRotation()) {
|
switch (cachedRotation) {
|
||||||
case Surface.ROTATION_0:
|
case Surface.ROTATION_0:
|
||||||
rotatedValue0 = values[0];
|
rotatedValue0 = values[0];
|
||||||
rotatedValue1 = values[1];
|
rotatedValue1 = values[1];
|
||||||
@@ -776,4 +783,12 @@ public class GodotInputHandler implements InputManager.InputDeviceListener, Sens
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
||||||
|
|
||||||
|
private void updateCachedRotation() {
|
||||||
|
cachedRotation = windowManager.getDefaultDisplay().getRotation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
|
updateCachedRotation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user