mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-05 22:19:42 +00:00
encapsulated reference collections
This commit is contained in:
parent
367919200f
commit
83ded18af0
25 changed files with 374 additions and 197 deletions
|
@ -128,6 +128,6 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Activator> *ref =
|
||||
ptr.get<ESM::Activator>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mActivators.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Activator>().insert(*ref), &cell);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Apparatus> *ref =
|
||||
ptr.get<ESM::Apparatus>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mAppas.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Apparatus>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
bool Apparatus::canSell (const MWWorld::Ptr& item, int npcServices) const
|
||||
|
|
|
@ -333,11 +333,11 @@ namespace MWClass
|
|||
|
||||
if(weapon->getTypeName() == typeid(ESM::Weapon).name() &&
|
||||
(weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::LongBladeTwoHand ||
|
||||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoClose ||
|
||||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoWide ||
|
||||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoClose ||
|
||||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoWide ||
|
||||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::SpearTwoWide ||
|
||||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::AxeTwoHand ||
|
||||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanBow ||
|
||||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::AxeTwoHand ||
|
||||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanBow ||
|
||||
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow))
|
||||
{
|
||||
return std::make_pair(3,"");
|
||||
|
@ -363,7 +363,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Armor> *ref =
|
||||
ptr.get<ESM::Armor>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mArmors.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Armor>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
int Armor::getEnchantmentPoints (const MWWorld::Ptr& ptr) const
|
||||
|
|
|
@ -186,7 +186,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Book> *ref =
|
||||
ptr.get<ESM::Book>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mBooks.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Book>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
int Book::getEnchantmentPoints (const MWWorld::Ptr& ptr) const
|
||||
|
|
|
@ -276,7 +276,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Clothing> *ref =
|
||||
ptr.get<ESM::Clothing>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mClothes.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Clothing>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
int Clothing::getEnchantmentPoints (const MWWorld::Ptr& ptr) const
|
||||
|
|
|
@ -257,7 +257,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Container> *ref =
|
||||
ptr.get<ESM::Container>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mContainers.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Container>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
void Container::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state)
|
||||
|
|
|
@ -680,7 +680,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Creature> *ref =
|
||||
ptr.get<ESM::Creature>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mCreatures.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Creature>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
bool Creature::isFlying(const MWWorld::Ptr &ptr) const
|
||||
|
|
|
@ -258,6 +258,6 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Door> *ref =
|
||||
ptr.get<ESM::Door>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mDoors.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Door>().insert(*ref), &cell);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace MWClass
|
|||
|
||||
return ref->mBase->mId;
|
||||
}
|
||||
|
||||
|
||||
void Ingredient::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
|
||||
{
|
||||
const std::string model = getModel(ptr);
|
||||
|
@ -89,16 +89,16 @@ namespace MWClass
|
|||
return ref->mBase->mData.mValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
boost::shared_ptr<MWWorld::Action> Ingredient::use (const MWWorld::Ptr& ptr) const
|
||||
{
|
||||
boost::shared_ptr<MWWorld::Action> action (new MWWorld::ActionEat (ptr));
|
||||
|
||||
action->setSound ("Swallow");
|
||||
|
||||
return action;
|
||||
return action;
|
||||
}
|
||||
|
||||
|
||||
void Ingredient::registerSelf()
|
||||
{
|
||||
boost::shared_ptr<Class> instance (new Ingredient);
|
||||
|
@ -189,7 +189,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Ingredient> *ref =
|
||||
ptr.get<ESM::Ingredient>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mIngreds.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Ingredient>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
bool Ingredient::canSell (const MWWorld::Ptr& item, int npcServices) const
|
||||
|
|
|
@ -227,7 +227,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Light> *ref =
|
||||
ptr.get<ESM::Light>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mLights.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Light>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
void Light::ensureCustomData (const MWWorld::Ptr& ptr) const
|
||||
|
|
|
@ -169,7 +169,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Lockpick> *ref =
|
||||
ptr.get<ESM::Lockpick>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mLockpicks.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Lockpick>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
bool Lockpick::canSell (const MWWorld::Ptr& item, int npcServices) const
|
||||
|
|
|
@ -218,13 +218,13 @@ namespace MWClass
|
|||
MWWorld::ManualRef newRef(store, base);
|
||||
MWWorld::LiveCellRef<ESM::Miscellaneous> *ref =
|
||||
newRef.getPtr().get<ESM::Miscellaneous>();
|
||||
newPtr = MWWorld::Ptr(&cell.mMiscItems.insert(*ref), &cell);
|
||||
newPtr = MWWorld::Ptr(&cell.get<ESM::Miscellaneous>().insert(*ref), &cell);
|
||||
newPtr.getCellRef().mGoldValue = goldAmount;
|
||||
newPtr.getRefData().setCount(1);
|
||||
} else {
|
||||
MWWorld::LiveCellRef<ESM::Miscellaneous> *ref =
|
||||
ptr.get<ESM::Miscellaneous>();
|
||||
newPtr = MWWorld::Ptr(&cell.mMiscItems.insert(*ref), &cell);
|
||||
newPtr = MWWorld::Ptr(&cell.get<ESM::Miscellaneous>().insert(*ref), &cell);
|
||||
}
|
||||
return newPtr;
|
||||
}
|
||||
|
|
|
@ -1253,7 +1253,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::NPC> *ref =
|
||||
ptr.get<ESM::NPC>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mNpcs.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::NPC>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
int Npc::getSkill(const MWWorld::Ptr& ptr, int skill) const
|
||||
|
|
|
@ -185,7 +185,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Potion> *ref =
|
||||
ptr.get<ESM::Potion>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mPotions.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Potion>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
bool Potion::canSell (const MWWorld::Ptr& item, int npcServices) const
|
||||
|
|
|
@ -168,7 +168,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Probe> *ref =
|
||||
ptr.get<ESM::Probe>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mProbes.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Probe>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
bool Probe::canSell (const MWWorld::Ptr& item, int npcServices) const
|
||||
|
|
|
@ -163,7 +163,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Repair> *ref =
|
||||
ptr.get<ESM::Repair>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mRepairs.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Repair>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
boost::shared_ptr<MWWorld::Action> Repair::use (const MWWorld::Ptr& ptr) const
|
||||
|
|
|
@ -58,6 +58,6 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Static> *ref =
|
||||
ptr.get<ESM::Static>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mStatics.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Static>().insert(*ref), &cell);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -426,7 +426,7 @@ namespace MWClass
|
|||
MWWorld::LiveCellRef<ESM::Weapon> *ref =
|
||||
ptr.get<ESM::Weapon>();
|
||||
|
||||
return MWWorld::Ptr(&cell.mWeapons.insert(*ref), &cell);
|
||||
return MWWorld::Ptr(&cell.get<ESM::Weapon>().insert(*ref), &cell);
|
||||
}
|
||||
|
||||
int Weapon::getEnchantmentPoints (const MWWorld::Ptr& ptr) const
|
||||
|
|
|
@ -38,6 +38,16 @@ namespace MWWorld
|
|||
mList.push_back(item);
|
||||
return mList.back();
|
||||
}
|
||||
|
||||
LiveCellRef<X> *searchViaHandle (const std::string& handle)
|
||||
{
|
||||
for (typename List::iterator iter (mList.begin()); iter!=mList.end(); ++iter)
|
||||
if (iter->mData.getCount()>0 && iter->mData.getBaseNode() &&
|
||||
iter->mData.getHandle()==handle)
|
||||
return &*iter;
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -233,6 +233,71 @@ namespace MWWorld
|
|||
return Ptr();
|
||||
}
|
||||
|
||||
Ptr CellStore::searchViaHandle (const std::string& handle)
|
||||
{
|
||||
if (LiveCellRef<ESM::Activator> *ref = mActivators.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Potion> *ref = mPotions.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Apparatus> *ref = mAppas.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Armor> *ref = mArmors.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Book> *ref = mBooks.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Clothing> *ref = mClothes.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Container> *ref = mContainers.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Creature> *ref = mCreatures.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Door> *ref = mDoors.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Ingredient> *ref = mIngreds.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::CreatureLevList> *ref = mCreatureLists.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::ItemLevList> *ref = mItemLists.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Light> *ref = mLights.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Lockpick> *ref = mLockpicks.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Miscellaneous> *ref = mMiscItems.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::NPC> *ref = mNpcs.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Probe> *ref = mProbes.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Repair> *ref = mRepairs.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Static> *ref = mStatics.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
if (LiveCellRef<ESM::Weapon> *ref = mWeapons.searchViaHandle (handle))
|
||||
return Ptr (ref, this);
|
||||
|
||||
return Ptr();
|
||||
}
|
||||
|
||||
float CellStore::getWaterLevel() const
|
||||
{
|
||||
return mWaterLevel;
|
||||
|
@ -243,6 +308,31 @@ namespace MWWorld
|
|||
mWaterLevel = level;
|
||||
}
|
||||
|
||||
int CellStore::count() const
|
||||
{
|
||||
return
|
||||
mActivators.mList.size()
|
||||
+ mPotions.mList.size()
|
||||
+ mAppas.mList.size()
|
||||
+ mArmors.mList.size()
|
||||
+ mBooks.mList.size()
|
||||
+ mClothes.mList.size()
|
||||
+ mContainers.mList.size()
|
||||
+ mDoors.mList.size()
|
||||
+ mIngreds.mList.size()
|
||||
+ mCreatureLists.mList.size()
|
||||
+ mItemLists.mList.size()
|
||||
+ mLights.mList.size()
|
||||
+ mLockpicks.mList.size()
|
||||
+ mMiscItems.mList.size()
|
||||
+ mProbes.mList.size()
|
||||
+ mRepairs.mList.size()
|
||||
+ mStatics.mList.size()
|
||||
+ mWeapons.mList.size()
|
||||
+ mCreatures.mList.size()
|
||||
+ mNpcs.mList.size();
|
||||
}
|
||||
|
||||
void CellStore::load (const MWWorld::ESMStore &store, std::vector<ESM::ESMReader> &esm)
|
||||
{
|
||||
if (mState!=State_Loaded)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <deque>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "livecellref.hpp"
|
||||
#include "esmstore.hpp"
|
||||
|
@ -34,6 +35,27 @@ namespace MWWorld
|
|||
std::vector<std::string> mIds;
|
||||
float mWaterLevel;
|
||||
|
||||
CellRefList<ESM::Activator> mActivators;
|
||||
CellRefList<ESM::Potion> mPotions;
|
||||
CellRefList<ESM::Apparatus> mAppas;
|
||||
CellRefList<ESM::Armor> mArmors;
|
||||
CellRefList<ESM::Book> mBooks;
|
||||
CellRefList<ESM::Clothing> mClothes;
|
||||
CellRefList<ESM::Container> mContainers;
|
||||
CellRefList<ESM::Creature> mCreatures;
|
||||
CellRefList<ESM::Door> mDoors;
|
||||
CellRefList<ESM::Ingredient> mIngreds;
|
||||
CellRefList<ESM::CreatureLevList> mCreatureLists;
|
||||
CellRefList<ESM::ItemLevList> mItemLists;
|
||||
CellRefList<ESM::Light> mLights;
|
||||
CellRefList<ESM::Lockpick> mLockpicks;
|
||||
CellRefList<ESM::Miscellaneous> mMiscItems;
|
||||
CellRefList<ESM::NPC> mNpcs;
|
||||
CellRefList<ESM::Probe> mProbes;
|
||||
CellRefList<ESM::Repair> mRepairs;
|
||||
CellRefList<ESM::Static> mStatics;
|
||||
CellRefList<ESM::Weapon> mWeapons;
|
||||
|
||||
public:
|
||||
|
||||
CellStore (const ESM::Cell *cell_);
|
||||
|
@ -50,31 +72,16 @@ namespace MWWorld
|
|||
///< Will return an empty Ptr if cell is not loaded. Does not check references in
|
||||
/// containers.
|
||||
|
||||
Ptr searchViaHandle (const std::string& handle);
|
||||
///< Will return an empty Ptr if cell is not loaded.
|
||||
|
||||
float getWaterLevel() const;
|
||||
|
||||
void setWaterLevel (float level);
|
||||
|
||||
// Lists for each individual object type
|
||||
CellRefList<ESM::Activator> mActivators;
|
||||
CellRefList<ESM::Potion> mPotions;
|
||||
CellRefList<ESM::Apparatus> mAppas;
|
||||
CellRefList<ESM::Armor> mArmors;
|
||||
CellRefList<ESM::Book> mBooks;
|
||||
CellRefList<ESM::Clothing> mClothes;
|
||||
CellRefList<ESM::Container> mContainers;
|
||||
CellRefList<ESM::Creature> mCreatures;
|
||||
CellRefList<ESM::Door> mDoors;
|
||||
CellRefList<ESM::Ingredient> mIngreds;
|
||||
CellRefList<ESM::CreatureLevList> mCreatureLists;
|
||||
CellRefList<ESM::ItemLevList> mItemLists;
|
||||
CellRefList<ESM::Light> mLights;
|
||||
CellRefList<ESM::Lockpick> mLockpicks;
|
||||
CellRefList<ESM::Miscellaneous> mMiscItems;
|
||||
CellRefList<ESM::NPC> mNpcs;
|
||||
CellRefList<ESM::Probe> mProbes;
|
||||
CellRefList<ESM::Repair> mRepairs;
|
||||
CellRefList<ESM::Static> mStatics;
|
||||
CellRefList<ESM::Weapon> mWeapons;
|
||||
int count() const;
|
||||
///< Return total number of references, including deleted ones.
|
||||
|
||||
|
||||
void load (const MWWorld::ESMStore &store, std::vector<ESM::ESMReader> &esm);
|
||||
|
||||
|
@ -83,6 +90,8 @@ namespace MWWorld
|
|||
/// Call functor (ref) for each reference. functor must return a bool. Returning
|
||||
/// false will abort the iteration.
|
||||
/// \return Iteration completed?
|
||||
///
|
||||
/// \note Creatures and NPCs are handled last.
|
||||
template<class Functor>
|
||||
bool forEach (Functor& functor)
|
||||
{
|
||||
|
@ -94,19 +103,19 @@ namespace MWWorld
|
|||
forEachImp (functor, mBooks) &&
|
||||
forEachImp (functor, mClothes) &&
|
||||
forEachImp (functor, mContainers) &&
|
||||
forEachImp (functor, mCreatures) &&
|
||||
forEachImp (functor, mDoors) &&
|
||||
forEachImp (functor, mIngreds) &&
|
||||
forEachImp (functor, mCreatureLists) &&
|
||||
forEachImp (functor, mItemLists) &&
|
||||
forEachImp (functor, mLights) &&
|
||||
forEachImp (functor, mLockpicks) &&
|
||||
forEachImp (functor, mMiscItems) &&
|
||||
forEachImp (functor, mNpcs) &&
|
||||
forEachImp (functor, mProbes) &&
|
||||
forEachImp (functor, mRepairs) &&
|
||||
forEachImp (functor, mStatics) &&
|
||||
forEachImp (functor, mWeapons);
|
||||
forEachImp (functor, mWeapons) &&
|
||||
forEachImp (functor, mCreatures) &&
|
||||
forEachImp (functor, mNpcs) &&
|
||||
forEachImp (functor, mCreatureLists);
|
||||
}
|
||||
|
||||
bool operator==(const CellStore &cell) {
|
||||
|
@ -133,6 +142,11 @@ namespace MWWorld
|
|||
|
||||
void readReferences (ESM::ESMReader& reader, const std::map<int, int>& contentFileMap);
|
||||
|
||||
template <class T>
|
||||
CellRefList<T>& get() {
|
||||
throw std::runtime_error ("Storage for this type not exist in cells");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template<class Functor, class List>
|
||||
|
@ -159,6 +173,126 @@ namespace MWWorld
|
|||
///
|
||||
/// Invalid \a ref objects are silently dropped.
|
||||
};
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Activator>& CellStore::get<ESM::Activator>()
|
||||
{
|
||||
return mActivators;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Potion>& CellStore::get<ESM::Potion>()
|
||||
{
|
||||
return mPotions;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Apparatus>& CellStore::get<ESM::Apparatus>()
|
||||
{
|
||||
return mAppas;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Armor>& CellStore::get<ESM::Armor>()
|
||||
{
|
||||
return mArmors;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Book>& CellStore::get<ESM::Book>()
|
||||
{
|
||||
return mBooks;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Clothing>& CellStore::get<ESM::Clothing>()
|
||||
{
|
||||
return mClothes;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Container>& CellStore::get<ESM::Container>()
|
||||
{
|
||||
return mContainers;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Creature>& CellStore::get<ESM::Creature>()
|
||||
{
|
||||
return mCreatures;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Door>& CellStore::get<ESM::Door>()
|
||||
{
|
||||
return mDoors;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Ingredient>& CellStore::get<ESM::Ingredient>()
|
||||
{
|
||||
return mIngreds;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::CreatureLevList>& CellStore::get<ESM::CreatureLevList>()
|
||||
{
|
||||
return mCreatureLists;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::ItemLevList>& CellStore::get<ESM::ItemLevList>()
|
||||
{
|
||||
return mItemLists;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Light>& CellStore::get<ESM::Light>()
|
||||
{
|
||||
return mLights;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Lockpick>& CellStore::get<ESM::Lockpick>()
|
||||
{
|
||||
return mLockpicks;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Miscellaneous>& CellStore::get<ESM::Miscellaneous>()
|
||||
{
|
||||
return mMiscItems;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::NPC>& CellStore::get<ESM::NPC>()
|
||||
{
|
||||
return mNpcs;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Probe>& CellStore::get<ESM::Probe>()
|
||||
{
|
||||
return mProbes;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Repair>& CellStore::get<ESM::Repair>()
|
||||
{
|
||||
return mRepairs;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Static>& CellStore::get<ESM::Static>()
|
||||
{
|
||||
return mStatics;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline CellRefList<ESM::Weapon>& CellStore::get<ESM::Weapon>()
|
||||
{
|
||||
return mWeapons;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -101,26 +101,26 @@ void MWWorld::LocalScripts::add (const std::string& scriptName, const Ptr& ptr)
|
|||
|
||||
void MWWorld::LocalScripts::addCell (CellStore *cell)
|
||||
{
|
||||
listCellScripts (*this, cell->mActivators, cell);
|
||||
listCellScripts (*this, cell->mPotions, cell);
|
||||
listCellScripts (*this, cell->mAppas, cell);
|
||||
listCellScripts (*this, cell->mArmors, cell);
|
||||
listCellScripts (*this, cell->mBooks, cell);
|
||||
listCellScripts (*this, cell->mClothes, cell);
|
||||
listCellScripts (*this, cell->mContainers, cell);
|
||||
listCellScriptsCont (*this, cell->mContainers, cell);
|
||||
listCellScripts (*this, cell->mCreatures, cell);
|
||||
listCellScriptsCont (*this, cell->mCreatures, cell);
|
||||
listCellScripts (*this, cell->mDoors, cell);
|
||||
listCellScripts (*this, cell->mIngreds, cell);
|
||||
listCellScripts (*this, cell->mLights, cell);
|
||||
listCellScripts (*this, cell->mLockpicks, cell);
|
||||
listCellScripts (*this, cell->mMiscItems, cell);
|
||||
listCellScripts (*this, cell->mNpcs, cell);
|
||||
listCellScriptsCont (*this, cell->mNpcs, cell);
|
||||
listCellScripts (*this, cell->mProbes, cell);
|
||||
listCellScripts (*this, cell->mRepairs, cell);
|
||||
listCellScripts (*this, cell->mWeapons, cell);
|
||||
listCellScripts (*this, cell->get<ESM::Activator>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Potion>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Apparatus>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Armor>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Book>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Clothing>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Container>(), cell);
|
||||
listCellScriptsCont (*this, cell->get<ESM::Container>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Creature>(), cell);
|
||||
listCellScriptsCont (*this, cell->get<ESM::Creature>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Door>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Ingredient>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Light>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Lockpick>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Miscellaneous>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::NPC>(), cell);
|
||||
listCellScriptsCont (*this, cell->get<ESM::NPC>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Probe>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Repair>(), cell);
|
||||
listCellScripts (*this, cell->get<ESM::Weapon>(), cell);
|
||||
}
|
||||
|
||||
void MWWorld::LocalScripts::clear()
|
||||
|
|
|
@ -22,6 +22,63 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
struct InsertFunctor
|
||||
{
|
||||
MWWorld::CellStore& mCell;
|
||||
bool mRescale;
|
||||
Loading::Listener& mLoadingListener;
|
||||
MWWorld::PhysicsSystem& mPhysics;
|
||||
MWRender::RenderingManager& mRendering;
|
||||
|
||||
InsertFunctor (MWWorld::CellStore& cell, bool rescale, Loading::Listener& loadingListener,
|
||||
MWWorld::PhysicsSystem& physics, MWRender::RenderingManager& rendering);
|
||||
|
||||
bool operator() (const MWWorld::Ptr& ptr);
|
||||
};
|
||||
|
||||
InsertFunctor::InsertFunctor (MWWorld::CellStore& cell, bool rescale,
|
||||
Loading::Listener& loadingListener, MWWorld::PhysicsSystem& physics,
|
||||
MWRender::RenderingManager& rendering)
|
||||
: mCell (cell), mRescale (rescale), mLoadingListener (loadingListener),
|
||||
mPhysics (physics), mRendering (rendering)
|
||||
{}
|
||||
|
||||
bool InsertFunctor::InsertFunctor::operator() (const MWWorld::Ptr& ptr)
|
||||
{
|
||||
if (mRescale)
|
||||
{
|
||||
if (ptr.getCellRef().mScale<0.5)
|
||||
ptr.getCellRef().mScale = 0.5;
|
||||
else if (ptr.getCellRef().mScale>2)
|
||||
ptr.getCellRef().mScale = 2;
|
||||
}
|
||||
|
||||
if (ptr.getRefData().getCount() && ptr.getRefData().isEnabled())
|
||||
{
|
||||
try
|
||||
{
|
||||
mRendering.addObject (ptr);
|
||||
ptr.getClass().insertObject (ptr, mPhysics);
|
||||
|
||||
float ax = Ogre::Radian(ptr.getRefData().getLocalRotation().rot[0]).valueDegrees();
|
||||
float ay = Ogre::Radian(ptr.getRefData().getLocalRotation().rot[1]).valueDegrees();
|
||||
float az = Ogre::Radian(ptr.getRefData().getLocalRotation().rot[2]).valueDegrees();
|
||||
MWBase::Environment::get().getWorld()->localRotateObject (ptr, ax, ay, az);
|
||||
|
||||
MWBase::Environment::get().getWorld()->scaleObject (ptr, ptr.getCellRef().mScale);
|
||||
ptr.getClass().adjustPosition (ptr);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::string error ("error during rendering: ");
|
||||
std::cerr << error + e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
mLoadingListener.increaseProgress (1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void insertCellRefList(MWRender::RenderingManager& rendering,
|
||||
|
@ -267,7 +324,7 @@ namespace MWWorld
|
|||
}
|
||||
|
||||
if (iter==mActiveCells.end())
|
||||
refsToLoad += countRefs(*MWBase::Environment::get().getWorld()->getExterior(x, y));
|
||||
refsToLoad += MWBase::Environment::get().getWorld()->getExterior(x, y)->count();
|
||||
}
|
||||
|
||||
loadingListener->setProgressRange(refsToLoad);
|
||||
|
@ -403,7 +460,7 @@ namespace MWWorld
|
|||
++current;
|
||||
}
|
||||
|
||||
int refsToLoad = countRefs(*cell);
|
||||
int refsToLoad = cell->count();
|
||||
loadingListener->setProgressRange(refsToLoad);
|
||||
|
||||
// Load cell.
|
||||
|
@ -451,55 +508,10 @@ namespace MWWorld
|
|||
mCellChanged = false;
|
||||
}
|
||||
|
||||
int Scene::countRefs (const CellStore& cell)
|
||||
{
|
||||
return cell.mActivators.mList.size()
|
||||
+ cell.mPotions.mList.size()
|
||||
+ cell.mAppas.mList.size()
|
||||
+ cell.mArmors.mList.size()
|
||||
+ cell.mBooks.mList.size()
|
||||
+ cell.mClothes.mList.size()
|
||||
+ cell.mContainers.mList.size()
|
||||
+ cell.mDoors.mList.size()
|
||||
+ cell.mIngreds.mList.size()
|
||||
+ cell.mCreatureLists.mList.size()
|
||||
+ cell.mItemLists.mList.size()
|
||||
+ cell.mLights.mList.size()
|
||||
+ cell.mLockpicks.mList.size()
|
||||
+ cell.mMiscItems.mList.size()
|
||||
+ cell.mProbes.mList.size()
|
||||
+ cell.mRepairs.mList.size()
|
||||
+ cell.mStatics.mList.size()
|
||||
+ cell.mWeapons.mList.size()
|
||||
+ cell.mCreatures.mList.size()
|
||||
+ cell.mNpcs.mList.size();
|
||||
}
|
||||
|
||||
void Scene::insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener)
|
||||
{
|
||||
// Loop through all references in the cell
|
||||
insertCellRefList(mRendering, cell.mActivators, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mPotions, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mAppas, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mArmors, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mBooks, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mClothes, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mContainers, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mDoors, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mIngreds, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mItemLists, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mLights, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mLockpicks, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mMiscItems, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mProbes, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mRepairs, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mStatics, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mWeapons, cell, *mPhysics, rescale, loadingListener);
|
||||
// Load NPCs and creatures _after_ everything else (important for adjustPosition to work correctly)
|
||||
insertCellRefList(mRendering, cell.mCreatures, cell, *mPhysics, rescale, loadingListener);
|
||||
insertCellRefList(mRendering, cell.mNpcs, cell, *mPhysics, rescale, loadingListener);
|
||||
// Since this adds additional creatures, load afterwards, or they would be loaded twice
|
||||
insertCellRefList(mRendering, cell.mCreatureLists, cell, *mPhysics, rescale, loadingListener);
|
||||
InsertFunctor functor (cell, rescale, *loadingListener, *mPhysics, mRendering);
|
||||
cell.forEach (functor);
|
||||
}
|
||||
|
||||
void Scene::addObjectToScene (const Ptr& ptr)
|
||||
|
|
|
@ -63,8 +63,6 @@ namespace MWWorld
|
|||
|
||||
void insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener);
|
||||
|
||||
int countRefs (const CellStore& cell);
|
||||
|
||||
public:
|
||||
|
||||
Scene (MWRender::RenderingManager& rendering, PhysicsSystem *physics);
|
||||
|
|
|
@ -48,27 +48,6 @@
|
|||
|
||||
using namespace Ogre;
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T>
|
||||
MWWorld::LiveCellRef<T> *searchViaHandle (const std::string& handle,
|
||||
MWWorld::CellRefList<T>& refList)
|
||||
{
|
||||
typedef typename MWWorld::CellRefList<T>::List::iterator iterator;
|
||||
|
||||
for (iterator iter (refList.mList.begin()); iter!=refList.mList.end(); ++iter)
|
||||
{
|
||||
if (iter->mData.getCount() > 0 && iter->mData.getBaseNode()){
|
||||
if (iter->mData.getHandle()==handle)
|
||||
{
|
||||
return &*iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
struct GameContentLoader : public ContentLoader
|
||||
|
@ -103,52 +82,6 @@ namespace MWWorld
|
|||
LoadersContainer mLoaders;
|
||||
};
|
||||
|
||||
Ptr World::getPtrViaHandle (const std::string& handle, CellStore& cell)
|
||||
{
|
||||
if (MWWorld::LiveCellRef<ESM::Activator> *ref =
|
||||
searchViaHandle (handle, cell.mActivators))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Potion> *ref = searchViaHandle (handle, cell.mPotions))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Apparatus> *ref = searchViaHandle (handle, cell.mAppas))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Armor> *ref = searchViaHandle (handle, cell.mArmors))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Book> *ref = searchViaHandle (handle, cell.mBooks))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Clothing> *ref = searchViaHandle (handle, cell.mClothes))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Container> *ref =
|
||||
searchViaHandle (handle, cell.mContainers))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Creature> *ref =
|
||||
searchViaHandle (handle, cell.mCreatures))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Door> *ref = searchViaHandle (handle, cell.mDoors))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Ingredient> *ref =
|
||||
searchViaHandle (handle, cell.mIngreds))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Light> *ref = searchViaHandle (handle, cell.mLights))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Lockpick> *ref = searchViaHandle (handle, cell.mLockpicks))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = searchViaHandle (handle, cell.mMiscItems))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::NPC> *ref = searchViaHandle (handle, cell.mNpcs))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Probe> *ref = searchViaHandle (handle, cell.mProbes))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Repair> *ref = searchViaHandle (handle, cell.mRepairs))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Static> *ref = searchViaHandle (handle, cell.mStatics))
|
||||
return Ptr (ref, &cell);
|
||||
if (MWWorld::LiveCellRef<ESM::Weapon> *ref = searchViaHandle (handle, cell.mWeapons))
|
||||
return Ptr (ref, &cell);
|
||||
return Ptr();
|
||||
}
|
||||
|
||||
|
||||
int World::getDaysPerMonth (int month) const
|
||||
{
|
||||
switch (month)
|
||||
|
@ -579,7 +512,7 @@ namespace MWWorld
|
|||
iter!=mWorldScene->getActiveCells().end(); ++iter)
|
||||
{
|
||||
CellStore* cellstore = *iter;
|
||||
Ptr ptr = getPtrViaHandle (handle, *cellstore);
|
||||
Ptr ptr = cellstore->searchViaHandle (handle);
|
||||
|
||||
if (!ptr.isEmpty())
|
||||
return ptr;
|
||||
|
@ -1505,7 +1438,7 @@ namespace MWWorld
|
|||
|
||||
Ogre::Vector2 World::getNorthVector (CellStore* cell)
|
||||
{
|
||||
MWWorld::CellRefList<ESM::Static>& statics = cell->mStatics;
|
||||
MWWorld::CellRefList<ESM::Static>& statics = cell->get<ESM::Static>();
|
||||
MWWorld::LiveCellRef<ESM::Static>* ref = statics.find("northmarker");
|
||||
if (!ref)
|
||||
return Vector2(0, 1);
|
||||
|
@ -1517,7 +1450,7 @@ namespace MWWorld
|
|||
|
||||
void World::getDoorMarkers (CellStore* cell, std::vector<World::DoorMarker>& out)
|
||||
{
|
||||
MWWorld::CellRefList<ESM::Door>& doors = cell->mDoors;
|
||||
MWWorld::CellRefList<ESM::Door>& doors = cell->get<ESM::Door>();
|
||||
CellRefList<ESM::Door>::List& refList = doors.mList;
|
||||
for (CellRefList<ESM::Door>::List::iterator it = refList.begin(); it != refList.end(); ++it)
|
||||
{
|
||||
|
@ -1900,7 +1833,7 @@ namespace MWWorld
|
|||
const Scene::CellStoreCollection& collection = mWorldScene->getActiveCells();
|
||||
for (Scene::CellStoreCollection::const_iterator cellIt = collection.begin(); cellIt != collection.end(); ++cellIt)
|
||||
{
|
||||
MWWorld::CellRefList<ESM::Container>& containers = (*cellIt)->mContainers;
|
||||
MWWorld::CellRefList<ESM::Container>& containers = (*cellIt)->get<ESM::Container>();
|
||||
CellRefList<ESM::Container>::List& refList = containers.mList;
|
||||
for (CellRefList<ESM::Container>::List::iterator container = refList.begin(); container != refList.end(); ++container)
|
||||
{
|
||||
|
@ -1972,7 +1905,7 @@ namespace MWWorld
|
|||
if (0 == cellStore) {
|
||||
return false;
|
||||
}
|
||||
const DoorList &doors = cellStore->mDoors.mList;
|
||||
const DoorList &doors = cellStore->get<ESM::Door>().mList;
|
||||
for (DoorList::const_iterator it = doors.begin(); it != doors.end(); ++it) {
|
||||
if (!it->mRef.mTeleport) {
|
||||
continue;
|
||||
|
@ -1994,7 +1927,7 @@ namespace MWWorld
|
|||
if (0 != source) {
|
||||
// Find door leading to our current teleport door
|
||||
// and use it destination to position inside cell.
|
||||
const DoorList &doors = source->mDoors.mList;
|
||||
const DoorList &doors = source->get<ESM::Door>().mList;
|
||||
for (DoorList::const_iterator jt = doors.begin(); jt != doors.end(); ++jt) {
|
||||
if (it->mRef.mTeleport &&
|
||||
Misc::StringUtils::ciEqual(name, jt->mRef.mDestCell))
|
||||
|
@ -2402,7 +2335,7 @@ namespace MWWorld
|
|||
{
|
||||
if (cell->isExterior())
|
||||
return false;
|
||||
MWWorld::CellRefList<ESM::Door>& doors = cell->mDoors;
|
||||
MWWorld::CellRefList<ESM::Door>& doors = cell->get<ESM::Door>();
|
||||
CellRefList<ESM::Door>::List& refList = doors.mList;
|
||||
|
||||
// Check if any door in the cell leads to an exterior directly
|
||||
|
|
Loading…
Reference in a new issue