encapsulated mIds

actorid
Marc Zinnschlag 11 years ago
parent 8ea686c6c8
commit 79e723ad06

@ -167,7 +167,7 @@ MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, CellStore& cell,
if (cell.getState()==CellStore::State_Preloaded)
{
if (std::binary_search (cell.mIds.begin(), cell.mIds.end(), name))
if (cell.hasId (name))
{
cell.load (mStore, mReader);
}
@ -175,65 +175,10 @@ MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, CellStore& cell,
return Ptr();
}
if (MWWorld::LiveCellRef<ESM::Activator> *ref = cell.mActivators.find (name))
return Ptr (ref, &cell);
Ptr ptr = cell.search (name);
if (MWWorld::LiveCellRef<ESM::Potion> *ref = cell.mPotions.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Apparatus> *ref = cell.mAppas.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Armor> *ref = cell.mArmors.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Book> *ref = cell.mBooks.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Clothing> *ref = cell.mClothes.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Container> *ref = cell.mContainers.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Creature> *ref = cell.mCreatures.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Door> *ref = cell.mDoors.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Ingredient> *ref = cell.mIngreds.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::CreatureLevList> *ref = cell.mCreatureLists.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::ItemLevList> *ref = cell.mItemLists.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Light> *ref = cell.mLights.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Lockpick> *ref = cell.mLockpicks.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = cell.mMiscItems.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::NPC> *ref = cell.mNpcs.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Probe> *ref = cell.mProbes.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Repair> *ref = cell.mRepairs.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Static> *ref = cell.mStatics.find (name))
return Ptr (ref, &cell);
if (MWWorld::LiveCellRef<ESM::Weapon> *ref = cell.mWeapons.find (name))
return Ptr (ref, &cell);
if (!ptr.isEmpty())
return ptr;
if (searchInContainers)
return cell.searchInContainer (name);

@ -1,6 +1,7 @@
#include "cellstore.hpp"
#include <iostream>
#include <algorithm>
#include <components/esm/cellstate.hpp>
#include <components/esm/cellid.hpp>
@ -155,6 +156,83 @@ namespace MWWorld
return mState;
}
bool CellStore::hasId (const std::string& id) const
{
if (mState==State_Unloaded)
return false;
if (mState==State_Preloaded)
return std::binary_search (mIds.begin(), mIds.end(), id);
/// \todo address const-issues
return const_cast<CellStore *> (this)->search (id).isEmpty();
}
Ptr CellStore::search (const std::string& id)
{
if (LiveCellRef<ESM::Activator> *ref = mActivators.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Potion> *ref = mPotions.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Apparatus> *ref = mAppas.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Armor> *ref = mArmors.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Book> *ref = mBooks.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Clothing> *ref = mClothes.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Container> *ref = mContainers.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Creature> *ref = mCreatures.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Door> *ref = mDoors.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Ingredient> *ref = mIngreds.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::CreatureLevList> *ref = mCreatureLists.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::ItemLevList> *ref = mItemLists.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Light> *ref = mLights.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Lockpick> *ref = mLockpicks.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Miscellaneous> *ref = mMiscItems.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::NPC> *ref = mNpcs.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Probe> *ref = mProbes.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Repair> *ref = mRepairs.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Static> *ref = mStatics.find (id))
return Ptr (ref, this);
if (LiveCellRef<ESM::Weapon> *ref = mWeapons.find (id))
return Ptr (ref, this);
return Ptr();
}
void CellStore::load (const MWWorld::ESMStore &store, std::vector<ESM::ESMReader> &esm)
{
if (mState!=State_Loaded)

@ -14,6 +14,7 @@ namespace ESM
namespace MWWorld
{
class Ptr;
/// A list of cell references
template <typename X>
@ -63,6 +64,7 @@ namespace MWWorld
const ESM::Cell *mCell;
State mState;
std::vector<std::string> mIds;
public:
@ -72,7 +74,13 @@ namespace MWWorld
State getState() const;
std::vector<std::string> mIds;
bool hasId (const std::string& id) const;
///< May return true for deleted IDs when in preload state. Will return false, if cell is
/// unloaded.
Ptr search (const std::string& id);
///< Will return an empty Ptr if cell is not loaded. Does not check references in
/// containers.
float mWaterLevel;

Loading…
Cancel
Save