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/wintermute/base | |
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/wintermute/base')
-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 |
3 files changed, 19 insertions, 2 deletions
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); } |