mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 06:13:45 -07:00
fix rumble support for linux
This commit is contained in:
parent
7cbe902cc2
commit
73065898c8
2 changed files with 22 additions and 20 deletions
|
@ -61,17 +61,17 @@ namespace Ship {
|
|||
if (Conf[ConfSection]["GUID"].compare("") == 0 || Conf[ConfSection]["GUID"].compare(INVALID_SDL_CONTROLLER_GUID) == 0 || Conf[ConfSection]["GUID"].compare(NewGuid) == 0) {
|
||||
auto NewCont = SDL_GameControllerOpen(i);
|
||||
|
||||
if (SDL_GameControllerHasSensor(NewCont, SDL_SENSOR_GYRO))
|
||||
{
|
||||
SDL_GameControllerSetSensorEnabled(NewCont, SDL_SENSOR_GYRO, SDL_TRUE);
|
||||
}
|
||||
|
||||
// We failed to load the controller. Go to next.
|
||||
if (NewCont == nullptr) {
|
||||
SPDLOG_ERROR("SDL Controller failed to open: ({})", SDL_GetError());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasSensor(NewCont, SDL_SENSOR_GYRO))
|
||||
{
|
||||
SDL_GameControllerSetSensorEnabled(NewCont, SDL_SENSOR_GYRO, SDL_TRUE);
|
||||
}
|
||||
|
||||
guid = NewGuid;
|
||||
Cont = NewCont;
|
||||
|
||||
|
@ -101,10 +101,9 @@ namespace Ship {
|
|||
}
|
||||
|
||||
bool SDLController::Close() {
|
||||
// LINUX_TODO:
|
||||
// if (SDL_GameControllerHasRumble(Cont)) {
|
||||
// SDL_GameControllerRumble(Cont, 0, 0, 0);
|
||||
// }
|
||||
if (CanRumble()) {
|
||||
SDL_GameControllerRumble(Cont, 0, 0, 0);
|
||||
}
|
||||
if (Cont != nullptr) {
|
||||
SDL_GameControllerClose(Cont);
|
||||
}
|
||||
|
@ -348,15 +347,14 @@ namespace Ship {
|
|||
|
||||
void SDLController::WriteToSource(ControllerCallback* controller)
|
||||
{
|
||||
// LINUX_TODO:
|
||||
// if (SDL_GameControllerHasRumble(Cont)) {
|
||||
// if (controller->rumble > 0) {
|
||||
// float rumble_strength = CVar_GetFloat(StringHelper::Sprintf("gCont%i_RumbleStrength", GetControllerNumber()).c_str(), 1.0f);
|
||||
// SDL_GameControllerRumble(Cont, 0xFFFF * rumble_strength, 0xFFFF * rumble_strength, 0);
|
||||
// } else {
|
||||
// SDL_GameControllerRumble(Cont, 0, 0, 0);
|
||||
// }
|
||||
// }
|
||||
if (CanRumble()) {
|
||||
if (controller->rumble > 0) {
|
||||
float rumble_strength = CVar_GetFloat(StringHelper::Sprintf("gCont%i_RumbleStrength", GetControllerNumber()).c_str(), 1.0f);
|
||||
SDL_GameControllerRumble(Cont, 0xFFFF * rumble_strength, 0xFFFF * rumble_strength, 0);
|
||||
} else {
|
||||
SDL_GameControllerRumble(Cont, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasLED(Cont)) {
|
||||
switch (controller->ledColor) {
|
||||
|
|
|
@ -13,8 +13,12 @@ namespace Ship {
|
|||
void ReadFromSource();
|
||||
void WriteToSource(ControllerCallback* controller);
|
||||
bool Connected() const { return Cont != nullptr; }
|
||||
// LINUX_TODO:
|
||||
bool CanRumble() const { return false; /* return SDL_GameControllerHasRumble(Cont); */ }
|
||||
bool CanRumble() const {
|
||||
#if SDL_COMPILEDVERSION >= SDL_VERSIONNUM(2,0,18)
|
||||
return SDL_GameControllerHasRumble(Cont);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string GetGuid() { return guid; };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue