Skip to content
Permalink
Browse files

input: disable vibrations when compiling with older SDL

  • Loading branch information
JaCzekanski committed Sep 7, 2019
1 parent 7369d2b commit a9d64b5673470b33ebc4b4007310c6b6778a3df1
Showing with 14 additions and 3 deletions.
  1. +1 −1 src/platform/windows/gui/file.cpp
  2. +13 −2 src/platform/windows/input/sdl_input_manager.cpp
@@ -29,7 +29,7 @@ const std::array<const char*, 9> supportedFiles = {

void openFile() {
if (!openFileWindow) {
path = fs::path(config["gui"]["lastPath"]);
path = fs::path(config["gui"]["lastPath"].get<std::string>());
readDirectory = true;
}

@@ -2,21 +2,31 @@
#include "utils/math.h"
#include "utils/string.h"

#if SDL_VERSION_ATLEAST(2, 0, 9)
#define VIBRATIONS_ENABLED
#else
#warning Vibrations are available for SDL >= 2.0.9
#endif

SdlInputManager::SdlInputManager() {
#ifdef VIBRATIONS_ENABLED
vibrationThread = std::thread(&SdlInputManager::vibrationThreadFunc, this);
#endif
busToken = bus.listen<Event::Controller::Vibration>(std::bind(&SdlInputManager::onVibrationEvent, this, std::placeholders::_1));
}

SdlInputManager::~SdlInputManager() {
bus.unlistenAll(busToken);

#ifdef VIBRATIONS_ENABLED
// Notify vibrationThread to stop execution
{
std::unique_lock<std::mutex> lk(vibrationMutex);
vibrationThreadExit = true;
vibrationHasNewData.notify_one();
}
vibrationThread.join();
#endif
}

void SdlInputManager::vibrationThreadFunc() {
@@ -27,10 +37,11 @@ void SdlInputManager::vibrationThreadFunc() {
if (vibrationThreadExit) {
break;
}
#ifdef VIBRATIONS_ENABLED
// TODO: Current solution might cut out vibration from different controllers
// Buffer them and send all in bulk at the end of the frame ?
SDL_JoystickRumble(SDL_GameControllerGetJoystick(vibrationData.controller), vibrationData.e.big * 0xff,
vibrationData.e.small * 0xffff, 16);
SDL_GameControllerRumble(vibrationData.controller, vibrationData.e.big * 0xff, vibrationData.e.small * 0xffff, 16);
#endif
}
}

0 comments on commit a9d64b5

Please sign in to comment.
You can’t perform that action at this time.