From be3b229a5f12abc7b847944e92468e10cfbe74a6 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 4 Oct 2014 15:36:52 +0200 Subject: [PATCH] fixed pathgrid loading --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/model/world/data.cpp | 8 ++-- apps/opencs/model/world/data.hpp | 7 ++-- apps/opencs/model/world/idcollection.hpp | 11 +++++- apps/opencs/model/world/pathgrid.cpp | 15 ++++++++ apps/opencs/model/world/pathgrid.hpp | 6 ++- apps/opencs/model/world/subcellcollection.hpp | 38 +++++++++++++++++++ 7 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 apps/opencs/model/world/subcellcollection.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 86f44d2b2a..c5f0a9028c 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -31,7 +31,7 @@ opencs_units_noqt (model/world ) opencs_hdrs_noqt (model/world - columnimp idcollection collection info + columnimp idcollection collection info subcellcollection ) diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index ccf86c5b86..dc8b142a42 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -59,8 +59,8 @@ int CSMWorld::Data::count (RecordBase::State state, const CollectionBase& collec } CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourcesManager) -: mEncoder (encoding), mRefs (mCells), mResourcesManager (resourcesManager), mReader (0), - mDialogue (0) +: mEncoder (encoding), mPathgrids (mCells), mRefs (mCells), + mResourcesManager (resourcesManager), mReader (0), mDialogue (0) { mGlobals.addColumn (new StringIdColumn); mGlobals.addColumn (new RecordStateColumn); @@ -595,12 +595,12 @@ CSMWorld::IdCollection& CSMWorld::Data::getMagicEffects() return mMagicEffects; } -const CSMWorld::IdCollection& CSMWorld::Data::getPathgrids() const +const CSMWorld::SubCellCollection& CSMWorld::Data::getPathgrids() const { return mPathgrids; } -CSMWorld::IdCollection& CSMWorld::Data::getPathgrids() +CSMWorld::SubCellCollection& CSMWorld::Data::getPathgrids() { return mPathgrids; } diff --git a/apps/opencs/model/world/data.hpp b/apps/opencs/model/world/data.hpp index cae16128c3..572622ff91 100644 --- a/apps/opencs/model/world/data.hpp +++ b/apps/opencs/model/world/data.hpp @@ -39,6 +39,7 @@ #include "refcollection.hpp" #include "infocollection.hpp" #include "pathgrid.hpp" +#include "subcellcollection.hpp" class QAbstractItemModel; @@ -74,7 +75,7 @@ namespace CSMWorld IdCollection mEnchantments; IdCollection mBodyParts; IdCollection mMagicEffects; - IdCollection mPathgrids; + SubCellCollection mPathgrids; IdCollection mDebugProfiles; IdCollection mSoundGens; InfoCollection mTopicInfos; @@ -209,9 +210,9 @@ namespace CSMWorld IdCollection& getMagicEffects(); - const IdCollection& getPathgrids() const; + const SubCellCollection& getPathgrids() const; - IdCollection& getPathgrids(); + SubCellCollection& getPathgrids(); /// Throws an exception, if \a id does not match a resources list. const Resources& getResources (const UniversalId& id) const; diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 940181c24b..0129ba3d8d 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -11,6 +11,8 @@ namespace CSMWorld template > class IdCollection : public Collection { + virtual void loadRecord (ESXRecordT& record, ESM::ESMReader& reader); + public: void load (ESM::ESMReader& reader, bool base); @@ -26,6 +28,13 @@ namespace CSMWorld /// \return Has the ID been deleted? }; + template + void IdCollection::loadRecord (ESXRecordT& record, + ESM::ESMReader& reader) + { + record.load (reader); + } + template void IdCollection::load (ESM::ESMReader& reader, bool base) { @@ -69,7 +78,7 @@ namespace CSMWorld record = this->getRecord (index).get(); } - record.load (reader); + loadRecord (record, reader); if (index==-1) { diff --git a/apps/opencs/model/world/pathgrid.cpp b/apps/opencs/model/world/pathgrid.cpp index 6226e361a6..1c82585df1 100644 --- a/apps/opencs/model/world/pathgrid.cpp +++ b/apps/opencs/model/world/pathgrid.cpp @@ -3,6 +3,21 @@ #include +void CSMWorld::Pathgrid::load (ESM::ESMReader &esm, const IdCollection& cells) +{ + load (esm); + + // correct ID + if (!mId.empty() && mId[0]!='#' && cells.searchId (mId)==-1) + { + std::ostringstream stream; + + stream << "#" << mData.mX << " " << mData.mY; + + mId = stream.str(); + } +} + void CSMWorld::Pathgrid::load (ESM::ESMReader &esm) { ESM::Pathgrid::load (esm); diff --git a/apps/opencs/model/world/pathgrid.hpp b/apps/opencs/model/world/pathgrid.hpp index 4e4525232a..3c9fcff504 100644 --- a/apps/opencs/model/world/pathgrid.hpp +++ b/apps/opencs/model/world/pathgrid.hpp @@ -6,6 +6,9 @@ #include +#include "idcollection.hpp" +#include "cell.hpp" + namespace CSMWorld { /// \brief Wrapper for Pathgrid record @@ -16,8 +19,9 @@ namespace CSMWorld { std::string mId; - void load (ESM::ESMReader &esm); + void load (ESM::ESMReader &esm, const IdCollection& cells); + void load (ESM::ESMReader &esm); }; } diff --git a/apps/opencs/model/world/subcellcollection.hpp b/apps/opencs/model/world/subcellcollection.hpp new file mode 100644 index 0000000000..28f0de6952 --- /dev/null +++ b/apps/opencs/model/world/subcellcollection.hpp @@ -0,0 +1,38 @@ +#ifndef CSM_WOLRD_SUBCOLLECTION_H +#define CSM_WOLRD_SUBCOLLECTION_H + +#include "idcollection.hpp" + +namespace CSMWorld +{ + /// \brief Single type collection of top level records that are associated with cells + template > + class SubCellCollection : public IdCollection + { + const IdCollection& mCells; + + virtual void loadRecord (ESXRecordT& record, ESM::ESMReader& reader); + + public: + + SubCellCollection (const IdCollection& cells); + + + }; + + template + void SubCellCollection::loadRecord (ESXRecordT& record, + ESM::ESMReader& reader) + { + record.load (reader, mCells); + } + + template + SubCellCollection::SubCellCollection ( + const IdCollection& cells) + : mCells (cells) + {} + +} + +#endif