1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 10:23:56 +00:00

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

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

See merge request OpenMW/openmw!1121
This commit is contained in:
psi29a 2021-08-26 14:29:49 +00:00
commit fff35dcb03
5 changed files with 69 additions and 2 deletions

View file

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

View file

@ -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);
}
}

View file

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

View file

@ -20,7 +20,7 @@ namespace CSMWorld
{ {
std::string mId; 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); void load (ESM::ESMReader &esm, bool &isDeleted);
}; };
} }

View file

@ -873,6 +873,26 @@ namespace MWWorld
// A proper fix should be made for future versions of the file format. // 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; 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 // Try to overwrite existing record
if (interior) if (interior)
{ {