diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index a0b434d99e..7d04cfc687 100644 --- a/apps/openmw/mwworld/cells.cpp +++ b/apps/openmw/mwworld/cells.cpp @@ -1,5 +1,9 @@ #include "cells.hpp" +#include + +#include + MWWorld::Ptr::CellStore *MWWorld::Cells::getCellStore (const ESM::Cell *cell) { if (cell->data.flags & ESM::Cell::Interior) @@ -68,7 +72,21 @@ MWWorld::Ptr::CellStore *MWWorld::Cells::getInterior (const std::string& name) MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, Ptr::CellStore& cell) { - cell.load (mStore, mReader); + if (cell.mState==Ptr::CellStore::State_Unloaded) + cell.preload (mStore, mReader); + + if (cell.mState==Ptr::CellStore::State_Preloaded) + { + std::string lowerCase; + + std::transform (name.begin(), name.end(), std::back_inserter (lowerCase), + (int(*)(int)) std::tolower); + + if (std::binary_search (cell.mIds.begin(), cell.mIds.end(), lowerCase)) + cell.load (mStore, mReader); + else + return Ptr(); + } if (ESMS::LiveCellRef *ref = cell.activators.find (name)) return Ptr (ref, &cell); diff --git a/components/esm_store/cell_store.hpp b/components/esm_store/cell_store.hpp index 9d0fe50390..1336cc2ab3 100644 --- a/components/esm_store/cell_store.hpp +++ b/components/esm_store/cell_store.hpp @@ -202,7 +202,7 @@ namespace ESMS std::transform (ref.refID.begin(), ref.refID.end(), std::back_inserter (lowerCase), (int(*)(int)) std::tolower); - mIds.push_back (ref.refID); + mIds.push_back (lowerCase); } std::sort (mIds.begin(), mIds.end());