Libretro: Lazy-load sensors
Vicki Pfau vi@endrift.com
Sat, 20 Mar 2021 22:58:52 -0700
1 files changed,
17 insertions(+),
8 deletions(-)
jump to
M
src/platform/libretro/libretro.c
→
src/platform/libretro/libretro.c
@@ -69,7 +69,8 @@ static int rumbleDown;
static struct mRumble rumble; static struct GBALuminanceSource lux; static struct mRotationSource rotation; -static bool rotationEnabled; +static bool tiltEnabled; +static bool gyroEnabled; static int luxLevelIndex; static uint8_t luxLevel; static bool luxSensorEnabled;@@ -100,9 +101,12 @@ sensorGetCallback = sensorInterface.get_sensor_input;
sensorStateCallback = sensorInterface.set_sensor_state; if (sensorStateCallback && sensorGetCallback) { - if (sensorStateCallback(0, RETRO_SENSOR_ACCELEROMETER_ENABLE, EVENT_RATE) - && sensorStateCallback(0, RETRO_SENSOR_GYROSCOPE_ENABLE, EVENT_RATE)) { - rotationEnabled = true; + if (sensorStateCallback(0, RETRO_SENSOR_ACCELEROMETER_ENABLE, EVENT_RATE)) { + tiltEnabled = true; + } + + if (sensorStateCallback(0, RETRO_SENSOR_GYROSCOPE_ENABLE, EVENT_RATE)) { + gyroEnabled = true; } if (sensorStateCallback(0, RETRO_SENSOR_ILLUMINANCE_ENABLE, EVENT_RATE)) {@@ -318,7 +322,8 @@ sensorsInitDone = false;
sensorGetCallback = 0; sensorStateCallback = 0; - rotationEnabled = false; + tiltEnabled = false; + gyroEnabled = false; rotation.sample = _updateRotation; rotation.readTiltX = _readTiltX; rotation.readTiltY = _readTiltY;@@ -363,7 +368,8 @@ sensorGetCallback = NULL;
sensorStateCallback = NULL; } - rotationEnabled = false; + tiltEnabled = false; + gyroEnabled = false; luxSensorEnabled = false; sensorsInitDone = false; }@@ -374,7 +380,6 @@ _doDeferredSetup();
} uint16_t keys; - _initSensors(); inputPollCallback(); bool updated = false;@@ -1023,6 +1028,7 @@ luxSensorUsed = strcmp(var.value, "sensor") == 0;
} if (luxSensorUsed) { + _initSensors(); float fLux = luxSensorEnabled ? sensorGetCallback(0, RETRO_SENSOR_ILLUMINANCE) : 0.0f; luxLevel = cbrtf(fLux) * 8; } else {@@ -1124,9 +1130,12 @@ UNUSED(source);
tiltX = 0; tiltY = 0; gyroZ = 0; - if (rotationEnabled) { + _initSensors(); + if (tiltEnabled) { tiltX = sensorGetCallback(0, RETRO_SENSOR_ACCELEROMETER_X) * 3e8f; tiltY = sensorGetCallback(0, RETRO_SENSOR_ACCELEROMETER_Y) * -3e8f; + } + if (gyroEnabled) { gyroZ = sensorGetCallback(0, RETRO_SENSOR_GYROSCOPE_Z) * -1.1e9f; } }