[Scummvm-git-logs] scummvm master -> ff5a1cb2ae6adf3097d56d37bb61e66a25c1639e
athrxx
noreply at scummvm.org
Tue Jun 28 21:59:53 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
ff5a1cb2ae KYRA: cleanup static resource loader
Commit: ff5a1cb2ae6adf3097d56d37bb61e66a25c1639e
https://github.com/scummvm/scummvm/commit/ff5a1cb2ae6adf3097d56d37bb61e66a25c1639e
Author: athrxx (athrxx at scummvm.org)
Date: 2022-06-28T23:59:38+02:00
Commit Message:
KYRA: cleanup static resource loader
(the latest changes were a bit on the ugly side)
Changed paths:
engines/kyra/graphics/screen.cpp
engines/kyra/resource/resource.h
engines/kyra/resource/staticres.cpp
diff --git a/engines/kyra/graphics/screen.cpp b/engines/kyra/graphics/screen.cpp
index d72852b8bc6..b8369f708e7 100644
--- a/engines/kyra/graphics/screen.cpp
+++ b/engines/kyra/graphics/screen.cpp
@@ -1391,7 +1391,7 @@ bool Screen::loadFont(FontId fontId, const char *filename) {
fa->push_back(fn1);
fa->push_back(fn2);
fnt = new MultiSubsetFont(fa);
- _vm->staticres()->renewPrefetchIdWithCustomLanguage(k2FontData, _vm->gameFlags().extraLang);
+ _vm->staticres()->setLanguage(_vm->gameFlags().extraLang, k2FontData);
const uint8 *oneByteData = _vm->staticres()->loadRawData(k2FontData, temp);
Common::MemoryReadStream str(oneByteData, temp);
fnt->load(str);
diff --git a/engines/kyra/resource/resource.h b/engines/kyra/resource/resource.h
index a7e8d23b1ee..11604872489 100644
--- a/engines/kyra/resource/resource.h
+++ b/engines/kyra/resource/resource.h
@@ -1275,15 +1275,18 @@ public:
const EoBCharacter *loadEoBNpcData(int id, int &entries);
#endif // ENABLE_EOB
+ // This sets up the internal resource mapping for the selected language. It should
+ // usually called with id '-1' so as to map all resources for the game, because the
+ // mapping is necessary to load a resource. Calling this will automatically unload
+ // the resource (all of them for id '-1').
+ bool setLanguage(Common::Language lang, int id = -1);
// use '-1' to prefetch/unload all ids
// prefetchId retruns false if only on of the resources
// can't be loaded and it breaks then the first res
// can't be loaded
bool prefetchId(int id);
- bool renewPrefetchIdWithCustomLanguage(int id, Common::Language lang);
void unloadId(int id);
private:
- bool tryKyraDatLoad();
Common::SeekableReadStream *loadIdMap(Common::Language lang);
KyraEngine_v1 *_vm;
diff --git a/engines/kyra/resource/staticres.cpp b/engines/kyra/resource/staticres.cpp
index acbeaed892b..8e6cfa07461 100644
--- a/engines/kyra/resource/staticres.cpp
+++ b/engines/kyra/resource/staticres.cpp
@@ -155,7 +155,7 @@ bool StaticResource::loadStaticResourceFile() {
if (!res->loadPakFile(staticDataFilename(), *i))
continue;
- if (tryKyraDatLoad()) {
+ if ((setLanguage(_vm->gameFlags().lang) && prefetchId(-1))) {
foundWorkingKyraDat = true;
break;
}
@@ -173,32 +173,6 @@ bool StaticResource::loadStaticResourceFile() {
return true;
}
-bool StaticResource::tryKyraDatLoad() {
- Common::SeekableReadStream *idMap = loadIdMap(_vm->gameFlags().lang);
- if (!idMap)
- return false;
-
- uint16 numIDs = idMap->readUint16BE();
- while (numIDs--) {
- uint16 id = idMap->readUint16BE();
- uint8 type = idMap->readByte();
- uint32 filename = idMap->readUint32BE();
-
- _dataTable[id] = DataDescriptor(filename, type);
- }
-
- const bool fileError = idMap->err();
- delete idMap;
- if (fileError)
- return false;
-
- // load all tables for now
- if (!prefetchId(-1))
- return false;
-
- return true;
-}
-
Common::SeekableReadStream *StaticResource::loadIdMap(Common::Language lang) {
Common::SeekableReadStream *index = _vm->resource()->createReadStream("INDEX");
if (!index)
@@ -334,6 +308,38 @@ const uint16 *StaticResource::loadRawDataBe16(int id, int &entries) {
return (const uint16 *)getData(id, kRawDataBe16, entries);
}
+bool StaticResource::setLanguage(Common::Language lang, int id) {
+ if (lang == Common::UNK_LANG)
+ lang = _vm->gameFlags().lang;
+
+ unloadId(id);
+
+ // load the ID map for our game
+ Common::SeekableReadStream *idMap = loadIdMap(lang);
+ if (!idMap)
+ return false;
+
+
+ int numIDs = idMap->readUint16BE();
+ while (numIDs--) {
+ uint16 id2 = idMap->readUint16BE();
+ uint8 type = idMap->readByte();
+ uint32 filename = idMap->readUint32BE();
+ if (id == -1 || id == id2) {
+ _dataTable[id2] = DataDescriptor(filename, type);
+ if (id == id2)
+ break;
+ }
+ }
+
+ const bool fileError = idMap->err();
+ delete idMap;
+ if (fileError || (id != -1 && numIDs == -1))
+ return false;
+
+ return true;
+}
+
bool StaticResource::prefetchId(int id) {
if (id == -1) {
for (DataMap::const_iterator i = _dataTable.begin(); i != _dataTable.end(); ++i) {
@@ -374,35 +380,6 @@ bool StaticResource::prefetchId(int id) {
return true;
}
-bool StaticResource::renewPrefetchIdWithCustomLanguage(int id, Common::Language lang) {
- if (lang != Common::UNK_LANG) {
- unloadId(id);
-
- // load the ID map for our game
- Common::SeekableReadStream *idMap = loadIdMap(lang);
- if (!idMap)
- return false;
-
- uint16 numIDs = idMap->readUint16BE();
- while (numIDs--) {
- uint16 id2 = idMap->readUint16BE();
- uint8 type = idMap->readByte();
- uint32 filename = idMap->readUint32BE();
- if (id2 != id)
- continue;
- _dataTable[id] = DataDescriptor(filename, type);
- break;
- }
-
- const bool fileError = idMap->err();
- delete idMap;
- if (!numIDs || fileError)
- return false;
- }
-
- return prefetchId(id);
-}
-
void StaticResource::unloadId(int id) {
Common::List<ResData>::iterator pos = _resList.begin();
for (; pos != _resList.end();) {
More information about the Scummvm-git-logs
mailing list