-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Adding sensor delay setting for android #22644
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC | |
private boolean use_debug_opengl = false; | ||
private boolean mStatePaused; | ||
private int mState; | ||
private int sensor_delay = SensorManager.SENSOR_DELAY_GAME; | ||
|
||
static private Intent mCurrentIntent; | ||
|
||
|
@@ -407,16 +408,28 @@ private void initializeGodot() { | |
GodotLib.io = io; | ||
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE); | ||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); | ||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME); | ||
mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY); | ||
mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME); | ||
mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); | ||
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME); | ||
mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); | ||
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME); | ||
|
||
GodotLib.initialize(this, io.needsReloadHooks(), getAssets(), use_apk_expansion); | ||
|
||
String sensor_delay_string = GodotLib.getGlobal("input_devices/sensors/sensor_delay"); | ||
if (sensor_delay_string.equals("Fastest")) { | ||
sensor_delay = SensorManager.SENSOR_DELAY_FASTEST; | ||
} else if (sensor_delay_string.equals("Game")) { | ||
sensor_delay = SensorManager.SENSOR_DELAY_GAME; | ||
} else if (sensor_delay_string.equals("Normal")) { | ||
sensor_delay = SensorManager.SENSOR_DELAY_NORMAL; | ||
} else if (sensor_delay_string.equals("UI")) { | ||
sensor_delay = SensorManager.SENSOR_DELAY_UI; | ||
} | ||
|
||
mSensorManager.registerListener(this, mAccelerometer, sensor_delay); | ||
mSensorManager.registerListener(this, mGravity, sensor_delay); | ||
mSensorManager.registerListener(this, mMagnetometer, sensor_delay); | ||
mSensorManager.registerListener(this, mGyroscope, sensor_delay); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code doesn't look correct as the sensor manager is registering listeners here in 'onCreate', and it's also doing the same thing below in 'onResume'. I'd recommend deleting the section here in favor of registering the listener in onResume. This would also allow to resolve the crashing issue commented above, as by the time 'onResume' is invoked, GodotLib.setup would have already been invoked, preventing GodotLib.getGlobal from crashing. |
||
|
||
result_callback = null; | ||
|
||
mPaymentsManager = PaymentsManager.createManager(this).initService(); | ||
|
@@ -641,10 +654,11 @@ public void run() { | |
GodotLib.focusin(); | ||
} | ||
}); | ||
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME); | ||
mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME); | ||
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME); | ||
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME); | ||
|
||
mSensorManager.registerListener(this, mAccelerometer, sensor_delay); | ||
mSensorManager.registerListener(this, mGravity, sensor_delay); | ||
mSensorManager.registerListener(this, mMagnetometer, sensor_delay); | ||
mSensorManager.registerListener(this, mGyroscope, sensor_delay); | ||
|
||
if (use_immersive && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check if the application runs on an android 4.4+ | ||
Window window = getWindow(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call seems to be crashing android for me, I don't know if getGlobal is unavailable at this point of time, or whether our project file hasn't been loaded yet, or if there is some other reason... Anyone have any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no idea but I got several reports related to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty much in the dark how this whole thing ties together, it all feels pretty messy to me. So yeah I still don't know if I'm doing this too early, if there is a better place to call this from, or if there is something wrong with getting the setting.
it's a shame because this is the final bit to get simple VR going well on Android :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call is crashing because GodotLib.getGlobal relies on ProjectSettings which is not initialized until GodotLib.setup has been invoked here.
I'm adding another comment below about how to possibly resolve the issue.