|
|
|
@ -25,252 +25,10 @@
|
|
|
|
|
#include "doingphysics.hpp"
|
|
|
|
|
#include "cellfunctors.hpp"
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
template<typename T>
|
|
|
|
|
void listCellScripts (const ESMS::ESMStore& store,
|
|
|
|
|
ESMS::CellRefList<T, MWWorld::RefData>& cellRefList, MWWorld::Scene::ScriptList& scriptList,
|
|
|
|
|
MWWorld::Ptr::CellStore *cell)
|
|
|
|
|
{
|
|
|
|
|
for (typename ESMS::CellRefList<T, MWWorld::RefData>::List::iterator iter (
|
|
|
|
|
cellRefList.list.begin());
|
|
|
|
|
iter!=cellRefList.list.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
if (!iter->base->script.empty() && iter->mData.getCount())
|
|
|
|
|
{
|
|
|
|
|
if (const ESM::Script *script = store.scripts.find (iter->base->script))
|
|
|
|
|
{
|
|
|
|
|
iter->mData.setLocals (*script);
|
|
|
|
|
|
|
|
|
|
scriptList.push_back (
|
|
|
|
|
std::make_pair (iter->base->script, MWWorld::Ptr (&*iter, cell)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
ESMS::LiveCellRef<T, MWWorld::RefData> *searchViaHandle (const std::string& handle,
|
|
|
|
|
ESMS::CellRefList<T, MWWorld::RefData>& refList)
|
|
|
|
|
{
|
|
|
|
|
typedef typename ESMS::CellRefList<T, MWWorld::RefData>::List::iterator iterator;
|
|
|
|
|
|
|
|
|
|
for (iterator iter (refList.list.begin()); iter!=refList.list.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
if (iter->mData.getHandle()==handle)
|
|
|
|
|
{
|
|
|
|
|
return &*iter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace MWWorld
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
void Scene::insertInteriorScripts (ESMS::CellStore<RefData>& cell)
|
|
|
|
|
{
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.activators, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.potions, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.appas, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.armors, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.books, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.clothes, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.containers, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.creatures, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.doors, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.ingreds, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.lights, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.lockpicks, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.miscItems, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.npcs, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.probes, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.repairs, mLocalScripts, &cell);
|
|
|
|
|
listCellScripts (mWorld->getStore(), cell.weapons, mLocalScripts, &cell);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ptr Scene::getPtr (const std::string& name, Ptr::CellStore& cell)
|
|
|
|
|
{
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Activator, RefData> *ref = cell.activators.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Potion, RefData> *ref = cell.potions.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Apparatus, RefData> *ref = cell.appas.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Armor, RefData> *ref = cell.armors.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Book, RefData> *ref = cell.books.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Clothing, RefData> *ref = cell.clothes.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Container, RefData> *ref = cell.containers.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Creature, RefData> *ref = cell.creatures.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Door, RefData> *ref = cell.doors.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Ingredient, RefData> *ref = cell.ingreds.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::CreatureLevList, RefData> *ref = cell.creatureLists.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::ItemLevList, RefData> *ref = cell.itemLists.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Light, RefData> *ref = cell.lights.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.lockpicks.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Miscellaneous, RefData> *ref = cell.miscItems.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::NPC, RefData> *ref = cell.npcs.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Probe, RefData> *ref = cell.probes.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Repair, RefData> *ref = cell.repairs.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Static, RefData> *ref = cell.statics.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Weapon, RefData> *ref = cell.weapons.find (name))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
return Ptr();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ptr Scene::getPtrViaHandle (const std::string& handle, Ptr::CellStore& cell)
|
|
|
|
|
{
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Activator, RefData> *ref =
|
|
|
|
|
searchViaHandle (handle, cell.activators))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Potion, RefData> *ref = searchViaHandle (handle, cell.potions))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Apparatus, RefData> *ref = searchViaHandle (handle, cell.appas))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Armor, RefData> *ref = searchViaHandle (handle, cell.armors))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Book, RefData> *ref = searchViaHandle (handle, cell.books))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Clothing, RefData> *ref = searchViaHandle (handle, cell.clothes))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Container, RefData> *ref =
|
|
|
|
|
searchViaHandle (handle, cell.containers))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Creature, RefData> *ref =
|
|
|
|
|
searchViaHandle (handle, cell.creatures))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Door, RefData> *ref = searchViaHandle (handle, cell.doors))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Ingredient, RefData> *ref =
|
|
|
|
|
searchViaHandle (handle, cell.ingreds))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Light, RefData> *ref = searchViaHandle (handle, cell.lights))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = searchViaHandle (handle, cell.lockpicks))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Miscellaneous, RefData> *ref = searchViaHandle (handle, cell.miscItems))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::NPC, RefData> *ref = searchViaHandle (handle, cell.npcs))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Probe, RefData> *ref = searchViaHandle (handle, cell.probes))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Repair, RefData> *ref = searchViaHandle (handle, cell.repairs))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Static, RefData> *ref = searchViaHandle (handle, cell.statics))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
if (ESMS::LiveCellRef<ESM::Weapon, RefData> *ref = searchViaHandle (handle, cell.weapons))
|
|
|
|
|
return Ptr (ref, &cell);
|
|
|
|
|
|
|
|
|
|
return Ptr();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MWRender::CellRender *Scene::searchRender (Ptr::CellStore *store)
|
|
|
|
|
{
|
|
|
|
|
CellRenderCollection::iterator iter = mActiveCells.find (store);
|
|
|
|
|
|
|
|
|
|
if (iter!=mActiveCells.end())
|
|
|
|
|
{
|
|
|
|
|
return iter->second;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
iter = mBufferedCells.find (store);
|
|
|
|
|
if (iter!=mBufferedCells.end())
|
|
|
|
|
return iter->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Scene::getDaysPerMonth (int month) const
|
|
|
|
|
{
|
|
|
|
|
switch (month)
|
|
|
|
|
{
|
|
|
|
|
case 0: return 31;
|
|
|
|
|
case 1: return 28;
|
|
|
|
|
case 2: return 31;
|
|
|
|
|
case 3: return 30;
|
|
|
|
|
case 4: return 31;
|
|
|
|
|
case 5: return 30;
|
|
|
|
|
case 6: return 31;
|
|
|
|
|
case 7: return 31;
|
|
|
|
|
case 8: return 30;
|
|
|
|
|
case 9: return 31;
|
|
|
|
|
case 10: return 30;
|
|
|
|
|
case 11: return 31;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw std::runtime_error ("month out of range");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Scene::removeScripts (Ptr::CellStore *cell)
|
|
|
|
|
{
|
|
|
|
|
ScriptList::iterator iter = mLocalScripts.begin();
|
|
|
|
|
|
|
|
|
|
while (iter!=mLocalScripts.end())
|
|
|
|
|
{
|
|
|
|
|
if (iter->second.getCell()==cell)
|
|
|
|
|
mLocalScripts.erase (iter++);
|
|
|
|
|
else
|
|
|
|
|
++iter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Scene::unloadCell (CellRenderCollection::iterator iter)
|
|
|
|
|
{
|
|
|
|
|
ListHandles functor;
|
|
|
|
@ -282,7 +40,8 @@ namespace MWWorld
|
|
|
|
|
mScene.removeObject (*iter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeScripts (iter->first);
|
|
|
|
|
mWorld->removeScripts (iter->first);
|
|
|
|
|
|
|
|
|
|
mEnvironment.mMechanicsManager->dropActors (iter->first);
|
|
|
|
|
mEnvironment.mSoundManager->stopSound (iter->first);
|
|
|
|
|
delete iter->second;
|
|
|
|
@ -292,7 +51,7 @@ namespace MWWorld
|
|
|
|
|
void Scene::loadCell (Ptr::CellStore *cell, MWRender::CellRender *render)
|
|
|
|
|
{
|
|
|
|
|
// register local scripts
|
|
|
|
|
insertInteriorScripts (*cell);
|
|
|
|
|
mWorld->insertInteriorScripts (*cell);
|
|
|
|
|
|
|
|
|
|
// This connects the cell data with the rendering scene.
|
|
|
|
|
std::pair<CellRenderCollection::iterator, bool> result =
|
|
|
|
@ -418,115 +177,16 @@ namespace MWWorld
|
|
|
|
|
delete mGlobalVariables;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Scene::ScriptList& Scene::getLocalScripts() const
|
|
|
|
|
{
|
|
|
|
|
return mLocalScripts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Scene::hasCellChanged() const
|
|
|
|
|
{
|
|
|
|
|
return mCellChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Globals::Data& Scene::getGlobalVariable (const std::string& name)
|
|
|
|
|
{
|
|
|
|
|
return (*mGlobalVariables)[name];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Globals::Data Scene::getGlobalVariable (const std::string& name) const
|
|
|
|
|
{
|
|
|
|
|
return (*mGlobalVariables)[name];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char Scene::getGlobalVariableType (const std::string& name) const
|
|
|
|
|
{
|
|
|
|
|
return mGlobalVariables->getType (name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ptr Scene::getPtr (const std::string& name, bool activeOnly)
|
|
|
|
|
{
|
|
|
|
|
// the player is always in an active cell.
|
|
|
|
|
if (name=="player")
|
|
|
|
|
{
|
|
|
|
|
return mWorld->getPlayer().getPlayer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// active cells
|
|
|
|
|
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
|
|
|
|
iter!=mActiveCells.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
Ptr ptr = getPtr (name, *iter->first);
|
|
|
|
|
|
|
|
|
|
if (!ptr.isEmpty())
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!activeOnly)
|
|
|
|
|
{
|
|
|
|
|
// TODO: inactive cells
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw std::runtime_error ("unknown ID: " + name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ptr Scene::getPtrViaHandle (const std::string& handle)
|
|
|
|
|
{
|
|
|
|
|
if (mWorld->getPlayer().getPlayer().getRefData().getHandle()==handle)
|
|
|
|
|
return mWorld->getPlayer().getPlayer();
|
|
|
|
|
|
|
|
|
|
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
|
|
|
|
iter!=mActiveCells.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
Ptr ptr = getPtrViaHandle (handle, *iter->first);
|
|
|
|
|
|
|
|
|
|
if (!ptr.isEmpty())
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw std::runtime_error ("unknown Ogre handle: " + handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Scene::enable (Ptr reference)
|
|
|
|
|
{
|
|
|
|
|
if (!reference.getRefData().isEnabled())
|
|
|
|
|
{
|
|
|
|
|
reference.getRefData().enable();
|
|
|
|
|
|
|
|
|
|
if (MWRender::CellRender *render = searchRender (reference.getCell()))
|
|
|
|
|
{
|
|
|
|
|
render->enable (reference.getRefData().getHandle());
|
|
|
|
|
|
|
|
|
|
if (mActiveCells.find (reference.getCell())!=mActiveCells.end())
|
|
|
|
|
Class::get (reference).enable (reference, mEnvironment);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Scene::disable (Ptr reference)
|
|
|
|
|
{
|
|
|
|
|
if (reference.getRefData().isEnabled())
|
|
|
|
|
{
|
|
|
|
|
reference.getRefData().disable();
|
|
|
|
|
|
|
|
|
|
if (MWRender::CellRender *render = searchRender (reference.getCell()))
|
|
|
|
|
{
|
|
|
|
|
render->disable (reference.getRefData().getHandle());
|
|
|
|
|
|
|
|
|
|
if (mActiveCells.find (reference.getCell())!=mActiveCells.end())
|
|
|
|
|
{
|
|
|
|
|
Class::get (reference).disable (reference, mEnvironment);
|
|
|
|
|
mEnvironment.mSoundManager->stopSound3D (reference);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::map<Ptr::CellStore *, MWRender::CellRender *> Scene::getActiveCells ()
|
|
|
|
|
{
|
|
|
|
|
return mActiveCells;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position)
|
|
|
|
|
{
|
|
|
|
|
SuppressDoingPhysics scopeGuard;
|
|
|
|
@ -561,7 +221,7 @@ namespace MWWorld
|
|
|
|
|
int x = 0;
|
|
|
|
|
int y = 0;
|
|
|
|
|
|
|
|
|
|
positionToIndex (position.pos[0], position.pos[1], x, y);
|
|
|
|
|
mWorld->positionToIndex (position.pos[0], position.pos[1], x, y);
|
|
|
|
|
|
|
|
|
|
changeCell (x, y, position, true);
|
|
|
|
|
}
|
|
|
|
@ -599,120 +259,5 @@ namespace MWWorld
|
|
|
|
|
{
|
|
|
|
|
mCellChanged = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Scene::getFacedHandle()
|
|
|
|
|
{
|
|
|
|
|
// FIXME
|
|
|
|
|
/*std::pair<std::string, float> result = mScene.getFacedHandle (*this);
|
|
|
|
|
|
|
|
|
|
if (result.first.empty() ||
|
|
|
|
|
result.second>getStore().gameSettings.find ("iMaxActivateDist")->i)
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
return result.first;*/
|
|
|
|
|
return std::string("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Scene::deleteObject (Ptr ptr)
|
|
|
|
|
{
|
|
|
|
|
if (ptr.getRefData().getCount()>0)
|
|
|
|
|
{
|
|
|
|
|
ptr.getRefData().setCount (0);
|
|
|
|
|
|
|
|
|
|
if (MWRender::CellRender *render = searchRender (ptr.getCell()))
|
|
|
|
|
{
|
|
|
|
|
if (mActiveCells.find (ptr.getCell())!=mActiveCells.end())
|
|
|
|
|
{
|
|
|
|
|
Class::get (ptr).disable (ptr, mEnvironment);
|
|
|
|
|
mEnvironment.mSoundManager->stopSound3D (ptr);
|
|
|
|
|
|
|
|
|
|
if (!DoingPhysics::isDoingPhysics())
|
|
|
|
|
mScene.removeObject (ptr.getRefData().getHandle());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render->deleteObject (ptr.getRefData().getHandle());
|
|
|
|
|
ptr.getRefData().setHandle ("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Scene::moveObject (Ptr ptr, float x, float y, float z)
|
|
|
|
|
{
|
|
|
|
|
ptr.getCellRef().pos.pos[0] = x;
|
|
|
|
|
ptr.getCellRef().pos.pos[1] = y;
|
|
|
|
|
ptr.getCellRef().pos.pos[2] = z;
|
|
|
|
|
|
|
|
|
|
if (ptr==mWorld->getPlayer().getPlayer())
|
|
|
|
|
{
|
|
|
|
|
if (mCurrentCell)
|
|
|
|
|
{
|
|
|
|
|
if (!(mCurrentCell->cell->data.flags & ESM::Cell::Interior))
|
|
|
|
|
{
|
|
|
|
|
// exterior -> adjust loaded cells
|
|
|
|
|
int cellX = 0;
|
|
|
|
|
int cellY = 0;
|
|
|
|
|
|
|
|
|
|
positionToIndex (x, y, cellX, cellY);
|
|
|
|
|
|
|
|
|
|
if (mCurrentCell->cell->data.gridX!=cellX || mCurrentCell->cell->data.gridY!=cellY)
|
|
|
|
|
{
|
|
|
|
|
changeCell (cellX, cellY, mWorld->getPlayer().getPlayer().getCellRef().pos, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mScene.moveObject (ptr.getRefData().getHandle(), Ogre::Vector3 (x, y, z),
|
|
|
|
|
!DoingPhysics::isDoingPhysics());
|
|
|
|
|
|
|
|
|
|
// TODO cell change for non-player ref
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Scene::indexToPosition (int cellX, int cellY, float &x, float &y, bool centre) const
|
|
|
|
|
{
|
|
|
|
|
const int cellSize = 8192;
|
|
|
|
|
|
|
|
|
|
x = cellSize * cellX;
|
|
|
|
|
y = cellSize * cellY;
|
|
|
|
|
|
|
|
|
|
if (centre)
|
|
|
|
|
{
|
|
|
|
|
x += cellSize/2;
|
|
|
|
|
y += cellSize/2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Scene::positionToIndex (float x, float y, int &cellX, int &cellY) const
|
|
|
|
|
{
|
|
|
|
|
const int cellSize = 8192;
|
|
|
|
|
|
|
|
|
|
cellX = static_cast<int> (x/cellSize);
|
|
|
|
|
|
|
|
|
|
if (x<0)
|
|
|
|
|
--cellX;
|
|
|
|
|
|
|
|
|
|
cellY = static_cast<int> (y/cellSize);
|
|
|
|
|
|
|
|
|
|
if (y<0)
|
|
|
|
|
--cellY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Scene::doPhysics (const std::vector<std::pair<std::string, Ogre::Vector3> >& actors,
|
|
|
|
|
float duration)
|
|
|
|
|
{
|
|
|
|
|
// FIXME
|
|
|
|
|
// mScene.doPhysics (duration, *this, actors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Scene::toggleCollisionMode()
|
|
|
|
|
{
|
|
|
|
|
return mScene.toggleCollisionMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Scene::toggleRenderMode (RenderMode mode)
|
|
|
|
|
{
|
|
|
|
|
return mScene.toggleRenderMode (mode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|