[Scummvm-git-logs] scummvm master -> 6b8f8f1233213adab12c3533d974a165dc75eb79
sev-
sev at scummvm.org
Thu Feb 11 23:41:35 UTC 2021
This automated email contains information about 17 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
2d6fdcaf3e COMMON: getVal no longer hides missing keys
cc51c9a483 COMMON: ConfMan no longer hides unknown key errors
8d1d570efb PETKA: Const correctness for getVal
c2f3ec18ab CRYOMNI: Use tryGetVal
5b10de7c8f CRYOMNI3D: Error instead of warn for missing image scripts
8f5ef19662 GRIM: Use getValOrDefault
a4e579936e MYST3: Let HashMap do the error
06cc82d493 SCI: Use getValOrDefault and tryGetVal
218f66d1e0 STARK: Use getValOrDefault
35ee057e0d WAGE: Use getValOrDefault
2300f0a7d4 MACGUI: Use getValOrDefault
2eb52fe900 COMMON: Retire dangerous non const operator[] on ConfMan
470505cc56 COMMON: ConfMan needs getValOrDefault
d6ad9f19cf BACKENDS: Keymapper needs getOrCreateVal
9b30f4a73d ENGIES: AdvDect needs getValOrDefault
0caeac64aa COMMON: Include the not found key in the error message
6b8f8f1233 GUI: Use tryGetVal for description
Commit: 2d6fdcaf3eb58a222517e22c5a3a0b4169cba574
https://github.com/scummvm/scummvm/commit/2d6fdcaf3eb58a222517e22c5a3a0b4169cba574
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
COMMON: getVal no longer hides missing keys
Changed paths:
common/hashmap.h
diff --git a/common/hashmap.h b/common/hashmap.h
index 31984dacfe..8e96dcd7da 100644
--- a/common/hashmap.h
+++ b/common/hashmap.h
@@ -244,9 +244,11 @@ public:
Val &operator[](const Key &key);
const Val &operator[](const Key &key) const;
+ Val &getOrCreateVal(const Key &key);
Val &getVal(const Key &key);
const Val &getVal(const Key &key) const;
- const Val &getVal(const Key &key, const Val &defaultVal) const;
+ const Val &getValOrDefault(const Key &key) const;
+ const Val &getValOrDefault(const Key &key, const Val &defaultVal) const;
bool tryGetVal(const Key &key, Val &out) const;
void setVal(const Key &key, const Val &val);
@@ -569,7 +571,7 @@ bool HashMap<Key, Val, HashFunc, EqualFunc>::contains(const Key &key) const {
template<class Key, class Val, class HashFunc, class EqualFunc>
Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator[](const Key &key) {
- return getVal(key);
+ return getOrCreateVal(key);
}
/**
@@ -586,7 +588,7 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator[](const Key &key) co
*/
template<class Key, class Val, class HashFunc, class EqualFunc>
-Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) {
+Val &HashMap<Key, Val, HashFunc, EqualFunc>::getOrCreateVal(const Key &key) {
size_type ctr = lookupAndCreateIfMissing(key);
assert(_storage[ctr] != nullptr);
return _storage[ctr]->_value;
@@ -596,9 +598,27 @@ Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) {
* @overload
*/
+template<class Key, class Val, class HashFunc, class EqualFunc>
+Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) {
+ size_type ctr = lookup(key);
+ if (_storage[ctr] != nullptr)
+ return _storage[ctr]->_value;
+ else
+ error("Unknown key");
+}
+
template<class Key, class Val, class HashFunc, class EqualFunc>
const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const {
- return getVal(key, _defaultVal);
+ size_type ctr = lookup(key);
+ if (_storage[ctr] != nullptr)
+ return _storage[ctr]->_value;
+ else
+ error("Unknown key");
+}
+
+template<class Key, class Val, class HashFunc, class EqualFunc>
+const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getValOrDefault(const Key &key) const {
+ return getValOrDefault(key, _defaultVal);
}
/**
@@ -606,7 +626,7 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const
*/
template<class Key, class Val, class HashFunc, class EqualFunc>
-const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key, const Val &defaultVal) const {
+const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getValOrDefault(const Key &key, const Val &defaultVal) const {
size_type ctr = lookup(key);
if (_storage[ctr] != nullptr)
return _storage[ctr]->_value;
Commit: cc51c9a483d0cd937ac20d05a267ed75bd8c66e0
https://github.com/scummvm/scummvm/commit/cc51c9a483d0cd937ac20d05a267ed75bd8c66e0
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
COMMON: ConfMan no longer hides unknown key errors
Changed paths:
common/config-manager.h
diff --git a/common/config-manager.h b/common/config-manager.h
index 7e201b4ca9..b4e094faf2 100644
--- a/common/config-manager.h
+++ b/common/config-manager.h
@@ -60,7 +60,7 @@ public:
private:
StringMap _entries;
StringMap _keyValueComments;
- String _domainComment;
+ String _domainComment;
public:
typedef StringMap::const_iterator const_iterator;
@@ -73,15 +73,16 @@ public:
/** Return the configuration value for the given key.
* If no entry exists for the given key in the configuration, it is created.
*/
- String &operator[](const String &key) { return _entries[key]; }
+ String &operator[](const String &key) { return _entries[key]; }
/** Return the configuration value for the given key.
* @note This function does *not* create a configuration entry
* for the given key if it does not exist.
*/
- const String &operator[](const String &key) const { return _entries[key]; }
+ const String &operator[](const String &key) const { return _entries[key]; }
void setVal(const String &key, const String &value) { _entries.setVal(key, value); } /*!< Assign a @p value to a @p key. */
+ String &getOrCreateVal(const String &key) { return _entries.getOrCreateVal(key); }
String &getVal(const String &key) { return _entries.getVal(key); } /*!< Retrieve the value of a @p key. */
const String &getVal(const String &key) const { return _entries.getVal(key); } /*!< @overload */
/**
@@ -89,7 +90,7 @@ public:
* @return True if the key exists, false otherwise.
* You can use this method if you frequently attempt to access keys that do not exist.
*/
- bool tryGetVal(const String &key, String &out) const { return _entries.tryGetVal(key, out); }
+ bool tryGetVal(const String &key, String &out) const { return _entries.tryGetVal(key, out); }
void clear() { _entries.clear(); } /*!< Clear all configuration entries in the domain. */
@@ -102,7 +103,7 @@ public:
const String &getKVComment(const String &key) const; /*!< Retrieve the key-value comment of a @p key. */
bool hasKVComment(const String &key) const; /*!< Check whether a @p key has a key-value comment. */
};
-
+
/** A hash map of existing configuration domains. */
typedef HashMap<String, Domain, IgnoreCase_Hash, IgnoreCase_EqualTo> DomainMap;
Commit: 8d1d570efb6cc547e50821549a93c1608d2a7b07
https://github.com/scummvm/scummvm/commit/8d1d570efb6cc547e50821549a93c1608d2a7b07
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
PETKA: Const correctness for getVal
Changed paths:
engines/petka/q_manager.cpp
diff --git a/engines/petka/q_manager.cpp b/engines/petka/q_manager.cpp
index f06ea45cb0..a02e91c387 100644
--- a/engines/petka/q_manager.cpp
+++ b/engines/petka/q_manager.cpp
@@ -90,7 +90,7 @@ void QManager::clearUnneeded() {
Graphics::Surface *QManager::getSurface(uint32 id, uint16 w, uint16 h) {
if (_resourceMap.contains(id)) {
- QResource &res = _resourceMap.getVal(id);
+ const QResource &res = _resourceMap.getVal(id);
return res.type == QResource::kSurface ? res.surface : nullptr;
}
@@ -109,7 +109,7 @@ Common::SeekableReadStream *QManager::loadFileStream(uint32 id) const {
Graphics::Surface *QManager::getSurface(uint32 id) {
if (_resourceMap.contains(id)) {
- QResource &res = _resourceMap.getVal(id);
+ const QResource &res = _resourceMap.getVal(id);
return res.type == QResource::kSurface ? res.surface : nullptr;
}
@@ -131,7 +131,7 @@ Graphics::Surface *QManager::getSurface(uint32 id) {
FlicDecoder *QManager::getFlic(uint32 id) {
if (_resourceMap.contains(id)) {
- QResource &res = _resourceMap.getVal(id);
+ const QResource &res = _resourceMap.getVal(id);
return res.type == QResource::kFlic ? res.flcDecoder : nullptr;
}
Commit: c2f3ec18abe76b4fc2167c143ce681278a868641
https://github.com/scummvm/scummvm/commit/c2f3ec18abe76b4fc2167c143ce681278a868641
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
CRYOMNI: Use tryGetVal
Changed paths:
engines/cryomni3d/font_manager.cpp
diff --git a/engines/cryomni3d/font_manager.cpp b/engines/cryomni3d/font_manager.cpp
index fffe3ff002..704198c617 100644
--- a/engines/cryomni3d/font_manager.cpp
+++ b/engines/cryomni3d/font_manager.cpp
@@ -70,8 +70,8 @@ void FontManager::loadFonts(const Common::Array<Common::String> &fontFiles,
for (Common::Array<Common::String>::const_iterator it = fontFiles.begin(); it != fontFiles.end();
it++) {
- Graphics::Font *fontEntry = fontsCache.getVal(*it, nullptr);
- if (fontEntry) {
+ Graphics::Font *fontEntry = nullptr;
+ if (fontsCache.tryGetVal(*it, fontEntry)) {
_fonts.push_back(fontEntry);
continue;
}
Commit: 5b10de7c8f71d810a44a4dcfae3f5ed349c8695b
https://github.com/scummvm/scummvm/commit/5b10de7c8f71d810a44a4dcfae3f5ed349c8695b
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
CRYOMNI3D: Error instead of warn for missing image scripts
Changed paths:
engines/cryomni3d/versailles/engine.cpp
diff --git a/engines/cryomni3d/versailles/engine.cpp b/engines/cryomni3d/versailles/engine.cpp
index 7e92414147..06496e1bab 100644
--- a/engines/cryomni3d/versailles/engine.cpp
+++ b/engines/cryomni3d/versailles/engine.cpp
@@ -1560,12 +1560,8 @@ void CryOmni3DEngine_Versailles::executeSeeAction(uint actionId) {
return;
}
- const FixedImgCallback cb = _imgScripts.getVal(actionId, nullptr);
- if (cb != nullptr) {
- handleFixedImg(cb);
- } else {
- warning("Image script %u not found", actionId);
- }
+ const FixedImgCallback cb = _imgScripts.getVal(actionId);
+ handleFixedImg(cb);
}
void CryOmni3DEngine_Versailles::executeSpeakAction(uint actionId) {
Commit: 8f5ef19662ffd54c452cf56971da24ec0d08e5d4
https://github.com/scummvm/scummvm/commit/8f5ef19662ffd54c452cf56971da24ec0d08e5d4
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
GRIM: Use getValOrDefault
Changed paths:
engines/grim/pool.h
diff --git a/engines/grim/pool.h b/engines/grim/pool.h
index ede5c59955..1d19e82fae 100644
--- a/engines/grim/pool.h
+++ b/engines/grim/pool.h
@@ -250,7 +250,7 @@ void PoolObject<T>::Pool::removeObject(int32 id) {
template <class T>
T *PoolObject<T>::Pool::getObject(int32 id) {
- return _map.getVal(id, NULL);
+ return _map.getValOrDefault(id, NULL);
}
template <class T>
Commit: a4e579936e71d4dce9810653d73f4e336876ba16
https://github.com/scummvm/scummvm/commit/a4e579936e71d4dce9810653d73f4e336876ba16
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
MYST3: Let HashMap do the error
Changed paths:
engines/myst3/database.cpp
diff --git a/engines/myst3/database.cpp b/engines/myst3/database.cpp
index 545bac38fc..8eb10af2d4 100644
--- a/engines/myst3/database.cpp
+++ b/engines/myst3/database.cpp
@@ -737,11 +737,7 @@ uint32 Database::getAgeLabelId(uint32 ageID) {
}
Common::String Database::getSoundName(uint32 id) {
- const Common::String result = _soundNames.getVal(id, "");
- if (result.empty())
- error("Unable to find a sound with id %d", id);
-
- return result;
+ return _soundNames.getVal(id);
}
void Database::loadAmbientCues(Common::ReadStream *s) {
Commit: 06cc82d493d1b50034141f6b4d4f274d94b5bfa1
https://github.com/scummvm/scummvm/commit/06cc82d493d1b50034141f6b4d4f274d94b5bfa1
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
SCI: Use getValOrDefault and tryGetVal
Changed paths:
engines/sci/engine/seg_manager.cpp
engines/sci/resource/resource.cpp
engines/sci/resource/resource_audio.cpp
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index fd6b86e405..9d3a504174 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -132,7 +132,7 @@ SegmentObj *SegManager::allocSegment(SegmentObj *mem, SegmentId *segid) {
Script *SegManager::allocateScript(int script_nr, SegmentId *segid) {
// Check if the script already has an allocated segment. If it
// does, return that segment.
- *segid = _scriptSegMap.getVal(script_nr, 0);
+ *segid = _scriptSegMap.getValOrDefault(script_nr, 0);
if (*segid > 0) {
return (Script *)_heap[*segid];
}
@@ -344,7 +344,7 @@ reg_t SegManager::findObjectByName(const Common::String &name, int index) {
// return the seg if script_id is valid and in the map, else 0
SegmentId SegManager::getScriptSegment(int script_id) const {
- return _scriptSegMap.getVal(script_id, 0);
+ return _scriptSegMap.getValOrDefault(script_id, 0);
}
SegmentId SegManager::getScriptSegment(int script_nr, ScriptLoadType load, bool applyScriptPatches) {
diff --git a/engines/sci/resource/resource.cpp b/engines/sci/resource/resource.cpp
index 2ab900d1bc..eb6d575390 100644
--- a/engines/sci/resource/resource.cpp
+++ b/engines/sci/resource/resource.cpp
@@ -626,7 +626,7 @@ void ResourceSource::loadResource(ResourceManager *resMan, Resource *res) {
}
Resource *ResourceManager::testResource(ResourceId id) {
- return _resMap.getVal(id, NULL);
+ return _resMap.getValOrDefault(id, NULL);
}
int ResourceManager::addAppropriateSources() {
@@ -1998,8 +1998,8 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map) {
return SCI_ERROR_NO_RESOURCE_FILES_FOUND;
}
- Resource *resource = _resMap.getVal(resId, NULL);
- if (!resource) {
+ Resource *resource = NULL;
+ if (!_resMap.tryGetVal(resId,resource)) {
addResource(resId, source, fileOffset, 0, map->getLocationName());
} else {
// If the resource is already present in a volume, change it to
@@ -2196,7 +2196,7 @@ Resource *ResourceManager::updateResource(ResourceId resId, ResourceSource *src,
Resource *ResourceManager::updateResource(ResourceId resId, ResourceSource *src, uint32 offset, uint32 size, const Common::String &sourceMapLocation) {
// Update a patched resource, whether it exists or not
- Resource *res = _resMap.getVal(resId, nullptr);
+ Resource *res = _resMap.getValOrDefault(resId, nullptr);
// When pulling from resource the "main" file may not even
// exist as both forks may be combined into MacBin
diff --git a/engines/sci/resource/resource_audio.cpp b/engines/sci/resource/resource_audio.cpp
index 7adbfa4d20..e142e816ad 100644
--- a/engines/sci/resource/resource_audio.cpp
+++ b/engines/sci/resource/resource_audio.cpp
@@ -363,9 +363,9 @@ int ResourceManager::readAudioMapSCI11(IntMapResourceSource *map) {
uint32 offset = 0;
const ResourceId mapResId(kResourceTypeMap, map->_mapNumber);
- Resource *mapRes = _resMap.getVal(mapResId, nullptr);
+ Resource *mapRes = nullptr;
- if (!mapRes) {
+ if (!_resMap.tryGetVal(mapResId,mapRes)) {
warning("Failed to open %s", mapResId.toString().c_str());
return SCI_ERROR_RESMAP_NOT_FOUND;
}
Commit: 218f66d1e0130959c7aa811e910c35138393189d
https://github.com/scummvm/scummvm/commit/218f66d1e0130959c7aa811e910c35138393189d
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
STARK: Use getValOrDefault
Changed paths:
engines/stark/resources/location.cpp
diff --git a/engines/stark/resources/location.cpp b/engines/stark/resources/location.cpp
index 1c4ae40cdd..6d8ffc9ef9 100644
--- a/engines/stark/resources/location.cpp
+++ b/engines/stark/resources/location.cpp
@@ -425,7 +425,7 @@ void Location::goToLayer(Layer *layer) {
}
ItemVisual *Location::getCharacterItem(int32 character) const {
- return _characterItemMap.getVal(character, nullptr);
+ return _characterItemMap.getValOrDefault(character, nullptr);
}
void Location::registerCharacterItem(int32 character, ItemVisual *item) {
Commit: 35ee057e0d600464874d87bb49f6c81f82b9833f
https://github.com/scummvm/scummvm/commit/35ee057e0d600464874d87bb49f6c81f82b9833f
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
WAGE: Use getValOrDefault
Changed paths:
engines/wage/randomhat.cpp
diff --git a/engines/wage/randomhat.cpp b/engines/wage/randomhat.cpp
index c108e3461d..5e721f12c8 100644
--- a/engines/wage/randomhat.cpp
+++ b/engines/wage/randomhat.cpp
@@ -53,7 +53,7 @@
namespace Wage {
void RandomHat::addTokens(int type, int count) {
- _tokens.setVal(type, _tokens.getVal(type, 0) + count);
+ _tokens.setVal(type, _tokens.getValOrDefault(type, 0) + count);
}
int RandomHat::countTokens() {
Commit: 2300f0a7d40969728ecebea6ec6cd85510851ecb
https://github.com/scummvm/scummvm/commit/2300f0a7d40969728ecebea6ec6cd85510851ecb
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
MACGUI: Use getValOrDefault
Changed paths:
graphics/macgui/macfontmanager.cpp
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 858b881ece..0f4ecd9012 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -156,7 +156,7 @@ void MacFontManager::loadFontsBDF() {
if (font->getFamilyName() && *font->getFamilyName()) {
fontName = Common::String::format("%s-%s-%d", font->getFamilyName(), font->getFontSlant(), font->getFontSize());
- macfont = new MacFont(_fontIds.getVal(font->getFamilyName(), kMacFontNonStandard), font->getFontSize(), parseFontSlant(font->getFontSlant()));
+ macfont = new MacFont(_fontIds.getValOrDefault(font->getFamilyName(), kMacFontNonStandard), font->getFontSize(), parseFontSlant(font->getFontSlant()));
} else { // Get it from the file name
fontName = (*it)->getName();
@@ -267,7 +267,7 @@ void MacFontManager::loadFonts(Common::MacResManager *fontFile) {
if (!fontstream) {
// The sfnt resource should be just a copy of a TTF
fontstream = fontFile->getResource(MKTAG('s', 'f', 'n', 't'), (*assoc)[i]._fontID);
- _ttfData[_fontIds.getVal(familyName, kMacFontNonStandard)] = fontstream;
+ _ttfData[_fontIds.getValOrDefault(familyName, kMacFontNonStandard)] = fontstream;
continue;
}
#endif
@@ -290,7 +290,7 @@ void MacFontManager::loadFonts(Common::MacResManager *fontFile) {
Common::String fontName = Common::String::format("%s-%d-%d", familyName.c_str(), (*assoc)[i]._fontStyle | familySlant, (*assoc)[i]._fontSize);
- macfont = new MacFont(_fontIds.getVal(familyName, kMacFontNonStandard), (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle | familySlant);
+ macfont = new MacFont(_fontIds.getValOrDefault(familyName, kMacFontNonStandard), (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle | familySlant);
FontMan.assignFontToName(fontName, font);
macfont->setFont(font, false);
Commit: 2eb52fe900740e6a886de7c7637035dfd086e578
https://github.com/scummvm/scummvm/commit/2eb52fe900740e6a886de7c7637035dfd086e578
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
COMMON: Retire dangerous non const operator[] on ConfMan
Changed paths:
base/commandLine.cpp
base/plugins.cpp
common/config-manager.cpp
common/config-manager.h
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index 479d3a5071..bde8c57a7c 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -1287,14 +1287,14 @@ void upgradeTargets() {
// the target referred to by dom. We update several things
// Always set the engine ID and game ID explicitly (in case of legacy targets)
- dom["engineid"] = g->engineId;
- dom["gameid"] = g->gameId;
+ dom.setVal("engineid", g->engineId);
+ dom.setVal("gameid", g->gameId);
// Always set the GUI options. The user should not modify them, and engines might
// gain more features over time, so we want to keep this list up-to-date.
if (!g->getGUIOptions().empty()) {
printf(" -> update guioptions to '%s'\n", g->getGUIOptions().c_str());
- dom["guioptions"] = g->getGUIOptions();
+ dom.setVal("guioptions", g->getGUIOptions());
} else if (dom.contains("guioptions")) {
dom.erase("guioptions");
}
@@ -1302,13 +1302,13 @@ void upgradeTargets() {
// Update the language setting but only if none has been set yet.
if (lang == Common::UNK_LANG && g->language != Common::UNK_LANG) {
printf(" -> set language to '%s'\n", Common::getLanguageCode(g->language));
- dom["language"] = Common::getLanguageCode(g->language);
+ dom.setVal("language", Common::getLanguageCode(g->language));
}
// Update the platform setting but only if none has been set yet.
if (plat == Common::kPlatformUnknown && g->platform != Common::kPlatformUnknown) {
printf(" -> set platform to '%s'\n", Common::getPlatformCode(g->platform));
- dom["platform"] = Common::getPlatformCode(g->platform);
+ dom.setVal("platform", Common::getPlatformCode(g->platform));
}
// TODO: We could also update the description. But not everybody will want that.
@@ -1318,7 +1318,7 @@ void upgradeTargets() {
#if 0
if (desc != g->description) {
printf(" -> update desc from '%s' to\n '%s' ?\n", desc.c_str(), g->description.c_str());
- dom["description"] = g->description;
+ dom.setVal("description", = g->description);
}
#endif
}
diff --git a/base/plugins.cpp b/base/plugins.cpp
index 184b80d4fd..936788f375 100644
--- a/base/plugins.cpp
+++ b/base/plugins.cpp
@@ -441,7 +441,7 @@ void PluginManagerUncached::updateConfigWithFileName(const Common::String &engin
Common::ConfigManager::Domain *domain = ConfMan.getDomain("engine_plugin_files");
assert(domain);
- (*domain)[engineId] = (*_currentPlugin)->getFileName();
+ (*domain).setVal(engineId, (*_currentPlugin)->getFileName());
ConfMan.flushToDisk();
}
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index 83d4aacdaa..3b118f655a 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -237,7 +237,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) {
value.trim();
// Finally, store the key/value pair in the active domain
- domain[key] = value;
+ domain.setVal(key, value);
// Store comment
domain.setKVComment(key, comment);
@@ -522,9 +522,9 @@ void ConfigManager::set(const String &key, const String &value) {
// Write the new key/value pair into the active domain, resp. into
// the application domain if no game domain is active.
if (_activeDomain)
- (*_activeDomain)[key] = value;
+ (*_activeDomain).setVal(key, value);
else
- _appDomain[key] = value;
+ _appDomain.setVal(key, value);
}
void ConfigManager::setAndFlush(const String &key, const Common::String &value) {
@@ -555,7 +555,7 @@ void ConfigManager::set(const String &key, const String &value, const String &do
error("ConfigManager::set(%s,%s,%s) called on non-existent domain",
key.c_str(), value.c_str(), domName.c_str());
- (*domain)[key] = value;
+ (*domain).setVal(key, value);
// TODO/FIXME: We used to erase the given key from the transient domain
// here. Do we still want to do that?
@@ -570,14 +570,14 @@ void ConfigManager::set(const String &key, const String &value, const String &do
// to replace it in a clean fashion...
#if 0
if (domName == kTransientDomain)
- _transientDomain[key] = value;
+ _transientDomain.setVal(key, value);
else {
if (domName == kApplicationDomain) {
- _appDomain[key] = value;
+ _appDomain.setVal(key, value;
if (_activeDomainName.empty() || !_gameDomains[_activeDomainName].contains(key))
_transientDomain.erase(key);
} else {
- _gameDomains[domName][key] = value;
+ _gameDomains[domName].setVal(key, value);
if (domName == _activeDomainName)
_transientDomain.erase(key);
}
@@ -598,7 +598,7 @@ void ConfigManager::setBool(const String &key, bool value, const String &domName
void ConfigManager::registerDefault(const String &key, const String &value) {
- _defaultsDomain[key] = value;
+ _defaultsDomain.setVal(key, value);
}
void ConfigManager::registerDefault(const String &key, const char *value) {
@@ -694,7 +694,7 @@ void ConfigManager::renameDomain(const String &oldName, const String &newName, D
Domain &newDom = map[newName];
Domain::const_iterator iter;
for (iter = oldDom.begin(); iter != oldDom.end(); ++iter)
- newDom[iter->_key] = iter->_value;
+ newDom.setVal(iter->_key, iter->_value);
map.erase(oldName);
}
diff --git a/common/config-manager.h b/common/config-manager.h
index b4e094faf2..b547638233 100644
--- a/common/config-manager.h
+++ b/common/config-manager.h
@@ -73,7 +73,6 @@ public:
/** Return the configuration value for the given key.
* If no entry exists for the given key in the configuration, it is created.
*/
- String &operator[](const String &key) { return _entries[key]; }
/** Return the configuration value for the given key.
* @note This function does *not* create a configuration entry
* for the given key if it does not exist.
Commit: 470505cc5658e53b87840463747ec6d608271ac0
https://github.com/scummvm/scummvm/commit/470505cc5658e53b87840463747ec6d608271ac0
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
COMMON: ConfMan needs getValOrDefault
Changed paths:
common/config-manager.cpp
common/config-manager.h
diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index 3b118f655a..28a0798a76 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -458,7 +458,7 @@ const String &ConfigManager::get(const String &key) const {
else if (_appDomain.contains(key))
return _appDomain[key];
- return _defaultsDomain.getVal(key);
+ return _defaultsDomain.getValOrDefault(key);
}
const String &ConfigManager::get(const String &key, const String &domName) const {
@@ -477,7 +477,7 @@ const String &ConfigManager::get(const String &key, const String &domName) const
if (domain->contains(key))
return (*domain)[key];
- return _defaultsDomain.getVal(key);
+ return _defaultsDomain.getValOrDefault(key);
}
int ConfigManager::getInt(const String &key, const String &domName) const {
diff --git a/common/config-manager.h b/common/config-manager.h
index b547638233..04a2629c13 100644
--- a/common/config-manager.h
+++ b/common/config-manager.h
@@ -89,6 +89,7 @@ public:
* @return True if the key exists, false otherwise.
* You can use this method if you frequently attempt to access keys that do not exist.
*/
+ const String &getValOrDefault(const String &key) const { return _entries.getValOrDefault(key); }
bool tryGetVal(const String &key, String &out) const { return _entries.tryGetVal(key, out); }
void clear() { _entries.clear(); } /*!< Clear all configuration entries in the domain. */
Commit: d6ad9f19cfec468e4751f5d892ec1bfd0b833783
https://github.com/scummvm/scummvm/commit/d6ad9f19cfec468e4751f5d892ec1bfd0b833783
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
BACKENDS: Keymapper needs getOrCreateVal
Changed paths:
backends/keymapper/keymap.cpp
diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp
index 665d5aafde..4f7e765429 100644
--- a/backends/keymapper/keymap.cpp
+++ b/backends/keymapper/keymap.cpp
@@ -68,7 +68,7 @@ void Keymap::addAction(Action *action) {
}
void Keymap::registerMapping(Action *action, const HardwareInput &hwInput) {
- ActionArray &actionArray = _hwActionMap.getVal(hwInput);
+ ActionArray &actionArray = _hwActionMap.getOrCreateVal(hwInput);
// Don't allow an input to map to the same action multiple times
ActionArray::const_iterator found = find(actionArray.begin(), actionArray.end(), action);
@@ -141,7 +141,7 @@ Keymap::KeymapMatch Keymap::getMappedActions(const Event &event, ActionArray &ac
case EVENT_KEYUP: {
KeyState normalizedKeystate = KeyboardHardwareInputSet::normalizeKeyState(event.kbd);
HardwareInput hardwareInput = HardwareInput::createKeyboard("", normalizedKeystate, U32String());
- actions.push_back(_hwActionMap[hardwareInput]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInput));
if (!actions.empty()) {
return kKeymapMatchExact;
}
@@ -162,7 +162,7 @@ Keymap::KeymapMatch Keymap::getMappedActions(const Event &event, ActionArray &ac
// Lastly check again for matches no non-sticky keyboard modifiers
normalizedKeystate.flags &= ~KBD_NON_STICKY;
hardwareInput = HardwareInput::createKeyboard("", normalizedKeystate, U32String());
- actions.push_back(_hwActionMap[hardwareInput]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInput));
return actions.empty() ? kKeymapMatchNone : kKeymapMatchPartial;
}
break;
@@ -170,47 +170,47 @@ Keymap::KeymapMatch Keymap::getMappedActions(const Event &event, ActionArray &ac
case EVENT_LBUTTONDOWN:
case EVENT_LBUTTONUP: {
HardwareInput hardwareInput = HardwareInput::createMouse("", MOUSE_BUTTON_LEFT, U32String());
- actions.push_back(_hwActionMap[hardwareInput]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInput));
break;
}
case EVENT_RBUTTONDOWN:
case EVENT_RBUTTONUP: {
HardwareInput hardwareInput = HardwareInput::createMouse("", MOUSE_BUTTON_RIGHT, U32String());
- actions.push_back(_hwActionMap[hardwareInput]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInput));
break;
}
case EVENT_MBUTTONDOWN:
case EVENT_MBUTTONUP: {
HardwareInput hardwareInput = HardwareInput::createMouse("", MOUSE_BUTTON_MIDDLE, U32String());
- actions.push_back(_hwActionMap[hardwareInput]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInput));
break;
}
case Common::EVENT_WHEELUP: {
HardwareInput hardwareInput = HardwareInput::createMouse("", MOUSE_WHEEL_UP, U32String());
- actions.push_back(_hwActionMap[hardwareInput]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInput));
break;
}
case Common::EVENT_WHEELDOWN: {
HardwareInput hardwareInput = HardwareInput::createMouse("", MOUSE_WHEEL_DOWN, U32String());
- actions.push_back(_hwActionMap[hardwareInput]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInput));
break;
}
case EVENT_X1BUTTONDOWN:
case EVENT_X1BUTTONUP: {
HardwareInput hardwareInput = HardwareInput::createMouse("", MOUSE_BUTTON_X1, U32String());
- actions.push_back(_hwActionMap[hardwareInput]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInput));
break;
}
case EVENT_X2BUTTONDOWN:
case EVENT_X2BUTTONUP: {
HardwareInput hardwareInput = HardwareInput::createMouse("", MOUSE_BUTTON_X2, U32String());
- actions.push_back(_hwActionMap[hardwareInput]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInput));
break;
}
case EVENT_JOYBUTTON_DOWN:
case EVENT_JOYBUTTON_UP: {
HardwareInput hardwareInput = HardwareInput::createJoystickButton("", event.joystick.button, U32String());
- actions.push_back(_hwActionMap[hardwareInput]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInput));
break;
}
case EVENT_JOYAXIS_MOTION: {
@@ -222,14 +222,14 @@ Keymap::KeymapMatch Keymap::getMappedActions(const Event &event, ActionArray &ac
// Axis position zero is part of both half axes, and triggers actions bound to both
HardwareInput hardwareInputPos = HardwareInput::createJoystickHalfAxis("", event.joystick.axis, true, U32String());
HardwareInput hardwareInputNeg = HardwareInput::createJoystickHalfAxis("", event.joystick.axis, false, U32String());
- actions.push_back(_hwActionMap[hardwareInputPos]);
- actions.push_back(_hwActionMap[hardwareInputNeg]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInputPos));
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInputNeg));
}
break;
}
case EVENT_CUSTOM_BACKEND_HARDWARE: {
HardwareInput hardwareInput = HardwareInput::createCustom("", event.customType, U32String());
- actions.push_back(_hwActionMap[hardwareInput]);
+ actions.push_back(_hwActionMap.getValOrDefault(hardwareInput));
break;
}
default:
Commit: 9b30f4a73de11a553f92e322eb47935242f1fd45
https://github.com/scummvm/scummvm/commit/9b30f4a73de11a553f92e322eb47935242f1fd45
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
ENGIES: AdvDect needs getValOrDefault
Changed paths:
engines/advancedDetector.cpp
diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp
index b4141e25a3..abfecf7aec 100644
--- a/engines/advancedDetector.cpp
+++ b/engines/advancedDetector.cpp
@@ -66,7 +66,7 @@ public:
}
Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const override {
- Common::FSNode fsNode = _fileMap[name];
+ Common::FSNode fsNode = _fileMap.getValOrDefault(name);
return fsNode.createReadStream();
}
Commit: 0caeac64aa2cd1bfc745069f7063ed7c19dbbfd2
https://github.com/scummvm/scummvm/commit/0caeac64aa2cd1bfc745069f7063ed7c19dbbfd2
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
COMMON: Include the not found key in the error message
Changed paths:
common/hashmap.cpp
common/hashmap.h
diff --git a/common/hashmap.cpp b/common/hashmap.cpp
index e9eac9fc94..ce03c6bdb5 100644
--- a/common/hashmap.cpp
+++ b/common/hashmap.cpp
@@ -52,6 +52,47 @@ uint hashit_lower(const char *p) {
return hash ^ size;
}
+
+template<> void unknownKeyError(::Common::String key) {
+ error("Unknown key \"%s\"", key.c_str());
+}
+
+template<> void unknownKeyError(signed char key) {
+ error("Unknown key \"%hhi\"", key);
+}
+
+template<> void unknownKeyError(unsigned char key) {
+ error("Unknown key \"%hhu\"", key);
+}
+
+template<> void unknownKeyError(short signed key) {
+ error("Unknown key \"%hi\"", key);
+}
+
+template<> void unknownKeyError(short unsigned key) {
+ error("Unknown key \"%hu\"", key);
+}
+
+template<> void unknownKeyError(long signed key) {
+ error("Unknown key \"%li\"", key);
+}
+
+template<> void unknownKeyError(long unsigned key) {
+ error("Unknown key \"%lu\"", key);
+}
+
+template<> void unknownKeyError(long long signed key) {
+ error("Unknown key \"%lli\"", key);
+}
+
+template<> void unknownKeyError(long long unsigned key) {
+ error("Unknown key \"%llu\"", key);
+}
+
+template<> void unknownKeyError(void *key) {
+ error("Unknown key \"%p\"", key);
+}
+
#ifdef DEBUG_HASH_COLLISIONS
static double
g_collisions = 0,
diff --git a/common/hashmap.h b/common/hashmap.h
index 8e96dcd7da..7d94adc2d2 100644
--- a/common/hashmap.h
+++ b/common/hashmap.h
@@ -42,6 +42,8 @@
#include "common/func.h"
+#include "common/str.h"
+
#ifdef DEBUG_HASH_COLLISIONS
#include "common/debug.h"
#endif
@@ -304,6 +306,32 @@ public:
}
};
+template <class Key>
+void NORETURN_PRE unknownKeyError(Key k) NORETURN_POST {
+ error("Unknown key");
+}
+
+template<>
+void NORETURN_PRE unknownKeyError(::Common::String key) NORETURN_POST;
+template<>
+void NORETURN_PRE unknownKeyError(signed char key) NORETURN_POST;
+template<>
+void NORETURN_PRE unknownKeyError(unsigned char key) NORETURN_POST;
+template<>
+void NORETURN_PRE unknownKeyError(short signed key) NORETURN_POST;
+template<>
+void NORETURN_PRE unknownKeyError(short unsigned key) NORETURN_POST;
+template<>
+void NORETURN_PRE unknownKeyError(long signed key) NORETURN_POST;
+template<>
+void NORETURN_PRE unknownKeyError(long unsigned key) NORETURN_POST;
+template<>
+void NORETURN_PRE unknownKeyError(long long signed key) NORETURN_POST;
+template<>
+void NORETURN_PRE unknownKeyError(long long unsigned key) NORETURN_POST;
+template<>
+void NORETURN_PRE unknownKeyError(void *key) NORETURN_POST;
+
//-------------------------------------------------------
// HashMap functions
@@ -604,7 +632,7 @@ Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) {
if (_storage[ctr] != nullptr)
return _storage[ctr]->_value;
else
- error("Unknown key");
+ unknownKeyError(key);
}
template<class Key, class Val, class HashFunc, class EqualFunc>
@@ -613,7 +641,7 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const
if (_storage[ctr] != nullptr)
return _storage[ctr]->_value;
else
- error("Unknown key");
+ unknownKeyError(key);
}
template<class Key, class Val, class HashFunc, class EqualFunc>
Commit: 6b8f8f1233213adab12c3533d974a165dc75eb79
https://github.com/scummvm/scummvm/commit/6b8f8f1233213adab12c3533d974a165dc75eb79
Author: Henrik "Henke37" Andersson (henke at henke37.cjb.net)
Date: 2021-02-12T00:41:23+01:00
Commit Message:
GUI: Use tryGetVal for description
Changed paths:
gui/launcher.cpp
diff --git a/gui/launcher.cpp b/gui/launcher.cpp
index 5d3448f6b8..865fff4695 100644
--- a/gui/launcher.cpp
+++ b/gui/launcher.cpp
@@ -283,9 +283,9 @@ void LauncherDialog::updateListing() {
// Turn it into a list of pointers
Common::List<LauncherEntry> domainList;
for (ConfigManager::DomainMap::const_iterator iter = domains.begin(); iter != domains.end(); ++iter) {
- String description(iter->_value.getVal("description"));
+ String description;
- if (description.empty()) {
+ if (!iter->_value.tryGetVal("description", description)) {
QualifiedGameDescriptor g = EngineMan.findTarget(iter->_key);
if (!g.description.empty())
description = g.description;
More information about the Scummvm-git-logs
mailing list