[Scummvm-git-logs] scummvm master -> 4fc6cef968fbf3dc12a6f60611689938dc76da8e
yinsimei
roseline.yin at gmail.com
Tue Jul 18 19:05:31 CEST 2017
This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
4c4690a1e3 SLUDGE: Update ZBuffer with changed backdrop
5d554d36ed SLUDGE: Objectify Timing
70c965a1c4 SLUDGE: Remove special settings
798ec60f54 SLUDGE: Objectify language manager
4fc6cef968 SLUDGE: Objectify resource manager
Commit: 4c4690a1e35eda0041a4ee81ab6f89c56ff96981
https://github.com/scummvm/scummvm/commit/4c4690a1e35eda0041a4ee81ab6f89c56ff96981
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-07-18T19:05:04+02:00
Commit Message:
SLUDGE: Update ZBuffer with changed backdrop
Changed paths:
engines/sludge/sprites.cpp
diff --git a/engines/sludge/sprites.cpp b/engines/sludge/sprites.cpp
index c0fe9e3..39bb652 100644
--- a/engines/sludge/sprites.cpp
+++ b/engines/sludge/sprites.cpp
@@ -305,6 +305,11 @@ void pasteSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &
Graphics::TransparentSurface tmp(single.surface, false);
tmp.blit(backdropSurface, x1, y1, Graphics::FLIP_NONE, nullptr,
TS_RGB(fontPal.originalRed, fontPal.originalGreen, fontPal.originalBlue));
+
+ // reset zBuffer with the new backdrop
+ if (zBuffer.numPanels) {
+ setZBuffer(zBuffer.originalNum);
+ }
}
// burnSpriteToBackDrop adds text in the colour specified by setBurnColour
@@ -316,6 +321,11 @@ void burnSpriteToBackDrop(int x1, int y1, sprite &single, const spritePalette &f
Graphics::TransparentSurface tmp(single.surface, false);
tmp.blit(backdropSurface, x1, y1, Graphics::FLIP_NONE, nullptr,
TS_RGB(currentBurnR, currentBurnG, currentBurnB));
+
+ // reset zBuffer with the new backdrop
+ if (zBuffer.numPanels) {
+ setZBuffer(zBuffer.originalNum);
+ }
}
void fontSprite(bool flip, int x, int y, sprite &single, const spritePalette &fontPal) {
Commit: 5d554d36edff3b2cc03e72625f707208f5d54a3c
https://github.com/scummvm/scummvm/commit/5d554d36edff3b2cc03e72625f707208f5d54a3c
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-07-18T19:05:04+02:00
Commit Message:
SLUDGE: Objectify Timing
Changed paths:
engines/sludge/main_loop.cpp
engines/sludge/sludge.h
engines/sludge/sludger.cpp
engines/sludge/timing.cpp
engines/sludge/timing.h
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index d2dcd8e..29bbcd0 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -188,7 +188,7 @@ int main_loop(const char *filename)
startNewFunctionNum(0, 0, NULL, noStack);
- Init_Timer();
+ g_sludge->_timer.init();
weAreDoneSoQuit = 0;
while (!weAreDoneSoQuit) {
@@ -197,7 +197,7 @@ int main_loop(const char *filename)
handleInput();
sludgeDisplay();
handleSoundLists();
- Wait_Frame();
+ g_sludge->_timer.waitFrame();
}
killSoundStuff();
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index e419b85..556dc94 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -29,6 +29,7 @@
#include "gui/debugger.h"
#include "sludge/console.h"
+#include "sludge/timing.h"
namespace Sludge {
@@ -62,6 +63,9 @@ public:
Common::String fatalMessage;
Common::String fatalInfo;
+ // timer
+ Timer _timer;
+
SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
virtual ~SludgeEngine();
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index e577102..aed5fab 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -71,7 +71,6 @@ int languageNum = -1;
int gameVersion;
int specialSettings;
FILETIME fileTime;
-extern int desiredfps;
bool captureAllKeys = false;
byte brightnessLevel = 255;
@@ -221,7 +220,7 @@ bool initSludge(const Common::String &filename) {
debug(kSludgeDebugDataLoad, "winHeight : %i", winHeight);
specialSettings = fp->readByte();
debug(kSludgeDebugDataLoad, "specialSettings : %i", specialSettings);
- desiredfps = 1000 / fp->readByte();
+ g_sludge->_timer.setDesiredfps(1000 / fp->readByte());
readString(fp); // Unused - was used for registration purposes.
diff --git a/engines/sludge/timing.cpp b/engines/sludge/timing.cpp
index 2e83e1d..2e38654 100644
--- a/engines/sludge/timing.cpp
+++ b/engines/sludge/timing.cpp
@@ -25,36 +25,31 @@
namespace Sludge {
-int desiredfps = 300; //holds desired frames per second
-
-uint32 starttime, endtime;
-uint32 desired_frame_time;
-
-void Init_Timer(void) {
- desired_frame_time = 1000 / desiredfps;
- starttime = g_system->getMillis();
+void Timer::init(void) {
+ _desired_frame_time = 1000 / _desiredfps;
+ _starttime = g_system->getMillis();
}
-void Init_Special_Timer(int t) {
- desired_frame_time = 1000 / t;
- starttime = g_system->getMillis();
+void Timer::initSpecial(int t) {
+ _desired_frame_time = 1000 / t;
+ _starttime = g_system->getMillis();
}
-void Wait_Frame(void) {
+void Timer::waitFrame(void) {
static uint32 addNextTime = 0;
uint32 timetaken;
for (;;) {
- endtime = g_system->getMillis();
- timetaken = addNextTime + endtime - starttime;
- if (timetaken >= desired_frame_time) break;
+ _endtime = g_system->getMillis();
+ timetaken = addNextTime + _endtime - _starttime;
+ if (timetaken >= _desired_frame_time) break;
g_system->delayMillis(1);
}
- addNextTime = timetaken - desired_frame_time;
- if (addNextTime > desired_frame_time) addNextTime = desired_frame_time;
+ addNextTime = timetaken - _desired_frame_time;
+ if (addNextTime > _desired_frame_time) addNextTime = _desired_frame_time;
- starttime = endtime;
+ _starttime = _endtime;
}
} // End of namespace Sludge
diff --git a/engines/sludge/timing.h b/engines/sludge/timing.h
index 16f406b..0d7ffec 100644
--- a/engines/sludge/timing.h
+++ b/engines/sludge/timing.h
@@ -24,11 +24,20 @@
namespace Sludge {
-void Init_Timer(void);
-void Init_Special_Timer(int t);
-void Get_Start_Time(void);
-void Get_End_Time(void);
-void Wait_Frame(void);
+class Timer {
+private:
+ int _desiredfps; // desired frames per second
+ uint32 _starttime, _endtime;
+ uint32 _desired_frame_time;
+
+public:
+ void setDesiredfps(int t) { _desiredfps = t; }
+ void init(void);
+ void initSpecial(int t);
+ void waitFrame(void);
+
+ Timer():_desiredfps(300), _starttime(0), _endtime(0), _desired_frame_time(0){}
+};
} // End of namespace Sludge
Commit: 70c965a1c41a7eca454371f710288e4b5bd55947
https://github.com/scummvm/scummvm/commit/70c965a1c41a7eca454371f710288e4b5bd55947
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-07-18T19:05:04+02:00
Commit Message:
SLUDGE: Remove special settings
Changed paths:
R engines/sludge/specialsettings.h
engines/sludge/main_loop.cpp
engines/sludge/movie.cpp
engines/sludge/sludger.cpp
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index 29bbcd0..78ce63b 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "common/config-manager.h"
#include "common/debug.h"
#include "common/events.h"
#include "common/keyboard.h"
@@ -45,7 +46,6 @@
#include "sludge/sludger.h"
#include "sludge/helpers.h"
#include "sludge/sludge.h"
-#include "sludge/specialsettings.h"
namespace Sludge {
@@ -58,7 +58,6 @@ HWND hMainWindow = NULL;
int realWinWidth = 640, realWinHeight = 480;
extern float cameraZoom;
-extern int specialSettings;
extern inputType input;
extern variableStack *noStack;
Graphics::Surface renderSurface;
@@ -182,7 +181,7 @@ int main_loop(const char *filename)
g_sludge->gameName = getNumberedString(1);
- if (!(specialSettings & SPECIAL_SILENT)) {
+ if (!ConfMan.hasKey("mute") || !ConfMan.getBool("mute")) {
initSoundStuff(hMainWindow);
}
diff --git a/engines/sludge/movie.cpp b/engines/sludge/movie.cpp
index 49a6919..65b6030 100644
--- a/engines/sludge/movie.cpp
+++ b/engines/sludge/movie.cpp
@@ -20,8 +20,6 @@
*
*/
-#include "sludge/specialsettings.h"
-
#include "sludge/newfatal.h"
#include "sludge/timing.h"
#include "sludge/movie.h"
@@ -29,8 +27,6 @@
namespace Sludge {
-extern int specialSettings;
-
// in main.c
int checkInput();
extern int weAreDoneSoQuit;
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index aed5fab..e2b5e47 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -47,7 +47,6 @@
#include "sludge/language.h"
#include "sludge/variable.h"
#include "sludge/sludge.h"
-#include "sludge/specialsettings.h"
#include "sludge/version.h"
#include "sludge/imgloader.h"
@@ -69,7 +68,6 @@ int selectedLanguage = 0;
int languageNum = -1;
int gameVersion;
-int specialSettings;
FILETIME fileTime;
bool captureAllKeys = false;
@@ -218,7 +216,7 @@ bool initSludge(const Common::String &filename) {
debug(kSludgeDebugDataLoad, "winWidth : %i", winWidth);
winHeight = fp->readUint16BE();
debug(kSludgeDebugDataLoad, "winHeight : %i", winHeight);
- specialSettings = fp->readByte();
+ int specialSettings = fp->readByte();
debug(kSludgeDebugDataLoad, "specialSettings : %i", specialSettings);
g_sludge->_timer.setDesiredfps(1000 / fp->readByte());
diff --git a/engines/sludge/specialsettings.h b/engines/sludge/specialsettings.h
deleted file mode 100644
index adcecec..0000000
--- a/engines/sludge/specialsettings.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-#define SPECIAL_REGISTERED 1
-#define SPECIAL_FULLSCREEN 2
-#define SPECIAL_MOUSE_1 4
-#define SPECIAL_SILENT 8
-#define SPECIAL_MOUSE_2 16
-#define SPECIAL_INVISIBLE 32
-#define SPECIAL_HIDELOGO 64
-#define SPECIAL_HIDELOADING 128
Commit: 798ec60f54064a6a7f5750ab792d06666f9ce8ea
https://github.com/scummvm/scummvm/commit/798ec60f54064a6a7f5750ab792d06666f9ce8ea
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-07-18T19:05:04+02:00
Commit Message:
SLUDGE: Objectify language manager
Changed paths:
engines/sludge/builtin.cpp
engines/sludge/fileset.cpp
engines/sludge/fileset.h
engines/sludge/language.cpp
engines/sludge/language.h
engines/sludge/loadsave.cpp
engines/sludge/sludge.cpp
engines/sludge/sludge.h
engines/sludge/sludger.cpp
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 0d295af..8358938 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -2438,7 +2438,7 @@ builtIn(getCharacterScale) {
builtIn(getLanguageID) {
UNUSEDALL
- setVariable(fun->reg, SVT_INT, gameSettings.languageID);
+ setVariable(fun->reg, SVT_INT, g_sludge->getLanguageID());
return BR_CONTINUE;
}
diff --git a/engines/sludge/fileset.cpp b/engines/sludge/fileset.cpp
index daec8bd..4920662 100644
--- a/engines/sludge/fileset.cpp
+++ b/engines/sludge/fileset.cpp
@@ -169,16 +169,13 @@ void finishAccess() {
int32 startIndex;
-void setFileIndices(Common::File *fp, uint numLanguages, uint skipBefore) {
- if (fp) {
- // Keep hold of the file handle, and let things get at it
- bigDataFile = fp;
- startIndex = fp->pos();
- } else {
- // No file pointer - this means that we reuse the bigDataFile
- fp = bigDataFile;
- fp->seek(startIndex, SEEK_SET);
- }
+void setBigDataFile(Common::File *fp) {
+ bigDataFile = fp;
+ startIndex = fp->pos();
+}
+
+void setFileIndices(uint numLanguages, uint skipBefore) {
+ bigDataFile->seek(startIndex, SEEK_SET);
sliceBusy = false;
if (skipBefore > numLanguages) {
@@ -189,29 +186,29 @@ void setFileIndices(Common::File *fp, uint numLanguages, uint skipBefore) {
// STRINGS
int skipAfter = numLanguages - skipBefore;
while (skipBefore) {
- fp->seek(fp->readUint32LE(), SEEK_SET);
+ bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_SET);
skipBefore--;
}
- startOfTextIndex = fp->pos() + 4;
+ startOfTextIndex = bigDataFile->pos() + 4;
debug(kSludgeDebugDataLoad, "startOfTextIndex: %i", startOfTextIndex);
- fp->seek(fp->readUint32LE(), SEEK_SET);
+ bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_SET);
while (skipAfter) {
- fp->seek(fp->readUint32LE(), SEEK_SET);
+ bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_SET);
skipAfter--;
}
- startOfSubIndex = fp->pos() + 4;
- fp->seek(fp->readUint32LE(), SEEK_CUR);
+ startOfSubIndex = bigDataFile->pos() + 4;
+ bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_CUR);
debug(kSludgeDebugDataLoad, "startOfSubIndex: %i", startOfSubIndex);
- startOfObjectIndex = fp->pos() + 4;
- fp->seek(fp->readUint32LE(), SEEK_CUR);
+ startOfObjectIndex = bigDataFile->pos() + 4;
+ bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_CUR);
debug(kSludgeDebugDataLoad, "startOfObjectIndex: %i", startOfObjectIndex);
// Remember that the data section starts here
- startOfDataIndex = fp->pos();
+ startOfDataIndex = bigDataFile->pos();
debug(kSludgeDebugDataLoad, "startOfDataIndex: %i", startOfDataIndex);
}
diff --git a/engines/sludge/fileset.h b/engines/sludge/fileset.h
index 3e9385d..fe2293d 100644
--- a/engines/sludge/fileset.h
+++ b/engines/sludge/fileset.h
@@ -28,7 +28,8 @@ namespace Sludge {
extern Common::File *bigDataFile;
-void setFileIndices(Common::File *fp, uint, uint);
+void setBigDataFile(Common::File *readStream);
+void setFileIndices(uint, uint);
uint openFileFromNum(int num);
bool openSubSlice(int num);
diff --git a/engines/sludge/language.cpp b/engines/sludge/language.cpp
index c1917ad..52c1dc8 100644
--- a/engines/sludge/language.cpp
+++ b/engines/sludge/language.cpp
@@ -23,6 +23,7 @@
#include "common/debug.h"
#include "sludge/allfiles.h"
+#include "sludge/fileset.h"
#include "sludge/newfatal.h"
#include "sludge/moreio.h"
#include "sludge/language.h"
@@ -31,40 +32,80 @@
namespace Sludge {
-uint *languageTable;
-Common::String *languageName;
-settingsStruct gameSettings;
+LanguageManager::~LanguageManager() {
+ if (_languageTable) {
+ delete []_languageTable;
+ _languageTable = NULL;
+ }
+
+ if (_languageNames) {
+ delete []_languageNames;
+ _languageNames = NULL;
+ }
+}
-void makeLanguageTable(Common::File *table) {
- languageTable = new uint[gameSettings.numLanguages + 1];
- if (!checkNew(languageTable))
+void LanguageManager::init(Common::File *fp) {
+ // get number of languages
+ _numLanguages =
+ (gameVersion >= VERSION(1, 3)) ? (fp->readByte()) : 0;
+ debug(kSludgeDebugDataLoad, "numLanguages : %c", _numLanguages);
+
+ // make language table
+ _languageTable = new uint[_numLanguages + 1];
+ if (!checkNew(_languageTable))
return;
- languageName = new Common::String[gameSettings.numLanguages + 1];
- if (!checkNew(languageName))
+ _languageNames = new Common::String[_numLanguages + 1];
+ if (!checkNew(_languageNames))
return;
- for (uint i = 0; i <= gameSettings.numLanguages; i++) {
- languageTable[i] = i ? table->readUint16BE() : 0;
- debug(kSludgeDebugDataLoad, "languageTable %i: %i", i, languageTable[i]);
- languageName[i].clear();
+ for (uint i = 0; i <= _numLanguages; i++) {
+ _languageTable[i] = i ? fp->readUint16BE() : 0;
+ debug(kSludgeDebugDataLoad, "languageTable %i: %i", i, _languageTable[i]);
+ _languageNames[i].clear();
if (gameVersion >= VERSION(2, 0)) {
- if (gameSettings.numLanguages) {
- languageName[i] = readString(table);
- debug(kSludgeDebugDataLoad, "languageName %i: %s\n", i, languageName[i].c_str());
+ if (_numLanguages) {
+ _languageNames[i] = readString(fp);
+ debug(kSludgeDebugDataLoad, "languageName %i: %s\n", i, _languageNames[i].c_str());
}
}
}
}
-int getLanguageForFileB() {
- int indexNum = -1;
+void LanguageManager::setLanguageID(uint id) {
+ _languageID = id;
+ // get index of language
+ setLanguageIndex(getLanguageForFileB());
+}
- for (uint i = 0; i <= gameSettings.numLanguages; i++) {
- if (languageTable[i] == gameSettings.languageID)
+int LanguageManager::getLanguageForFileB() {
+ int indexNum = -1;
+ for (uint i = 0; i <= _numLanguages; i++) {
+ if (_languageTable[i] == _languageID)
indexNum = i;
}
return indexNum;
}
+void LanguageManager::saveLanguageSetting(Common::WriteStream *writeStream) {
+ writeStream->writeByte(_numLanguages);
+}
+
+void LanguageManager::loadLanguageSetting(Common::SeekableReadStream *readStream) {
+ uint languageIdx = readStream->readByte();
+ setLanguageIndex(languageIdx);
+}
+
+void LanguageManager::setLanguageIndex(int idx) {
+ if (idx < 0)
+ fatal("Can't find the translation data specified!");
+
+ if (idx != _languageIdx) {
+ // Load the saved language!
+ _languageIdx = idx;
+ // Now set file indices properly to the chosen language.
+ setFileIndices(_numLanguages, _languageIdx);
+ }
+}
+
} // End of namespace Sludge
diff --git a/engines/sludge/language.h b/engines/sludge/language.h
index 2f8d6c0..9d3f2d2 100644
--- a/engines/sludge/language.h
+++ b/engines/sludge/language.h
@@ -28,17 +28,32 @@
namespace Sludge {
-struct settingsStruct {
- uint languageID;
- uint numLanguages;
+class LanguageManager {
+public:
+ LanguageManager() :
+ _languageID(0),
+ _languageIdx(-1),
+ _numLanguages(0),
+ _languageTable(0),
+ _languageNames(0) {}
+ ~LanguageManager();
+
+ void init(Common::File *table);
+ void setLanguageID(uint id);
+ void saveLanguageSetting(Common::WriteStream *writeStream);
+ void loadLanguageSetting(Common::SeekableReadStream *readStream);
+
+private:
+ uint _languageID; // id of selected language
+ int _languageIdx; // index of selected language in table
+ uint _numLanguages; // number of existing languages in game
+ uint *_languageTable; // indexes of existing languages
+ Common::String *_languageNames; // language names
+
+ int getLanguageForFileB();
+ void setLanguageIndex(int idx);
};
-extern settingsStruct gameSettings;
-
-int getLanguageForFileB();
-
-void makeLanguageTable(Common::File *table);
-
} // End of namespace Sludge
#endif
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index 6a653b9..0ddb71c 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -29,6 +29,7 @@
#include "sludge/variable.h"
#include "sludge/language.h"
#include "sludge/moreio.h"
+#include "sludge/sludge.h"
#include "sludge/sludger.h"
#include "sludge/people.h"
#include "sludge/talk.h"
@@ -40,7 +41,6 @@
#include "sludge/cursors.h"
#include "sludge/statusba.h"
#include "sludge/sound.h"
-#include "sludge/fileset.h"
#include "sludge/loadsave.h"
#include "sludge/bg_effects.h"
#include "sludge/thumbnail.h"
@@ -80,7 +80,6 @@ extern byte currentBurnR, currentBurnG, currentBurnB;
extern uint currentBlankColour; // in backdrop.cpp
extern parallaxLayer *parallaxStuff; // "
extern int lightMapMode; // "
-extern int languageNum;
//----------------------------------------------------------------------
// Globals (so we know what's saved already and what's a reference
@@ -464,7 +463,7 @@ bool saveGame(const Common::String &fname) {
saveParallaxRecursive(parallaxStuff, fp);
fp->writeByte(0);
- fp->writeByte(languageNum); // Selected language
+ g_sludge->_languageMan->saveLanguageSetting(fp);
saveSnapshot(fp);
@@ -663,12 +662,7 @@ bool loadGame(const Common::String &fname) {
return false;
}
- int selectedLanguage = fp->readByte();
- if (selectedLanguage != languageNum) {
- // Load the saved language!
- languageNum = selectedLanguage;
- setFileIndices(NULL, gameSettings.numLanguages, languageNum);
- }
+ g_sludge->_languageMan->loadLanguageSetting(fp);
}
nosnapshot();
diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp
index 6004e47..fe8a96f 100644
--- a/engines/sludge/sludge.cpp
+++ b/engines/sludge/sludge.cpp
@@ -61,6 +61,9 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
fatalMessage = "";
fatalInfo = "Initialisation error! Something went wrong before we even got started!";
+
+ // Init managers
+ _languageMan = new LanguageManager();
}
SludgeEngine::~SludgeEngine() {
@@ -81,6 +84,10 @@ SludgeEngine::~SludgeEngine() {
_origFormat = nullptr;
delete _pixelFormat;
_pixelFormat = nullptr;
+
+ // Dispose managers
+ delete _languageMan;
+ _languageMan = nullptr;
}
Common::Error SludgeEngine::run() {
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index 556dc94..0816d22 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -29,6 +29,7 @@
#include "gui/debugger.h"
#include "sludge/console.h"
+#include "sludge/language.h"
#include "sludge/timing.h"
namespace Sludge {
@@ -57,7 +58,6 @@ public:
// global String variables
Common::String launchMe;
Common::String loadNow;
- Common::String gameName;
Common::String gamePath;
Common::String bundleFolder;
Common::String fatalMessage;
@@ -66,6 +66,9 @@ public:
// timer
Timer _timer;
+ // managers
+ LanguageManager *_languageMan;
+
SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
virtual ~SludgeEngine();
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index e2b5e47..e0f20bb 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -65,7 +65,6 @@ Common::String *allUserFunc = NULL;
int numResourceNames = 0;
Common::String *allResourceNames = NULL;
int selectedLanguage = 0;
-int languageNum = -1;
int gameVersion;
FILETIME fileTime;
@@ -230,10 +229,7 @@ bool initSludge(const Common::String &filename) {
Common::String dataFol = (gameVersion >= VERSION(1, 3)) ? readString(fp) : "";
debug(kSludgeDebugDataLoad, "dataFol : %s", dataFol.c_str());
- gameSettings.numLanguages =
- (gameVersion >= VERSION(1, 3)) ? (fp->readByte()) : 0;
- debug(kSludgeDebugDataLoad, "numLanguages : %c", gameSettings.numLanguages);
- makeLanguageTable(fp);
+ g_sludge->_languageMan->init(fp);
if (gameVersion >= VERSION(1, 6)) {
fp->readByte();
@@ -282,21 +278,9 @@ bool initSludge(const Common::String &filename) {
for (a = 0; a < numGlobals; a++)
initVarNew(globalVars[a]);
- // Get the original (untranslated) name of the game and convert it to Unicode.
- // We use this to find saved preferences and saved games.
- setFileIndices(fp, gameSettings.numLanguages, 0);
- Common::String gameNameOrig = getNumberedString(1);
-
- Common::String gameName = encodeFilename(gameNameOrig);
-
// Get language selected by user
- gameSettings.languageID = g_sludge->getLanguageID();
-
- // Now set file indices properly to the chosen language.
- languageNum = getLanguageForFileB();
- if (languageNum < 0)
- return fatal("Can't find the translation data specified!");
- setFileIndices(NULL, gameSettings.numLanguages, languageNum);
+ setBigDataFile(fp);
+ g_sludge->_languageMan->setLanguageID(g_sludge->getLanguageID());
if (!dataFol.empty()) {
Common::String dataFolder = encodeFilename(dataFol);
Commit: 4fc6cef968fbf3dc12a6f60611689938dc76da8e
https://github.com/scummvm/scummvm/commit/4fc6cef968fbf3dc12a6f60611689938dc76da8e
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-07-18T19:05:04+02:00
Commit Message:
SLUDGE: Objectify resource manager
Changed paths:
engines/sludge/backdrop.cpp
engines/sludge/fileset.cpp
engines/sludge/fileset.h
engines/sludge/floor.cpp
engines/sludge/language.cpp
engines/sludge/main_loop.cpp
engines/sludge/objtypes.cpp
engines/sludge/sludge.cpp
engines/sludge/sludge.h
engines/sludge/sludger.cpp
engines/sludge/sound.cpp
engines/sludge/sprites.cpp
engines/sludge/variable.cpp
engines/sludge/zbuffer.cpp
diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
index 9e211f4..0f94f56 100644
--- a/engines/sludge/backdrop.cpp
+++ b/engines/sludge/backdrop.cpp
@@ -165,17 +165,17 @@ bool killResizeBackdrop(int x, int y) {
void loadBackDrop(int fileNum, int x, int y) {
debug(kSludgeDebugGraphics, "Load back drop");
setResourceForFatal(fileNum);
- if (!openFileFromNum(fileNum)) {
+ if (!g_sludge->_resMan->openFileFromNum(fileNum)) {
fatal("Can't load overlay image");
return;
}
- if (!loadHSI(bigDataFile, x, y, false)) {
+ if (!loadHSI(g_sludge->_resMan->getData(), x, y, false)) {
Common::String mess = Common::String::format("Can't paste overlay image outside scene dimensions\n\nX = %i\nY = %i\nWidth = %i\nHeight = %i", x, y, sceneWidth, sceneHeight);
fatal(mess);
}
- finishAccess();
+ g_sludge->_resMan->finishAccess();
setResourceForFatal(-1);
// set zBuffer if it's not set
@@ -187,16 +187,16 @@ void loadBackDrop(int fileNum, int x, int y) {
void mixBackDrop(int fileNum, int x, int y) {
setResourceForFatal(fileNum);
- if (!openFileFromNum(fileNum)) {
+ if (!g_sludge->_resMan->openFileFromNum(fileNum)) {
fatal("Can't load overlay image");
return;
}
- if (!mixHSI(bigDataFile, x, y)) {
+ if (!mixHSI(g_sludge->_resMan->getData(), x, y)) {
fatal("Can't paste overlay image outside screen dimensions");
}
- finishAccess();
+ g_sludge->_resMan->finishAccess();
setResourceForFatal(-1);
}
@@ -310,13 +310,13 @@ void drawBackDrop() {
bool loadLightMap(int v) {
setResourceForFatal(v);
- if (!openFileFromNum(v))
+ if (!g_sludge->_resMan->openFileFromNum(v))
return fatal("Can't open light map.");
killLightMap();
lightMapNumber = v;
- if (!ImgLoader::loadImage(bigDataFile, &lightMap))
+ if (!ImgLoader::loadImage(g_sludge->_resMan->getData(), &lightMap))
return false;
if (lightMapMode == LIGHTMAPMODE_HOTSPOT) {
@@ -325,8 +325,7 @@ bool loadLightMap(int v) {
}
}
- finishAccess();
-
+ g_sludge->_resMan->finishAccess();
setResourceForFatal(-1);
return true;
@@ -334,7 +333,7 @@ bool loadLightMap(int v) {
bool loadParallax(uint16 v, uint16 fracX, uint16 fracY) {
setResourceForFatal(v);
- if (!openFileFromNum(v))
+ if (!g_sludge->_resMan->openFileFromNum(v))
return fatal("Can't open parallax image");
parallaxLayer *nP = new parallaxLayer;
@@ -348,7 +347,7 @@ bool loadParallax(uint16 v, uint16 fracX, uint16 fracY) {
}
nP->prev = NULL;
- if (!ImgLoader::loadImage(bigDataFile, &nP->surface, 0))
+ if (!ImgLoader::loadImage(g_sludge->_resMan->getData(), &nP->surface, 0))
return false;
nP->fileNum = v;
@@ -388,7 +387,7 @@ bool loadParallax(uint16 v, uint16 fracX, uint16 fracY) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#endif
- finishAccess();
+ g_sludge->_resMan->finishAccess();
setResourceForFatal(-1);
return true;
}
diff --git a/engines/sludge/fileset.cpp b/engines/sludge/fileset.cpp
index 4920662..4f88fe9 100644
--- a/engines/sludge/fileset.cpp
+++ b/engines/sludge/fileset.cpp
@@ -31,50 +31,44 @@
namespace Sludge {
-bool sliceBusy = true;
-
-Common::File *bigDataFile = NULL;
-
-uint32 startOfDataIndex, startOfTextIndex, startOfSubIndex, startOfObjectIndex;
-
-bool openSubSlice(int num) {
- if (sliceBusy) {
+bool ResourceManager::openSubSlice(int num) {
+ if (_sliceBusy) {
fatal("Can't read from data file", "I'm already reading something");
return false;
}
- bigDataFile->seek(startOfSubIndex + (num << 2), 0);
- bigDataFile->seek(bigDataFile->readUint32LE(), 0);
+ _bigDataFile->seek(_startOfSubIndex + (num << 2), 0);
+ _bigDataFile->seek(_bigDataFile->readUint32LE(), 0);
- return sliceBusy = true;
+ return _sliceBusy = true;
}
-bool openObjectSlice(int num) {
- if (sliceBusy) {
+bool ResourceManager::openObjectSlice(int num) {
+ if (_sliceBusy) {
fatal("Can't read from data file", "I'm already reading something");
return false;
}
- bigDataFile->seek(startOfObjectIndex + (num << 2), 0);
- bigDataFile->seek(bigDataFile->readUint32LE(), 0);
- return sliceBusy = true;
+ _bigDataFile->seek(_startOfObjectIndex + (num << 2), 0);
+ _bigDataFile->seek(_bigDataFile->readUint32LE(), 0);
+ return _sliceBusy = true;
}
-uint openFileFromNum(int num) {
- if (sliceBusy) {
+uint ResourceManager::openFileFromNum(int num) {
+ if (_sliceBusy) {
fatal("Can't read from data file", "I'm already reading something");
return 0;
}
- bigDataFile->seek(startOfDataIndex + (num << 2), 0);
- bigDataFile->seek(bigDataFile->readUint32LE(), 1);
- sliceBusy = true;
+ _bigDataFile->seek(_startOfDataIndex + (num << 2), 0);
+ _bigDataFile->seek(_bigDataFile->readUint32LE(), 1);
+ _sliceBusy = true;
- return bigDataFile->readUint32LE();
+ return _bigDataFile->readUint32LE();
}
// Converts a string from Windows CP-1252 to UTF-8.
// This is needed for old games.
-Common::String convertString(const Common::String &s) {
+Common::String ResourceManager::convertString(const Common::String &s) {
#if 0
static char *buf = NULL;
@@ -137,18 +131,17 @@ Common::String convertString(const Common::String &s) {
return s; //TODO: false value
}
-Common::String getNumberedString(int value) {
-
- if (sliceBusy) {
+Common::String ResourceManager::getNumberedString(int value) {
+ if (_sliceBusy) {
fatal("Can't read from data file", "I'm already reading something");
return NULL;
}
- bigDataFile->seek((value << 2) + startOfTextIndex, 0);
- value = bigDataFile->readUint32LE();
- bigDataFile->seek(value, 0);
+ _bigDataFile->seek((value << 2) + _startOfTextIndex, 0);
+ value = _bigDataFile->readUint32LE();
+ _bigDataFile->seek(value, 0);
- Common::String s = readString(bigDataFile);
+ Common::String s = readString(_bigDataFile);
if (gameVersion < VERSION(2, 2)) {
// This is an older game - We need to convert the string to UTF-8
@@ -158,25 +151,23 @@ Common::String getNumberedString(int value) {
return s;
}
-bool startAccess() {
- int wasBusy = sliceBusy;
- sliceBusy = true;
+bool ResourceManager::startAccess() {
+ int wasBusy = _sliceBusy;
+ _sliceBusy = true;
return wasBusy;
}
-void finishAccess() {
- sliceBusy = false;
+void ResourceManager::finishAccess() {
+ _sliceBusy = false;
}
-int32 startIndex;
-
-void setBigDataFile(Common::File *fp) {
- bigDataFile = fp;
- startIndex = fp->pos();
+void ResourceManager::setData(Common::File *fp) {
+ _bigDataFile = fp;
+ _startIndex = fp->pos();
}
-void setFileIndices(uint numLanguages, uint skipBefore) {
- bigDataFile->seek(startIndex, SEEK_SET);
- sliceBusy = false;
+void ResourceManager::setFileIndices(uint numLanguages, uint skipBefore) {
+ _bigDataFile->seek(_startIndex, SEEK_SET);
+ _sliceBusy = false;
if (skipBefore > numLanguages) {
warning("Not a valid language ID! Using default instead.");
@@ -186,30 +177,30 @@ void setFileIndices(uint numLanguages, uint skipBefore) {
// STRINGS
int skipAfter = numLanguages - skipBefore;
while (skipBefore) {
- bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_SET);
+ _bigDataFile->seek(_bigDataFile->readUint32LE(), SEEK_SET);
skipBefore--;
}
- startOfTextIndex = bigDataFile->pos() + 4;
- debug(kSludgeDebugDataLoad, "startOfTextIndex: %i", startOfTextIndex);
+ _startOfTextIndex = _bigDataFile->pos() + 4;
+ debug(kSludgeDebugDataLoad, "startOfTextIndex: %i", _startOfTextIndex);
- bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_SET);
+ _bigDataFile->seek(_bigDataFile->readUint32LE(), SEEK_SET);
while (skipAfter) {
- bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_SET);
+ _bigDataFile->seek(_bigDataFile->readUint32LE(), SEEK_SET);
skipAfter--;
}
- startOfSubIndex = bigDataFile->pos() + 4;
- bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_CUR);
- debug(kSludgeDebugDataLoad, "startOfSubIndex: %i", startOfSubIndex);
+ _startOfSubIndex = _bigDataFile->pos() + 4;
+ _bigDataFile->seek(_bigDataFile->readUint32LE(), SEEK_CUR);
+ debug(kSludgeDebugDataLoad, "startOfSubIndex: %i", _startOfSubIndex);
- startOfObjectIndex = bigDataFile->pos() + 4;
- bigDataFile->seek(bigDataFile->readUint32LE(), SEEK_CUR);
- debug(kSludgeDebugDataLoad, "startOfObjectIndex: %i", startOfObjectIndex);
+ _startOfObjectIndex = _bigDataFile->pos() + 4;
+ _bigDataFile->seek(_bigDataFile->readUint32LE(), SEEK_CUR);
+ debug(kSludgeDebugDataLoad, "startOfObjectIndex: %i", _startOfObjectIndex);
// Remember that the data section starts here
- startOfDataIndex = bigDataFile->pos();
- debug(kSludgeDebugDataLoad, "startOfDataIndex: %i", startOfDataIndex);
+ _startOfDataIndex = _bigDataFile->pos();
+ debug(kSludgeDebugDataLoad, "startOfDataIndex: %i", _startOfDataIndex);
}
} // End of namespace Sludge
diff --git a/engines/sludge/fileset.h b/engines/sludge/fileset.h
index fe2293d..9cde705 100644
--- a/engines/sludge/fileset.h
+++ b/engines/sludge/fileset.h
@@ -26,18 +26,39 @@
namespace Sludge {
-extern Common::File *bigDataFile;
+class ResourceManager {
-void setBigDataFile(Common::File *readStream);
-void setFileIndices(uint, uint);
+public:
+ ResourceManager():
+ _sliceBusy(true),
+ _bigDataFile(0),
+ _startOfDataIndex(0),
+ _startOfTextIndex(0),
+ _startOfSubIndex(0),
+ _startOfObjectIndex(0),
+ _startIndex(0) {}
-uint openFileFromNum(int num);
-bool openSubSlice(int num);
-bool openObjectSlice(int num);
-Common::String getNumberedString(int value);
+ void setData(Common::File *readStream);
+ void setFileIndices(uint, uint);
+ Common::SeekableReadStream *getData() { return _bigDataFile; }
-bool startAccess();
-void finishAccess();
+ uint openFileFromNum(int num);
+ bool openSubSlice(int num);
+ bool openObjectSlice(int num);
+ Common::String getNumberedString(int value);
+
+ bool startAccess();
+ void finishAccess();
+
+private:
+ bool _sliceBusy;
+ Common::File *_bigDataFile;
+ uint32 _startOfDataIndex, _startOfTextIndex, _startOfSubIndex, _startOfObjectIndex;
+ int32 _startIndex;
+
+private:
+ Common::String convertString(const Common::String &s);
+};
} // End of namespace Sludge
diff --git a/engines/sludge/floor.cpp b/engines/sludge/floor.cpp
index 7e9677a..6b8f781 100644
--- a/engines/sludge/floor.cpp
+++ b/engines/sludge/floor.cpp
@@ -26,6 +26,7 @@
#include "sludge/newfatal.h"
#include "sludge/fileset.h"
#include "sludge/moreio.h"
+#include "sludge/sludge.h"
#include "sludge/floor.h"
namespace Sludge {
@@ -130,13 +131,13 @@ bool setFloor(int fileNum) {
setResourceForFatal(fileNum);
- if (!openFileFromNum(fileNum))
+ if (!g_sludge->_resMan->openFileFromNum(fileNum))
return false;
// Find out how many polygons there are and reserve memory
currentFloor->originalNum = fileNum;
- currentFloor->numPolygons = bigDataFile->readByte();
+ currentFloor->numPolygons = g_sludge->_resMan->getData()->readByte();
currentFloor->polygon = new floorPolygon[currentFloor->numPolygons];
if (!checkNew(currentFloor->polygon))
return false;
@@ -147,7 +148,7 @@ bool setFloor(int fileNum) {
// Find out how many vertex IDs there are and reserve memory
- currentFloor->polygon[i].numVertices = bigDataFile->readByte();
+ currentFloor->polygon[i].numVertices = g_sludge->_resMan->getData()->readByte();
currentFloor->polygon[i].vertexID = new int[currentFloor->polygon[i].numVertices];
if (!checkNew(currentFloor->polygon[i].vertexID))
return false;
@@ -155,24 +156,24 @@ bool setFloor(int fileNum) {
// Read in each vertex ID
for (j = 0; j < currentFloor->polygon[i].numVertices; j++) {
- currentFloor->polygon[i].vertexID[j] = bigDataFile->readUint16BE();
+ currentFloor->polygon[i].vertexID[j] = g_sludge->_resMan->getData()->readUint16BE();
}
}
// Find out how many vertices there are and reserve memory
- i = bigDataFile->readUint16BE();
+ i = g_sludge->_resMan->getData()->readUint16BE();
currentFloor->vertex = new Common::Point[i];
if (!checkNew(currentFloor->vertex))
return false;
for (j = 0; j < i; j++) {
- currentFloor->vertex[j].x = bigDataFile->readUint16BE();
- currentFloor->vertex[j].y = bigDataFile->readUint16BE();
+ currentFloor->vertex[j].x = g_sludge->_resMan->getData()->readUint16BE();
+ currentFloor->vertex[j].y = g_sludge->_resMan->getData()->readUint16BE();
}
- finishAccess();
+ g_sludge->_resMan->finishAccess();
// Now build the movement martix
diff --git a/engines/sludge/language.cpp b/engines/sludge/language.cpp
index 52c1dc8..a446941 100644
--- a/engines/sludge/language.cpp
+++ b/engines/sludge/language.cpp
@@ -104,7 +104,7 @@ void LanguageManager::setLanguageIndex(int idx) {
// Load the saved language!
_languageIdx = idx;
// Now set file indices properly to the chosen language.
- setFileIndices(_numLanguages, _languageIdx);
+ g_sludge->_resMan->setFileIndices(_numLanguages, _languageIdx);
}
}
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index 78ce63b..8f31167 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -179,8 +179,6 @@ int main_loop(const char *filename)
initStatusBar();
resetRandW();
- g_sludge->gameName = getNumberedString(1);
-
if (!ConfMan.hasKey("mute") || !ConfMan.getBool("mute")) {
initSoundStuff(hMainWindow);
}
diff --git a/engines/sludge/objtypes.cpp b/engines/sludge/objtypes.cpp
index 8b7f258..57365e2 100644
--- a/engines/sludge/objtypes.cpp
+++ b/engines/sludge/objtypes.cpp
@@ -25,6 +25,7 @@
#include "sludge/variable.h"
#include "sludge/newfatal.h"
#include "sludge/moreio.h"
+#include "sludge/sludge.h"
#include "sludge/fileset.h"
#include "sludge/version.h"
@@ -32,8 +33,6 @@ namespace Sludge {
objectType *allObjectTypes = NULL;
-#define DEBUG_COMBINATIONS 0
-
bool initObjectTypes() {
return true;
}
@@ -55,40 +54,41 @@ objectType *loadObjectType(int i) {
objectType *newType = new objectType;
if (checkNew(newType)) {
- if (openObjectSlice(i)) {
- nameNum = bigDataFile->readUint16BE();
- newType->r = (byte)bigDataFile->readByte();
- newType->g = (byte)bigDataFile->readByte();
- newType->b = (byte)bigDataFile->readByte();
- newType->speechGap = bigDataFile->readByte();
- newType->walkSpeed = bigDataFile->readByte();
- newType->wrapSpeech = bigDataFile->readUint32LE();
- newType->spinSpeed = bigDataFile->readUint16BE();
+ if (g_sludge->_resMan->openObjectSlice(i)) {
+ Common::SeekableReadStream *readStream = g_sludge->_resMan->getData();
+ nameNum = readStream->readUint16BE();
+ newType->r = (byte)readStream->readByte();
+ newType->g = (byte)readStream->readByte();
+ newType->b = (byte)readStream->readByte();
+ newType->speechGap = readStream->readByte();
+ newType->walkSpeed = readStream->readByte();
+ newType->wrapSpeech = readStream->readUint32LE();
+ newType->spinSpeed = readStream->readUint16BE();
if (gameVersion >= VERSION(1, 6)) {
// aaLoad
- bigDataFile->readByte();
- bigDataFile->readFloatLE();
- bigDataFile->readFloatLE();
+ readStream->readByte();
+ readStream->readFloatLE();
+ readStream->readFloatLE();
}
if (gameVersion >= VERSION(1, 4)) {
- newType->flags = bigDataFile->readUint16BE();
+ newType->flags = readStream->readUint16BE();
} else {
newType->flags = 0;
}
- newType->numCom = bigDataFile->readUint16BE();
+ newType->numCom = readStream->readUint16BE();
newType->allCombis = (newType->numCom) ? new combination[newType->numCom] : NULL;
for (a = 0; a < newType->numCom; a++) {
- newType->allCombis[a].withObj = bigDataFile->readUint16BE();
- newType->allCombis[a].funcNum = bigDataFile->readUint16BE();
+ newType->allCombis[a].withObj = readStream->readUint16BE();
+ newType->allCombis[a].funcNum = readStream->readUint16BE();
}
- finishAccess();
- newType->screenName = getNumberedString(nameNum);
+ g_sludge->_resMan->finishAccess();
+ newType->screenName = g_sludge->_resMan->getNumberedString(nameNum);
newType->objectNum = i;
newType->next = allObjectTypes;
allObjectTypes = newType;
diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp
index fe8a96f..ff62459 100644
--- a/engines/sludge/sludge.cpp
+++ b/engines/sludge/sludge.cpp
@@ -55,7 +55,6 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
// Init Strings
launchMe = "";
loadNow = "";
- gameName = "";
gamePath = "";
bundleFolder = "";
@@ -63,6 +62,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
fatalInfo = "Initialisation error! Something went wrong before we even got started!";
// Init managers
+ _resMan = new ResourceManager();
_languageMan = new LanguageManager();
}
@@ -88,6 +88,8 @@ SludgeEngine::~SludgeEngine() {
// Dispose managers
delete _languageMan;
_languageMan = nullptr;
+ delete _resMan;
+ _resMan = nullptr;
}
Common::Error SludgeEngine::run() {
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index 0816d22..8d41b5c 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -29,6 +29,7 @@
#include "gui/debugger.h"
#include "sludge/console.h"
+#include "sludge/fileset.h"
#include "sludge/language.h"
#include "sludge/timing.h"
@@ -67,6 +68,7 @@ public:
Timer _timer;
// managers
+ ResourceManager *_resMan;
LanguageManager *_languageMan;
SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index e0f20bb..e1fd3c8 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -279,7 +279,7 @@ bool initSludge(const Common::String &filename) {
initVarNew(globalVars[a]);
// Get language selected by user
- setBigDataFile(fp);
+ g_sludge->_resMan->setData(fp);
g_sludge->_languageMan->setLanguageID(g_sludge->getLanguageID());
if (!dataFol.empty()) {
@@ -942,33 +942,32 @@ bool runSludge() {
}
bool loadFunctionCode(loadedFunction *newFunc) {
-
- debug(kSludgeDebugDataLoad, "Current address: %i", bigDataFile->pos());
uint numLines, numLinesRead;
- if (!openSubSlice(newFunc->originalNumber))
+ if (!g_sludge->_resMan->openSubSlice(newFunc->originalNumber))
return false;
debug(kSludgeDebugDataLoad, "Load function code");
- newFunc->unfreezable = bigDataFile->readByte();
- numLines = bigDataFile->readUint16BE();
+ Common::SeekableReadStream *readStream = g_sludge->_resMan->getData();
+ newFunc->unfreezable = readStream->readByte();
+ numLines = readStream->readUint16BE();
debug(kSludgeDebugDataLoad, "numLines: %i", numLines);
- newFunc->numArgs = bigDataFile->readUint16BE();
+ newFunc->numArgs = readStream->readUint16BE();
debug(kSludgeDebugDataLoad, "numArgs: %i", newFunc->numArgs);
- newFunc->numLocals = bigDataFile->readUint16BE();
+ newFunc->numLocals = readStream->readUint16BE();
debug(kSludgeDebugDataLoad, "numLocals: %i", newFunc->numLocals);
newFunc->compiledLines = new lineOfCode[numLines];
if (!checkNew(newFunc->compiledLines))
return false;
for (numLinesRead = 0; numLinesRead < numLines; numLinesRead++) {
- newFunc->compiledLines[numLinesRead].theCommand = (sludgeCommand) bigDataFile->readByte();
- newFunc->compiledLines[numLinesRead].param = bigDataFile->readUint16BE();
+ newFunc->compiledLines[numLinesRead].theCommand = (sludgeCommand)readStream->readByte();
+ newFunc->compiledLines[numLinesRead].param = readStream->readUint16BE();
debug(kSludgeDebugDataLoad, "command line %i: %i", numLinesRead,
newFunc->compiledLines[numLinesRead].theCommand);
}
- finishAccess();
+ g_sludge->_resMan->finishAccess();
// Now we need to reserve memory for the local variables
newFunc->localVars = new variable[newFunc->numLocals];
diff --git a/engines/sludge/sound.cpp b/engines/sludge/sound.cpp
index d77f3d4..702a8c9 100644
--- a/engines/sludge/sound.cpp
+++ b/engines/sludge/sound.cpp
@@ -381,20 +381,21 @@ int makeSoundAudioStream(int f, Audio::AudioStream *&audiostream, bool loopy) {
}
setResourceForFatal(f);
- uint32 length = openFileFromNum(f);
+ uint32 length = g_sludge->_resMan->openFileFromNum(f);
if (!length)
return -1;
- uint curr_ptr = bigDataFile->pos();
- Audio::RewindableAudioStream *stream = Audio::makeWAVStream(bigDataFile->readStream(length), DisposeAfterUse::NO);
+ Common::SeekableReadStream *readStream = g_sludge->_resMan->getData();
+ uint curr_ptr = readStream->pos();
+ Audio::RewindableAudioStream *stream = Audio::makeWAVStream(readStream->readStream(length), DisposeAfterUse::NO);
#ifdef USE_VORBIS
if (!stream) {
- bigDataFile->seek(curr_ptr);
- stream = Audio::makeVorbisStream(bigDataFile->readStream(length), DisposeAfterUse::NO);
+ readStream->seek(curr_ptr);
+ stream = Audio::makeVorbisStream(readStream->readStream(length), DisposeAfterUse::NO);
}
#endif
- finishAccess();
+ g_sludge->_resMan->finishAccess();
if (stream) {
audiostream = Audio::makeLoopingAudioStream(stream, loopy ? 0 : 1);
diff --git a/engines/sludge/sprites.cpp b/engines/sludge/sprites.cpp
index 39bb652..ce8d61e 100644
--- a/engines/sludge/sprites.cpp
+++ b/engines/sludge/sprites.cpp
@@ -123,18 +123,19 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
byte *data;
setResourceForFatal(fileNum);
- if (!openFileFromNum(fileNum))
+ if (!g_sludge->_resMan->openFileFromNum(fileNum))
return fatal("Can't open sprite bank / font");
loadhere.isFont = isFont;
- total = bigDataFile->readUint16BE();
+ Common::SeekableReadStream *readStream = g_sludge->_resMan->getData();
+ total = readStream->readUint16BE();
if (!total) {
- spriteBankVersion = bigDataFile->readByte();
+ spriteBankVersion = readStream->readByte();
if (spriteBankVersion == 1) {
total = 0;
} else {
- total = bigDataFile->readUint16BE();
+ total = readStream->readUint16BE();
}
}
@@ -153,7 +154,7 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
// version 1, 2, read how many now
if (spriteBankVersion && spriteBankVersion < 3) {
- howmany = bigDataFile->readByte();
+ howmany = readStream->readByte();
startIndex = 1;
}
@@ -161,13 +162,13 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
if (spriteBankVersion == 3) {
debug(kSludgeDebugGraphics, "png sprite");
for (int i = 0; i < total; i++) {
- loadhere.sprites[i].xhot = bigDataFile->readSint16LE();
- loadhere.sprites[i].yhot = bigDataFile->readSint16LE();
- if (!ImgLoader::loadPNGImage(bigDataFile, &loadhere.sprites[i].surface, false)) {
+ loadhere.sprites[i].xhot = readStream->readSint16LE();
+ loadhere.sprites[i].yhot = readStream->readSint16LE();
+ if (!ImgLoader::loadPNGImage(readStream, &loadhere.sprites[i].surface, false)) {
return fatal("fail to read png sprite");
}
}
- finishAccess();
+ g_sludge->_resMan->finishAccess();
setResourceForFatal(-1);
return true;
}
@@ -177,15 +178,15 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
uint picwidth, picheight;
// load sprite width, height, relative position
if (spriteBankVersion == 2) {
- picwidth = bigDataFile->readUint16BE();
- picheight = bigDataFile->readUint16BE();
- loadhere.sprites[i].xhot = bigDataFile->readSint16LE();
- loadhere.sprites[i].yhot = bigDataFile->readSint16LE();
+ picwidth = readStream->readUint16BE();
+ picheight = readStream->readUint16BE();
+ loadhere.sprites[i].xhot = readStream->readSint16LE();
+ loadhere.sprites[i].yhot = readStream->readSint16LE();
} else {
- picwidth = (byte)bigDataFile->readByte();
- picheight = (byte)bigDataFile->readByte();
- loadhere.sprites[i].xhot = bigDataFile->readByte();
- loadhere.sprites[i].yhot = bigDataFile->readByte();
+ picwidth = (byte)readStream->readByte();
+ picheight = (byte)readStream->readByte();
+ loadhere.sprites[i].xhot = readStream->readByte();
+ loadhere.sprites[i].yhot = readStream->readByte();
}
// init data
@@ -205,11 +206,11 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
uint pip = 0;
while (pip < size) {
- byte col = bigDataFile->readByte();
+ byte col = readStream->readByte();
int looper;
if (col > howmany) {
col -= howmany + 1;
- looper = bigDataFile->readByte() + 1;
+ looper = readStream->readByte() + 1;
} else
looper = 1;
@@ -218,8 +219,8 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
}
}
} else { // RAW DATA
- uint bytes_read = bigDataFile->read(data, picwidth * picheight);
- if (bytes_read != picwidth * picheight && bigDataFile->err()) {
+ uint bytes_read = readStream->read(data, picwidth * picheight);
+ if (bytes_read != picwidth * picheight && readStream->err()) {
warning("Reading error in loadSpriteBank.");
}
}
@@ -227,17 +228,17 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
// read howmany for version 0
if (!spriteBankVersion) {
- howmany = bigDataFile->readByte();
- startIndex = bigDataFile->readByte();
+ howmany = readStream->readByte();
+ startIndex = readStream->readByte();
}
// Make palette for version 0, 1, 2
if (!reserveSpritePal(loadhere.myPalette, howmany + startIndex))
return false;
for (int i = 0; i < howmany; i++) {
- loadhere.myPalette.r[i + startIndex] = (byte)bigDataFile->readByte();
- loadhere.myPalette.g[i + startIndex] = (byte)bigDataFile->readByte();
- loadhere.myPalette.b[i + startIndex] = (byte)bigDataFile->readByte();
+ loadhere.myPalette.r[i + startIndex] = (byte)readStream->readByte();
+ loadhere.myPalette.g[i + startIndex] = (byte)readStream->readByte();
+ loadhere.myPalette.b[i + startIndex] = (byte)readStream->readByte();
loadhere.myPalette.pal[i + startIndex] =
(uint16)g_sludge->getOrigPixelFormat()->RGBToColor(
loadhere.myPalette.r[i + startIndex],
@@ -290,7 +291,7 @@ bool loadSpriteBank(int fileNum, spriteBank &loadhere, bool isFont) {
delete[] spriteData;
spriteData = NULL;
- finishAccess();
+ g_sludge->_resMan->finishAccess();
setResourceForFatal(-1);
diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp
index b13e123..b445095 100644
--- a/engines/sludge/variable.cpp
+++ b/engines/sludge/variable.cpp
@@ -260,7 +260,7 @@ void makeTextVar(variable &thisVar, const Common::String &txt) {
}
bool loadStringToVar(variable &thisVar, int value) {
- makeTextVar(thisVar, getNumberedString(value));
+ makeTextVar(thisVar, g_sludge->_resMan->getNumberedString(value));
return (bool)(thisVar.varData.theString != NULL);
}
diff --git a/engines/sludge/zbuffer.cpp b/engines/sludge/zbuffer.cpp
index e3b3056..b01bc9f 100644
--- a/engines/sludge/zbuffer.cpp
+++ b/engines/sludge/zbuffer.cpp
@@ -88,25 +88,26 @@ bool setZBuffer(int num) {
setResourceForFatal(num);
zBuffer.originalNum = num;
- if (!openFileFromNum(num))
+ if (!g_sludge->_resMan->openFileFromNum(num))
return false;
- if (bigDataFile->readByte() != 'S')
+ Common::ReadStream *readStream = g_sludge->_resMan->getData();
+ if (readStream->readByte() != 'S')
return fatal("Not a Z-buffer file");
- if (bigDataFile->readByte() != 'z')
+ if (readStream->readByte() != 'z')
return fatal("Not a Z-buffer file");
- if (bigDataFile->readByte() != 'b')
+ if (readStream->readByte() != 'b')
return fatal("Not a Z-buffer file");
uint width, height;
- switch (bigDataFile->readByte()) {
+ switch (readStream->readByte()) {
case 0:
width = 640;
height = 480;
break;
case 1:
- width = bigDataFile->readUint16BE();
- height = bigDataFile->readUint16BE();
+ width = readStream->readUint16BE();
+ height = readStream->readUint16BE();
break;
default:
@@ -117,9 +118,9 @@ bool setZBuffer(int num) {
return fatal("Z-buffer width and height don't match scene width and height", tmp);
}
- zBuffer.numPanels = bigDataFile->readByte();
+ zBuffer.numPanels = readStream->readByte();
for (int y = 0; y < zBuffer.numPanels; y++) {
- yPalette[y] = bigDataFile->readUint16BE();
+ yPalette[y] = readStream->readUint16BE();
}
sortZPal(yPalette, sorted, zBuffer.numPanels);
for (int y = 0; y < zBuffer.numPanels; y++) {
@@ -141,10 +142,10 @@ bool setZBuffer(int num) {
for (uint x = 0; x < sceneWidth; x++) {
int n;
if (stillToGo == 0) {
- n = bigDataFile->readByte();
+ n = readStream->readByte();
stillToGo = n >> 4;
if (stillToGo == 15)
- stillToGo = bigDataFile->readUint16BE() + 16l;
+ stillToGo = readStream->readUint16BE() + 16l;
else
stillToGo++;
n &= 15;
@@ -167,7 +168,7 @@ bool setZBuffer(int num) {
stillToGo--;
}
}
- finishAccess();
+ g_sludge->_resMan->finishAccess();
setResourceForFatal(-1);
return true;
}
More information about the Scummvm-git-logs
mailing list