Skip to content

Commit

Permalink
Load SDL's gamecontrollerdb from assets directory, not relative to exe.
Browse files Browse the repository at this point in the history
Fixes #9460.

Also remove support for that env variable.
  • Loading branch information
hrydgard committed Mar 21, 2017
1 parent b4fa8ae commit 1b69936
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions SDL/SDLJoystick.cpp
@@ -1,6 +1,7 @@
#include "SDL/SDLJoystick.h"
#include "Core/Config.h"
#include "Common/FileUtil.h"
#include "file/vfs.h"

#include <iostream>
#include <string>
Expand All @@ -18,31 +19,22 @@ SDLJoystick::SDLJoystick(bool init_SDL ) : registeredAsEventHandler(false) {
if (init_SDL) {
SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER);
}

char* dbEnvPath = getenv("PPSSPP_GAME_CONTROLLER_DB_PATH");
if (dbEnvPath != NULL) {
if (!File::Exists(dbEnvPath)) {
cout << "WARNING! " << dbEnvPath << " does not exist!" << endl;
} else {
cout << "loading control pad mappings from " << dbEnvPath << ": ";
if (SDL_GameControllerAddMappingsFromFile(dbEnvPath) == -1) {
cout << "FAILED! Will try load from your assests directory instead..." << endl;
} else {
cout << "SUCCESS!" << endl;
setUpControllers();
return;
}
}
}

auto dbPath = File::GetExeDirectory() + "assets/gamecontrollerdb.txt";

const char *dbPath = "gamecontrollerdb.txt";
cout << "loading control pad mappings from " << dbPath << ": ";

if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) == -1) {
cout << "FAILED! Please place gamecontrollerdb.txt in your assets directory." << endl;
return;
size_t size;
u8 *mappingData = VFSReadFile(dbPath, &size);
if (mappingData) {
SDL_RWops *rw = SDL_RWFromConstMem(mappingData, size);
// 1 to free the rw after use
if (SDL_GameControllerAddMappingsFromRW(rw, 1) == -1) {
cout << "Failed to read mapping data - corrupt?" << endl;
}
delete[] mappingData;
} else {
cout << "gamecontrollerdb.txt missing" << endl;
}

cout << "SUCCESS!" << endl;
setUpControllers();
}
Expand Down Expand Up @@ -124,8 +116,10 @@ keycode_t SDLJoystick::getKeycodeForButton(SDL_GameControllerButton button) {
return NKCODE_BUTTON_THUMBL;
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
return NKCODE_BUTTON_THUMBR;
case SDL_CONTROLLER_BUTTON_INVALID:
default:
return NKCODE_UNKNOWN;
}
return NKCODE_UNKNOWN;
}

void SDLJoystick::ProcessInput(SDL_Event &event){
Expand Down

0 comments on commit 1b69936

Please sign in to comment.