mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 14:23:44 -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) {
|
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);
|
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.
|
// We failed to load the controller. Go to next.
|
||||||
if (NewCont == nullptr) {
|
if (NewCont == nullptr) {
|
||||||
SPDLOG_ERROR("SDL Controller failed to open: ({})", SDL_GetError());
|
SPDLOG_ERROR("SDL Controller failed to open: ({})", SDL_GetError());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SDL_GameControllerHasSensor(NewCont, SDL_SENSOR_GYRO))
|
||||||
|
{
|
||||||
|
SDL_GameControllerSetSensorEnabled(NewCont, SDL_SENSOR_GYRO, SDL_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
guid = NewGuid;
|
guid = NewGuid;
|
||||||
Cont = NewCont;
|
Cont = NewCont;
|
||||||
|
|
||||||
|
@ -101,10 +101,9 @@ namespace Ship {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SDLController::Close() {
|
bool SDLController::Close() {
|
||||||
// LINUX_TODO:
|
if (CanRumble()) {
|
||||||
// if (SDL_GameControllerHasRumble(Cont)) {
|
SDL_GameControllerRumble(Cont, 0, 0, 0);
|
||||||
// SDL_GameControllerRumble(Cont, 0, 0, 0);
|
}
|
||||||
// }
|
|
||||||
if (Cont != nullptr) {
|
if (Cont != nullptr) {
|
||||||
SDL_GameControllerClose(Cont);
|
SDL_GameControllerClose(Cont);
|
||||||
}
|
}
|
||||||
|
@ -348,15 +347,14 @@ namespace Ship {
|
||||||
|
|
||||||
void SDLController::WriteToSource(ControllerCallback* controller)
|
void SDLController::WriteToSource(ControllerCallback* controller)
|
||||||
{
|
{
|
||||||
// LINUX_TODO:
|
if (CanRumble()) {
|
||||||
// if (SDL_GameControllerHasRumble(Cont)) {
|
if (controller->rumble > 0) {
|
||||||
// if (controller->rumble > 0) {
|
float rumble_strength = CVar_GetFloat(StringHelper::Sprintf("gCont%i_RumbleStrength", GetControllerNumber()).c_str(), 1.0f);
|
||||||
// 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);
|
||||||
// SDL_GameControllerRumble(Cont, 0xFFFF * rumble_strength, 0xFFFF * rumble_strength, 0);
|
} else {
|
||||||
// } else {
|
SDL_GameControllerRumble(Cont, 0, 0, 0);
|
||||||
// SDL_GameControllerRumble(Cont, 0, 0, 0);
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
if (SDL_GameControllerHasLED(Cont)) {
|
if (SDL_GameControllerHasLED(Cont)) {
|
||||||
switch (controller->ledColor) {
|
switch (controller->ledColor) {
|
||||||
|
|
|
@ -13,8 +13,12 @@ namespace Ship {
|
||||||
void ReadFromSource();
|
void ReadFromSource();
|
||||||
void WriteToSource(ControllerCallback* controller);
|
void WriteToSource(ControllerCallback* controller);
|
||||||
bool Connected() const { return Cont != nullptr; }
|
bool Connected() const { return Cont != nullptr; }
|
||||||
// LINUX_TODO:
|
bool CanRumble() const {
|
||||||
bool CanRumble() const { return false; /* return SDL_GameControllerHasRumble(Cont); */ }
|
#if SDL_COMPILEDVERSION >= SDL_VERSIONNUM(2,0,18)
|
||||||
|
return SDL_GameControllerHasRumble(Cont);
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::string GetGuid() { return guid; };
|
std::string GetGuid() { return guid; };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue