preload cell's reference list when accessing a reference outside of the actice cells (memory usage and speed optimisation)

actorid
Marc Zinnschlag 13 years ago
parent af4f48fd3f
commit 02ce672fdc

@ -1,5 +1,9 @@
#include "cells.hpp"
#include <cctype>
#include <algorithm>
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<ESM::Activator, RefData> *ref = cell.activators.find (name))
return Ptr (ref, &cell);

@ -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());

Loading…
Cancel
Save