diff --git a/src/cheat/CheatManager.cxx b/src/cheat/CheatManager.cxx index 3f4db3fb4..62834abb2 100644 --- a/src/cheat/CheatManager.cxx +++ b/src/cheat/CheatManager.cxx @@ -253,8 +253,8 @@ void CheatManager::saveCheatDatabase() return; stringstream out; - for(const auto& iter: myCheatMap) - out << "\"" << iter.first << "\" " << "\"" << iter.second << "\"" << endl; + for(const auto& [md5, cheat]: myCheatMap) + out << "\"" << md5 << "\" " << "\"" << cheat << "\"" << endl; try { myOSystem.cheatFile().write(out); } catch(...) { return; } diff --git a/src/common/HighScoresManager.cxx b/src/common/HighScoresManager.cxx index 9411d0a7a..7f281ae60 100644 --- a/src/common/HighScoresManager.cxx +++ b/src/common/HighScoresManager.cxx @@ -147,27 +147,6 @@ bool HighScoresManager::get(const Properties& props, uInt32& numVariationsR, info.scoreAddr = getPropScoreAddr(jprops); - //if(jprops.contains(SCORE_ADDRESSES)) - //{ - // const json addrProps = jprops.at(SCORE_ADDRESSES); - - // if(!addrProps.empty() && addrProps.is_array()) - // { - // int a = 0; - - // for(const json& addresses : addrProps) - // { - // const string address = addresses.get(); - - // if(address.empty()) - // info.scoreAddr[a++] = DEFAULT_ADDRESS; - // else - // info.scoreAddr[a++] = fromHexStr(address); - // } - - // } - //} - return enabled(); } @@ -286,10 +265,7 @@ const string HighScoresManager::notes(const json& jprops) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*bool HighScoresManager::armRAM(const json& jprops) const { - //string armRAM = getPropIdx(jprops, PropType::Cart_Formats, IDX_ARM_RAM); - - //return armRAM.empty() ? DEFAULT_ARM_RAM : armRAM != "0"; - return false; + return getPropStr(jprops, ARM_RAM); }*/ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -320,9 +296,8 @@ uInt32 HighScoresManager::numAddrBytes(const json& jprops) const Int32 HighScoresManager::numVariations() const { json jprops; - uInt16 vars = numVariations(properties(jprops)); - return vars;; + return numVariations(properties(jprops)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -584,7 +559,8 @@ Int32 HighScoresManager::fromBCD(uInt8 bcd) const return (bcd >> 4) * 10 + bcd % 16; } -const string HighScoresManager::VARIATIONS_COUNT = "variations_number"; +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +const string HighScoresManager::VARIATIONS_COUNT = "variations_count"; const string HighScoresManager::VARIATIONS_ADDRESS = "variations_address"; const string HighScoresManager::VARIATIONS_BCD = "variations_bcd"; const string HighScoresManager::VARIATIONS_ZERO_BASED = "variations_zero_based"; diff --git a/src/common/JoyMap.cxx b/src/common/JoyMap.cxx index db7ac6304..428c063c2 100644 --- a/src/common/JoyMap.cxx +++ b/src/common/JoyMap.cxx @@ -162,13 +162,13 @@ string JoyMap::getEventMappingDesc(int stick, const Event::Type event, const Eve { ostringstream buf; - for(auto item : myMap) + for (const auto& [_mapping, _event]: myMap) { - if(item.second == event && item.first.mode == mode) + if (_event == event && _mapping.mode == mode) { if(buf.str() != "") buf << ", "; - buf << "J" << stick << getDesc(event, item.first); + buf << "J" << stick << getDesc(event, _mapping); } } return buf.str(); @@ -179,9 +179,9 @@ JoyMap::JoyMappingArray JoyMap::getEventMapping(const Event::Type event, const E { JoyMappingArray map; - for(auto item : myMap) - if(item.second == event && item.first.mode == mode) - map.push_back(item.first); + for (const auto& [_mapping, _event]: myMap) + if (_event == event && _mapping.mode == mode) + map.push_back(_mapping); return map; } @@ -191,23 +191,23 @@ json JoyMap::saveMapping(const EventMode mode) const { json eventMappings = json::array(); - for(auto& item : myMap) { - if(item.first.mode != mode) continue; + for (const auto& [_mapping, _event]: myMap) { + if (_mapping.mode != mode) continue; json eventMapping = json::object(); - eventMapping["event"] = item.second; + eventMapping["event"] = _event; - if(item.first.button != JOY_CTRL_NONE) eventMapping["button"] = item.first.button; + if (_mapping.button != JOY_CTRL_NONE) eventMapping["button"] = _mapping.button; - if(item.first.axis != JoyAxis::NONE) { - eventMapping["axis"] = item.first.axis; - eventMapping["axisDirection"] = item.first.adir; + if (_mapping.axis != JoyAxis::NONE) { + eventMapping["axis"] = _mapping.axis; + eventMapping["axisDirection"] = _mapping.adir; } - if(item.first.hat != -1) { - eventMapping["hat"] = item.first.hat; - eventMapping["hatDirection"] = item.first.hdir; + if (_mapping.hat != -1) { + eventMapping["hat"] = _mapping.hat; + eventMapping["hatDirection"] = _mapping.hdir; } eventMappings.push_back(eventMapping); diff --git a/src/common/KeyMap.cxx b/src/common/KeyMap.cxx index c027827d6..76ee3b3cc 100644 --- a/src/common/KeyMap.cxx +++ b/src/common/KeyMap.cxx @@ -194,13 +194,13 @@ string KeyMap::getEventMappingDesc(const Event::Type event, const EventMode mode { ostringstream buf; - for(auto item : myMap) + for (const auto& [_mapping, _event]: myMap) { - if(item.second == event && item.first.mode == mode) + if (_event == event && _mapping.mode == mode) { if(buf.str() != "") buf << ", "; - buf << getDesc(item.first); + buf << getDesc(_mapping); } } return buf.str(); @@ -211,9 +211,9 @@ KeyMap::MappingArray KeyMap::getEventMapping(const Event::Type event, const Even { MappingArray map; - for(auto item : myMap) - if(item.second == event && item.first.mode == mode) - map.push_back(item.first); + for (const auto& [_mapping, _event]: myMap) + if (_event == event && _mapping.mode == mode) + map.push_back(_mapping); return map; } @@ -223,17 +223,16 @@ json KeyMap::saveMapping(const EventMode mode) const { json mappings = json::array(); - for(auto item : myMap) - { - if(item.first.mode != mode) continue; + for (const auto& [_mapping, _event]: myMap) { + if (_mapping.mode != mode) continue; json mapping = json::object(); - mapping["event"] = item.second; - mapping["key"] = item.first.key; + mapping["event"] = _event; + mapping["key"] = _mapping.key; - if(item.first.mod != StellaMod::KBDM_NONE) - mapping["mod"] = item.first.mod; + if (_mapping.mod != StellaMod::KBDM_NONE) + mapping["mod"] = serializeModkeyMask(_mapping.mod); mappings.push_back(mapping); } diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 3b41cf854..e0ebb55f1 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -122,8 +122,8 @@ int PhysicalJoystickHandler::add(const PhysicalJoystickPtr& stick) // For non-unique names that already have a database entry, // we append ' #x', where 'x' increases consecutively int count = 0; - for(const auto& i: myDatabase) - if(BSPF::startsWithIgnoreCase(i.first, stick->name) && i.second.joy) + for(const auto& [_name, _info]: myDatabase) + if(BSPF::startsWithIgnoreCase(_name, stick->name) && _info.joy) ++count; if(count > 0) @@ -223,39 +223,39 @@ void PhysicalJoystickHandler::mapStelladaptors(const string& saport) saOrder[0] = 2; saOrder[1] = 1; } - for(auto& stick: mySticks) + for(auto& [_id, _joyptr]: mySticks) { // remove previously added emulated ports - size_t pos = stick.second->name.find(" (emulates "); + size_t pos = _joyptr->name.find(" (emulates "); if(pos != std::string::npos) - stick.second->name.erase(pos); + _joyptr->name.erase(pos); - if(BSPF::startsWithIgnoreCase(stick.second->name, "Stelladaptor")) + if(BSPF::startsWithIgnoreCase(_joyptr->name, "Stelladaptor")) { if(saOrder[saCount] == 1) { - stick.second->name += " (emulates left joystick port)"; - stick.second->type = PhysicalJoystick::JT_STELLADAPTOR_LEFT; + _joyptr->name += " (emulates left joystick port)"; + _joyptr->type = PhysicalJoystick::JT_STELLADAPTOR_LEFT; } else if(saOrder[saCount] == 2) { - stick.second->name += " (emulates right joystick port)"; - stick.second->type = PhysicalJoystick::JT_STELLADAPTOR_RIGHT; + _joyptr->name += " (emulates right joystick port)"; + _joyptr->type = PhysicalJoystick::JT_STELLADAPTOR_RIGHT; } saCount++; } - else if(BSPF::startsWithIgnoreCase(stick.second->name, "2600-daptor")) + else if(BSPF::startsWithIgnoreCase(_joyptr->name, "2600-daptor")) { if(saOrder[saCount] == 1) { - stick.second->name += " (emulates left joystick port)"; - stick.second->type = PhysicalJoystick::JT_2600DAPTOR_LEFT; + _joyptr->name += " (emulates left joystick port)"; + _joyptr->type = PhysicalJoystick::JT_2600DAPTOR_LEFT; } else if(saOrder[saCount] == 2) { - stick.second->name += " (emulates right joystick port)"; - stick.second->type = PhysicalJoystick::JT_2600DAPTOR_RIGHT; + _joyptr->name += " (emulates right joystick port)"; + _joyptr->type = PhysicalJoystick::JT_2600DAPTOR_RIGHT; } saCount++; } @@ -354,8 +354,8 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, Event::Type even void PhysicalJoystickHandler::setDefaultMapping(Event::Type event, EventMode mode) { eraseMapping(event, mode); - for (auto& i : mySticks) - setStickDefaultMapping(i.first, event, mode); + for (const auto& [_id, _joyptr]: mySticks) + setStickDefaultMapping(_id, event, mode); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -529,24 +529,24 @@ void PhysicalJoystickHandler::eraseMapping(Event::Type event, EventMode mode) // Otherwise, only reset the given event if(event == Event::NoType) { - for (auto& stick : mySticks) + for (auto& [_id, _joyptr]: mySticks) { - stick.second->eraseMap(mode); // erase all events + _joyptr->eraseMap(mode); // erase all events if(mode == EventMode::kEmulationMode) { - stick.second->eraseMap(EventMode::kCommonMode); - stick.second->eraseMap(EventMode::kJoystickMode); - stick.second->eraseMap(EventMode::kPaddlesMode); - stick.second->eraseMap(EventMode::kKeypadMode); + _joyptr->eraseMap(EventMode::kCommonMode); + _joyptr->eraseMap(EventMode::kJoystickMode); + _joyptr->eraseMap(EventMode::kPaddlesMode); + _joyptr->eraseMap(EventMode::kKeypadMode); } } } else { - for (auto& stick : mySticks) + for (auto& [_id, _joyptr]: mySticks) { - stick.second->eraseEvent(event, mode); // only reset the specific event - stick.second->eraseEvent(event, getEventMode(event, mode)); + _joyptr->eraseEvent(event, mode); // only reset the specific event + _joyptr->eraseEvent(event, getEventMode(event, mode)); } } } @@ -558,9 +558,9 @@ void PhysicalJoystickHandler::saveMapping() // any changes that have been made during the program run json mapping = json::array(); - for(const auto& i: myDatabase) + for(const auto& [_name, _info]: myDatabase) { - json map = i.second.joy ? i.second.joy->getMap() : i.second.mapping; + json map = _info.joy ? _info.joy->getMap() : _info.mapping; if (!map.is_null()) mapping.emplace_back(map); } @@ -574,19 +574,16 @@ string PhysicalJoystickHandler::getMappingDesc(Event::Type event, EventMode mode ostringstream buf; EventMode evMode = getEventMode(event, mode); - for(const auto& s: mySticks) + for(const auto& [_id, _joyptr]: mySticks) { - uInt32 stick = s.first; - const PhysicalJoystickPtr j = s.second; - - if(j) + if(_joyptr) { //Joystick mapping / labeling - if(j->joyMap.getEventMapping(event, evMode).size()) + if(_joyptr->joyMap.getEventMapping(event, evMode).size()) { if(buf.str() != "") buf << ", "; - buf << j->joyMap.getEventMappingDesc(stick, event, evMode); + buf << _joyptr->joyMap.getEventMappingDesc(_id, event, evMode); } } } @@ -819,8 +816,8 @@ void PhysicalJoystickHandler::handleHatEvent(int stick, int hat, int value) VariantList PhysicalJoystickHandler::database() const { VariantList db; - for(const auto& i: myDatabase) - VarList::push_back(db, i.first, i.second.joy ? i.second.joy->ID : -1); + for(const auto& [_name, _info]: myDatabase) + VarList::push_back(db, _name, _info.joy ? _info.joy->ID : -1); return db; } @@ -830,13 +827,13 @@ ostream& operator<<(ostream& os, const PhysicalJoystickHandler& jh) { os << "---------------------------------------------------------" << endl << "joy database:" << endl; - for(const auto& i: jh.myDatabase) - os << i.first << endl << i.second << endl << endl; + for(const auto& [_name, _info]: jh.myDatabase) + os << _name << endl << _info << endl << endl; os << "---------------------" << endl << "joy active:" << endl; - for(const auto& i: jh.mySticks) - os << i.first << ": " << *i.second << endl; + for(const auto& [_id, _joyptr]: jh.mySticks) + os << _id << ": " << *_joyptr << endl; os << "---------------------------------------------------------" << endl << endl << endl; diff --git a/src/common/main.cxx b/src/common/main.cxx index dddae47bd..9ba6862d2 100644 --- a/src/common/main.cxx +++ b/src/common/main.cxx @@ -123,11 +123,11 @@ void parseCommandLine(int ac, char* av[], #if 0 cout << "Global opts:" << endl; - for(const auto& x: globalOpts) - cout << " -> " << x.first << ": " << x.second << endl; + for(const auto& [key, value]: globalOpts) + cout << " -> " << key << ": " << value << endl; cout << "Local opts:" << endl; - for(const auto& x: localOpts) - cout << " -> " << x.first << ": " << x.second << endl; + for(const auto& [key, value]: localOpts) + cout << " -> " << key << ": " << value << endl; #endif } diff --git a/src/common/repository/KeyValueRepositoryConfigfile.cxx b/src/common/repository/KeyValueRepositoryConfigfile.cxx index 44a840b81..ca9f6b3a4 100644 --- a/src/common/repository/KeyValueRepositoryConfigfile.cxx +++ b/src/common/repository/KeyValueRepositoryConfigfile.cxx @@ -100,8 +100,8 @@ void KeyValueRepositoryConfigfile::save(const std::map& values) << ";" << endl; // Write out each of the key and value pairs - for(const auto& pair: values) - out << pair.first << " = " << pair.second << endl; + for(const auto& [key, value]: values) + out << key << " = " << value << endl; try { diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index cd631bc7e..d6f87b15d 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -635,9 +635,9 @@ string DebuggerParser::saveScriptFile(string file) stringstream out; Debugger::FunctionDefMap funcs = debugger.getFunctionDefMap(); - for(const auto& f: funcs) - if (!debugger.isBuiltinFunction(f.first)) - out << "function " << f.first << " {" << f.second << "}" << endl; + for(const auto& [name, cmd]: funcs) + if (!debugger.isBuiltinFunction(name)) + out << "function " << name << " {" << cmd << "}" << endl; for(const auto& w: myWatches) out << "watch " << w << endl; @@ -1526,10 +1526,8 @@ void DebuggerParser::executeListfunctions() const Debugger::FunctionDefMap& functions = debugger.getFunctionDefMap(); if(functions.size() > 0) - { - for(const auto& iter: functions) - commandResult << iter.first << " -> " << iter.second << endl; - } + for(const auto& [name, cmd]: functions) + commandResult << name << " -> " << cmd << endl; else commandResult << "no user-defined functions"; } diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index 70e795bdf..b21c709fc 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -253,7 +253,7 @@ void Settings::setRepository(shared_ptr repository) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Settings::load(const Options& options) { - Options fromFile = myRespository->load(); + Options fromFile = myRespository->load(); for (const auto& opt: fromFile) setValue(opt.first, opt.second, false); diff --git a/src/gui/ContextMenu.cxx b/src/gui/ContextMenu.cxx index ae1ee09be..125923d83 100644 --- a/src/gui/ContextMenu.cxx +++ b/src/gui/ContextMenu.cxx @@ -123,27 +123,25 @@ void ContextMenu::setSelectedIndex(int idx) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ContextMenu::setSelected(const Variant& tag, const Variant& defaultTag) { - if(tag != "") // indicates that the defaultTag should be used instead + auto SEARCH_AND_SELECT = [&](const Variant& t) { for(uInt32 item = 0; item < _entries.size(); ++item) { - if(BSPF::equalsIgnoreCase(_entries[item].second.toString(), tag.toString())) + if(BSPF::equalsIgnoreCase(_entries[item].second.toString(), t.toString())) { setSelectedIndex(item); - return; + return true; } } - } + return false; + }; - // If we get this far, the value wasn't found; use the default value - for(uInt32 item = 0; item < _entries.size(); ++item) - { - if(BSPF::equalsIgnoreCase(_entries[item].second.toString(), defaultTag.toString())) - { - setSelectedIndex(item); - return; - } - } + // First try searching for a valid tag + bool tagSelected = tag != "" && SEARCH_AND_SELECT(tag); + + // Otherwise use the default tag + if(!tagSelected) + SEARCH_AND_SELECT(defaultTag); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/HighScoresDialog.cxx b/src/gui/HighScoresDialog.cxx index 6007713ad..ab838ac1c 100644 --- a/src/gui/HighScoresDialog.cxx +++ b/src/gui/HighScoresDialog.cxx @@ -416,6 +416,7 @@ void HighScoresDialog::updateWidgets(bool init) } } _defaultWidget->setEnabled(myHighScores[0] > 0); + setDirty(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -481,6 +482,7 @@ void HighScoresDialog::deleteRank(int rank) myHighScoreRank--; myEditRank--; myEditNameWidgets[myEditRank]->setText(myEditNameWidgets[myEditRank + 1]->getText()); + setDirty(); } myDirty = true; } diff --git a/src/gui/JoystickDialog.cxx b/src/gui/JoystickDialog.cxx index 218179e72..0073fb2ae 100644 --- a/src/gui/JoystickDialog.cxx +++ b/src/gui/JoystickDialog.cxx @@ -80,10 +80,10 @@ void JoystickDialog::loadConfig() myJoyIDs.clear(); StringList sticks; - for(const auto& i: instance().eventHandler().physicalJoystickDatabase()) + for(const auto& [_name, _id]: instance().eventHandler().physicalJoystickDatabase()) { - sticks.push_back(i.first); - myJoyIDs.push_back(i.second.toInt()); + sticks.push_back(_name); + myJoyIDs.push_back(_id.toInt()); } myJoyList->setList(sticks); myJoyList->setSelected(0);