diff options
author | Einar Johan Trøan Sømåen | 2012-08-07 13:32:26 +0200 |
---|---|---|
committer | Einar Johan Trøan Sømåen | 2012-08-07 13:32:26 +0200 |
commit | e32b79bff1260f8d2853404f750acc22209a323b (patch) | |
tree | b1d3191d6c3e91137af713511102792af99c893a /engines | |
parent | 9bda50ef48e47160c2788399bf7a4d4b04848aca (diff) | |
download | scummvm-rg350-e32b79bff1260f8d2853404f750acc22209a323b.tar.gz scummvm-rg350-e32b79bff1260f8d2853404f750acc22209a323b.tar.bz2 scummvm-rg350-e32b79bff1260f8d2853404f750acc22209a323b.zip |
WINTERMUTE: Save the random-seed as well.
Diffstat (limited to 'engines')
-rw-r--r-- | engines/wintermute/ad/ad_actor.cpp | 6 | ||||
-rw-r--r-- | engines/wintermute/ad/ad_talk_holder.cpp | 4 | ||||
-rw-r--r-- | engines/wintermute/base/base_engine.cpp | 7 | ||||
-rw-r--r-- | engines/wintermute/base/base_engine.h | 9 | ||||
-rw-r--r-- | engines/wintermute/base/saveload.cpp | 5 | ||||
-rw-r--r-- | engines/wintermute/utils/utils.cpp | 5 | ||||
-rw-r--r-- | engines/wintermute/wintermute.cpp | 8 | ||||
-rw-r--r-- | engines/wintermute/wintermute.h | 4 |
8 files changed, 27 insertions, 21 deletions
diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index b4e9d80a02..aa148c9c85 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -43,7 +43,7 @@ #include "engines/wintermute/base/scriptables/script_value.h"
#include "engines/wintermute/base/scriptables/script_stack.h"
#include "engines/wintermute/base/particles/part_emitter.h"
-#include "engines/wintermute/wintermute.h"
+#include "engines/wintermute/base/base_engine.h"
namespace WinterMute {
@@ -1262,7 +1262,7 @@ BaseSprite *AdActor::getTalkStance(const char *stance) { }
if (talkAnims.getSize() > 0) {
- int rnd = g_wintermute->randInt(0, talkAnims.getSize() - 1);
+ int rnd = BaseEngine::instance().randInt(0, talkAnims.getSize() - 1);
ret = talkAnims[rnd]->getSprite(_dir);
} else {
if (_standSprite) {
@@ -1307,7 +1307,7 @@ BaseSprite *AdActor::getTalkStanceOld(const char *stance) { ret = _standSprite->getSprite(_dir);
} else {
// TODO: remember last
- int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1);
+ int rnd = BaseEngine::instance().randInt(0, _talkSprites.getSize() - 1);
ret = _talkSprites[rnd]->getSprite(_dir);
}
}
diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index 5a2b3df31b..a5ab7f3a6d 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -34,7 +34,7 @@ #include "engines/wintermute/base/base_game.h"
#include "engines/wintermute/base/base_sprite.h"
#include "engines/wintermute/platform_osystem.h"
-#include "engines/wintermute/wintermute.h"
+#include "engines/wintermute/base/base_engine.h"
#include "common/str.h"
namespace WinterMute {
@@ -111,7 +111,7 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { ret = _sprite;
} else {
// TODO: remember last
- int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1);
+ int rnd = BaseEngine::instance().randInt(0, _talkSprites.getSize() - 1);
ret = _talkSprites[rnd];
}
}
diff --git a/engines/wintermute/base/base_engine.cpp b/engines/wintermute/base/base_engine.cpp index 8e3e6cf0e0..04088d299e 100644 --- a/engines/wintermute/base/base_engine.cpp +++ b/engines/wintermute/base/base_engine.cpp @@ -40,11 +40,14 @@ namespace WinterMute { BaseEngine::BaseEngine() { _fileManager = NULL; _gameRef = NULL; + _rnd = NULL; _gameId = ""; } void BaseEngine::init() { _fileManager = new BaseFileManager(); + // Don't forget to register your random source + _rnd = new Common::RandomSource("WinterMute"); } BaseEngine::~BaseEngine() { @@ -77,4 +80,8 @@ void BaseEngine::LOG(bool res, const char *fmt, ...) { } } +uint32 BaseEngine::randInt(int from, int to) { + return _rnd->getRandomNumberRng(from, to); +} + } // end of namespace WinterMute diff --git a/engines/wintermute/base/base_engine.h b/engines/wintermute/base/base_engine.h index b9dcfcb845..253ef048ab 100644 --- a/engines/wintermute/base/base_engine.h +++ b/engines/wintermute/base/base_engine.h @@ -29,8 +29,9 @@ #ifndef WINTERMUTE_BASE_ENGINE_H #define WINTERMUTE_BASE_ENGINE_H - #include "common/str.h" - #include "common/singleton.h" +#include "common/str.h" +#include "common/singleton.h" +#include "common/random.h" namespace WinterMute { @@ -42,12 +43,16 @@ class BaseEngine : public Common::Singleton<WinterMute::BaseEngine> { BaseFileManager *_fileManager; Common::String _gameId; BaseGame *_gameRef; + // We need random numbers + Common::RandomSource *_rnd; public: BaseEngine(); ~BaseEngine(); static void createInstance(const Common::String &gameid); void setGameRef(BaseGame *gameRef) { _gameRef = gameRef; } + Common::RandomSource *getRandomSource() { return _rnd; } + uint32 randInt(int from, int to); BaseGame *getGameRef() { return _gameRef; } BaseFileManager *getFileManager() { return _fileManager; } static void LOG(bool res, const char *fmt, ...); diff --git a/engines/wintermute/base/saveload.cpp b/engines/wintermute/base/saveload.cpp index aea474fd44..5b51749b43 100644 --- a/engines/wintermute/base/saveload.cpp +++ b/engines/wintermute/base/saveload.cpp @@ -30,6 +30,7 @@ #include "engines/wintermute/wintermute.h" #include "engines/wintermute/base/saveload.h" #include "engines/wintermute/ad/ad_scene.h" +#include "engines/wintermute/base/base_engine.h" #include "engines/wintermute/base/base_game.h" // Temporary #include "engines/wintermute/base/base_region.h" #include "engines/wintermute/base/base_sub_frame.h" @@ -54,6 +55,9 @@ bool SaveLoad::loadGame(const Common::String &filename, BaseGame *gameRef) { //if (DID_SUCCEED(ret = cleanup())) { if (DID_SUCCEED(ret = SystemClassRegistry::getInstance()->loadTable(gameRef, pm))) { if (DID_SUCCEED(ret = SystemClassRegistry::getInstance()->loadInstances(gameRef, pm))) { + // Restore random-seed: + BaseEngine::instance().getRandomSource()->setSeed(pm->getDWORD()); + // data initialization after load SaveLoad::initAfterLoad(); @@ -92,6 +96,7 @@ bool SaveLoad::saveGame(int slot, const char *desc, bool quickSave, BaseGame *ga gameRef->_renderer->initSaveLoad(true, quickSave); // TODO: The original code inited the indicator before the conditionals if (DID_SUCCEED(ret = SystemClassRegistry::getInstance()->saveTable(gameRef, pm, quickSave))) { if (DID_SUCCEED(ret = SystemClassRegistry::getInstance()->saveInstances(gameRef, pm, quickSave))) { + pm->putDWORD(BaseEngine::instance().getRandomSource()->getSeed()); if (DID_SUCCEED(ret = pm->saveFile(filename))) { ConfMan.setInt("most_recent_saveslot", slot); } diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index 6571147a80..f8a7b0e547 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -28,6 +28,7 @@ #include "engines/wintermute/utils/utils.h"
#include "engines/wintermute/wintermute.h"
+#include "engines/wintermute/base/base_engine.h"
namespace WinterMute {
@@ -126,14 +127,14 @@ int BaseUtils::randomInt(int from, int to) { to = from;
from = i;
}
- return g_wintermute->randInt(from, to);
+ return BaseEngine::instance().randInt(from, to);
// return (rand() % (to - from + 1)) + from;
}
//////////////////////////////////////////////////////////////////////////
float BaseUtils::randomFloat(float from, float to) {
const uint32 randMax = RAND_MAX;
- float randNum = (float)g_wintermute->randInt(0, randMax) / (float)randMax;
+ float randNum = (float)BaseEngine::instance().randInt(0, randMax) / (float)randMax;
return from + (to - from) * randNum;
}
diff --git a/engines/wintermute/wintermute.cpp b/engines/wintermute/wintermute.cpp index 2dadd51b09..b97bb22e6b 100644 --- a/engines/wintermute/wintermute.cpp +++ b/engines/wintermute/wintermute.cpp @@ -53,7 +53,6 @@ WinterMuteEngine::WinterMuteEngine() : Engine(g_system) { _classReg->registerClasses(); _game = new AdGame(""); - _rnd = NULL; } WinterMuteEngine::WinterMuteEngine(OSystem *syst, const ADGameDescription *desc) @@ -74,8 +73,6 @@ WinterMuteEngine::WinterMuteEngine(OSystem *syst, const ADGameDescription *desc) DebugMan.addDebugChannel(kWinterMuteDebugFont, "font", "Text-drawing-related messages"); DebugMan.addDebugChannel(kWinterMuteDebugFileAccess, "file-access", "Non-critical problems like missing files"); DebugMan.addDebugChannel(kWinterMuteDebugAudio, "audio", "audio-playback-related issues"); - // Don't forget to register your random source - _rnd = new Common::RandomSource("WinterMute"); _game = NULL; @@ -86,7 +83,6 @@ WinterMuteEngine::WinterMuteEngine(OSystem *syst, const ADGameDescription *desc) WinterMuteEngine::~WinterMuteEngine() { // Dispose your resources here deinit(); - delete _rnd; delete _game; delete _console; g_wintermute = NULL; @@ -381,8 +377,4 @@ bool WinterMuteEngine::getGameInfo(const Common::FSList &fslist, Common::String return retVal; } -uint32 WinterMuteEngine::randInt(int from, int to) { - return _rnd->getRandomNumberRng(from, to); -} - } // End of namespace WinterMute diff --git a/engines/wintermute/wintermute.h b/engines/wintermute/wintermute.h index 8dd1b0b98e..fb94fd9175 100644 --- a/engines/wintermute/wintermute.h +++ b/engines/wintermute/wintermute.h @@ -23,7 +23,6 @@ #ifndef WINTERMUTE_H #define WINTERMUTE_H -#include "common/random.h" #include "engines/engine.h" #include "engines/advancedDetector.h" #include "gui/debugger.h" @@ -52,7 +51,6 @@ public: virtual bool hasFeature(EngineFeature f) const; Common::SaveFileManager *getSaveFileMan() { return _saveFileMan; } SystemClassRegistry *getClassRegistry(){ return _classReg; } - uint32 randInt(int from, int to); virtual Common::Error loadGameState(int slot); virtual bool canLoadGameStateCurrently(); virtual Common::Error saveGameState(int slot, const Common::String &desc); @@ -66,8 +64,6 @@ private: Console *_console; BaseGame *_game; SystemClassRegistry *_classReg; - // We need random numbers - Common::RandomSource *_rnd; const ADGameDescription *_gameDescription; }; |