mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Load SDL's gamecontrollerdb from assets directory, not relative to exe. Fixes #9460.
Also remove support for that env variable.
This commit is contained in:
parent
b4fa8ae82b
commit
1b699363ca
1 changed files with 17 additions and 23 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include "SDL/SDLJoystick.h"
|
#include "SDL/SDLJoystick.h"
|
||||||
#include "Core/Config.h"
|
#include "Core/Config.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
|
#include "file/vfs.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -18,31 +19,22 @@ SDLJoystick::SDLJoystick(bool init_SDL ) : registeredAsEventHandler(false) {
|
||||||
if (init_SDL) {
|
if (init_SDL) {
|
||||||
SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER);
|
SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* dbEnvPath = getenv("PPSSPP_GAME_CONTROLLER_DB_PATH");
|
const char *dbPath = "gamecontrollerdb.txt";
|
||||||
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";
|
|
||||||
cout << "loading control pad mappings from " << dbPath << ": ";
|
cout << "loading control pad mappings from " << dbPath << ": ";
|
||||||
|
|
||||||
if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) == -1) {
|
size_t size;
|
||||||
cout << "FAILED! Please place gamecontrollerdb.txt in your assets directory." << endl;
|
u8 *mappingData = VFSReadFile(dbPath, &size);
|
||||||
return;
|
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;
|
cout << "SUCCESS!" << endl;
|
||||||
setUpControllers();
|
setUpControllers();
|
||||||
}
|
}
|
||||||
|
@ -124,8 +116,10 @@ keycode_t SDLJoystick::getKeycodeForButton(SDL_GameControllerButton button) {
|
||||||
return NKCODE_BUTTON_THUMBL;
|
return NKCODE_BUTTON_THUMBL;
|
||||||
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
|
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
|
||||||
return NKCODE_BUTTON_THUMBR;
|
return NKCODE_BUTTON_THUMBR;
|
||||||
|
case SDL_CONTROLLER_BUTTON_INVALID:
|
||||||
|
default:
|
||||||
|
return NKCODE_UNKNOWN;
|
||||||
}
|
}
|
||||||
return NKCODE_UNKNOWN;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLJoystick::ProcessInput(SDL_Event &event){
|
void SDLJoystick::ProcessInput(SDL_Event &event){
|
||||||
|
|
Loading…
Add table
Reference in a new issue