Merge branch 'Ignore-empty-pgrd' into 'master'

Do not store empty PGRD records.  Should resolve Issue #6209.

See merge request OpenMW/openmw!1121
pull/3097/head
psi29a 3 years ago
commit fff35dcb03

@ -19,7 +19,7 @@ opencs_hdrs_noqt (model/doc
opencs_units (model/world
idtable idtableproxymodel regionmap data commanddispatcher idtablebase resourcetable nestedtableproxymodel idtree infotableproxymodel landtexturetableproxymodel
actoradapter
actoradapter idcollection
)

@ -0,0 +1,43 @@
#include "idcollection.hpp"
namespace CSMWorld
{
template<>
int IdCollection<Pathgrid, IdAccessor<Pathgrid> >::load (ESM::ESMReader& reader, bool base)
{
Pathgrid record;
bool isDeleted = false;
loadRecord (record, reader, isDeleted);
std::string id = IdAccessor<Pathgrid>().getId (record);
int index = this->searchId (id);
if (record.mPoints.empty() || record.mEdges.empty())
isDeleted = true;
if (isDeleted)
{
if (index==-1)
{
// deleting a record that does not exist
// ignore it for now
/// \todo report the problem to the user
return -1;
}
if (base)
{
this->removeRows (index, 1);
return -1;
}
std::unique_ptr<Record<Pathgrid> > baseRecord(new Record<Pathgrid>(this->getRecord(index)));
baseRecord->mState = RecordBase::State_Deleted;
this->setRecord(index, std::move(baseRecord));
return index;
}
return load (record, base, index);
}
}

@ -5,6 +5,7 @@
#include "collection.hpp"
#include "land.hpp"
#include "pathgrid.hpp"
namespace CSMWorld
{
@ -153,6 +154,9 @@ namespace CSMWorld
return true;
}
template<>
int IdCollection<Pathgrid, IdAccessor<Pathgrid> >::load(ESM::ESMReader& reader, bool base);
}
#endif

@ -20,7 +20,7 @@ namespace CSMWorld
{
std::string mId;
void load (ESM::ESMReader &esm, bool &isDeleted, const IdCollection<Cell>& cells);
void load (ESM::ESMReader &esm, bool &isDeleted, const IdCollection<Cell, IdAccessor<Cell> >& cells);
void load (ESM::ESMReader &esm, bool &isDeleted);
};
}

@ -873,6 +873,26 @@ namespace MWWorld
// A proper fix should be made for future versions of the file format.
bool interior = pathgrid.mData.mX == 0 && pathgrid.mData.mY == 0 && mCells->search(pathgrid.mCell) != nullptr;
// deal with mods that have empty pathgrid records (Issue #6209)
// we assume that these records are empty on purpose (i.e. to remove old pathgrid on an updated cell)
if (isDeleted || pathgrid.mPoints.empty() || pathgrid.mEdges.empty())
{
if (interior)
{
Interior::iterator it = mInt.find(pathgrid.mCell);
if (it != mInt.end())
mInt.erase(it);
}
else
{
Exterior::iterator it = mExt.find(std::make_pair(pathgrid.mData.mX, pathgrid.mData.mY));
if (it != mExt.end())
mExt.erase(it);
}
return RecordId("", isDeleted);
}
// Try to overwrite existing record
if (interior)
{

Loading…
Cancel
Save