Skip to content

Commit 9cecc92

Browse files
committed
Preserve static cell insertion order
1 parent ebad87b commit 9cecc92

File tree

2 files changed

+9
-32
lines changed

2 files changed

+9
-32
lines changed

apps/openmw/mwworld/store.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -639,20 +639,9 @@ namespace MWWorld
639639
for (const auto& [_, cell] : mDynamicInt)
640640
mCells.erase(cell->mId);
641641
mDynamicInt.clear();
642-
setUp();
643-
}
644-
645-
void Store<ESM::Cell>::setUp()
646-
{
647-
mSharedInt.clear();
648-
mSharedInt.reserve(mInt.size());
649-
for (auto& [_, cell] : mInt)
650-
mSharedInt.push_back(cell);
651642

652-
mSharedExt.clear();
653-
mSharedExt.reserve(mExt.size());
654-
for (auto& [_, cell] : mExt)
655-
mSharedExt.push_back(cell);
643+
mSharedInt.erase(mSharedInt.begin() + mInt.size(), mSharedInt.end());
644+
mSharedExt.erase(mSharedExt.begin() + mExt.size(), mSharedExt.end());
656645
}
657646
RecordId Store<ESM::Cell>::load(ESM::ESMReader& esm)
658647
{
@@ -685,7 +674,10 @@ namespace MWWorld
685674
{
686675
cell.loadCell(esm, true);
687676
if (newCell)
677+
{
688678
mInt[cell.mName] = &cell;
679+
mSharedInt.push_back(&cell);
680+
}
689681
}
690682
else
691683
{
@@ -698,7 +690,10 @@ namespace MWWorld
698690
// push the new references on the list of references to manage
699691
cell.postLoad(esm);
700692
if (newCell)
693+
{
701694
mExt[std::make_pair(cell.mData.mX, cell.mData.mY)] = &cell;
695+
mSharedExt.push_back(&cell);
696+
}
702697
else
703698
{
704699
// merge lists of leased references, use newer data in case of conflict

apps/openmw/mwworld/store.hpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -360,27 +360,10 @@ namespace MWWorld
360360
template <>
361361
class Store<ESM::Cell> : public DynamicStore
362362
{
363-
struct DynamicExtCmp
364-
{
365-
bool operator()(const std::pair<int, int>& left, const std::pair<int, int>& right) const
366-
{
367-
if (left.first == right.first && left.second == right.second)
368-
return false;
369-
370-
if (left.first == right.first)
371-
return left.second > right.second;
372-
373-
// Exterior cells are listed in descending, row-major order,
374-
// this is a workaround for an ambiguous chargen_plank reference in the vanilla game.
375-
// there is one at -22,16 and one at -2,-9, the latter should be used.
376-
return left.first > right.first;
377-
}
378-
};
379-
380363
typedef std::unordered_map<std::string, ESM::Cell*, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual>
381364
DynamicInt;
382365

383-
typedef std::map<std::pair<int, int>, ESM::Cell*, DynamicExtCmp> DynamicExt;
366+
typedef std::map<std::pair<int, int>, ESM::Cell*> DynamicExt;
384367

385368
std::unordered_map<ESM::RefId, ESM::Cell> mCells;
386369

@@ -410,7 +393,6 @@ namespace MWWorld
410393
const ESM::Cell* find(int x, int y) const;
411394

412395
void clearDynamic() override;
413-
void setUp() override;
414396

415397
RecordId load(ESM::ESMReader& esm) override;
416398

0 commit comments

Comments
 (0)