Move WorldModel::getPtr(const ESM::RefId&, CellStore&) to CellStore

The function does not depend on WorldModel.
macos_ci
elsid 2 years ago
parent df6630a15c
commit a04eb9d26c
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -1283,4 +1283,23 @@ namespace MWWorld
return {};
}
Ptr CellStore::getPtr(ESM::RefId id)
{
if (mState == CellStore::State_Unloaded)
preload();
if (mState == CellStore::State_Preloaded)
{
if (!std::binary_search(mIds.begin(), mIds.end(), id))
return Ptr();
load();
}
Ptr ptr = search(id);
if (!ptr.isEmpty() && isAccessible(ptr.getRefData(), ptr.getCellRef()))
return ptr;
return Ptr();
}
}

@ -322,6 +322,8 @@ namespace MWWorld
Ptr getMovedActor(int actorId) const;
Ptr getPtr(ESM::RefId id);
bool operator==(const CellStore& right) const;
private:

@ -695,7 +695,7 @@ namespace MWWorld
{
// TODO: caching still doesn't work efficiently here (only works for the one CellStore that the reference is
// in)
Ptr ptr = mWorldModel.getPtr(name, *cellstore);
Ptr ptr = cellstore->getPtr(name);
if (!ptr.isEmpty())
return ptr;

@ -116,7 +116,7 @@ MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefNum& refNum) const
MWWorld::Ptr MWWorld::WorldModel::getPtrAndCache(const ESM::RefId& name, CellStore& cellStore)
{
Ptr ptr = getPtr(name, cellStore);
Ptr ptr = cellStore.getPtr(name);
if (!ptr.isEmpty() && ptr.isInCell())
{
@ -332,36 +332,13 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellByPosition(
return getExterior(cellIndex);
}
MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name, CellStore& cell)
{
if (cell.getState() == CellStore::State_Unloaded)
cell.preload();
if (cell.getState() == CellStore::State_Preloaded)
{
if (cell.hasId(name))
{
cell.load();
}
else
return Ptr();
}
Ptr ptr = cell.search(name);
if (!ptr.isEmpty() && MWWorld::CellStore::isAccessible(ptr.getRefData(), ptr.getCellRef()))
return ptr;
return Ptr();
}
MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name)
{
// First check the cache
for (IdCache::iterator iter(mIdCache.begin()); iter != mIdCache.end(); ++iter)
if (iter->first == name && iter->second)
{
Ptr ptr = getPtr(name, *iter->second);
Ptr ptr = iter->second->getPtr(name);
if (!ptr.isEmpty())
return ptr;
}

@ -66,7 +66,6 @@ namespace MWWorld
Ptr getPtr(const ESM::RefNum& refNum) const;
Ptr getPtr(const ESM::RefId& name, CellStore& cellStore);
Ptr getPtr(const ESM::RefId& name);
template <typename Fn>

Loading…
Cancel
Save