mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-13 12:40:04 +00:00
preload cell's reference list when accessing a reference outside of the actice cells (memory usage and speed optimisation)
This commit is contained in:
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…
x
Reference in New Issue
Block a user