Classes shouldn't use MWBase::Environment to access their own members.

sceneinput
Jordan Ayers 10 years ago
parent 5558962b14
commit be7bd9529d

@ -66,7 +66,7 @@ namespace
void OMW::Engine::executeLocalScripts()
{
MWWorld::LocalScripts& localScripts = MWBase::Environment::get().getWorld()->getLocalScripts();
MWWorld::LocalScripts& localScripts = mEnvironment.getWorld()->getLocalScripts();
localScripts.startIteration();
@ -76,7 +76,7 @@ void OMW::Engine::executeLocalScripts()
MWScript::InterpreterContext interpreterContext (
&script.second.getRefData().getLocals(), script.second);
MWBase::Environment::get().getScriptManager()->run (script.first, interpreterContext);
mEnvironment.getScriptManager()->run (script.first, interpreterContext);
}
localScripts.setIgnore (MWWorld::Ptr());
@ -90,7 +90,7 @@ void OMW::Engine::frame(float frametime)
mEnvironment.setFrameDuration (frametime);
// update input
MWBase::Environment::get().getInputManager()->update(frametime, false);
mEnvironment.getInputManager()->update(frametime, false);
// When the window is minimized, pause everything. Currently this *has* to be here to work around a MyGUI bug.
// If we are not currently rendering, then RenderItems will not be reused resulting in a memory leak upon changing widget textures.
@ -99,76 +99,76 @@ void OMW::Engine::frame(float frametime)
// sound
if (mUseSound)
MWBase::Environment::get().getSoundManager()->update(frametime);
mEnvironment.getSoundManager()->update(frametime);
// Main menu opened? Then scripts are also paused.
bool paused = MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_MainMenu);
bool paused = mEnvironment.getWindowManager()->containsMode(MWGui::GM_MainMenu);
// update game state
MWBase::Environment::get().getStateManager()->update (frametime);
mEnvironment.getStateManager()->update (frametime);
bool guiActive = MWBase::Environment::get().getWindowManager()->isGuiMode();
bool guiActive = mEnvironment.getWindowManager()->isGuiMode();
osg::Timer_t beforeScriptTick = osg::Timer::instance()->tick();
if (MWBase::Environment::get().getStateManager()->getState()==
if (mEnvironment.getStateManager()->getState()==
MWBase::StateManager::State_Running)
{
if (!paused)
{
if (MWBase::Environment::get().getWorld()->getScriptsEnabled())
if (mEnvironment.getWorld()->getScriptsEnabled())
{
// local scripts
executeLocalScripts();
// global scripts
MWBase::Environment::get().getScriptManager()->getGlobalScripts().run();
mEnvironment.getScriptManager()->getGlobalScripts().run();
}
MWBase::Environment::get().getWorld()->markCellAsUnchanged();
mEnvironment.getWorld()->markCellAsUnchanged();
}
if (!guiActive)
MWBase::Environment::get().getWorld()->advanceTime(
frametime*MWBase::Environment::get().getWorld()->getTimeScaleFactor()/3600);
mEnvironment.getWorld()->advanceTime(
frametime*mEnvironment.getWorld()->getTimeScaleFactor()/3600);
}
osg::Timer_t afterScriptTick = osg::Timer::instance()->tick();
// update actors
osg::Timer_t beforeMechanicsTick = osg::Timer::instance()->tick();
if (MWBase::Environment::get().getStateManager()->getState()!=
if (mEnvironment.getStateManager()->getState()!=
MWBase::StateManager::State_NoGame)
{
MWBase::Environment::get().getMechanicsManager()->update(frametime,
mEnvironment.getMechanicsManager()->update(frametime,
guiActive);
}
osg::Timer_t afterMechanicsTick = osg::Timer::instance()->tick();
if (MWBase::Environment::get().getStateManager()->getState()==
if (mEnvironment.getStateManager()->getState()==
MWBase::StateManager::State_Running)
{
MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr();
if(!guiActive && player.getClass().getCreatureStats(player).isDead())
MWBase::Environment::get().getStateManager()->endGame();
mEnvironment.getStateManager()->endGame();
}
// update world
osg::Timer_t beforePhysicsTick = osg::Timer::instance()->tick();;
if (MWBase::Environment::get().getStateManager()->getState()!=
if (mEnvironment.getStateManager()->getState()!=
MWBase::StateManager::State_NoGame)
{
MWBase::Environment::get().getWorld()->update(frametime, guiActive);
mEnvironment.getWorld()->update(frametime, guiActive);
}
osg::Timer_t afterPhysicsTick = osg::Timer::instance()->tick();
// update GUI
MWBase::Environment::get().getWindowManager()->onFrame(frametime);
if (MWBase::Environment::get().getStateManager()->getState()!=
mEnvironment.getWindowManager()->onFrame(frametime);
if (mEnvironment.getStateManager()->getState()!=
MWBase::StateManager::State_NoGame)
{
#if 0
MWBase::Environment::get().getWindowManager()->wmUpdateFps(fps);
mEnvironment.getWindowManager()->wmUpdateFps(fps);
#endif
MWBase::Environment::get().getWindowManager()->update();
mEnvironment.getWindowManager()->update();
}
int frameNumber = mViewer->getFrameStamp()->getFrameNumber();
@ -511,7 +511,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
mEnvironment.setWorld( new MWWorld::World (mViewer, rootNode, mResourceSystem.get(),
mFileCollections, mContentFiles, mEncoder, mFallbackMap,
mActivationDistanceOverride, mCellName, mStartupScript));
MWBase::Environment::get().getWorld()->setupPlayer();
mEnvironment.getWorld()->setupPlayer();
input->setPlayer(&mEnvironment.getWorld()->getPlayer());
window->initUI();
@ -528,7 +528,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
mScriptContext->setExtensions (&mExtensions);
mEnvironment.setScriptManager (new MWScript::ScriptManager (MWBase::Environment::get().getWorld()->getStore(),
mEnvironment.setScriptManager (new MWScript::ScriptManager (mEnvironment.getWorld()->getStore(),
mVerboseScripts, *mScriptContext, mWarningsMode,
mScriptBlacklistUse ? mScriptBlacklist : std::vector<std::string>()));
@ -543,7 +543,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
// scripts
if (mCompileAll)
{
std::pair<int, int> result = MWBase::Environment::get().getScriptManager()->compileAll();
std::pair<int, int> result = mEnvironment.getScriptManager()->compileAll();
if (result.first)
std::cout
<< "compiled " << result.second << " of " << result.first << " scripts ("
@ -648,38 +648,38 @@ void OMW::Engine::go()
if (!mSaveGameFile.empty())
{
MWBase::Environment::get().getStateManager()->loadGame(mSaveGameFile);
mEnvironment.getStateManager()->loadGame(mSaveGameFile);
}
else if (!mSkipMenu)
{
// start in main menu
MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
mEnvironment.getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
try
{
// Is there an ini setting for this filename or something?
MWBase::Environment::get().getSoundManager()->streamMusic("Special/morrowind title.mp3");
mEnvironment.getSoundManager()->streamMusic("Special/morrowind title.mp3");
std::string logo = mFallbackMap["Movies_Morrowind_Logo"];
if (!logo.empty())
MWBase::Environment::get().getWindowManager()->playVideo(logo, true);
mEnvironment.getWindowManager()->playVideo(logo, true);
}
catch (...) {}
}
else
{
MWBase::Environment::get().getStateManager()->newGame (!mNewGame);
mEnvironment.getStateManager()->newGame (!mNewGame);
}
// Start the main rendering loop
osg::Timer frameTimer;
double simulationTime = 0.0;
while (!mViewer->done() && !MWBase::Environment::get().getStateManager()->hasQuitRequest())
while (!mViewer->done() && !mEnvironment.getStateManager()->hasQuitRequest())
{
double dt = frameTimer.time_s();
frameTimer.setStartTick();
dt = std::min(dt, 0.2);
bool guiActive = MWBase::Environment::get().getWindowManager()->isGuiMode();
bool guiActive = mEnvironment.getWindowManager()->isGuiMode();
if (!guiActive)
simulationTime += dt;
@ -700,15 +700,15 @@ void OMW::Engine::go()
void OMW::Engine::activate()
{
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
if (mEnvironment.getWindowManager()->isGuiMode())
return;
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr();
if (player.getClass().getCreatureStats(player).getMagicEffects().get(ESM::MagicEffect::Paralyze).getMagnitude() > 0
|| player.getClass().getCreatureStats(player).getKnockedDown())
return;
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getFacedObject();
MWWorld::Ptr ptr = mEnvironment.getWorld()->getFacedObject();
if (ptr.isEmpty())
return;
@ -724,7 +724,7 @@ void OMW::Engine::activate()
return;
}
MWBase::Environment::get().getWorld()->activate(ptr, MWBase::Environment::get().getWorld()->getPlayerPtr());
mEnvironment.getWorld()->activate(ptr, mEnvironment.getWorld()->getPlayerPtr());
}
void OMW::Engine::screenshot()

@ -1367,7 +1367,7 @@ namespace MWMechanics
// Doesn't handle possible edge case where no one reported the assault, but in such a case,
// for bystanders it is not possible to tell who attacked first, anyway.
if (victimStats.getCrimeId() != -1)
MWBase::Environment::get().getMechanicsManager()->commitCrime(attacker, victim, MWBase::MechanicsManager::OT_Murder);
commitCrime(attacker, victim, MWBase::MechanicsManager::OT_Murder);
}

@ -1421,7 +1421,7 @@ namespace MWWorld
if (ptr.getClass().isActor())
{
// Collided with actor, ask actor to try to avoid door
if(ptr != MWBase::Environment::get().getWorld()->getPlayerPtr() ) {
if(ptr != getPlayerPtr() ) {
MWMechanics::AiSequence& seq = ptr.getClass().getCreatureStats(ptr).getAiSequence();
if(seq.getTypeId() != MWMechanics::AiPackage::TypeIdAvoidDoor) //Only add it once
seq.stack(MWMechanics::AiAvoidDoor(it->first),ptr);
@ -1738,7 +1738,7 @@ namespace MWWorld
else
{
cellid.mPaged = true;
MWBase::Environment::get().getWorld()->positionToIndex(
positionToIndex(
ref.mRef.getDoorDest().pos[0],
ref.mRef.getDoorDest().pos[1],
cellid.mIndex.mX,
@ -2516,7 +2516,7 @@ namespace MWWorld
if (reported)
{
npcStats.setBounty(npcStats.getBounty()+
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("iWereWolfBounty")->getInt());
mStore.get<ESM::GameSetting>().find("iWereWolfBounty")->getInt());
windowManager->messageBox("#{sCrimeMessage}");
}
}

Loading…
Cancel
Save