1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-03 13:39:40 +00:00

Add prng to World instance and serialize state in Save

This commit is contained in:
ζeh Matt 2022-03-06 20:02:03 +02:00
parent aa6cba9b17
commit b502dc12f0
No known key found for this signature in database
GPG key ID: 18CE582C71A225B0
5 changed files with 31 additions and 2 deletions

View file

@ -9,6 +9,7 @@
#include <deque> #include <deque>
#include <components/esm3/cellid.hpp> #include <components/esm3/cellid.hpp>
#include <components/misc/rng.hpp>
#include <osg/Timer> #include <osg/Timer>
@ -658,6 +659,8 @@ namespace MWBase
virtual void reportStats(unsigned int frameNumber, osg::Stats& stats) const = 0; virtual void reportStats(unsigned int frameNumber, osg::Stats& stats) const = 0;
virtual std::vector<MWWorld::Ptr> getAll(const std::string& id) = 0; virtual std::vector<MWWorld::Ptr> getAll(const std::string& id) = 0;
virtual Misc::Rng::Generator& getPrng() = 0;
}; };
} }

View file

@ -359,6 +359,12 @@ namespace MWWorld
writer.writeHNT("LEVT", mLevitationEnabled); writer.writeHNT("LEVT", mLevitationEnabled);
writer.endRecord(ESM::REC_ENAB); writer.endRecord(ESM::REC_ENAB);
std::stringstream ssPrng;
ssPrng << mPrng;
writer.startRecord(ESM::REC_RAND);
writer.writeHString(ssPrng.str());
writer.endRecord(ESM::REC_RAND);
writer.startRecord(ESM::REC_CAM_); writer.startRecord(ESM::REC_CAM_);
writer.writeHNT("FIRS", isFirstPerson()); writer.writeHNT("FIRS", isFirstPerson());
writer.endRecord(ESM::REC_CAM_); writer.endRecord(ESM::REC_CAM_);
@ -376,6 +382,14 @@ namespace MWWorld
reader.getHNT(mTeleportEnabled, "TELE"); reader.getHNT(mTeleportEnabled, "TELE");
reader.getHNT(mLevitationEnabled, "LEVT"); reader.getHNT(mLevitationEnabled, "LEVT");
return; return;
case ESM::REC_RAND:
{
std::stringstream ssPrng;
ssPrng << reader.getHString();
ssPrng.seekg(0);
ssPrng >> mPrng;
}
break;
case ESM::REC_PLAY: case ESM::REC_PLAY:
mStore.checkPlayer(); mStore.checkPlayer();
mPlayer->readRecord(reader, type); mPlayer->readRecord(reader, type);
@ -3999,4 +4013,10 @@ namespace MWWorld
{ {
return mCells.getAll(id); return mCells.getAll(id);
} }
Misc::Rng::Generator& World::getPrng()
{
return mPrng;
}
} }

View file

@ -4,6 +4,7 @@
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
#include <components/misc/rng.hpp>
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
@ -84,7 +85,7 @@ namespace MWWorld
GroundcoverStore mGroundcoverStore; GroundcoverStore mGroundcoverStore;
LocalScripts mLocalScripts; LocalScripts mLocalScripts;
MWWorld::Globals mGlobalVariables; MWWorld::Globals mGlobalVariables;
Misc::Rng::Generator mPrng;
Cells mCells; Cells mCells;
std::string mCurrentWorldSpace; std::string mCurrentWorldSpace;
@ -736,6 +737,8 @@ namespace MWWorld
void reportStats(unsigned int frameNumber, osg::Stats& stats) const override; void reportStats(unsigned int frameNumber, osg::Stats& stats) const override;
std::vector<MWWorld::Ptr> getAll(const std::string& id) override; std::vector<MWWorld::Ptr> getAll(const std::string& id) override;
Misc::Rng::Generator& getPrng() override;
}; };
} }

View file

@ -173,6 +173,9 @@ enum RecNameInts : unsigned int
// format 16 - Lua scripts in saved games // format 16 - Lua scripts in saved games
REC_LUAM = fourCC("LUAM"), // LuaManager data REC_LUAM = fourCC("LUAM"), // LuaManager data
// format 21 - Random state in saved games.
REC_RAND = fourCC("RAND"), // Random state.
}; };
/// Common subrecords /// Common subrecords

View file

@ -4,7 +4,7 @@
#include "esmwriter.hpp" #include "esmwriter.hpp"
unsigned int ESM::SavedGame::sRecordId = ESM::REC_SAVE; unsigned int ESM::SavedGame::sRecordId = ESM::REC_SAVE;
int ESM::SavedGame::sCurrentFormat = 20; int ESM::SavedGame::sCurrentFormat = 21;
void ESM::SavedGame::load (ESMReader &esm) void ESM::SavedGame::load (ESMReader &esm)
{ {