mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-19 22:53:53 +00:00
Optimize ManualRef: look up correct Store instead of searching
This commit is contained in:
parent
4b5f02f644
commit
cba50c7338
1 changed files with 39 additions and 36 deletions
|
@ -19,54 +19,57 @@ namespace MWWorld
|
||||||
ManualRef& operator= (const ManualRef&);
|
ManualRef& operator= (const ManualRef&);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool create (const MWWorld::Store<T>& list, const std::string& name)
|
void create (const MWWorld::Store<T>& list, const std::string& name)
|
||||||
{
|
{
|
||||||
if (const T *instance = list.search (name))
|
const T* base = list.find(name);
|
||||||
{
|
|
||||||
LiveCellRef<T> ref;
|
|
||||||
ref.mBase = instance;
|
|
||||||
ref.mRef.mRefNum.mIndex = 0;
|
|
||||||
ref.mRef.mRefNum.mContentFile = -1;
|
|
||||||
|
|
||||||
mRef = ref;
|
LiveCellRef<T> ref;
|
||||||
mPtr = Ptr (&boost::any_cast<LiveCellRef<T>&> (mRef), 0);
|
ref.mBase = base;
|
||||||
|
ref.mRef.mRefNum.mIndex = 0;
|
||||||
|
ref.mRef.mRefNum.mContentFile = -1;
|
||||||
|
|
||||||
return true;
|
mRef = ref;
|
||||||
}
|
mPtr = Ptr (&boost::any_cast<LiveCellRef<T>&> (mRef), 0);
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ManualRef (const MWWorld::ESMStore& store, const std::string& name, const int count=1)
|
ManualRef (const MWWorld::ESMStore& store, const std::string& name, const int count=1)
|
||||||
{
|
{
|
||||||
// create
|
std::string lowerName = Misc::StringUtils::lowerCase (name);
|
||||||
if (!create (store.get<ESM::Activator>(), name) &&
|
switch (store.find (lowerName))
|
||||||
!create (store.get<ESM::Potion>(), name) &&
|
{
|
||||||
!create (store.get<ESM::Apparatus>(), name) &&
|
case ESM::REC_ACTI: create (store.get<ESM::Activator>(), lowerName); break;
|
||||||
!create (store.get<ESM::Armor>(), name) &&
|
case ESM::REC_ALCH: create (store.get<ESM::Potion>(), lowerName); break;
|
||||||
!create (store.get<ESM::Book>(), name) &&
|
case ESM::REC_APPA: create (store.get<ESM::Apparatus>(), lowerName); break;
|
||||||
!create (store.get<ESM::Clothing>(), name) &&
|
case ESM::REC_ARMO: create (store.get<ESM::Armor>(), lowerName); break;
|
||||||
!create (store.get<ESM::Container>(), name) &&
|
case ESM::REC_BOOK: create (store.get<ESM::Book>(), lowerName); break;
|
||||||
!create (store.get<ESM::Creature>(), name) &&
|
case ESM::REC_CLOT: create (store.get<ESM::Clothing>(), lowerName); break;
|
||||||
!create (store.get<ESM::Door>(), name) &&
|
case ESM::REC_CONT: create (store.get<ESM::Container>(), lowerName); break;
|
||||||
!create (store.get<ESM::Ingredient>(), name) &&
|
case ESM::REC_CREA: create (store.get<ESM::Creature>(), lowerName); break;
|
||||||
!create (store.get<ESM::CreatureLevList>(), name) &&
|
case ESM::REC_DOOR: create (store.get<ESM::Door>(), lowerName); break;
|
||||||
!create (store.get<ESM::ItemLevList>(), name) &&
|
case ESM::REC_INGR: create (store.get<ESM::Ingredient>(), lowerName); break;
|
||||||
!create (store.get<ESM::Light>(), name) &&
|
case ESM::REC_LEVC: create (store.get<ESM::CreatureLevList>(), lowerName); break;
|
||||||
!create (store.get<ESM::Lockpick>(), name) &&
|
case ESM::REC_LEVI: create (store.get<ESM::ItemLevList>(), lowerName); break;
|
||||||
!create (store.get<ESM::Miscellaneous>(), name) &&
|
case ESM::REC_LIGH: create (store.get<ESM::Light>(), lowerName); break;
|
||||||
!create (store.get<ESM::NPC>(), name) &&
|
case ESM::REC_LOCK: create (store.get<ESM::Lockpick>(), lowerName); break;
|
||||||
!create (store.get<ESM::Probe>(), name) &&
|
case ESM::REC_MISC: create (store.get<ESM::Miscellaneous>(), lowerName); break;
|
||||||
!create (store.get<ESM::Repair>(), name) &&
|
case ESM::REC_NPC_: create (store.get<ESM::NPC>(), lowerName); break;
|
||||||
!create (store.get<ESM::Static>(), name) &&
|
case ESM::REC_PROB: create (store.get<ESM::Probe>(), lowerName); break;
|
||||||
!create (store.get<ESM::Weapon>(), name))
|
case ESM::REC_REPA: create (store.get<ESM::Repair>(), lowerName); break;
|
||||||
throw std::logic_error ("failed to create manual cell ref for " + name);
|
case ESM::REC_STAT: create (store.get<ESM::Static>(), lowerName); break;
|
||||||
|
case ESM::REC_WEAP: create (store.get<ESM::Weapon>(), lowerName); break;
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
throw std::logic_error ("failed to create manual cell ref for " + lowerName + " (unknown ID)");
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw std::logic_error ("failed to create manual cell ref for " + lowerName + " (unknown type)");
|
||||||
|
}
|
||||||
|
|
||||||
// initialise
|
// initialise
|
||||||
ESM::CellRef& cellRef = mPtr.getCellRef();
|
ESM::CellRef& cellRef = mPtr.getCellRef();
|
||||||
cellRef.mRefID = Misc::StringUtils::lowerCase (name);
|
cellRef.mRefID = lowerName;
|
||||||
cellRef.mRefNum.mIndex = 0;
|
cellRef.mRefNum.mIndex = 0;
|
||||||
cellRef.mRefNum.mContentFile = -1;
|
cellRef.mRefNum.mContentFile = -1;
|
||||||
cellRef.mScale = 1;
|
cellRef.mScale = 1;
|
||||||
|
|
Loading…
Reference in a new issue