From 619a111a117a753fa1f02e61845774fe9713114a Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 23 Feb 2019 22:39:13 +0300 Subject: [PATCH] Run startup script once at engine start when game is running (bug #4877) --- CHANGELOG.md | 1 + apps/openmw/engine.cpp | 7 ++++++- apps/openmw/mwworld/worldimp.cpp | 9 +++------ apps/openmw/mwworld/worldimp.hpp | 4 +--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fac0b4ac0..da3b2b0cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Bug #4837: CTD when a mesh with NiLODNode root node with particles is loaded Bug #4860: Actors outside of processing range visible for one frame after spawning Bug #4876: AI ratings handling inconsistencies + Bug #4877: Startup script executes only on a new game start Bug #4888: Global variable stray explicit reference calls break script compilation Feature #2229: Improve pathfinding AI Feature #3442: Default values for fallbacks from ini file diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 2a4145c98..a68bf4c36 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -546,7 +546,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings) // Create the world mEnvironment.setWorld( new MWWorld::World (mViewer, rootNode, mResourceSystem.get(), mWorkQueue.get(), mFileCollections, mContentFiles, mEncoder, mFallbackMap, - mActivationDistanceOverride, mCellName, mStartupScript, mResDir.string(), mCfgMgr.getUserDataPath().string())); + mActivationDistanceOverride, mCellName, mResDir.string(), mCfgMgr.getUserDataPath().string())); mEnvironment.getWorld()->setupPlayer(); input->setPlayer(&mEnvironment.getWorld()->getPlayer()); @@ -719,6 +719,11 @@ void OMW::Engine::go() mEnvironment.getStateManager()->newGame (!mNewGame); } + if (!mStartupScript.empty() && mEnvironment.getStateManager()->getState() == MWState::StateManager::State_Running) + { + mEnvironment.getWindowManager()->executeInConsole(mStartupScript); + } + // Start the main rendering loop osg::Timer frameTimer; double simulationTime = 0.0; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index e3658285d..1109c9865 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -157,12 +157,12 @@ namespace MWWorld const Files::Collections& fileCollections, const std::vector& contentFiles, ToUTF8::Utf8Encoder* encoder, const std::map& fallbackMap, - int activationDistanceOverride, const std::string& startCell, const std::string& startupScript, - const std::string& resourcePath, const std::string& userDataPath) + int activationDistanceOverride, const std::string& startCell, + const std::string& resourcePath, const std::string& userDataPath) : mResourceSystem(resourceSystem), mFallback(fallbackMap), mLocalScripts (mStore), mSky (true), mCells (mStore, mEsm), mGodMode(false), mScriptsEnabled(true), mContentFiles (contentFiles), mUserDataPath(userDataPath), - mActivationDistanceOverride (activationDistanceOverride), mStartupScript(startupScript), + mActivationDistanceOverride (activationDistanceOverride), mStartCell (startCell), mDistanceToFacedObject(-1), mTeleportEnabled(true), mLevitationEnabled(true), mGoToJail(false), mDaysInPrison(0), mPlayerTraveling(false), mPlayerInJail(false), mSpellPreloadTimer(0.f) @@ -307,9 +307,6 @@ namespace MWWorld if (!mPhysics->toggleCollisionMode()) mPhysics->toggleCollisionMode(); - if (!mStartupScript.empty()) - MWBase::Environment::get().getWindowManager()->executeInConsole(mStartupScript); - MWBase::Environment::get().getWindowManager()->updatePlayer(); } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 98e82bb86..88d77eed3 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -117,8 +117,6 @@ namespace MWWorld int mActivationDistanceOverride; - std::string mStartupScript; - std::map mDoorStates; ///< only holds doors that are currently moving. 1 = opening, 2 = closing @@ -198,7 +196,7 @@ namespace MWWorld const Files::Collections& fileCollections, const std::vector& contentFiles, ToUTF8::Utf8Encoder* encoder, const std::map& fallbackMap, - int activationDistanceOverride, const std::string& startCell, const std::string& startupScript, const std::string& resourcePath, const std::string& userDataPath); + int activationDistanceOverride, const std::string& startCell, const std::string& resourcePath, const std::string& userDataPath); virtual ~World();