mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-01 03:45:32 +00:00
Avoid using temporary vector to get items owned by
This commit is contained in:
parent
10fafabd7f
commit
1e4565a15c
3 changed files with 7 additions and 20 deletions
|
@ -269,7 +269,7 @@ namespace MWWorld
|
|||
/// \attention This function also lists deleted (count 0) objects!
|
||||
/// \return Iteration completed?
|
||||
template<class Visitor>
|
||||
bool forEach (Visitor& visitor)
|
||||
bool forEach (Visitor&& visitor)
|
||||
{
|
||||
if (mState != State_Loaded)
|
||||
return false;
|
||||
|
|
|
@ -330,7 +330,7 @@ namespace MWWorld
|
|||
const auto navigator = MWBase::Environment::get().getWorld()->getNavigator();
|
||||
ListAndResetObjectsVisitor visitor;
|
||||
|
||||
(*iter)->forEach<ListAndResetObjectsVisitor>(visitor);
|
||||
(*iter)->forEach(visitor);
|
||||
const auto world = MWBase::Environment::get().getWorld();
|
||||
for (const auto& ptr : visitor.mObjects)
|
||||
{
|
||||
|
|
|
@ -2745,28 +2745,15 @@ namespace MWWorld
|
|||
}
|
||||
}
|
||||
|
||||
struct ListObjectsVisitor
|
||||
{
|
||||
std::vector<MWWorld::Ptr> mObjects;
|
||||
|
||||
bool operator() (Ptr ptr)
|
||||
{
|
||||
if (ptr.getRefData().getBaseNode())
|
||||
mObjects.push_back(ptr);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void World::getItemsOwnedBy (const MWWorld::ConstPtr& npc, std::vector<MWWorld::Ptr>& out)
|
||||
{
|
||||
for (CellStore* cellstore : mWorldScene->getActiveCells())
|
||||
{
|
||||
ListObjectsVisitor visitor;
|
||||
cellstore->forEach(visitor);
|
||||
|
||||
for (const Ptr &object : visitor.mObjects)
|
||||
if (Misc::StringUtils::ciEqual(object.getCellRef().getOwner(), npc.getCellRef().getRefId()))
|
||||
out.push_back(object);
|
||||
cellstore->forEach([&] (const auto& ptr) {
|
||||
if (ptr.getRefData().getBaseNode() && Misc::StringUtils::ciEqual(ptr.getCellRef().getOwner(), npc.getCellRef().getRefId()))
|
||||
out.push_back(ptr);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue