fixed pathgrid loading

deque
Marc Zinnschlag 10 years ago
parent f4c9897bbd
commit be3b229a5f

@ -31,7 +31,7 @@ opencs_units_noqt (model/world
)
opencs_hdrs_noqt (model/world
columnimp idcollection collection info
columnimp idcollection collection info subcellcollection
)

@ -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<ESM::Global>);
mGlobals.addColumn (new RecordStateColumn<ESM::Global>);
@ -595,12 +595,12 @@ CSMWorld::IdCollection<ESM::MagicEffect>& CSMWorld::Data::getMagicEffects()
return mMagicEffects;
}
const CSMWorld::IdCollection<CSMWorld::Pathgrid>& CSMWorld::Data::getPathgrids() const
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& CSMWorld::Data::getPathgrids() const
{
return mPathgrids;
}
CSMWorld::IdCollection<CSMWorld::Pathgrid>& CSMWorld::Data::getPathgrids()
CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& CSMWorld::Data::getPathgrids()
{
return mPathgrids;
}

@ -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<ESM::Enchantment> mEnchantments;
IdCollection<ESM::BodyPart> mBodyParts;
IdCollection<ESM::MagicEffect> mMagicEffects;
IdCollection<Pathgrid> mPathgrids;
SubCellCollection<Pathgrid> mPathgrids;
IdCollection<ESM::DebugProfile> mDebugProfiles;
IdCollection<ESM::SoundGenerator> mSoundGens;
InfoCollection mTopicInfos;
@ -209,9 +210,9 @@ namespace CSMWorld
IdCollection<ESM::MagicEffect>& getMagicEffects();
const IdCollection<Pathgrid>& getPathgrids() const;
const SubCellCollection<Pathgrid>& getPathgrids() const;
IdCollection<Pathgrid>& getPathgrids();
SubCellCollection<Pathgrid>& getPathgrids();
/// Throws an exception, if \a id does not match a resources list.
const Resources& getResources (const UniversalId& id) const;

@ -11,6 +11,8 @@ namespace CSMWorld
template<typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT> >
class IdCollection : public Collection<ESXRecordT, IdAccessorT>
{
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<typename ESXRecordT, typename IdAccessorT>
void IdCollection<ESXRecordT, IdAccessorT>::loadRecord (ESXRecordT& record,
ESM::ESMReader& reader)
{
record.load (reader);
}
template<typename ESXRecordT, typename IdAccessorT>
void IdCollection<ESXRecordT, IdAccessorT>::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)
{

@ -3,6 +3,21 @@
#include <sstream>
void CSMWorld::Pathgrid::load (ESM::ESMReader &esm, const IdCollection<Cell>& 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);

@ -6,6 +6,9 @@
#include <components/esm/loadpgrd.hpp>
#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<Cell>& cells);
void load (ESM::ESMReader &esm);
};
}

@ -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<typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT> >
class SubCellCollection : public IdCollection<ESXRecordT, IdAccessorT>
{
const IdCollection<Cell>& mCells;
virtual void loadRecord (ESXRecordT& record, ESM::ESMReader& reader);
public:
SubCellCollection (const IdCollection<Cell>& cells);
};
template<typename ESXRecordT, typename IdAccessorT>
void SubCellCollection<ESXRecordT, IdAccessorT>::loadRecord (ESXRecordT& record,
ESM::ESMReader& reader)
{
record.load (reader, mCells);
}
template<typename ESXRecordT, typename IdAccessorT>
SubCellCollection<ESXRecordT, IdAccessorT>::SubCellCollection (
const IdCollection<Cell>& cells)
: mCells (cells)
{}
}
#endif
Loading…
Cancel
Save