1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

Disable controller gyro with older SDL

This commit is contained in:
uramer 2022-01-19 21:32:46 +01:00
parent 4021d23cff
commit 15e9c6615c

View File

@ -406,14 +406,16 @@ namespace MWInput
void ControllerManager::enableGyroSensor() void ControllerManager::enableGyroSensor()
{ {
mGyroAvailable = false; mGyroAvailable = false;
SDL_GameController* cntrl = mBindingsManager->getControllerOrNull(); #if SDL_VERSION_ATLEAST(2, 0, 14)
if (!cntrl) SDL_GameController* cntrl = mBindingsManager->getControllerOrNull();
return; if (!cntrl)
if (!SDL_GameControllerHasSensor(cntrl, SDL_SENSOR_GYRO)) return;
return; if (!SDL_GameControllerHasSensor(cntrl, SDL_SENSOR_GYRO))
if (SDL_GameControllerSetSensorEnabled(cntrl, SDL_SENSOR_GYRO, SDL_TRUE) < 0) return;
return; if (SDL_GameControllerSetSensorEnabled(cntrl, SDL_SENSOR_GYRO, SDL_TRUE) < 0)
mGyroAvailable = true; return;
mGyroAvailable = true;
#endif
} }
bool ControllerManager::isGyroAvailable() const bool ControllerManager::isGyroAvailable() const
@ -424,9 +426,11 @@ namespace MWInput
std::array<float, 3> ControllerManager::getGyroValues() const std::array<float, 3> ControllerManager::getGyroValues() const
{ {
float gyro[3] = { 0.f }; float gyro[3] = { 0.f };
SDL_GameController* cntrl = mBindingsManager->getControllerOrNull(); #if SDL_VERSION_ATLEAST(2, 0, 14)
if (cntrl && mGyroAvailable) SDL_GameController* cntrl = mBindingsManager->getControllerOrNull();
SDL_GameControllerGetSensorData(cntrl, SDL_SENSOR_GYRO, gyro, 3); if (cntrl && mGyroAvailable)
SDL_GameControllerGetSensorData(cntrl, SDL_SENSOR_GYRO, gyro, 3);
#endif
return std::array<float, 3>({gyro[0], gyro[1], gyro[2]}); return std::array<float, 3>({gyro[0], gyro[1], gyro[2]});
} }
} }