From 02ce672fdc1812c507d625f7c9a6065123b70b9a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 24 Sep 2011 11:45:59 +0200 Subject: [PATCH] preload cell's reference list when accessing a reference outside of the actice cells (memory usage and speed optimisation) --- apps/openmw/mwworld/cells.cpp | 20 +++++++++++++++++++- components/esm_store/cell_store.hpp | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/cells.cpp b/apps/openmw/mwworld/cells.cpp index a0b434d99..7d04cfc68 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 9d0fe5039..1336cc2ab 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());