From fe0c9ec9b7059a73f64a108b2663c9d095fa294a Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 7 Sep 2014 19:09:23 +0200 Subject: [PATCH] Change priorities in World::searchPtr Fixes performance bottleneck of scripts searching through all Containers in all active cells every frame. Can be observed near cell (2,-6) --- apps/openmw/mwworld/worldimp.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 44dc69ee8..b8c83e09b 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -578,28 +578,37 @@ namespace MWWorld std::string lowerCaseName = Misc::StringUtils::lowerCase(name); - // active cells for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { + // TODO: caching still doesn't work efficiently here (only works for the one CellStore that the reference is in) CellStore* cellstore = *iter; - Ptr ptr = mCells.getPtr (lowerCaseName, *cellstore, true); + Ptr ptr = mCells.getPtr (lowerCaseName, *cellstore, false); if (!ptr.isEmpty()) return ptr; } - Ptr ptr = mPlayer->getPlayer().getClass() - .getContainerStore(mPlayer->getPlayer()).search(lowerCaseName); - - if (!ptr.isEmpty()) - return ptr; - if (!activeOnly) { ret = mCells.getPtr (lowerCaseName); + if (!ret.isEmpty()) + return ret; } - return ret; + + for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); + iter!=mWorldScene->getActiveCells().end(); ++iter) + { + CellStore* cellstore = *iter; + Ptr ptr = cellstore->searchInContainer(lowerCaseName); + if (!ptr.isEmpty()) + return ptr; + } + + Ptr ptr = mPlayer->getPlayer().getClass() + .getContainerStore(mPlayer->getPlayer()).search(lowerCaseName); + + return ptr; } Ptr World::getPtr (const std::string& name, bool activeOnly)