Skip to content

Commit

Permalink
Merge remote-tracking branch 'scrawl/editor_saving'
Browse files Browse the repository at this point in the history
  • Loading branch information
zinnschlag committed Aug 23, 2015
2 parents 542c648 + 32ad8c8 commit 562f5cd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
15 changes: 9 additions & 6 deletions apps/opencs/model/doc/saving.cpp
Expand Up @@ -80,22 +80,25 @@ CSMDoc::Saving::Saving (Document& document, const boost::filesystem::path& proje
appendStage (new WriteCollectionStage<CSMWorld::IdCollection<ESM::StartScript> >
(mDocument.getData().getStartScripts(), mState));

appendStage (new WriteDialogueCollectionStage (mDocument, mState, false));

appendStage (new WriteDialogueCollectionStage (mDocument, mState, true));

appendStage (new WriteRefIdCollectionStage (mDocument, mState));

appendStage (new CollectionReferencesStage (mDocument, mState));

appendStage (new WriteCellCollectionStage (mDocument, mState));

appendStage (new WritePathgridCollectionStage (mDocument, mState));
// Dialogue can reference objects and cells so must be written after these records for vanilla-compatible files

appendStage (new WriteLandCollectionStage (mDocument, mState));
appendStage (new WriteDialogueCollectionStage (mDocument, mState, false));

appendStage (new WriteDialogueCollectionStage (mDocument, mState, true));

appendStage (new WritePathgridCollectionStage (mDocument, mState));

appendStage (new WriteLandTextureCollectionStage (mDocument, mState));

// references Land Textures
appendStage (new WriteLandCollectionStage (mDocument, mState));

// close file and clean up
appendStage (new CloseSaveStage (mState));

Expand Down
2 changes: 2 additions & 0 deletions apps/opencs/model/doc/savingstages.cpp
Expand Up @@ -454,6 +454,8 @@ void CSMDoc::WriteLandTextureCollectionStage::perform (int stage, Messages& mess

mState.getWriter().startRecord (record.sRecordId);

mState.getWriter().writeHNString("NAME", record.mId);

record.save (mState.getWriter());

mState.getWriter().endRecord (record.sRecordId);
Expand Down
8 changes: 1 addition & 7 deletions apps/opencs/model/world/landtexture.cpp
Expand Up @@ -9,13 +9,7 @@ namespace CSMWorld
{
ESM::LandTexture::load(esm);

int plugin = esm.getIndex();

std::ostringstream stream;

stream << mIndex << "_" << plugin;

mId = stream.str();
mPluginIndex = esm.getIndex();
}

}
7 changes: 2 additions & 5 deletions apps/opencs/model/world/landtexture.hpp
Expand Up @@ -7,13 +7,10 @@

namespace CSMWorld
{
/// \brief Wrapper for LandTexture record. Encodes mIndex and the plugin index (obtained from ESMReader)
/// in the ID.
///
/// \attention The mId field of the ESM::LandTexture struct is not used.
/// \brief Wrapper for LandTexture record, providing info which plugin the LandTexture was loaded from.
struct LandTexture : public ESM::LandTexture
{
std::string mId;
int mPluginIndex;

void load (ESM::ESMReader &esm);
};
Expand Down
16 changes: 12 additions & 4 deletions apps/opencs/view/render/terrainstorage.cpp
Expand Up @@ -29,10 +29,18 @@ namespace CSVRender

const ESM::LandTexture* TerrainStorage::getLandTexture(int index, short plugin)
{
std::ostringstream stream;
stream << index << "_" << plugin;

return &mData.getLandTextures().getRecord(stream.str()).get();
int numRecords = mData.getLandTextures().getSize();

for (int i=0; i<numRecords; ++i)
{
const CSMWorld::LandTexture* ltex = &mData.getLandTextures().getRecord(i).get();
if (ltex->mIndex == index && ltex->mPluginIndex == plugin)
return ltex;
}

std::stringstream error;
error << "Can't find LandTexture " << index << " from plugin " << plugin;
throw std::runtime_error(error.str());
}

void TerrainStorage::getBounds(float &minX, float &maxX, float &minY, float &maxY)
Expand Down

0 comments on commit 562f5cd

Please sign in to comment.