1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-10 03:39:55 +00:00

added save stage for globals

This commit is contained in:
Marc Zinnschlag 2013-09-16 12:51:57 +02:00
parent 874ce26bef
commit bf0fba68af
4 changed files with 74 additions and 5 deletions

View File

@ -2058,9 +2058,9 @@ void CSMDoc::Document::addOptionalGlobals()
{
static const char *sGlobals[] =
{
"dayspassed",
"pcwerewolf",
"pcyear",
"DaysPassed",
"PCWerewolf",
"PCYear",
0
};

View File

@ -1,9 +1,14 @@
#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 "document.hpp"
CSMDoc::Saving::Saving (Document& document)
: 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 WriteCollectionStage<CSMWorld::IdCollection<ESM::Global> >
(mDocument.getData().getGlobals(), mState, ESM::REC_GLOB));
appendStage (new CloseSaveStage (mState));

View File

@ -1,8 +1,14 @@
#ifndef CSM_DOC_SAVINGSTAGES_H
#define CSM_DOC_SAVINGSTAGES_H
#include <components/esm/defs.hpp>
#include "stage.hpp"
#include "savingstate.hpp"
#include "../world/record.hpp"
namespace CSMDoc
{
class Document;
@ -40,6 +46,62 @@ namespace CSMDoc
///< 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
{
SavingState& mState;

View File

@ -90,7 +90,7 @@ class ESMWriter
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 endRecord(const std::string& name);
void writeHString(const std::string& data);