From aa87370d8f50f56a4e002d4200d51cac8257c74e Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 22 Sep 2011 11:54:08 +0200 Subject: [PATCH] Issue #28: moved cell-specific getPtr function from World to Cells --- apps/openmw/mwworld/cells.cpp | 67 +++++++++++++++++++++++++++++++++++ apps/openmw/mwworld/cells.hpp | 1 + apps/openmw/mwworld/world.cpp | 67 +---------------------------------- apps/openmw/mwworld/world.hpp | 2 -- 4 files changed, 69 insertions(+), 68 deletions(-) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index 67a2a7590..57960e321 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -36,3 +36,70 @@ MWWorld::Ptr::CellStore *MWWorld::Cells::getInterior (const std::string& name) return &result->second; } + +MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, Ptr::CellStore& cell) +{ + cell.load (mStore, mReader); + + if (ESMS::LiveCellRef *ref = cell.activators.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.potions.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.appas.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.armors.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.books.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.clothes.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.containers.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.creatures.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.doors.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.ingreds.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.creatureLists.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.itemLists.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.lights.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.lockpicks.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.miscItems.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.npcs.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.probes.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.repairs.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.statics.find (name)) + return Ptr (ref, &cell); + + if (ESMS::LiveCellRef *ref = cell.weapons.find (name)) + return Ptr (ref, &cell); + + return Ptr(); +} diff --git a/apps/openmw/mwworld/cells.hpp b/apps/openmw/mwworld/cells.hpp index 217f61360..2e1e6a587 100644 --- a/apps/openmw/mwworld/cells.hpp +++ b/apps/openmw/mwworld/cells.hpp @@ -37,6 +37,7 @@ namespace MWWorld Ptr::CellStore *getInterior (const std::string& name); + Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore); }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 2e665fd1d..961cda6df 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -89,71 +89,6 @@ namespace MWWorld listCellScripts (mStore, cell.weapons, mLocalScripts, &cell); } - Ptr World::getPtr (const std::string& name, Ptr::CellStore& cell) - { - if (ESMS::LiveCellRef *ref = cell.activators.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.potions.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.appas.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.armors.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.books.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.clothes.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.containers.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.creatures.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.doors.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.ingreds.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.creatureLists.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.itemLists.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.lights.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.lockpicks.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.miscItems.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.npcs.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.probes.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.repairs.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.statics.find (name)) - return Ptr (ref, &cell); - - if (ESMS::LiveCellRef *ref = cell.weapons.find (name)) - return Ptr (ref, &cell); - - return Ptr(); - } - Ptr World::getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell) { if (ESMS::LiveCellRef *ref = @@ -408,7 +343,7 @@ namespace MWWorld for (Scene::CellRenderCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter) { - Ptr ptr = getPtr (name, *iter->first); + Ptr ptr = mCells.getPtr (name, *iter->first); if (!ptr.isEmpty()) return ptr; diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index fd1195268..90d612163 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -87,8 +87,6 @@ namespace MWWorld World (const World&); World& operator= (const World&); - Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore); - Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore); MWRender::CellRender *searchRender (Ptr::CellStore *store);