1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-28 14:53:58 +00:00

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

This commit is contained in:
Jordan Ayers 2015-08-16 16:56:44 -05:00
parent 5558962b14
commit be7bd9529d
3 changed files with 41 additions and 41 deletions

View File

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

View File

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

View File

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