Skip to content

Commit

Permalink
Adding sensor delay setting for android
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiaanOlij committed Oct 6, 2018
1 parent 45842c0 commit 095968e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
4 changes: 4 additions & 0 deletions core/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,10 @@ ProjectSettings::ProjectSettings() {
Compression::gzip_level = GLOBAL_DEF("compression/formats/gzip/compression_level", Z_DEFAULT_COMPRESSION);
custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");

// this is only for android but needs a place, setting sensor precision
GLOBAL_DEF("input_devices/sensors/sensor_delay", "Game");
set_custom_property_info("input_devices/sensors/sensor_delay", PropertyInfo(Variant::STRING, "input_devices/sensors/sensor_delay", PROPERTY_HINT_ENUM, "Fastest,Game,Normal,UI"));

using_datapack = false;
}

Expand Down
30 changes: 21 additions & 9 deletions platform/android/java/src/org/godotengine/godot/Godot.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
private boolean mStatePaused;
private int mState;
private boolean keep_screen_on = true;
private int sensor_delay = SensorManager.SENSOR_DELAY_GAME;

static private Intent mCurrentIntent;

Expand Down Expand Up @@ -279,7 +280,7 @@ public void onVideoInit() {
// ...add to FrameLayout
layout.addView(edittext);

mView = new GodotView(getApplication(), io, use_gl3, use_32_bits, use_debug_opengl,this);
mView = new GodotView(getApplication(), io, use_gl3, use_32_bits, use_debug_opengl, this);
layout.addView(mView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
edittext.setView(mView);
io.setEdit(edittext);
Expand Down Expand Up @@ -420,18 +421,29 @@ private void initializeGodot() {
command_line = new_cmdline;
}

String sensor_delay_string = GodotLib.getGlobal("input_devices/sensors/sensor_delay");
if (sensor_delay_string == "Fastest") {
sensor_delay = SensorManager.SENSOR_DELAY_FASTEST;
} else if (sensor_delay_string == "Game") {
sensor_delay = SensorManager.SENSOR_DELAY_GAME;
} else if (sensor_delay_string == "Normal") {
sensor_delay = SensorManager.SENSOR_DELAY_NORMAL;
} else if (sensor_delay_string == "UI") {
sensor_delay = SensorManager.SENSOR_DELAY_UI;
}

io = new GodotIO(this);
io.unique_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
GodotLib.io = io;
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, mAccelerometer, sensor_delay);
mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, mGravity, sensor_delay);
mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, mMagnetometer, sensor_delay);
mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, mGyroscope, sensor_delay);

GodotLib.initialize(this, io.needsReloadHooks(), getAssets(), use_apk_expansion);

Expand Down Expand Up @@ -660,10 +672,10 @@ 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 >= 19.0) { // check if the application runs on an android 4.4+
Window window = getWindow();
Expand Down

0 comments on commit 095968e

Please sign in to comment.