mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-01 10:11:33 +00:00
Move WorldModel::getPtr(const ESM::RefId&, CellStore&) to CellStore
The function does not depend on WorldModel.
This commit is contained in:
parent
df6630a15c
commit
a04eb9d26c
5 changed files with 24 additions and 27 deletions
|
@ -1283,4 +1283,23 @@ namespace MWWorld
|
||||||
return {};
|
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 getMovedActor(int actorId) const;
|
||||||
|
|
||||||
|
Ptr getPtr(ESM::RefId id);
|
||||||
|
|
||||||
bool operator==(const CellStore& right) const;
|
bool operator==(const CellStore& right) const;
|
||||||
|
|
||||||
private:
|
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
|
// TODO: caching still doesn't work efficiently here (only works for the one CellStore that the reference is
|
||||||
// in)
|
// in)
|
||||||
Ptr ptr = mWorldModel.getPtr(name, *cellstore);
|
Ptr ptr = cellstore->getPtr(name);
|
||||||
|
|
||||||
if (!ptr.isEmpty())
|
if (!ptr.isEmpty())
|
||||||
return ptr;
|
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)
|
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())
|
if (!ptr.isEmpty() && ptr.isInCell())
|
||||||
{
|
{
|
||||||
|
@ -332,36 +332,13 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellByPosition(
|
||||||
return getExterior(cellIndex);
|
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)
|
MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name)
|
||||||
{
|
{
|
||||||
// First check the cache
|
// First check the cache
|
||||||
for (IdCache::iterator iter(mIdCache.begin()); iter != mIdCache.end(); ++iter)
|
for (IdCache::iterator iter(mIdCache.begin()); iter != mIdCache.end(); ++iter)
|
||||||
if (iter->first == name && iter->second)
|
if (iter->first == name && iter->second)
|
||||||
{
|
{
|
||||||
Ptr ptr = getPtr(name, *iter->second);
|
Ptr ptr = iter->second->getPtr(name);
|
||||||
if (!ptr.isEmpty())
|
if (!ptr.isEmpty())
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,6 @@ namespace MWWorld
|
||||||
|
|
||||||
Ptr getPtr(const ESM::RefNum& refNum) const;
|
Ptr getPtr(const ESM::RefNum& refNum) const;
|
||||||
|
|
||||||
Ptr getPtr(const ESM::RefId& name, CellStore& cellStore);
|
|
||||||
Ptr getPtr(const ESM::RefId& name);
|
Ptr getPtr(const ESM::RefId& name);
|
||||||
|
|
||||||
template <typename Fn>
|
template <typename Fn>
|
||||||
|
|
Loading…
Reference in a new issue