mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 07:39:40 +00:00
added save stage for globals
This commit is contained in:
parent
874ce26bef
commit
bf0fba68af
4 changed files with 74 additions and 5 deletions
|
@ -2058,9 +2058,9 @@ void CSMDoc::Document::addOptionalGlobals()
|
||||||
{
|
{
|
||||||
static const char *sGlobals[] =
|
static const char *sGlobals[] =
|
||||||
{
|
{
|
||||||
"dayspassed",
|
"DaysPassed",
|
||||||
"pcwerewolf",
|
"PCWerewolf",
|
||||||
"pcyear",
|
"PCYear",
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
|
|
||||||
#include "saving.hpp"
|
#include "saving.hpp"
|
||||||
|
|
||||||
#include "state.hpp"
|
#include <components/esm/defs.hpp>
|
||||||
|
|
||||||
|
#include "../world/data.hpp"
|
||||||
|
#include "../world/idcollection.hpp"
|
||||||
|
|
||||||
|
#include "state.hpp"
|
||||||
#include "savingstages.hpp"
|
#include "savingstages.hpp"
|
||||||
|
#include "document.hpp"
|
||||||
|
|
||||||
CSMDoc::Saving::Saving (Document& document)
|
CSMDoc::Saving::Saving (Document& document)
|
||||||
: Operation (State_Saving, true, true), mDocument (document), mState (*this)
|
: Operation (State_Saving, true, true), mDocument (document), mState (*this)
|
||||||
|
@ -12,6 +17,8 @@ CSMDoc::Saving::Saving (Document& document)
|
||||||
|
|
||||||
appendStage (new WriteHeaderStage (mDocument, mState));
|
appendStage (new WriteHeaderStage (mDocument, mState));
|
||||||
|
|
||||||
|
appendStage (new WriteCollectionStage<CSMWorld::IdCollection<ESM::Global> >
|
||||||
|
(mDocument.getData().getGlobals(), mState, ESM::REC_GLOB));
|
||||||
|
|
||||||
|
|
||||||
appendStage (new CloseSaveStage (mState));
|
appendStage (new CloseSaveStage (mState));
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
#ifndef CSM_DOC_SAVINGSTAGES_H
|
#ifndef CSM_DOC_SAVINGSTAGES_H
|
||||||
#define CSM_DOC_SAVINGSTAGES_H
|
#define CSM_DOC_SAVINGSTAGES_H
|
||||||
|
|
||||||
|
#include <components/esm/defs.hpp>
|
||||||
|
|
||||||
#include "stage.hpp"
|
#include "stage.hpp"
|
||||||
|
|
||||||
|
#include "savingstate.hpp"
|
||||||
|
|
||||||
|
#include "../world/record.hpp"
|
||||||
|
|
||||||
namespace CSMDoc
|
namespace CSMDoc
|
||||||
{
|
{
|
||||||
class Document;
|
class Document;
|
||||||
|
@ -40,6 +46,62 @@ namespace CSMDoc
|
||||||
///< Messages resulting from this stage will be appended to \a messages.
|
///< Messages resulting from this stage will be appended to \a messages.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<class CollectionT>
|
||||||
|
class WriteCollectionStage : public Stage
|
||||||
|
{
|
||||||
|
const CollectionT& mCollection;
|
||||||
|
SavingState& mState;
|
||||||
|
ESM::RecNameInts mRecordType;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
WriteCollectionStage (const CollectionT& collection, SavingState& state,
|
||||||
|
ESM::RecNameInts recordType);
|
||||||
|
|
||||||
|
virtual int setup();
|
||||||
|
///< \return number of steps
|
||||||
|
|
||||||
|
virtual void perform (int stage, std::vector<std::string>& messages);
|
||||||
|
///< Messages resulting from this stage will be appended to \a messages.
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class CollectionT>
|
||||||
|
WriteCollectionStage<CollectionT>::WriteCollectionStage (const CollectionT& collection,
|
||||||
|
SavingState& state, ESM::RecNameInts recordType)
|
||||||
|
: mCollection (collection), mState (state), mRecordType (recordType)
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<class CollectionT>
|
||||||
|
int WriteCollectionStage<CollectionT>::setup()
|
||||||
|
{
|
||||||
|
return mCollection.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class CollectionT>
|
||||||
|
void WriteCollectionStage<CollectionT>::perform (int stage, std::vector<std::string>& messages)
|
||||||
|
{
|
||||||
|
CSMWorld::RecordBase::State state = mCollection.getRecord (stage).mState;
|
||||||
|
|
||||||
|
if (state==CSMWorld::RecordBase::State_Modified ||
|
||||||
|
state==CSMWorld::RecordBase::State_ModifiedOnly)
|
||||||
|
{
|
||||||
|
std::string type;
|
||||||
|
for (int i=0; i<4; ++i)
|
||||||
|
/// \todo make endianess agnostic (change ESMWriter interface?)
|
||||||
|
type += reinterpret_cast<const char *> (&mRecordType)[i];
|
||||||
|
|
||||||
|
mState.getWriter().startRecord (type);
|
||||||
|
mCollection.getRecord (stage).mModified.save (mState.getWriter());
|
||||||
|
mState.getWriter().endRecord (type);
|
||||||
|
}
|
||||||
|
else if (state==CSMWorld::RecordBase::State_Deleted)
|
||||||
|
{
|
||||||
|
/// \todo write record with delete flag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class CloseSaveStage : public Stage
|
class CloseSaveStage : public Stage
|
||||||
{
|
{
|
||||||
SavingState& mState;
|
SavingState& mState;
|
||||||
|
|
|
@ -90,7 +90,7 @@ class ESMWriter
|
||||||
write((char*)&data, size);
|
write((char*)&data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startRecord(const std::string& name, uint32_t flags);
|
void startRecord(const std::string& name, uint32_t flags = 0);
|
||||||
void startSubRecord(const std::string& name);
|
void startSubRecord(const std::string& name);
|
||||||
void endRecord(const std::string& name);
|
void endRecord(const std::string& name);
|
||||||
void writeHString(const std::string& data);
|
void writeHString(const std::string& data);
|
||||||
|
|
Loading…
Reference in a new issue