diff options
author | Simei Yin | 2018-05-28 21:55:06 +0200 |
---|---|---|
committer | Simei Yin | 2018-05-29 22:37:10 +0200 |
commit | 1ec5ef3e4df9ee3606bb4b3092fcf0d6f515563e (patch) | |
tree | 315932a77380517ca7121f9b70b31981a0329321 /engines | |
parent | 0548765479b69f2aaaf153e6370ed262a80c1d2d (diff) | |
download | scummvm-rg350-1ec5ef3e4df9ee3606bb4b3092fcf0d6f515563e.tar.gz scummvm-rg350-1ec5ef3e4df9ee3606bb4b3092fcf0d6f515563e.tar.bz2 scummvm-rg350-1ec5ef3e4df9ee3606bb4b3092fcf0d6f515563e.zip |
SLUDGE: Move resource names to ResourceManager
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sludge/fileset.cpp | 27 | ||||
-rw-r--r-- | engines/sludge/fileset.h | 8 | ||||
-rw-r--r-- | engines/sludge/newfatal.cpp | 19 | ||||
-rw-r--r-- | engines/sludge/newfatal.h | 1 | ||||
-rw-r--r-- | engines/sludge/sludger.cpp | 16 | ||||
-rw-r--r-- | engines/sludge/variable.cpp | 2 |
6 files changed, 42 insertions, 31 deletions
diff --git a/engines/sludge/fileset.cpp b/engines/sludge/fileset.cpp index fcdec32335..c9c3e7a43b 100644 --- a/engines/sludge/fileset.cpp +++ b/engines/sludge/fileset.cpp @@ -48,12 +48,14 @@ void ResourceManager::init() { _startOfSubIndex = 0; _startOfObjectIndex = 0; _startIndex = 0; + _allResourceNames.clear(); } void ResourceManager::kill() { if (_bigDataFile) { delete _bigDataFile; _bigDataFile = nullptr; } + _allResourceNames.clear(); } bool ResourceManager::openSubSlice(int num) { @@ -216,6 +218,31 @@ void ResourceManager::finishAccess() { _sliceBusy = false; } +void ResourceManager::readResourceNames(Common::SeekableReadStream *readStream) { + int numResourceNames = readStream->readUint16BE(); + debugC(2, kSludgeDebugDataLoad, "numResourceNames %i", numResourceNames); + _allResourceNames.reserve(numResourceNames); + + for (int fn = 0; fn < numResourceNames; fn++) { + _allResourceNames[fn].clear(); + _allResourceNames[fn] = readString(readStream); + debugC(2, kSludgeDebugDataLoad, "Resource %i: %s", fn, _allResourceNames[fn].c_str()); + } +} + +const Common::String ResourceManager::resourceNameFromNum(int i) { + if (i == -1) + return ""; + + if (_allResourceNames.empty()) + return "RESOURCE"; + + if (i < (int)_allResourceNames.size()) + return _allResourceNames[i]; + + return "Unknown resource"; +} + void ResourceManager::setData(Common::File *fp) { _bigDataFile = fp; _startIndex = fp->pos(); diff --git a/engines/sludge/fileset.h b/engines/sludge/fileset.h index 83200ceeb8..fb6a696f47 100644 --- a/engines/sludge/fileset.h +++ b/engines/sludge/fileset.h @@ -44,15 +44,23 @@ public: bool openObjectSlice(int num); Common::String getNumberedString(int value); + // Access control flag bool startAccess(); void finishAccess(); + // Resource names + void readResourceNames(Common::SeekableReadStream *readStream); + const Common::String resourceNameFromNum(int i); + bool hasResourceNames() { return !_allResourceNames.empty(); } + private: bool _sliceBusy; Common::File *_bigDataFile; uint32 _startOfDataIndex, _startOfTextIndex, _startOfSubIndex, _startOfObjectIndex; int32 _startIndex; + Common::Array<Common::String> _allResourceNames; + private: static uint32 _cp1250ToUTF32[128]; Common::String convertString(const Common::String &s); diff --git a/engines/sludge/newfatal.cpp b/engines/sludge/newfatal.cpp index 820b497e8e..a5069ae306 100644 --- a/engines/sludge/newfatal.cpp +++ b/engines/sludge/newfatal.cpp @@ -24,6 +24,7 @@ #include "sludge/allfiles.h" #include "sludge/errors.h" +#include "sludge/fileset.h" #include "sludge/newfatal.h" #include "sludge/sludge.h" #include "sludge/sound.h" @@ -35,9 +36,6 @@ DECLARE_SINGLETON(Sludge::FatalMsgManager); namespace Sludge { -extern int numResourceNames /* = 0*/; -extern Common::String *allResourceNames /*= ""*/; - int inFatal(const Common::String &str) { g_sludge->_soundMan->killSoundStuff(); error("%s", str.c_str()); @@ -73,8 +71,9 @@ void FatalMsgManager::setResourceForFatal(int n) { } int FatalMsgManager::fatal(const Common::String &str1) { - if (numResourceNames && _resourceForFatal != -1) { - Common::String r = resourceNameFromNum(_resourceForFatal); + ResourceManager *resMan = g_sludge->_resMan; + if (resMan->hasResourceNames() && _resourceForFatal != -1) { + Common::String r = resMan->resourceNameFromNum(_resourceForFatal); Common::String newStr = _fatalInfo + "\nResource: " + r + "\n\n" + str1; inFatal(newStr); } else { @@ -98,14 +97,4 @@ int fatal(const Common::String &str1, const Common::String &str2) { return 0; } -const Common::String resourceNameFromNum(int i) { - if (i == -1) - return NULL; - if (numResourceNames == 0) - return "RESOURCE"; - if (i < numResourceNames) - return allResourceNames[i]; - return "Unknown resource"; -} - } // End of namespace Sludge diff --git a/engines/sludge/newfatal.h b/engines/sludge/newfatal.h index 08a26db4e7..81ca4b7616 100644 --- a/engines/sludge/newfatal.h +++ b/engines/sludge/newfatal.h @@ -66,7 +66,6 @@ inline void setResourceForFatal(int n) { int checkNew(const void *mem); int fatal(const Common::String &str1, const Common::String &str2); -const Common::String resourceNameFromNum(int i); } // End of namespace Sludge diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp index cab0342c6d..f297ff12f5 100644 --- a/engines/sludge/sludger.cpp +++ b/engines/sludge/sludger.cpp @@ -60,8 +60,6 @@ extern Common::String *allBIFNames; extern int numUserFunc; extern Common::String *allUserFunc; -int numResourceNames = 0; -Common::String *allResourceNames = NULL; int selectedLanguage = 0; int gameVersion; @@ -206,19 +204,9 @@ bool initSludge(const Common::String &filename) { allUserFunc[fn].clear(); allUserFunc[fn] = readString(fp); } + if (gameVersion >= VERSION(1, 3)) { - numResourceNames = fp->readUint16BE(); - debugC(2, kSludgeDebugDataLoad, "numResourceNames %i", - numResourceNames); - allResourceNames = new Common::String[numResourceNames]; - if (!checkNew(allResourceNames)) - return false; - - for (int fn = 0; fn < numResourceNames; fn++) { - allResourceNames[fn].clear(); - allResourceNames[fn] = readString(fp); - debugC(2, kSludgeDebugDataLoad, "Resource %i: %s", fn, allResourceNames[fn].c_str()); - } + g_sludge->_resMan->readResourceNames(fp); } } diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index 5537377869..8ed2297008 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -303,7 +303,7 @@ Common::String getTextFromAnyVar(const Variable &from) { } case SVT_FILE: { - return resourceNameFromNum(from.varData.intValue); + return g_sludge->_resMan->resourceNameFromNum(from.varData.intValue); } case SVT_OBJTYPE: { |