Cleanup, confine g_controllerMap access to KeyMap.cpp

This commit is contained in:
Henrik Rydgård
2023-04-01 20:28:42 +02:00
parent d523005c2b
commit c1b5aed9b7
5 changed files with 46 additions and 23 deletions
+31 -8
View File
@@ -515,20 +515,28 @@ bool InputMappingToPspButton(const InputMapping &mapping, std::vector<int> *pspB
}
bool InputMappingsFromPspButton(int btn, std::vector<MultiInputMapping> *mappings, bool ignoreMouse) {
auto iter = g_controllerMap.find(btn);
if (iter == g_controllerMap.end()) {
return false;
}
bool mapped = false;
for (auto iter = g_controllerMap.begin(); iter != g_controllerMap.end(); ++iter) {
if (iter->first == btn) {
for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) {
if (mappings && (!ignoreMouse || iter2->HasMouse())) {
mapped = true;
mappings->push_back(*iter2);
}
}
for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) {
if (mappings && (!ignoreMouse || iter2->HasMouse())) {
mapped = true;
mappings->push_back(*iter2);
}
}
return mapped;
}
bool PspButtonHasMappings(int btn) {
auto iter = g_controllerMap.find(btn);
if (iter == g_controllerMap.end()) {
return false;
}
return !iter->second.empty();
}
MappedAnalogAxes MappedAxesForDevice(int deviceId) {
MappedAnalogAxes result{};
@@ -605,6 +613,16 @@ bool ReplaceSingleKeyMapping(int btn, int index, MultiInputMapping key) {
return true;
}
void DeleteNthMapping(int key, int number) {
auto iter = g_controllerMap.find(key);
if (iter != g_controllerMap.end()) {
if (number < iter->second.size()) {
iter->second.erase(iter->second.begin() + number);
g_controllerMapGeneration++;
}
}
}
void SetInputMapping(int btn, const MultiInputMapping &key, bool replace) {
if (key.empty()) {
g_controllerMap.erase(btn);
@@ -717,6 +735,11 @@ void SaveToIni(IniFile &file) {
}
}
void ClearAllMappings() {
g_controllerMap.clear();
g_controllerMapGeneration++;
}
bool IsOuya(const std::string &name) {
return name == "OUYA:OUYA Console";
}