forked from mirror/openmw-tes3mp
integrated CellStore pointer into Ptr class
This commit is contained in:
parent
0f742ce7f9
commit
8134c5b760
6 changed files with 99 additions and 144 deletions
|
@ -16,11 +16,9 @@
|
||||||
|
|
||||||
namespace MWScript
|
namespace MWScript
|
||||||
{
|
{
|
||||||
InterpreterContext::PtrWithCell InterpreterContext::getReference (
|
MWWorld::Ptr InterpreterContext::getReference (
|
||||||
const std::string& id, bool activeOnly)
|
const std::string& id, bool activeOnly)
|
||||||
{
|
{
|
||||||
PtrWithCell ref;
|
|
||||||
|
|
||||||
if (!id.empty())
|
if (!id.empty())
|
||||||
{
|
{
|
||||||
return mEnvironment.mWorld->getPtr (id, activeOnly);
|
return mEnvironment.mWorld->getPtr (id, activeOnly);
|
||||||
|
@ -30,15 +28,13 @@ namespace MWScript
|
||||||
if (mReference.isEmpty())
|
if (mReference.isEmpty())
|
||||||
throw std::runtime_error ("no implicit reference");
|
throw std::runtime_error ("no implicit reference");
|
||||||
|
|
||||||
return PtrWithCell (mReference, mEnvironment.mWorld->find (mReference));
|
return mReference;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InterpreterContext::CPtrWithCell InterpreterContext::getReference (
|
const MWWorld::Ptr InterpreterContext::getReference (
|
||||||
const std::string& id, bool activeOnly) const
|
const std::string& id, bool activeOnly) const
|
||||||
{
|
{
|
||||||
CPtrWithCell ref;
|
|
||||||
|
|
||||||
if (!id.empty())
|
if (!id.empty())
|
||||||
{
|
{
|
||||||
return mEnvironment.mWorld->getPtr (id, activeOnly);
|
return mEnvironment.mWorld->getPtr (id, activeOnly);
|
||||||
|
@ -48,7 +44,7 @@ namespace MWScript
|
||||||
if (mReference.isEmpty())
|
if (mReference.isEmpty())
|
||||||
throw std::runtime_error ("no implicit reference");
|
throw std::runtime_error ("no implicit reference");
|
||||||
|
|
||||||
return CPtrWithCell (mReference, mEnvironment.mWorld->find (mReference));
|
return mReference;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,15 +175,14 @@ namespace MWScript
|
||||||
float InterpreterContext::getDistance (const std::string& name, const std::string& id) const
|
float InterpreterContext::getDistance (const std::string& name, const std::string& id) const
|
||||||
{
|
{
|
||||||
// TODO handle exterior cells (when ref and ref2 are located in different cells)
|
// TODO handle exterior cells (when ref and ref2 are located in different cells)
|
||||||
CPtrWithCell ref2 = getReference (id, false);
|
const MWWorld::Ptr ref2 = getReference (id, false);
|
||||||
|
|
||||||
std::pair<MWWorld::Ptr, MWWorld::World::CellStore *> ref =
|
const MWWorld::Ptr ref = mEnvironment.mWorld->getPtr (name, true);
|
||||||
mEnvironment.mWorld->getPtr (name, true);
|
|
||||||
|
|
||||||
double diff[3];
|
double diff[3];
|
||||||
|
|
||||||
for (int i=0; i<3; ++i)
|
for (int i=0; i<3; ++i)
|
||||||
diff[i] = ref.first.getCellRef().pos.pos[i] - ref2.first.getCellRef().pos.pos[i];
|
diff[i] = ref.getCellRef().pos.pos[i] - ref2.getCellRef().pos.pos[i];
|
||||||
|
|
||||||
return std::sqrt (diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2]);
|
return std::sqrt (diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2]);
|
||||||
}
|
}
|
||||||
|
@ -204,19 +199,19 @@ namespace MWScript
|
||||||
|
|
||||||
bool InterpreterContext::isDisabled (const std::string& id) const
|
bool InterpreterContext::isDisabled (const std::string& id) const
|
||||||
{
|
{
|
||||||
CPtrWithCell ref = getReference (id, false);
|
const MWWorld::Ptr ref = getReference (id, false);
|
||||||
return !ref.first.getRefData().isEnabled();
|
return !ref.getRefData().isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterpreterContext::enable (const std::string& id)
|
void InterpreterContext::enable (const std::string& id)
|
||||||
{
|
{
|
||||||
PtrWithCell ref = getReference (id, false);
|
MWWorld::Ptr ref = getReference (id, false);
|
||||||
mEnvironment.mWorld->enable (ref);
|
mEnvironment.mWorld->enable (ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterpreterContext::disable (const std::string& id)
|
void InterpreterContext::disable (const std::string& id)
|
||||||
{
|
{
|
||||||
PtrWithCell ref = getReference (id, false);
|
MWWorld::Ptr ref = getReference (id, false);
|
||||||
mEnvironment.mWorld->disable (ref);
|
mEnvironment.mWorld->disable (ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,10 @@ namespace MWScript
|
||||||
Locals *mLocals;
|
Locals *mLocals;
|
||||||
MWWorld::Ptr mReference;
|
MWWorld::Ptr mReference;
|
||||||
|
|
||||||
typedef std::pair<MWWorld::Ptr, MWWorld::World::CellStore *> PtrWithCell;
|
|
||||||
typedef std::pair<const MWWorld::Ptr, const MWWorld::World::CellStore *> CPtrWithCell;
|
|
||||||
|
|
||||||
PtrWithCell getReference (const std::string& id, bool activeOnly);
|
MWWorld::Ptr getReference (const std::string& id, bool activeOnly);
|
||||||
|
|
||||||
CPtrWithCell getReference (const std::string& id, bool activeOnly) const;
|
const MWWorld::Ptr getReference (const std::string& id, bool activeOnly) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -205,7 +205,7 @@ namespace MWScript
|
||||||
std::string text = runtime.getStringLiteral (runtime[0]);
|
std::string text = runtime.getStringLiteral (runtime[0]);
|
||||||
runtime.pop();
|
runtime.pop();
|
||||||
|
|
||||||
context.getSoundManager().say (context.getWorld().getPtr (id, true).first,
|
context.getSoundManager().say (context.getWorld().getPtr (id, true),
|
||||||
file, text, context);
|
file, text, context);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -223,8 +223,7 @@ namespace MWScript
|
||||||
runtime.pop();
|
runtime.pop();
|
||||||
|
|
||||||
runtime.push (context.getSoundManager().sayDone (
|
runtime.push (context.getSoundManager().sayDone (
|
||||||
context.getWorld().getPtr (id, true).first,
|
context.getWorld().getPtr (id, true), context));
|
||||||
context));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -248,8 +247,7 @@ namespace MWScript
|
||||||
runtime.pop();
|
runtime.pop();
|
||||||
|
|
||||||
context.getSoundManager().playSound3D (
|
context.getSoundManager().playSound3D (
|
||||||
context.getWorld().getPtr (id, true).first, sound,
|
context.getWorld().getPtr (id, true), sound, 1.0, 1.0, mLoop, context);
|
||||||
1.0, 1.0, mLoop, context);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -279,8 +277,7 @@ namespace MWScript
|
||||||
runtime.pop();
|
runtime.pop();
|
||||||
|
|
||||||
context.getSoundManager().playSound3D (
|
context.getSoundManager().playSound3D (
|
||||||
context.getWorld().getPtr (id, true).first, sound, volume,
|
context.getWorld().getPtr (id, true), sound, volume, pitch, mLoop, context);
|
||||||
pitch, mLoop, context);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -301,7 +298,7 @@ namespace MWScript
|
||||||
runtime.pop();
|
runtime.pop();
|
||||||
|
|
||||||
context.getSoundManager().stopSound3D (
|
context.getSoundManager().stopSound3D (
|
||||||
context.getWorld().getPtr (id, true).first, sound, context);
|
context.getWorld().getPtr (id, true), sound, context);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -321,7 +318,7 @@ namespace MWScript
|
||||||
runtime.pop();
|
runtime.pop();
|
||||||
|
|
||||||
runtime.push (context.getSoundManager().getSoundPlaying (
|
runtime.push (context.getSoundManager().getSoundPlaying (
|
||||||
context.getWorld().getPtr (id, true).first,
|
context.getWorld().getPtr (id, true),
|
||||||
runtime.getStringLiteral (index), context));
|
runtime.getStringLiteral (index), context));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,13 +15,18 @@ namespace MWWorld
|
||||||
|
|
||||||
class Ptr
|
class Ptr
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef ESMS::CellStore<RefData> CellStore;
|
||||||
|
|
||||||
boost::any mPtr;
|
boost::any mPtr;
|
||||||
ESM::CellRef *mCellRef;
|
ESM::CellRef *mCellRef;
|
||||||
RefData *mRefData;
|
RefData *mRefData;
|
||||||
|
CellStore *mCell;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Ptr() : mCellRef (0), mRefData (0) {}
|
Ptr() : mCellRef (0), mRefData (0), mCell (0) {}
|
||||||
|
|
||||||
bool isEmpty() const
|
bool isEmpty() const
|
||||||
{
|
{
|
||||||
|
@ -29,11 +34,12 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Ptr (ESMS::LiveCellRef<T, RefData> *liveCellRef)
|
Ptr (ESMS::LiveCellRef<T, RefData> *liveCellRef, CellStore *cell)
|
||||||
{
|
{
|
||||||
mPtr = liveCellRef;
|
mPtr = liveCellRef;
|
||||||
mCellRef = &liveCellRef->ref;
|
mCellRef = &liveCellRef->ref;
|
||||||
mRefData = &liveCellRef->mData;
|
mRefData = &liveCellRef->mData;
|
||||||
|
mCell = cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -53,6 +59,12 @@ namespace MWWorld
|
||||||
assert (mRefData);
|
assert (mRefData);
|
||||||
return *mRefData;
|
return *mRefData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ptr::CellStore *getCell() const
|
||||||
|
{
|
||||||
|
assert (mCell);
|
||||||
|
return mCell;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,8 @@ namespace
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void listCellScripts (const ESMS::ESMStore& store,
|
void listCellScripts (const ESMS::ESMStore& store,
|
||||||
ESMS::CellRefList<T, MWWorld::RefData>& cellRefList, MWWorld::World::ScriptList& scriptList)
|
ESMS::CellRefList<T, MWWorld::RefData>& cellRefList, MWWorld::World::ScriptList& scriptList,
|
||||||
|
MWWorld::Ptr::CellStore *cell)
|
||||||
{
|
{
|
||||||
for (typename ESMS::CellRefList<T, MWWorld::RefData>::List::iterator iter (
|
for (typename ESMS::CellRefList<T, MWWorld::RefData>::List::iterator iter (
|
||||||
cellRefList.list.begin());
|
cellRefList.list.begin());
|
||||||
|
@ -28,116 +29,102 @@ namespace
|
||||||
iter->mData.setLocals (*script);
|
iter->mData.setLocals (*script);
|
||||||
|
|
||||||
scriptList.push_back (
|
scriptList.push_back (
|
||||||
std::make_pair (iter->base->script, MWWorld::Ptr (&*iter)));
|
std::make_pair (iter->base->script, MWWorld::Ptr (&*iter, cell)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool hasReference (ESMS::CellRefList<T, MWWorld::RefData>& cellRefList, const MWWorld::Ptr& ptr)
|
|
||||||
{
|
|
||||||
for (typename ESMS::CellRefList<T, MWWorld::RefData>::List::iterator iter (
|
|
||||||
cellRefList.list.begin());
|
|
||||||
iter!=cellRefList.list.end(); ++iter)
|
|
||||||
{
|
|
||||||
if (&iter->mData==&ptr.getRefData())
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
void World::insertInteriorScripts (ESMS::CellStore<RefData>& cell)
|
void World::insertInteriorScripts (ESMS::CellStore<RefData>& cell)
|
||||||
{
|
{
|
||||||
listCellScripts (mStore, cell.activators, mLocalScripts);
|
listCellScripts (mStore, cell.activators, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.potions, mLocalScripts);
|
listCellScripts (mStore, cell.potions, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.appas, mLocalScripts);
|
listCellScripts (mStore, cell.appas, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.armors, mLocalScripts);
|
listCellScripts (mStore, cell.armors, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.books, mLocalScripts);
|
listCellScripts (mStore, cell.books, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.clothes, mLocalScripts);
|
listCellScripts (mStore, cell.clothes, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.containers, mLocalScripts);
|
listCellScripts (mStore, cell.containers, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.creatures, mLocalScripts);
|
listCellScripts (mStore, cell.creatures, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.doors, mLocalScripts);
|
listCellScripts (mStore, cell.doors, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.ingreds, mLocalScripts);
|
listCellScripts (mStore, cell.ingreds, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.lights, mLocalScripts);
|
listCellScripts (mStore, cell.lights, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.lockpicks, mLocalScripts);
|
listCellScripts (mStore, cell.lockpicks, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.miscItems, mLocalScripts);
|
listCellScripts (mStore, cell.miscItems, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.npcs, mLocalScripts);
|
listCellScripts (mStore, cell.npcs, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.probes, mLocalScripts);
|
listCellScripts (mStore, cell.probes, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.repairs, mLocalScripts);
|
listCellScripts (mStore, cell.repairs, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.weapons, mLocalScripts);
|
listCellScripts (mStore, cell.weapons, mLocalScripts, &cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr World::getPtr (const std::string& name, CellStore& cell)
|
Ptr World::getPtr (const std::string& name, Ptr::CellStore& cell)
|
||||||
{
|
{
|
||||||
if (ESMS::LiveCellRef<ESM::Activator, RefData> *ref = cell.activators.find (name))
|
if (ESMS::LiveCellRef<ESM::Activator, RefData> *ref = cell.activators.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Potion, RefData> *ref = cell.potions.find (name))
|
if (ESMS::LiveCellRef<ESM::Potion, RefData> *ref = cell.potions.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Apparatus, RefData> *ref = cell.appas.find (name))
|
if (ESMS::LiveCellRef<ESM::Apparatus, RefData> *ref = cell.appas.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Armor, RefData> *ref = cell.armors.find (name))
|
if (ESMS::LiveCellRef<ESM::Armor, RefData> *ref = cell.armors.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Book, RefData> *ref = cell.books.find (name))
|
if (ESMS::LiveCellRef<ESM::Book, RefData> *ref = cell.books.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Clothing, RefData> *ref = cell.clothes.find (name))
|
if (ESMS::LiveCellRef<ESM::Clothing, RefData> *ref = cell.clothes.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Container, RefData> *ref = cell.containers.find (name))
|
if (ESMS::LiveCellRef<ESM::Container, RefData> *ref = cell.containers.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Creature, RefData> *ref = cell.creatures.find (name))
|
if (ESMS::LiveCellRef<ESM::Creature, RefData> *ref = cell.creatures.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Door, RefData> *ref = cell.doors.find (name))
|
if (ESMS::LiveCellRef<ESM::Door, RefData> *ref = cell.doors.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Ingredient, RefData> *ref = cell.ingreds.find (name))
|
if (ESMS::LiveCellRef<ESM::Ingredient, RefData> *ref = cell.ingreds.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::CreatureLevList, RefData> *ref = cell.creatureLists.find (name))
|
if (ESMS::LiveCellRef<ESM::CreatureLevList, RefData> *ref = cell.creatureLists.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::ItemLevList, RefData> *ref = cell.itemLists.find (name))
|
if (ESMS::LiveCellRef<ESM::ItemLevList, RefData> *ref = cell.itemLists.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Light, RefData> *ref = cell.lights.find (name))
|
if (ESMS::LiveCellRef<ESM::Light, RefData> *ref = cell.lights.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.lockpicks.find (name))
|
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.lockpicks.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Misc, RefData> *ref = cell.miscItems.find (name))
|
if (ESMS::LiveCellRef<ESM::Misc, RefData> *ref = cell.miscItems.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::NPC, RefData> *ref = cell.npcs.find (name))
|
if (ESMS::LiveCellRef<ESM::NPC, RefData> *ref = cell.npcs.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.probes.find (name))
|
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.probes.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.repairs.find (name))
|
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.repairs.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Static, RefData> *ref = cell.statics.find (name))
|
if (ESMS::LiveCellRef<ESM::Static, RefData> *ref = cell.statics.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Weapon, RefData> *ref = cell.weapons.find (name))
|
if (ESMS::LiveCellRef<ESM::Weapon, RefData> *ref = cell.weapons.find (name))
|
||||||
return ref;
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
return Ptr();
|
return Ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
MWRender::CellRender *World::searchRender (CellStore *store)
|
MWRender::CellRender *World::searchRender (Ptr::CellStore *store)
|
||||||
{
|
{
|
||||||
CellRenderCollection::iterator iter = mActiveCells.find (store);
|
CellRenderCollection::iterator iter = mActiveCells.find (store);
|
||||||
|
|
||||||
|
@ -157,7 +144,7 @@ namespace MWWorld
|
||||||
|
|
||||||
World::World (Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir,
|
World::World (Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir,
|
||||||
const std::string& master, const std::string& startCell, bool newGame)
|
const std::string& master, const std::string& startCell, bool newGame)
|
||||||
: mSkyManager (0), mScene (renderer), mPlayerPos (0)
|
: mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0)
|
||||||
{
|
{
|
||||||
boost::filesystem::path masterPath (dataDir);
|
boost::filesystem::path masterPath (dataDir);
|
||||||
masterPath /= master;
|
masterPath /= master;
|
||||||
|
@ -169,6 +156,7 @@ namespace MWWorld
|
||||||
mStore.load (mEsm);
|
mStore.load (mEsm);
|
||||||
|
|
||||||
mInteriors[startCell].loadInt (startCell, mStore, mEsm);
|
mInteriors[startCell].loadInt (startCell, mStore, mEsm);
|
||||||
|
mCurrentCell = &mInteriors[startCell];
|
||||||
|
|
||||||
insertInteriorScripts (mInteriors[startCell]);
|
insertInteriorScripts (mInteriors[startCell]);
|
||||||
|
|
||||||
|
@ -251,15 +239,12 @@ namespace MWWorld
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Ptr, World::CellStore *> World::getPtr (const std::string& name, bool activeOnly)
|
Ptr World::getPtr (const std::string& name, bool activeOnly)
|
||||||
{
|
{
|
||||||
// the player is always in an active cell.
|
// the player is always in an active cell.
|
||||||
if (name=="player")
|
if (name=="player")
|
||||||
{
|
{
|
||||||
// TODO: find real cell (might need to be stored in playerPos). For now we
|
return Ptr (mPlayerPos->getPlayer(), mCurrentCell);
|
||||||
// use the first active cell. This will fail the moment we move into an
|
|
||||||
// exterior cell.
|
|
||||||
return std::make_pair (mPlayerPos->getPlayer(), mActiveCells.begin()->first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// active cells
|
// active cells
|
||||||
|
@ -269,7 +254,7 @@ namespace MWWorld
|
||||||
Ptr ptr = getPtr (name, *iter->first);
|
Ptr ptr = getPtr (name, *iter->first);
|
||||||
|
|
||||||
if (!ptr.isEmpty())
|
if (!ptr.isEmpty())
|
||||||
return std::make_pair (ptr, iter->first);
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!activeOnly)
|
if (!activeOnly)
|
||||||
|
@ -280,58 +265,29 @@ namespace MWWorld
|
||||||
throw std::runtime_error ("unknown ID: " + name);
|
throw std::runtime_error ("unknown ID: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::enable (std::pair<Ptr, CellStore *>& reference)
|
void World::enable (Ptr reference)
|
||||||
{
|
{
|
||||||
if (!reference.first.getRefData().isEnabled())
|
if (!reference.getRefData().isEnabled())
|
||||||
{
|
{
|
||||||
reference.first.getRefData().enable();
|
reference.getRefData().enable();
|
||||||
|
|
||||||
if (MWRender::CellRender *render = searchRender (reference.second))
|
if (MWRender::CellRender *render = searchRender (reference.getCell()))
|
||||||
{
|
{
|
||||||
render->enable (reference.first.getRefData().getHandle());
|
render->enable (reference.getRefData().getHandle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::disable (std::pair<Ptr, CellStore *>& reference)
|
void World::disable (Ptr reference)
|
||||||
{
|
{
|
||||||
if (!reference.first.getRefData().isEnabled())
|
if (!reference.getRefData().isEnabled())
|
||||||
{
|
{
|
||||||
reference.first.getRefData().enable();
|
reference.getRefData().enable();
|
||||||
|
|
||||||
if (MWRender::CellRender *render = searchRender (reference.second))
|
if (MWRender::CellRender *render = searchRender (reference.getCell()))
|
||||||
{
|
{
|
||||||
render->disable (reference.first.getRefData().getHandle());
|
render->disable (reference.getRefData().getHandle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
World::CellStore *World::find (const Ptr& ptr)
|
|
||||||
{
|
|
||||||
for (CellRenderCollection::iterator iter (mActiveCells.begin()); iter!=mActiveCells.end();
|
|
||||||
++iter)
|
|
||||||
{
|
|
||||||
if (
|
|
||||||
hasReference (iter->first->activators, ptr) ||
|
|
||||||
hasReference (iter->first->potions, ptr) ||
|
|
||||||
hasReference (iter->first->appas, ptr) ||
|
|
||||||
hasReference (iter->first->armors, ptr) ||
|
|
||||||
hasReference (iter->first->books, ptr) ||
|
|
||||||
hasReference (iter->first->clothes, ptr) ||
|
|
||||||
hasReference (iter->first->containers, ptr) ||
|
|
||||||
hasReference (iter->first->creatures, ptr) ||
|
|
||||||
hasReference (iter->first->doors, ptr) ||
|
|
||||||
hasReference (iter->first->ingreds, ptr) ||
|
|
||||||
hasReference (iter->first->lights, ptr) ||
|
|
||||||
hasReference (iter->first->lockpicks, ptr) ||
|
|
||||||
hasReference (iter->first->miscItems, ptr) ||
|
|
||||||
hasReference (iter->first->npcs, ptr) ||
|
|
||||||
hasReference (iter->first->probes, ptr) ||
|
|
||||||
hasReference (iter->first->repairs, ptr) ||
|
|
||||||
hasReference (iter->first->weapons, ptr))
|
|
||||||
return iter->first;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw std::runtime_error ("failed to locate reference in active cell");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,20 +36,20 @@ namespace MWWorld
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef std::vector<std::pair<std::string, Ptr> > ScriptList;
|
typedef std::vector<std::pair<std::string, Ptr> > ScriptList;
|
||||||
typedef ESMS::CellStore<RefData> CellStore;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
typedef std::map<CellStore *, MWRender::CellRender *> CellRenderCollection;
|
typedef std::map<Ptr::CellStore *, MWRender::CellRender *> CellRenderCollection;
|
||||||
|
|
||||||
MWRender::SkyManager* mSkyManager;
|
MWRender::SkyManager* mSkyManager;
|
||||||
MWRender::MWScene mScene;
|
MWRender::MWScene mScene;
|
||||||
MWRender::PlayerPos *mPlayerPos;
|
MWRender::PlayerPos *mPlayerPos;
|
||||||
|
Ptr::CellStore *mCurrentCell; // the cell, the player is in
|
||||||
CellRenderCollection mActiveCells;
|
CellRenderCollection mActiveCells;
|
||||||
CellRenderCollection mBufferedCells; // loaded, but not active (buffering not implementd yet)
|
CellRenderCollection mBufferedCells; // loaded, but not active (buffering not implementd yet)
|
||||||
ESM::ESMReader mEsm;
|
ESM::ESMReader mEsm;
|
||||||
ESMS::ESMStore mStore;
|
ESMS::ESMStore mStore;
|
||||||
std::map<std::string, CellStore> mInteriors;
|
std::map<std::string, Ptr::CellStore> mInteriors;
|
||||||
ScriptList mLocalScripts;
|
ScriptList mLocalScripts;
|
||||||
std::map<std::string, Interpreter::Type_Data> mGlobalVariables;
|
std::map<std::string, Interpreter::Type_Data> mGlobalVariables;
|
||||||
|
|
||||||
|
@ -59,9 +59,9 @@ namespace MWWorld
|
||||||
|
|
||||||
void insertInteriorScripts (ESMS::CellStore<RefData>& cell);
|
void insertInteriorScripts (ESMS::CellStore<RefData>& cell);
|
||||||
|
|
||||||
Ptr getPtr (const std::string& name, CellStore& cellStore);
|
Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore);
|
||||||
|
|
||||||
MWRender::CellRender *searchRender (CellStore *store);
|
MWRender::CellRender *searchRender (Ptr::CellStore *store);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -82,16 +82,13 @@ namespace MWWorld
|
||||||
|
|
||||||
Interpreter::Type_Data& getGlobalVariable (const std::string& name);
|
Interpreter::Type_Data& getGlobalVariable (const std::string& name);
|
||||||
|
|
||||||
std::pair<Ptr, CellStore *> getPtr (const std::string& name, bool activeOnly);
|
Ptr getPtr (const std::string& name, bool activeOnly);
|
||||||
///< Return a pointer to a liveCellRef with the given name.
|
///< Return a pointer to a liveCellRef with the given name.
|
||||||
/// \param activeOnly do non search inactive cells.
|
/// \param activeOnly do non search inactive cells.
|
||||||
|
|
||||||
void enable (std::pair<Ptr, CellStore *>& reference);
|
void enable (Ptr reference);
|
||||||
|
|
||||||
void disable (std::pair<Ptr, CellStore *>& reference);
|
void disable (Ptr reference);
|
||||||
|
|
||||||
CellStore *find (const Ptr& ptr);
|
|
||||||
///< Only active cells are searched.
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue