mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-16 05:42:55 +00:00
ci/sdl: minor cleanup
This commit is contained in:
parent
ceed42a0ee
commit
3f7a2c6d4d
@ -77,6 +77,73 @@ static bool HandleEventAndContinue(const SDL_Event& e)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void EnableSDLLogging()
|
||||
{
|
||||
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
|
||||
SDL_LogSetOutputFunction(
|
||||
[](void*, int category, SDL_LogPriority priority, const char* message) {
|
||||
std::string category_name;
|
||||
switch (category)
|
||||
{
|
||||
case SDL_LOG_CATEGORY_APPLICATION:
|
||||
category_name = "app";
|
||||
break;
|
||||
case SDL_LOG_CATEGORY_ERROR:
|
||||
category_name = "error";
|
||||
break;
|
||||
case SDL_LOG_CATEGORY_ASSERT:
|
||||
category_name = "assert";
|
||||
break;
|
||||
case SDL_LOG_CATEGORY_SYSTEM:
|
||||
category_name = "system";
|
||||
break;
|
||||
case SDL_LOG_CATEGORY_AUDIO:
|
||||
category_name = "audio";
|
||||
break;
|
||||
case SDL_LOG_CATEGORY_VIDEO:
|
||||
category_name = "video";
|
||||
break;
|
||||
case SDL_LOG_CATEGORY_RENDER:
|
||||
category_name = "render";
|
||||
break;
|
||||
case SDL_LOG_CATEGORY_INPUT:
|
||||
category_name = "input";
|
||||
break;
|
||||
case SDL_LOG_CATEGORY_TEST:
|
||||
category_name = "test";
|
||||
break;
|
||||
default:
|
||||
category_name = fmt::format("unknown({})", category);
|
||||
break;
|
||||
}
|
||||
|
||||
auto log_level = Common::Log::LogLevel::LNOTICE;
|
||||
switch (priority)
|
||||
{
|
||||
case SDL_LOG_PRIORITY_VERBOSE:
|
||||
case SDL_LOG_PRIORITY_DEBUG:
|
||||
log_level = Common::Log::LogLevel::LDEBUG;
|
||||
break;
|
||||
case SDL_LOG_PRIORITY_INFO:
|
||||
log_level = Common::Log::LogLevel::LINFO;
|
||||
break;
|
||||
case SDL_LOG_PRIORITY_WARN:
|
||||
log_level = Common::Log::LogLevel::LWARNING;
|
||||
break;
|
||||
case SDL_LOG_PRIORITY_ERROR:
|
||||
log_level = Common::Log::LogLevel::LERROR;
|
||||
break;
|
||||
case SDL_LOG_PRIORITY_CRITICAL:
|
||||
log_level = Common::Log::LogLevel::LNOTICE;
|
||||
break;
|
||||
}
|
||||
|
||||
GENERIC_LOG_FMT(Common::Log::LogType::CONTROLLERINTERFACE, log_level, "{}: {}",
|
||||
category_name, message);
|
||||
},
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
@ -90,6 +157,8 @@ void Init()
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
#endif
|
||||
|
||||
EnableSDLLogging();
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 9)
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
|
||||
#endif
|
||||
@ -205,9 +274,9 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index)
|
||||
AddAnalogInputs(new Axis(i, m_joystick, -32768), new Axis(i, m_joystick, 32767));
|
||||
}
|
||||
|
||||
m_haptic = nullptr;
|
||||
|
||||
#ifdef USE_SDL_HAPTIC
|
||||
if (SDL_JoystickIsHaptic(m_joystick))
|
||||
{
|
||||
m_haptic = SDL_HapticOpenFromJoystick(m_joystick);
|
||||
if (m_haptic)
|
||||
{
|
||||
@ -240,6 +309,7 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index)
|
||||
AddOutput(new LeftRightEffect(m_haptic, LeftRightEffect::Motor::Weak));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 9)
|
||||
@ -250,8 +320,9 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index)
|
||||
#endif
|
||||
|
||||
#ifdef USE_SDL_GAMECONTROLLER
|
||||
if (SDL_IsGameController(sdl_index))
|
||||
{
|
||||
m_controller = SDL_GameControllerOpen(sdl_index);
|
||||
|
||||
if (m_controller)
|
||||
{
|
||||
if (SDL_GameControllerSetSensorEnabled(m_controller, SDL_SENSOR_ACCEL, SDL_TRUE) == 0)
|
||||
@ -278,18 +349,28 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index)
|
||||
AddInput(new MotionInput("Gyro Yaw Right", m_controller, SDL_SENSOR_GYRO, 1, -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Joystick::~Joystick()
|
||||
{
|
||||
#ifdef USE_SDL_GAMECONTROLLER
|
||||
if (m_controller)
|
||||
{
|
||||
SDL_GameControllerClose(m_controller);
|
||||
m_controller = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_SDL_HAPTIC
|
||||
if (m_haptic)
|
||||
{
|
||||
// stop/destroy all effects
|
||||
SDL_HapticStopAll(m_haptic);
|
||||
// close haptic first
|
||||
// close haptic before joystick
|
||||
SDL_HapticClose(m_haptic);
|
||||
m_haptic = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#define INIT_FLAGS SDL_INIT_JOYSTICK
|
||||
|
||||
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
||||
#define USE_SDL_HAPTIC
|
||||
#endif
|
||||
@ -198,11 +196,11 @@ private:
|
||||
std::string m_name;
|
||||
|
||||
#ifdef USE_SDL_HAPTIC
|
||||
SDL_Haptic* m_haptic;
|
||||
SDL_Haptic* m_haptic = nullptr;
|
||||
#endif
|
||||
|
||||
#ifdef USE_SDL_GAMECONTROLLER
|
||||
SDL_GameController* m_controller;
|
||||
SDL_GameController* m_controller = nullptr;
|
||||
#endif
|
||||
};
|
||||
} // namespace ciface::SDL
|
||||
|
Loading…
x
Reference in New Issue
Block a user