Merge pull request #781 from hhromic/add-gamecontrollerdb

SDLControllerInterface: Add support for optional game controller database
This commit is contained in:
Connor McLaughlin 2020-08-22 13:05:27 +10:00 committed by GitHub
commit afe397a04d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -1,5 +1,6 @@
#include "sdl_controller_interface.h"
#include "common/assert.h"
#include "common/file_system.h"
#include "common/log.h"
#include "core/controller.h"
#include "core/host_interface.h"
@ -23,6 +24,17 @@ bool SDLControllerInterface::Initialize(CommonHostInterface* host_interface)
FrontendCommon::EnsureSDLInitialized();
const std::string gcdb_file_name = GetGameControllerDBFileName();
if (FileSystem::FileExists(gcdb_file_name.c_str()))
{
Log_InfoPrintf("Loading game controller mappings from '%s'", gcdb_file_name.c_str());
if (SDL_GameControllerAddMappingsFromFile(gcdb_file_name.c_str()) < 0)
{
Log_ErrorPrintf("SDL_GameControllerAddMappingsFromFile(%s) failed: %s",
gcdb_file_name.c_str(), SDL_GetError());
}
}
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) < 0)
{
Log_ErrorPrintf("SDL_InitSubSystem(SDL_INIT_JOYSTICK |SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) failed");
@ -48,6 +60,11 @@ void SDLControllerInterface::Shutdown()
ControllerInterface::Shutdown();
}
std::string SDLControllerInterface::GetGameControllerDBFileName() const
{
return m_host_interface->GetUserDirectoryRelativePath("gamecontrollerdb.txt");
}
void SDLControllerInterface::PollEvents()
{
for (;;)

View file

@ -17,6 +17,9 @@ public:
bool Initialize(CommonHostInterface* host_interface) override;
void Shutdown() override;
/// Returns the path of the optional game controller database file.
std::string GetGameControllerDBFileName() const;
// Removes all bindings. Call before setting new bindings.
void ClearBindings() override;