Commit 35f47807 authored by Marc Zinnschlag's avatar Marc Zinnschlag

Issue #255: deleted the old environment class and using the new one instead

parent 7102a825
......@@ -44,7 +44,7 @@ add_openmw_dir (mwsound
)
add_openmw_dir (mwworld
refdata world physicssystem scene environment globals class action nullaction actionteleport
refdata world physicssystem scene globals class action nullaction actionteleport
containerstore actiontalk actiontake manualref player cellfunctors
cells localscripts customdata weather inventorystore ptr
)
......
......@@ -50,10 +50,12 @@
#include "mwmechanics/mechanicsmanager.hpp"
#include "mwbase/environment.hpp"
void OMW::Engine::executeLocalScripts()
{
MWWorld::LocalScripts& localScripts = mEnvironment.mWorld->getLocalScripts();
MWWorld::LocalScripts& localScripts = MWBase::Environment::get().getWorld()->getLocalScripts();
localScripts.startIteration();
......@@ -61,11 +63,11 @@ void OMW::Engine::executeLocalScripts()
{
std::pair<std::string, MWWorld::Ptr> script = localScripts.getNext();
MWScript::InterpreterContext interpreterContext (mEnvironment,
MWScript::InterpreterContext interpreterContext (
&script.second.getRefData().getLocals(), script.second);
mEnvironment.mScriptManager->run (script.first, interpreterContext);
MWBase::Environment::get().getScriptManager()->run (script.first, interpreterContext);
if (mEnvironment.mWorld->hasCellChanged())
if (MWBase::Environment::get().getWorld()->hasCellChanged())
break;
}
......@@ -81,7 +83,7 @@ void OMW::Engine::updateFocusReport (float duration)
std::string name;
std::string handle = mEnvironment.mWorld->getFacedHandle();
std::string handle = MWBase::Environment::get().getWorld()->getFacedHandle();
if (!handle.empty())
{
......@@ -90,7 +92,7 @@ void OMW::Engine::updateFocusReport (float duration)
// therefore, we are catching the "Unknown Ogre handle" exception that occurs in this case
try
{
MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle);
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getPtrViaHandle (handle);
if (!ptr.isEmpty()){
name = MWWorld::Class::get (ptr).getName (ptr);
......@@ -124,27 +126,27 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
{
try
{
mEnvironment.mFrameDuration = evt.timeSinceLastFrame;
mEnvironment.setFrameDuration (evt.timeSinceLastFrame);
// update input
mEnvironment.mInputManager->update();
MWBase::Environment::get().getInputManager()->update();
// sound
if (mUseSound)
mEnvironment.mSoundManager->update (evt.timeSinceLastFrame);
MWBase::Environment::get().getSoundManager()->update (evt.timeSinceLastFrame);
// update GUI
Ogre::RenderWindow* window = mOgre->getWindow();
mEnvironment.mWindowManager->wmUpdateFps(window->getLastFPS(),
MWBase::Environment::get().getWindowManager()->wmUpdateFps(window->getLastFPS(),
window->getTriangleCount(),
window->getBatchCount());
mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration);
MWBase::Environment::get().getWindowManager()->onFrame(mEnvironment.getFrameDuration());
// global scripts
mEnvironment.mScriptManager->getGlobalScripts().run (mEnvironment);
MWBase::Environment::get().getScriptManager()->getGlobalScripts().run();
bool changed = mEnvironment.mWorld->hasCellChanged();
bool changed = MWBase::Environment::get().getWorld()->hasCellChanged();
// local scripts
executeLocalScripts(); // This does not handle the case where a global script causes a cell
......@@ -152,28 +154,28 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
// frame.
// passing of time
if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game)
mEnvironment.mWorld->advanceTime (
mEnvironment.mFrameDuration*mEnvironment.mWorld->getTimeScaleFactor()/3600);
if (MWBase::Environment::get().getWindowManager()->getMode()==MWGui::GM_Game)
MWBase::Environment::get().getWorld()->advanceTime (
mEnvironment.getFrameDuration()*MWBase::Environment::get().getWorld()->getTimeScaleFactor()/3600);
if (changed) // keep change flag for another frame, if cell changed happend in local script
mEnvironment.mWorld->markCellAsUnchanged();
MWBase::Environment::get().getWorld()->markCellAsUnchanged();
// update actors
std::vector<std::pair<std::string, Ogre::Vector3> > movement;
mEnvironment.mMechanicsManager->update (movement, mEnvironment.mFrameDuration,
mEnvironment.mWindowManager->getMode()!=MWGui::GM_Game);
MWBase::Environment::get().getMechanicsManager()->update (movement, mEnvironment.getFrameDuration(),
MWBase::Environment::get().getWindowManager()->getMode()!=MWGui::GM_Game);
if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game)
mEnvironment.mWorld->doPhysics (movement, mEnvironment.mFrameDuration);
if (MWBase::Environment::get().getWindowManager()->getMode()==MWGui::GM_Game)
MWBase::Environment::get().getWorld()->doPhysics (movement, mEnvironment.getFrameDuration());
// update world
mEnvironment.mWorld->update (evt.timeSinceLastFrame);
MWBase::Environment::get().getWorld()->update (evt.timeSinceLastFrame);
// report focus object (for debugging)
if (mReportFocus)
updateFocusReport (mEnvironment.mFrameDuration);
updateFocusReport (mEnvironment.getFrameDuration());
}
catch (const std::exception& e)
{
......@@ -203,12 +205,13 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
OMW::Engine::~Engine()
{
delete mEnvironment.mWorld;
delete mEnvironment.mSoundManager;
delete mEnvironment.mMechanicsManager;
delete mEnvironment.mDialogueManager;
delete mEnvironment.mJournal;
delete mEnvironment.mScriptManager;
delete MWBase::Environment::get().getInputManager();
delete MWBase::Environment::get().getSoundManager();
delete MWBase::Environment::get().getMechanicsManager();
delete MWBase::Environment::get().getDialogueManager();
delete MWBase::Environment::get().getJournal();
delete MWBase::Environment::get().getScriptManager();
delete MWBase::Environment::get().getWorld();
delete mScriptContext;
delete mOgre;
}
......@@ -312,7 +315,6 @@ void OMW::Engine::setReportFocus (bool report)
void OMW::Engine::go()
{
mFocusTDiff = 0;
assert (!mEnvironment.mWorld);
assert (!mCellName.empty());
assert (!mMaster.empty());
assert (!mOgre);
......@@ -381,66 +383,66 @@ void OMW::Engine::go()
MWGui::CursorReplace replacer;
// Create the world
mEnvironment.mWorld = new MWWorld::World (*mOgre, mFileCollections, mMaster,
mResDir, mNewGame, mEnvironment, mEncoding, mFallbackMap);
mEnvironment.setWorld (new MWWorld::World (*mOgre, mFileCollections, mMaster,
mResDir, mNewGame, mEncoding, mFallbackMap));
// Create window manager - this manages all the MW-specific GUI windows
MWScript::registerExtensions (mExtensions);
mEnvironment.mWindowManager = new MWGui::WindowManager(mEnvironment,
mExtensions, mFpsLevel, mNewGame, mOgre, mCfgMgr.getLogPath().string() + std::string("/"));
mEnvironment.setWindowManager (new MWGui::WindowManager(
mExtensions, mFpsLevel, mNewGame, mOgre, mCfgMgr.getLogPath().string() + std::string("/")));
// Create sound system
mEnvironment.mSoundManager = new MWSound::SoundManager(mUseSound, mEnvironment);
mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound));
// Create script system
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full,
mEnvironment);
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
mScriptContext->setExtensions (&mExtensions);
mEnvironment.mScriptManager = new MWScript::ScriptManager (mEnvironment.mWorld->getStore(),
mVerboseScripts, *mScriptContext);
mEnvironment.setScriptManager (new MWScript::ScriptManager (MWBase::Environment::get().getWorld()->getStore(),
mVerboseScripts, *mScriptContext));
// Create game mechanics system
mEnvironment.mMechanicsManager = new MWMechanics::MechanicsManager (mEnvironment);
mEnvironment.setMechanicsManager (new MWMechanics::MechanicsManager);
// Create dialog system
mEnvironment.mJournal = new MWDialogue::Journal (mEnvironment);
mEnvironment.mDialogueManager = new MWDialogue::DialogueManager (mEnvironment,mExtensions);
mEnvironment.setJournal (new MWDialogue::Journal);
mEnvironment.setDialogueManager (new MWDialogue::DialogueManager (mExtensions));
// load cell
ESM::Position pos;
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
pos.pos[2] = 0;
if (const ESM::Cell *exterior = mEnvironment.mWorld->getExterior (mCellName))
if (const ESM::Cell *exterior = MWBase::Environment::get().getWorld()->getExterior (mCellName))
{
mEnvironment.mWorld->indexToPosition (exterior->data.gridX, exterior->data.gridY,
MWBase::Environment::get().getWorld()->indexToPosition (exterior->data.gridX, exterior->data.gridY,
pos.pos[0], pos.pos[1], true);
mEnvironment.mWorld->changeToExteriorCell (pos);
MWBase::Environment::get().getWorld()->changeToExteriorCell (pos);
}
else
{
pos.pos[0] = pos.pos[1] = 0;
mEnvironment.mWorld->changeToInteriorCell (mCellName, pos);
MWBase::Environment::get().getWorld()->changeToInteriorCell (mCellName, pos);
}
// Sets up the input system
MWInput::MWInputManager input(*mOgre, mEnvironment.mWorld->getPlayer(),
*mEnvironment.mWindowManager, mDebug, *this);
mEnvironment.mInputManager = &input;
mEnvironment.setInputManager (new MWInput::MWInputManager (*mOgre,
MWBase::Environment::get().getWorld()->getPlayer(),
*MWBase::Environment::get().getWindowManager(), mDebug, *this));
std::cout << "\nPress Q/ESC or close window to exit.\n";
mOgre->getRoot()->addFrameListener (this);
// Play some good 'ol tunes
mEnvironment.mSoundManager->playPlaylist(std::string("Explore"));
MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Explore"));
// scripts
if (mCompileAll)
{
std::pair<int, int> result = mEnvironment.mScriptManager->compileAll();
std::pair<int, int> result = MWBase::Environment::get().getScriptManager()->compileAll();
if (result.first)
std::cout
......@@ -461,10 +463,10 @@ void OMW::Engine::go()
void OMW::Engine::activate()
{
if (mEnvironment.mWindowManager->getMode()!=MWGui::GM_Game)
if (MWBase::Environment::get().getWindowManager()->getMode()!=MWGui::GM_Game)
return;
std::string handle = mEnvironment.mWorld->getFacedHandle();
std::string handle = MWBase::Environment::get().getWorld()->getFacedHandle();
if (handle.empty())
return;
......@@ -475,7 +477,7 @@ void OMW::Engine::activate()
MWWorld::Ptr ptr;
try
{
ptr = mEnvironment.mWorld->getPtrViaHandle (handle);
ptr = MWBase::Environment::get().getWorld()->getPtrViaHandle (handle);
if (ptr.isEmpty())
return;
......@@ -485,12 +487,10 @@ void OMW::Engine::activate()
return;
}
MWScript::InterpreterContext interpreterContext (mEnvironment,
&ptr.getRefData().getLocals(), ptr);
MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr);
boost::shared_ptr<MWWorld::Action> action =
MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayer().getPlayer(),
mEnvironment);
MWWorld::Class::get (ptr).activate (ptr, MWBase::Environment::get().getWorld()->getPlayer().getPlayer());
interpreterContext.activate (ptr, action);
......@@ -498,8 +498,8 @@ void OMW::Engine::activate()
if (!script.empty())
{
mEnvironment.mWorld->getLocalScripts().setIgnore (ptr);
mEnvironment.mScriptManager->run (script, interpreterContext);
MWBase::Environment::get().getWorld()->getLocalScripts().setIgnore (ptr);
MWBase::Environment::get().getScriptManager()->run (script, interpreterContext);
}
if (!interpreterContext.hasActivationBeenHandled())
......
......@@ -10,7 +10,8 @@
#include <components/compiler/extensions.hpp>
#include <components/files/collections.hpp>
#include "mwworld/environment.hpp"
#include "mwbase/environment.hpp"
#include "mwworld/ptr.hpp"
namespace Compiler
......@@ -78,7 +79,7 @@ namespace OMW
std::string mFocusName;
std::map<std::string,std::string> mFallbackMap;
MWWorld::Environment mEnvironment;
MWBase::Environment mEnvironment;
Compiler::Extensions mExtensions;
Compiler::Context *mScriptContext;
......
......@@ -7,7 +7,7 @@ MWBase::Environment *MWBase::Environment::sThis = 0;
MWBase::Environment::Environment()
: mWorld (0), mSoundManager (0), mScriptManager (0), mWindowManager (0),
mMechanicsManager (0), mDialogueManager (0), mJournal (0), mFrameDuration (0)
mMechanicsManager (0), mDialogueManager (0), mJournal (0), mInputManager (0), mFrameDuration (0)
{
assert (!sThis);
sThis = this;
......@@ -53,6 +53,11 @@ void MWBase::Environment::setJournal (MWDialogue::Journal *journal)
mJournal = journal;
}
void MWBase::Environment::setInputManager (MWInput::MWInputManager *inputManager)
{
mInputManager = inputManager;
}
void MWBase::Environment::setFrameDuration (float duration)
{
mFrameDuration = duration;
......@@ -100,6 +105,12 @@ MWDialogue::Journal *MWBase::Environment::getJournal() const
return mJournal;
}
MWInput::MWInputManager *MWBase::Environment::getInputManager() const
{
assert (mInputManager);
return mInputManager;
}
float MWBase::Environment::getFrameDuration() const
{
return mFrameDuration;
......
......@@ -56,6 +56,7 @@ namespace MWBase
MWMechanics::MechanicsManager *mMechanicsManager;
MWDialogue::DialogueManager *mDialogueManager;
MWDialogue::Journal *mJournal;
MWInput::MWInputManager *mInputManager;
float mFrameDuration;
Environment (const Environment&);
......@@ -84,6 +85,8 @@ namespace MWBase
void setJournal (MWDialogue::Journal *journal);
void setInputManager (MWInput::MWInputManager *inputManager);
void setFrameDuration (float duration);
///< Set length of current frame in seconds.
......@@ -101,6 +104,8 @@ namespace MWBase
MWDialogue::Journal *getJournal() const;
MWInput::MWInputManager *getInputManager() const;
float getFrameDuration() const;
static const Environment& get();
......
......@@ -18,7 +18,7 @@ namespace MWClass
assert (ref->base != NULL);
const std::string &model = ref->base->model;
if (!model.empty())
{
MWRender::Objects& objects = renderingInterface.getObjects();
......@@ -27,7 +27,7 @@ namespace MWClass
}
}
void Activator::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
void Activator::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
ESMS::LiveCellRef<ESM::Activator, MWWorld::RefData> *ref =
ptr.get<ESM::Activator>();
......
......@@ -12,7 +12,7 @@ namespace MWClass
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
///< Add reference into a cell for rendering
virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const;
virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const;
virtual std::string getName (const MWWorld::Ptr& ptr) const;
///< \return name (the one that is to be presented to the user; not the internal one);
......
......@@ -5,9 +5,10 @@
#include <components/esm_store/cell_store.hpp>
#include "../mwbase/environment.hpp"
#include "../mwworld/ptr.hpp"
#include "../mwworld/actiontake.hpp"
#include "../mwworld/environment.hpp"
#include "../mwrender/objects.hpp"
......@@ -31,7 +32,7 @@ namespace MWClass
}
}
void Apparatus::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
void Apparatus::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
ESMS::LiveCellRef<ESM::Apparatus, MWWorld::RefData> *ref =
ptr.get<ESM::Apparatus>();
......@@ -54,9 +55,9 @@ namespace MWClass
}
boost::shared_ptr<MWWorld::Action> Apparatus::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
const MWWorld::Ptr& actor) const
{
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr), 1.0, 1.0, MWSound::Play_NoTrack);
MWBase::Environment::get().getSoundManager()->playSound3D (ptr, getUpSoundId(ptr), 1.0, 1.0, MWSound::Play_NoTrack);
return boost::shared_ptr<MWWorld::Action> (
new MWWorld::ActionTake (ptr));
......
......@@ -12,14 +12,14 @@ namespace MWClass
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
///< Add reference into a cell for rendering
virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const;
virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const;
virtual std::string getName (const MWWorld::Ptr& ptr) const;
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual boost::shared_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const;
const MWWorld::Ptr& actor) const;
///< Generate action for activation
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
......
......@@ -9,11 +9,11 @@
#include "../mwworld/ptr.hpp"
#include "../mwworld/actiontake.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwworld/environment.hpp"
#include "../mwworld/world.hpp"
#include "../mwbase/environment.hpp"
#include "../mwrender/objects.hpp"
#include "../mwsound/soundmanager.hpp"
......@@ -36,7 +36,7 @@ namespace MWClass
}
}
void Armor::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const
void Armor::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
{
ESMS::LiveCellRef<ESM::Armor, MWWorld::RefData> *ref =
ptr.get<ESM::Armor>();
......@@ -58,9 +58,9 @@ namespace MWClass
}
boost::shared_ptr<MWWorld::Action> Armor::activate (const MWWorld::Ptr& ptr,
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
const MWWorld::Ptr& actor) const
{
environment.mSoundManager->playSound3D (ptr, getUpSoundId(ptr, environment), 1.0, 1.0, MWSound::Play_NoTrack);
MWBase::Environment::get().getSoundManager()->playSound3D (ptr, getUpSoundId(ptr), 1.0, 1.0, MWSound::Play_NoTrack);
return boost::shared_ptr<MWWorld::Action> (
new MWWorld::ActionTake (ptr));
......@@ -121,7 +121,7 @@ namespace MWClass
return std::make_pair (slots, false);
}
int Armor::getEquipmentSkill (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const
int Armor::getEquipmentSkill (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Armor, MWWorld::RefData> *ref =
ptr.get<ESM::Armor>();
......@@ -147,13 +147,13 @@ namespace MWClass
if (typeGmst.empty())
return -1;
float iWeight = environment.mWorld->getStore().gameSettings.find (typeGmst)->i;
float iWeight = MWBase::Environment::get().getWorld()->getStore().gameSettings.find (typeGmst)->i;
if (iWeight * environment.mWorld->getStore().gameSettings.find ("fLightMaxMod")->f>=
if (iWeight * MWBase::Environment::get().getWorld()->getStore().gameSettings.find ("fLightMaxMod")->f>=
ref->base->data.weight)
return ESM::Skill::LightArmor;
if (iWeight * environment.mWorld->getStore().gameSettings.find ("fMedMaxMod")->f>=
if (iWeight * MWBase::Environment::get().getWorld()->getStore().gameSettings.find ("fMedMaxMod")->f>=
ref->base->data.weight)
return ESM::Skill::MediumArmor;
......@@ -175,9 +175,9 @@ namespace MWClass
registerClass (typeid (ESM::Armor).name(), instance);
}
std::string Armor::getUpSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const
std::string Armor::getUpSoundId (const MWWorld::Ptr& ptr) const
{
int es = getEquipmentSkill(ptr, environment);
int es = getEquipmentSkill(ptr);
if (es == ESM::Skill::LightArmor)
return std::string("Item Armor Light Up");
else if (es == ESM::Skill::MediumArmor)
......@@ -186,9 +186,9 @@ namespace MWClass
return std::string("Item Armor Heavy Up");
}
std::string Armor::getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const
std::string Armor::getDownSoundId (const MWWorld::Ptr& ptr) const
{
int es = getEquipmentSkill(ptr, environment);
int es = getEquipmentSkill(ptr);
if (es == ESM::Skill::LightArmor)
return std::string("Item Armor Light Down");
else if (es == ESM::Skill::MediumArmor)
......
......@@ -12,14 +12,14 @@ namespace MWClass
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const;
///< Add reference into a cell for rendering
virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics, MWWorld::Environment& environment) const;
virtual void insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const;
virtual std::string getName (const MWWorld::Ptr& ptr) const;
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.