forked from teamnwah/openmw-tes3coop
Merge Land/LandTextures
This commit is contained in:
parent
7021d354c6
commit
6d9d98c02c
3 changed files with 65 additions and 137 deletions
|
@ -38,9 +38,9 @@ CSMTools::MergeOperation::MergeOperation (CSMDoc::Document& document, ToUTF8::Fr
|
||||||
appendStage (new MergeRefIdsStage (mState));
|
appendStage (new MergeRefIdsStage (mState));
|
||||||
appendStage (new MergeReferencesStage (mState));
|
appendStage (new MergeReferencesStage (mState));
|
||||||
appendStage (new MergeReferencesStage (mState));
|
appendStage (new MergeReferencesStage (mState));
|
||||||
appendStage (new ListLandTexturesMergeStage (mState));
|
appendStage (new PopulateLandTexturesMergeStage (mState));
|
||||||
appendStage (new MergeLandTexturesStage (mState));
|
|
||||||
appendStage (new MergeLandStage (mState));
|
appendStage (new MergeLandStage (mState));
|
||||||
|
appendStage (new FixLandsAndLandTexturesMergeStage (mState));
|
||||||
|
|
||||||
appendStage (new FinishMergedDocumentStage (mState, encoding));
|
appendStage (new FinishMergedDocumentStage (mState, encoding));
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
#include "mergestate.hpp"
|
#include "mergestate.hpp"
|
||||||
|
|
||||||
#include "../doc/document.hpp"
|
#include "../doc/document.hpp"
|
||||||
|
#include "../world/commands.hpp"
|
||||||
#include "../world/data.hpp"
|
#include "../world/data.hpp"
|
||||||
|
#include "../world/idtable.hpp"
|
||||||
|
|
||||||
|
|
||||||
CSMTools::StartMergeStage::StartMergeStage (MergeState& state)
|
CSMTools::StartMergeStage::StartMergeStage (MergeState& state)
|
||||||
|
@ -109,102 +111,32 @@ void CSMTools::MergeReferencesStage::perform (int stage, CSMDoc::Messages& messa
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CSMTools::ListLandTexturesMergeStage::ListLandTexturesMergeStage (MergeState& state)
|
CSMTools::PopulateLandTexturesMergeStage::PopulateLandTexturesMergeStage (MergeState& state)
|
||||||
: mState (state)
|
: mState (state)
|
||||||
{}
|
|
||||||
|
|
||||||
int CSMTools::ListLandTexturesMergeStage::setup()
|
|
||||||
{
|
{
|
||||||
return mState.mSource.getData().getLand().getSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMTools::ListLandTexturesMergeStage::perform (int stage, CSMDoc::Messages& messages)
|
int CSMTools::PopulateLandTexturesMergeStage::setup()
|
||||||
{
|
{
|
||||||
const CSMWorld::Record<CSMWorld::Land>& record =
|
|
||||||
mState.mSource.getData().getLand().getRecord (stage);
|
|
||||||
|
|
||||||
if (!record.isDeleted())
|
|
||||||
{
|
|
||||||
const CSMWorld::Land& land = record.get();
|
|
||||||
|
|
||||||
// make sure record is loaded
|
|
||||||
land.loadData (ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML |
|
|
||||||
ESM::Land::DATA_VCLR | ESM::Land::DATA_VTEX);
|
|
||||||
|
|
||||||
if (const ESM::Land::LandData *data = land.getLandData (ESM::Land::DATA_VTEX))
|
|
||||||
{
|
|
||||||
// list texture indices
|
|
||||||
std::pair<uint16_t, int> key;
|
|
||||||
key.second = land.mPlugin;
|
|
||||||
|
|
||||||
for (int i=0; i<ESM::Land::LAND_NUM_TEXTURES; ++i)
|
|
||||||
{
|
|
||||||
key.first = data->mTextures[i];
|
|
||||||
|
|
||||||
mState.mTextureIndices[key] = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CSMTools::MergeLandTexturesStage::MergeLandTexturesStage (MergeState& state)
|
|
||||||
: mState (state), mNext (mState.mTextureIndices.end())
|
|
||||||
{}
|
|
||||||
|
|
||||||
int CSMTools::MergeLandTexturesStage::setup()
|
|
||||||
{
|
|
||||||
// Should use the size of mState.mTextureIndices instead, but that is not available at this
|
|
||||||
// point. Unless there are any errors in the land and land texture records this will not
|
|
||||||
// make a difference.
|
|
||||||
return mState.mSource.getData().getLandTextures().getSize();
|
return mState.mSource.getData().getLandTextures().getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMTools::MergeLandTexturesStage::perform (int stage, CSMDoc::Messages& messages)
|
void CSMTools::PopulateLandTexturesMergeStage::perform (int stage, CSMDoc::Messages& messages)
|
||||||
{
|
{
|
||||||
if (stage==0)
|
const CSMWorld::Record<CSMWorld::LandTexture>& record =
|
||||||
mNext = mState.mTextureIndices.begin();
|
mState.mSource.getData().getLandTextures().getRecord (stage);
|
||||||
|
|
||||||
bool found = false;
|
if (!record.isDeleted())
|
||||||
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
if (mNext==mState.mTextureIndices.end())
|
mState.mTarget->getData().getLandTextures().appendRecord(record);
|
||||||
return;
|
|
||||||
|
|
||||||
mNext->second = stage+1;
|
|
||||||
|
|
||||||
std::ostringstream stream;
|
|
||||||
stream << mNext->first.first-1 << "_" << mNext->first.second;
|
|
||||||
|
|
||||||
int index = mState.mSource.getData().getLandTextures().searchId (stream.str());
|
|
||||||
|
|
||||||
if (index!=-1)
|
|
||||||
{
|
|
||||||
CSMWorld::LandTexture texture =
|
|
||||||
mState.mSource.getData().getLandTextures().getRecord (index).get();
|
|
||||||
|
|
||||||
stream.clear();
|
|
||||||
stream << mNext->second-1 << "_0";
|
|
||||||
|
|
||||||
texture.mIndex = mNext->second-1;
|
|
||||||
texture.mId = stream.str();
|
|
||||||
|
|
||||||
CSMWorld::Record<CSMWorld::LandTexture> newRecord (
|
|
||||||
CSMWorld::RecordBase::State_ModifiedOnly, 0, &texture);
|
|
||||||
|
|
||||||
mState.mTarget->getData().getLandTextures().appendRecord (newRecord);
|
|
||||||
|
|
||||||
found = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++mNext;
|
|
||||||
}
|
|
||||||
while (!found);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CSMTools::MergeLandStage::MergeLandStage (MergeState& state) : mState (state) {}
|
CSMTools::MergeLandStage::MergeLandStage (MergeState& state)
|
||||||
|
: mState (state)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int CSMTools::MergeLandStage::setup()
|
int CSMTools::MergeLandStage::setup()
|
||||||
{
|
{
|
||||||
|
@ -218,40 +150,35 @@ void CSMTools::MergeLandStage::perform (int stage, CSMDoc::Messages& messages)
|
||||||
|
|
||||||
if (!record.isDeleted())
|
if (!record.isDeleted())
|
||||||
{
|
{
|
||||||
const CSMWorld::Land& land = record.get();
|
mState.mTarget->getData().getLand().appendRecord (record);
|
||||||
|
}
|
||||||
land.loadData (ESM::Land::DATA_VCLR | ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML |
|
}
|
||||||
ESM::Land::DATA_VTEX);
|
|
||||||
|
|
||||||
CSMWorld::Land newLand (land);
|
CSMTools::FixLandsAndLandTexturesMergeStage::FixLandsAndLandTexturesMergeStage (MergeState& state)
|
||||||
|
: mState (state)
|
||||||
newLand.mPlugin = 0;
|
{
|
||||||
|
}
|
||||||
if (land.mDataTypes & ESM::Land::DATA_VTEX)
|
|
||||||
{
|
int CSMTools::FixLandsAndLandTexturesMergeStage::setup()
|
||||||
// adjust land texture references
|
{
|
||||||
if (ESM::Land::LandData *data = newLand.getLandData())
|
// We will have no more than the source
|
||||||
{
|
return mState.mSource.getData().getLand().getSize();
|
||||||
std::pair<uint16_t, int> key;
|
}
|
||||||
key.second = land.mPlugin;
|
|
||||||
|
void CSMTools::FixLandsAndLandTexturesMergeStage::perform (int stage, CSMDoc::Messages& messages)
|
||||||
for (int i=0; i<ESM::Land::LAND_NUM_TEXTURES; ++i)
|
{
|
||||||
{
|
if (stage < mState.mTarget->getData().getLand().getSize())
|
||||||
key.first = data->mTextures[i];
|
{
|
||||||
std::map<std::pair<uint16_t, int>, int>::const_iterator iter =
|
CSMWorld::IdTable& landTable = dynamic_cast<CSMWorld::IdTable&>(
|
||||||
mState.mTextureIndices.find (key);
|
*mState.mTarget->getData().getTableModel(CSMWorld::UniversalId::Type_Lands));
|
||||||
|
|
||||||
if (iter!=mState.mTextureIndices.end())
|
CSMWorld::IdTable& ltexTable = dynamic_cast<CSMWorld::IdTable&>(
|
||||||
data->mTextures[i] = iter->second;
|
*mState.mTarget->getData().getTableModel(CSMWorld::UniversalId::Type_LandTextures));
|
||||||
else
|
|
||||||
data->mTextures[i] = 0;
|
std::string id = mState.mTarget->getData().getLand().getId(stage);
|
||||||
}
|
|
||||||
}
|
CSMWorld::TouchLandCommand cmd(landTable, ltexTable, id);
|
||||||
}
|
cmd.redo();
|
||||||
|
|
||||||
CSMWorld::Record<CSMWorld::Land> newRecord (
|
|
||||||
CSMWorld::RecordBase::State_ModifiedOnly, 0, &newLand);
|
|
||||||
|
|
||||||
mState.mTarget->getData().getLand().appendRecord (newRecord);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,29 +116,14 @@ namespace CSMTools
|
||||||
///< Messages resulting from this stage will be appended to \a messages.
|
///< Messages resulting from this stage will be appended to \a messages.
|
||||||
};
|
};
|
||||||
|
|
||||||
class ListLandTexturesMergeStage : public CSMDoc::Stage
|
/// Adds all land texture records that could potentially be referenced when merging
|
||||||
|
class PopulateLandTexturesMergeStage : public CSMDoc::Stage
|
||||||
{
|
{
|
||||||
MergeState& mState;
|
MergeState& mState;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ListLandTexturesMergeStage (MergeState& state);
|
PopulateLandTexturesMergeStage (MergeState& state);
|
||||||
|
|
||||||
virtual int setup();
|
|
||||||
///< \return number of steps
|
|
||||||
|
|
||||||
virtual void perform (int stage, CSMDoc::Messages& messages);
|
|
||||||
///< Messages resulting from this stage will be appended to \a messages.
|
|
||||||
};
|
|
||||||
|
|
||||||
class MergeLandTexturesStage : public CSMDoc::Stage
|
|
||||||
{
|
|
||||||
MergeState& mState;
|
|
||||||
std::map<std::pair<uint16_t, int>, int>::iterator mNext;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
MergeLandTexturesStage (MergeState& state);
|
|
||||||
|
|
||||||
virtual int setup();
|
virtual int setup();
|
||||||
///< \return number of steps
|
///< \return number of steps
|
||||||
|
@ -161,6 +146,22 @@ namespace CSMTools
|
||||||
virtual void perform (int stage, CSMDoc::Messages& messages);
|
virtual void perform (int stage, CSMDoc::Messages& messages);
|
||||||
///< Messages resulting from this stage will be appended to \a messages.
|
///< Messages resulting from this stage will be appended to \a messages.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Flattens the added land and land texture records.
|
||||||
|
class FixLandsAndLandTexturesMergeStage : public CSMDoc::Stage
|
||||||
|
{
|
||||||
|
MergeState& mState;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FixLandsAndLandTexturesMergeStage (MergeState& state);
|
||||||
|
|
||||||
|
virtual int setup();
|
||||||
|
///< \return number of steps
|
||||||
|
|
||||||
|
virtual void perform (int stage, CSMDoc::Messages& messages);
|
||||||
|
///< Messages resulting from this stage will be appended to \a messages.
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue