mirror of
https://github.com/OpenMW/openmw.git
synced 2025-10-18 02:16:37 +00:00
FIX: Track the highest local refNum during plugin loading and increment it for each cloned/created reference
This commit is contained in:
parent
2cb7d6c392
commit
79d86bf2bd
2 changed files with 14 additions and 3 deletions
|
@ -175,6 +175,9 @@ void CSMWorld::RefCollection::load(ESM::ESMReader& reader, int cellIndex, bool b
|
|||
ref.mIdNum = mNextId; // FIXME: fragile
|
||||
ref.mId = ESM::RefId::stringRefId(getNewId());
|
||||
|
||||
if (!base && ref.mRefNum.mIndex >= mHighestUsedRefNum)
|
||||
mHighestUsedRefNum = ref.mRefNum.mIndex;
|
||||
|
||||
cache.emplace(ref.mRefNum, ref.mIdNum);
|
||||
|
||||
auto record = std::make_unique<Record<CellRef>>();
|
||||
|
@ -222,6 +225,11 @@ std::string CSMWorld::RefCollection::getNewId()
|
|||
return "ref#" + std::to_string(mNextId++);
|
||||
}
|
||||
|
||||
uint32_t CSMWorld::RefCollection::getNextRefNum()
|
||||
{
|
||||
return ++mHighestUsedRefNum;
|
||||
}
|
||||
|
||||
unsigned int CSMWorld::RefCollection::extractIdNum(std::string_view id) const
|
||||
{
|
||||
std::string::size_type separator = id.find_last_of('#');
|
||||
|
@ -283,6 +291,7 @@ void CSMWorld::RefCollection::appendBlankRecord(const ESM::RefId& id, UniversalI
|
|||
|
||||
record->get().mId = id;
|
||||
record->get().mIdNum = extractIdNum(id.getRefIdString());
|
||||
record->get().mRefNum.mIndex = getNextRefNum();
|
||||
|
||||
Collection<CellRef>::appendRecord(std::move(record));
|
||||
}
|
||||
|
@ -298,15 +307,13 @@ void CSMWorld::RefCollection::cloneRecord(
|
|||
|
||||
copy->get().mId = destination;
|
||||
copy->get().mIdNum = extractIdNum(destination.getRefIdString());
|
||||
copy->get().mRefNum.mIndex = getNextRefNum();
|
||||
|
||||
if (copy->get().mRefNum.hasContentFile())
|
||||
{
|
||||
mRefIndex.insert(std::make_pair(static_cast<Record<CellRef>*>(copy.get())->get().mIdNum, index));
|
||||
copy->get().mRefNum.mContentFile = -1;
|
||||
copy->get().mRefNum.mIndex = index;
|
||||
}
|
||||
else
|
||||
copy->get().mRefNum.mIndex = copy->get().mIdNum;
|
||||
|
||||
insertRecord(std::move(copy), getAppendIndex(destination, type)); // call RefCollection::insertRecord()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef CSM_WOLRD_REFCOLLECTION_H
|
||||
#define CSM_WOLRD_REFCOLLECTION_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
@ -40,9 +41,12 @@ namespace CSMWorld
|
|||
std::map<unsigned int, int> mRefIndex; // CellRef index keyed by CSMWorld::CellRef::mIdNum
|
||||
|
||||
int mNextId;
|
||||
uint32_t mHighestUsedRefNum = 0;
|
||||
|
||||
unsigned int extractIdNum(std::string_view id) const;
|
||||
|
||||
uint32_t getNextRefNum();
|
||||
|
||||
int getIntIndex(unsigned int id) const;
|
||||
|
||||
int searchId(unsigned int id) const;
|
||||
|
|
Loading…
Reference in a new issue