mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 15:09:39 +00:00
added getPtr function that works via Ogre handle
This commit is contained in:
parent
69cc88bcaf
commit
d1c000313f
2 changed files with 223 additions and 131 deletions
|
@ -28,15 +28,23 @@ namespace
|
||||||
if (!iter->base->script.empty())
|
if (!iter->base->script.empty())
|
||||||
{
|
{
|
||||||
if (const ESM::Script *script = store.scripts.find (iter->base->script))
|
if (const ESM::Script *script = store.scripts.find (iter->base->script))
|
||||||
{
|
{
|
||||||
iter->mData.setLocals (*script);
|
iter->mData.setLocals (*script);
|
||||||
|
|
||||||
scriptList.push_back (
|
scriptList.push_back (
|
||||||
std::make_pair (iter->base->script, MWWorld::Ptr (&*iter, cell)));
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
|
@ -61,7 +69,7 @@ namespace MWWorld
|
||||||
listCellScripts (mStore, cell.repairs, mLocalScripts, &cell);
|
listCellScripts (mStore, cell.repairs, mLocalScripts, &cell);
|
||||||
listCellScripts (mStore, cell.weapons, mLocalScripts, &cell);
|
listCellScripts (mStore, cell.weapons, mLocalScripts, &cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr World::getPtr (const std::string& name, Ptr::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))
|
||||||
|
@ -69,68 +77,131 @@ namespace MWWorld
|
||||||
|
|
||||||
if (ESMS::LiveCellRef<ESM::Potion, RefData> *ref = cell.potions.find (name))
|
if (ESMS::LiveCellRef<ESM::Potion, RefData> *ref = cell.potions.find (name))
|
||||||
return Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
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 Ptr (ref, &cell);
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
return Ptr();
|
return Ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ptr World::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::Misc, 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::Tool, RefData> *ref = searchViaHandle (handle, cell.probes))
|
||||||
|
return Ptr (ref, &cell);
|
||||||
|
|
||||||
|
if (ESMS::LiveCellRef<ESM::Tool, 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 *World::searchRender (Ptr::CellStore *store)
|
MWRender::CellRender *World::searchRender (Ptr::CellStore *store)
|
||||||
{
|
{
|
||||||
CellRenderCollection::iterator iter = mActiveCells.find (store);
|
CellRenderCollection::iterator iter = mActiveCells.find (store);
|
||||||
|
|
||||||
if (iter!=mActiveCells.end())
|
if (iter!=mActiveCells.end())
|
||||||
{
|
{
|
||||||
return iter->second;
|
return iter->second;
|
||||||
|
@ -141,10 +212,10 @@ namespace MWWorld
|
||||||
if (iter!=mBufferedCells.end())
|
if (iter!=mBufferedCells.end())
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int World::getDaysPerMonth (int month) const
|
int World::getDaysPerMonth (int month) const
|
||||||
{
|
{
|
||||||
switch (month)
|
switch (month)
|
||||||
|
@ -162,84 +233,84 @@ namespace MWWorld
|
||||||
case 10: return 30;
|
case 10: return 30;
|
||||||
case 11: return 31;
|
case 11: return 31;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::runtime_error ("month out of range");
|
throw std::runtime_error ("month out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
World::World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir,
|
World::World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir,
|
||||||
const std::string& master, bool newGame, Environment& environment)
|
const std::string& master, bool newGame, Environment& environment)
|
||||||
: mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0),
|
: mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0), mGlobalVariables (0),
|
||||||
mSky (false), mCellChanged (false), mEnvironment (environment)
|
mSky (false), mCellChanged (false), mEnvironment (environment)
|
||||||
{
|
{
|
||||||
boost::filesystem::path masterPath (dataDir);
|
boost::filesystem::path masterPath (dataDir);
|
||||||
masterPath /= master;
|
masterPath /= master;
|
||||||
|
|
||||||
std::cout << "Loading ESM " << masterPath.string() << "\n";
|
std::cout << "Loading ESM " << masterPath.string() << "\n";
|
||||||
|
|
||||||
// This parses the ESM file and loads a sample cell
|
// This parses the ESM file and loads a sample cell
|
||||||
mEsm.open (masterPath.file_string());
|
mEsm.open (masterPath.file_string());
|
||||||
mStore.load (mEsm);
|
mStore.load (mEsm);
|
||||||
|
|
||||||
mPlayerPos = new MWRender::PlayerPos (mScene.getCamera(), mStore.npcs.find ("player"));
|
mPlayerPos = new MWRender::PlayerPos (mScene.getCamera(), mStore.npcs.find ("player"));
|
||||||
|
|
||||||
// global variables
|
// global variables
|
||||||
mGlobalVariables = new Globals (mStore);
|
mGlobalVariables = new Globals (mStore);
|
||||||
|
|
||||||
if (newGame)
|
if (newGame)
|
||||||
{
|
{
|
||||||
// set new game mark
|
// set new game mark
|
||||||
mGlobalVariables->setInt ("chargenstate", 1);
|
mGlobalVariables->setInt ("chargenstate", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
mSkyManager =
|
mSkyManager =
|
||||||
MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera());
|
MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera());
|
||||||
}
|
}
|
||||||
|
|
||||||
World::~World()
|
World::~World()
|
||||||
{
|
{
|
||||||
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
||||||
iter!=mActiveCells.end(); ++iter)
|
iter!=mActiveCells.end(); ++iter)
|
||||||
delete iter->second;
|
delete iter->second;
|
||||||
|
|
||||||
for (CellRenderCollection::iterator iter (mBufferedCells.begin());
|
for (CellRenderCollection::iterator iter (mBufferedCells.begin());
|
||||||
iter!=mBufferedCells.end(); ++iter)
|
iter!=mBufferedCells.end(); ++iter)
|
||||||
delete iter->second;
|
delete iter->second;
|
||||||
|
|
||||||
delete mPlayerPos;
|
delete mPlayerPos;
|
||||||
delete mSkyManager;
|
delete mSkyManager;
|
||||||
delete mGlobalVariables;
|
delete mGlobalVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
MWRender::PlayerPos& World::getPlayerPos()
|
MWRender::PlayerPos& World::getPlayerPos()
|
||||||
{
|
{
|
||||||
return *mPlayerPos;
|
return *mPlayerPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESMS::ESMStore& World::getStore()
|
ESMS::ESMStore& World::getStore()
|
||||||
{
|
{
|
||||||
return mStore;
|
return mStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
const World::ScriptList& World::getLocalScripts() const
|
const World::ScriptList& World::getLocalScripts() const
|
||||||
{
|
{
|
||||||
return mLocalScripts;
|
return mLocalScripts;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::hasCellChanged() const
|
bool World::hasCellChanged() const
|
||||||
{
|
{
|
||||||
return mCellChanged;
|
return mCellChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
Globals::Data& World::getGlobalVariable (const std::string& name)
|
Globals::Data& World::getGlobalVariable (const std::string& name)
|
||||||
{
|
{
|
||||||
return (*mGlobalVariables)[name];
|
return (*mGlobalVariables)[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
char World::getGlobalVariableType (const std::string& name) const
|
char World::getGlobalVariableType (const std::string& name) const
|
||||||
{
|
{
|
||||||
return mGlobalVariables->getType (name);
|
return mGlobalVariables->getType (name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr 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.
|
||||||
|
@ -247,35 +318,51 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
return mPlayerPos->getPlayer();
|
return mPlayerPos->getPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
// active cells
|
// active cells
|
||||||
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
for (CellRenderCollection::iterator iter (mActiveCells.begin());
|
||||||
iter!=mActiveCells.end(); ++iter)
|
iter!=mActiveCells.end(); ++iter)
|
||||||
{
|
{
|
||||||
Ptr ptr = getPtr (name, *iter->first);
|
Ptr ptr = getPtr (name, *iter->first);
|
||||||
|
|
||||||
if (!ptr.isEmpty())
|
if (!ptr.isEmpty())
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!activeOnly)
|
if (!activeOnly)
|
||||||
{
|
{
|
||||||
// TODO: inactive cells
|
// TODO: inactive cells
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::runtime_error ("unknown ID: " + name);
|
throw std::runtime_error ("unknown ID: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ptr World::getPtrViaHandle (const std::string& handle)
|
||||||
|
{
|
||||||
|
// TODO player
|
||||||
|
|
||||||
|
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 World::enable (Ptr reference)
|
void World::enable (Ptr reference)
|
||||||
{
|
{
|
||||||
if (!reference.getRefData().isEnabled())
|
if (!reference.getRefData().isEnabled())
|
||||||
{
|
{
|
||||||
reference.getRefData().enable();
|
reference.getRefData().enable();
|
||||||
|
|
||||||
if (MWRender::CellRender *render = searchRender (reference.getCell()))
|
if (MWRender::CellRender *render = searchRender (reference.getCell()))
|
||||||
{
|
{
|
||||||
render->enable (reference.getRefData().getHandle());
|
render->enable (reference.getRefData().getHandle());
|
||||||
|
|
||||||
if (mActiveCells.find (reference.getCell())!=mActiveCells.end() &&
|
if (mActiveCells.find (reference.getCell())!=mActiveCells.end() &&
|
||||||
(reference.getType()==typeid (ESMS::LiveCellRef<ESM::NPC, RefData>) ||
|
(reference.getType()==typeid (ESMS::LiveCellRef<ESM::NPC, RefData>) ||
|
||||||
reference.getType()==typeid (ESMS::LiveCellRef<ESM::Creature, RefData>)))
|
reference.getType()==typeid (ESMS::LiveCellRef<ESM::Creature, RefData>)))
|
||||||
|
@ -285,69 +372,69 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::disable (Ptr reference)
|
void World::disable (Ptr reference)
|
||||||
{
|
{
|
||||||
if (!reference.getRefData().isEnabled())
|
if (!reference.getRefData().isEnabled())
|
||||||
{
|
{
|
||||||
reference.getRefData().enable();
|
reference.getRefData().enable();
|
||||||
|
|
||||||
if (MWRender::CellRender *render = searchRender (reference.getCell()))
|
if (MWRender::CellRender *render = searchRender (reference.getCell()))
|
||||||
{
|
{
|
||||||
render->disable (reference.getRefData().getHandle());
|
render->disable (reference.getRefData().getHandle());
|
||||||
|
|
||||||
if (mActiveCells.find (reference.getCell())!=mActiveCells.end() &&
|
if (mActiveCells.find (reference.getCell())!=mActiveCells.end() &&
|
||||||
(reference.getType()==typeid (ESMS::LiveCellRef<ESM::NPC, RefData>) ||
|
(reference.getType()==typeid (ESMS::LiveCellRef<ESM::NPC, RefData>) ||
|
||||||
reference.getType()==typeid (ESMS::LiveCellRef<ESM::Creature, RefData>)))
|
reference.getType()==typeid (ESMS::LiveCellRef<ESM::Creature, RefData>)))
|
||||||
{
|
{
|
||||||
mEnvironment.mMechanicsManager->removeActor (reference);
|
mEnvironment.mMechanicsManager->removeActor (reference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::advanceTime (double hours)
|
void World::advanceTime (double hours)
|
||||||
{
|
{
|
||||||
hours += mGlobalVariables->getFloat ("gamehour");
|
hours += mGlobalVariables->getFloat ("gamehour");
|
||||||
|
|
||||||
setHour (hours);
|
setHour (hours);
|
||||||
|
|
||||||
int days = hours / 24;
|
int days = hours / 24;
|
||||||
|
|
||||||
if (days>0)
|
if (days>0)
|
||||||
mGlobalVariables->setInt ("dayspassed", days + mGlobalVariables->getInt ("dayspassed"));
|
mGlobalVariables->setInt ("dayspassed", days + mGlobalVariables->getInt ("dayspassed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::setHour (double hour)
|
void World::setHour (double hour)
|
||||||
{
|
{
|
||||||
if (hour<0)
|
if (hour<0)
|
||||||
hour = 0;
|
hour = 0;
|
||||||
|
|
||||||
int days = hour / 24;
|
int days = hour / 24;
|
||||||
|
|
||||||
hour = std::fmod (hour, 24);
|
hour = std::fmod (hour, 24);
|
||||||
|
|
||||||
mGlobalVariables->setFloat ("gamehour", hour);
|
mGlobalVariables->setFloat ("gamehour", hour);
|
||||||
|
|
||||||
mSkyManager->setHour (hour);
|
mSkyManager->setHour (hour);
|
||||||
|
|
||||||
if (days>0)
|
if (days>0)
|
||||||
setDay (days + mGlobalVariables->getInt ("day"));
|
setDay (days + mGlobalVariables->getInt ("day"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::setDay (int day)
|
void World::setDay (int day)
|
||||||
{
|
{
|
||||||
if (day<0)
|
if (day<0)
|
||||||
day = 0;
|
day = 0;
|
||||||
|
|
||||||
int month = mGlobalVariables->getInt ("month");
|
int month = mGlobalVariables->getInt ("month");
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int days = getDaysPerMonth (month);
|
int days = getDaysPerMonth (month);
|
||||||
if (day<days)
|
if (day<days)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (month<11)
|
if (month<11)
|
||||||
{
|
{
|
||||||
++month;
|
++month;
|
||||||
|
@ -357,37 +444,37 @@ namespace MWWorld
|
||||||
month = 0;
|
month = 0;
|
||||||
mGlobalVariables->setInt ("year", mGlobalVariables->getInt ("year")+1);
|
mGlobalVariables->setInt ("year", mGlobalVariables->getInt ("year")+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
day -= days;
|
day -= days;
|
||||||
}
|
}
|
||||||
|
|
||||||
mGlobalVariables->setInt ("day", day);
|
mGlobalVariables->setInt ("day", day);
|
||||||
mGlobalVariables->setInt ("month", month);
|
mGlobalVariables->setInt ("month", month);
|
||||||
|
|
||||||
mSkyManager->setDate (day, month);
|
mSkyManager->setDate (day, month);
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::setMonth (int month)
|
void World::setMonth (int month)
|
||||||
{
|
{
|
||||||
if (month<0)
|
if (month<0)
|
||||||
month = 0;
|
month = 0;
|
||||||
|
|
||||||
int years = month / 12;
|
int years = month / 12;
|
||||||
month = month % 12;
|
month = month % 12;
|
||||||
|
|
||||||
int days = getDaysPerMonth (month);
|
int days = getDaysPerMonth (month);
|
||||||
|
|
||||||
if (mGlobalVariables->getInt ("day")>=days)
|
if (mGlobalVariables->getInt ("day")>=days)
|
||||||
mGlobalVariables->setInt ("day", days-1);
|
mGlobalVariables->setInt ("day", days-1);
|
||||||
|
|
||||||
mGlobalVariables->setInt ("month", month);
|
mGlobalVariables->setInt ("month", month);
|
||||||
|
|
||||||
if (years>0)
|
if (years>0)
|
||||||
mGlobalVariables->setInt ("year", years+mGlobalVariables->getInt ("year"));
|
mGlobalVariables->setInt ("year", years+mGlobalVariables->getInt ("year"));
|
||||||
|
|
||||||
mSkyManager->setDate (mGlobalVariables->getInt ("day"), month);
|
mSkyManager->setDate (mGlobalVariables->getInt ("day"), month);
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::toggleSky()
|
void World::toggleSky()
|
||||||
{
|
{
|
||||||
if (mSky)
|
if (mSky)
|
||||||
|
@ -405,36 +492,36 @@ namespace MWWorld
|
||||||
mSkyManager->enable();
|
mSkyManager->enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int World::getMasserPhase() const
|
int World::getMasserPhase() const
|
||||||
{
|
{
|
||||||
return mSkyManager->getMasserPhase();
|
return mSkyManager->getMasserPhase();
|
||||||
}
|
}
|
||||||
|
|
||||||
int World::getSecundaPhase() const
|
int World::getSecundaPhase() const
|
||||||
{
|
{
|
||||||
return mSkyManager->getSecundaPhase();
|
return mSkyManager->getSecundaPhase();
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::setMoonColour (bool red)
|
void World::setMoonColour (bool red)
|
||||||
{
|
{
|
||||||
mSkyManager->setMoonColour (red);
|
mSkyManager->setMoonColour (red);
|
||||||
}
|
}
|
||||||
|
|
||||||
float World::getTimeScaleFactor() const
|
float World::getTimeScaleFactor() const
|
||||||
{
|
{
|
||||||
return mGlobalVariables->getInt ("timescale");
|
return mGlobalVariables->getInt ("timescale");
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::changeCell (const std::string& cellName, const ESM::Position& position)
|
void World::changeCell (const std::string& cellName, const ESM::Position& position)
|
||||||
{
|
{
|
||||||
// Load cell.
|
// Load cell.
|
||||||
mInteriors[cellName].loadInt (cellName, mStore, mEsm);
|
mInteriors[cellName].loadInt (cellName, mStore, mEsm);
|
||||||
Ptr::CellStore *cell = &mInteriors[cellName];
|
Ptr::CellStore *cell = &mInteriors[cellName];
|
||||||
|
|
||||||
// remove active
|
// remove active
|
||||||
CellRenderCollection::iterator active = mActiveCells.begin();
|
CellRenderCollection::iterator active = mActiveCells.begin();
|
||||||
|
|
||||||
if (active!=mActiveCells.end())
|
if (active!=mActiveCells.end())
|
||||||
{
|
{
|
||||||
mEnvironment.mMechanicsManager->dropActors (active->first);
|
mEnvironment.mMechanicsManager->dropActors (active->first);
|
||||||
|
@ -444,7 +531,7 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
// register local scripts
|
// register local scripts
|
||||||
mLocalScripts.clear(); // FIXME won't work with exteriors
|
mLocalScripts.clear(); // FIXME won't work with exteriors
|
||||||
insertInteriorScripts (*cell);
|
insertInteriorScripts (*cell);
|
||||||
|
|
||||||
// adjust player
|
// adjust player
|
||||||
|
@ -458,11 +545,11 @@ namespace MWWorld
|
||||||
new MWRender::InteriorCellRender (*cell, mStore, mScene)));
|
new MWRender::InteriorCellRender (*cell, mStore, mScene)));
|
||||||
|
|
||||||
if (result.second)
|
if (result.second)
|
||||||
{
|
{
|
||||||
// Load the cell and insert it into the renderer
|
// Load the cell and insert it into the renderer
|
||||||
result.first->second->show();
|
result.first->second->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actors
|
// Actors
|
||||||
mEnvironment.mMechanicsManager->addActor (mPlayerPos->getPlayer());
|
mEnvironment.mMechanicsManager->addActor (mPlayerPos->getPlayer());
|
||||||
mEnvironment.mMechanicsManager->watchActor (mPlayerPos->getPlayer());
|
mEnvironment.mMechanicsManager->watchActor (mPlayerPos->getPlayer());
|
||||||
|
@ -496,12 +583,12 @@ namespace MWWorld
|
||||||
// TODO set weather
|
// TODO set weather
|
||||||
toggleSky();
|
toggleSky();
|
||||||
}
|
}
|
||||||
|
|
||||||
mCellChanged = true;
|
mCellChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::markCellAsUnchanged()
|
void World::markCellAsUnchanged()
|
||||||
{
|
{
|
||||||
mCellChanged = false;
|
mCellChanged = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,23 +30,23 @@ namespace MWRender
|
||||||
class SkyManager;
|
class SkyManager;
|
||||||
class CellRender;
|
class CellRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
class Environment;
|
class Environment;
|
||||||
|
|
||||||
/// \brief The game world and its visual representation
|
/// \brief The game world and its visual representation
|
||||||
|
|
||||||
class World
|
class World
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef std::vector<std::pair<std::string, Ptr> > ScriptList;
|
typedef std::vector<std::pair<std::string, Ptr> > ScriptList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
typedef std::map<Ptr::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;
|
||||||
|
@ -61,70 +61,75 @@ namespace MWWorld
|
||||||
bool mSky;
|
bool mSky;
|
||||||
bool mCellChanged;
|
bool mCellChanged;
|
||||||
Environment& mEnvironment;
|
Environment& mEnvironment;
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
World (const World&);
|
World (const World&);
|
||||||
World& operator= (const World&);
|
World& operator= (const World&);
|
||||||
|
|
||||||
void insertInteriorScripts (ESMS::CellStore<RefData>& cell);
|
void insertInteriorScripts (ESMS::CellStore<RefData>& cell);
|
||||||
|
|
||||||
Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore);
|
Ptr getPtr (const std::string& name, Ptr::CellStore& cellStore);
|
||||||
|
|
||||||
|
Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore);
|
||||||
|
|
||||||
MWRender::CellRender *searchRender (Ptr::CellStore *store);
|
MWRender::CellRender *searchRender (Ptr::CellStore *store);
|
||||||
|
|
||||||
int getDaysPerMonth (int month) const;
|
int getDaysPerMonth (int month) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& master,
|
World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& master,
|
||||||
const std::string& dataDir, bool newGame, Environment& environment);
|
const std::string& dataDir, bool newGame, Environment& environment);
|
||||||
|
|
||||||
~World();
|
~World();
|
||||||
|
|
||||||
MWRender::PlayerPos& getPlayerPos();
|
MWRender::PlayerPos& getPlayerPos();
|
||||||
|
|
||||||
ESMS::ESMStore& getStore();
|
ESMS::ESMStore& getStore();
|
||||||
|
|
||||||
const ScriptList& getLocalScripts() const;
|
const ScriptList& getLocalScripts() const;
|
||||||
///< Names and local variable state of all local scripts in active cells.
|
///< Names and local variable state of all local scripts in active cells.
|
||||||
|
|
||||||
bool hasCellChanged() const;
|
bool hasCellChanged() const;
|
||||||
///< Has the player moved to a different cell, since the last frame?
|
///< Has the player moved to a different cell, since the last frame?
|
||||||
|
|
||||||
Globals::Data& getGlobalVariable (const std::string& name);
|
Globals::Data& getGlobalVariable (const std::string& name);
|
||||||
|
|
||||||
char getGlobalVariableType (const std::string& name) const;
|
char getGlobalVariableType (const std::string& name) const;
|
||||||
///< Return ' ', if there is no global variable with this name.
|
///< Return ' ', if there is no global variable with this name.
|
||||||
|
|
||||||
Ptr 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.
|
||||||
|
|
||||||
|
Ptr getPtrViaHandle (const std::string& handle);
|
||||||
|
///< Return a pointer to a liveCellRef with the given Ogre handle.
|
||||||
|
|
||||||
void enable (Ptr reference);
|
void enable (Ptr reference);
|
||||||
|
|
||||||
void disable (Ptr reference);
|
void disable (Ptr reference);
|
||||||
|
|
||||||
void advanceTime (double hours);
|
void advanceTime (double hours);
|
||||||
|
|
||||||
void setHour (double hour);
|
void setHour (double hour);
|
||||||
|
|
||||||
void setMonth (int month);
|
void setMonth (int month);
|
||||||
|
|
||||||
void setDay (int day);
|
void setDay (int day);
|
||||||
|
|
||||||
void toggleSky();
|
void toggleSky();
|
||||||
|
|
||||||
int getMasserPhase() const;
|
int getMasserPhase() const;
|
||||||
|
|
||||||
int getSecundaPhase() const;
|
int getSecundaPhase() const;
|
||||||
|
|
||||||
void setMoonColour (bool red);
|
void setMoonColour (bool red);
|
||||||
|
|
||||||
float getTimeScaleFactor() const;
|
float getTimeScaleFactor() const;
|
||||||
|
|
||||||
void changeCell (const std::string& cellName, const ESM::Position& position);
|
void changeCell (const std::string& cellName, const ESM::Position& position);
|
||||||
///< works only for interior cells currently.
|
///< works only for interior cells currently.
|
||||||
|
|
||||||
void markCellAsUnchanged();
|
void markCellAsUnchanged();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue