globals script cleanup; fixed potential case folding bug

actorid
Marc Zinnschlag 11 years ago
parent fc37c77a91
commit 74793c1c2f

@ -35,8 +35,6 @@ namespace MWBase
virtual ~ScriptManager() {} virtual ~ScriptManager() {}
virtual void resetGlobalScripts() = 0;
virtual void run (const std::string& name, Interpreter::Context& interpreterContext) = 0; virtual void run (const std::string& name, Interpreter::Context& interpreterContext) = 0;
///< Run the script with the given name (compile first, if not compiled yet) ///< Run the script with the given name (compile first, if not compiled yet)

@ -3,6 +3,8 @@
#include <cassert> #include <cassert>
#include <components/misc/stringops.hpp>
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
@ -15,25 +17,12 @@ namespace MWScript
GlobalScripts::GlobalScripts (const MWWorld::ESMStore& store) GlobalScripts::GlobalScripts (const MWWorld::ESMStore& store)
: mStore (store) : mStore (store)
{ {
reset(); addStartup();
}
void GlobalScripts::reset()
{
mScripts.clear();
addScript ("Main");
MWWorld::Store<ESM::StartScript>::iterator iter =
mStore.get<ESM::StartScript>().begin();
for (; iter != mStore.get<ESM::StartScript>().end(); ++iter) {
addScript (iter->mScript);
}
} }
void GlobalScripts::addScript (const std::string& name) void GlobalScripts::addScript (const std::string& name)
{ {
if (mScripts.find (name)==mScripts.end()) if (mScripts.find (Misc::StringUtils::lowerCase (name))==mScripts.end())
if (const ESM::Script *script = mStore.get<ESM::Script>().find (name)) if (const ESM::Script *script = mStore.get<ESM::Script>().find (name))
{ {
Locals locals; Locals locals;
@ -46,7 +35,8 @@ namespace MWScript
void GlobalScripts::removeScript (const std::string& name) void GlobalScripts::removeScript (const std::string& name)
{ {
std::map<std::string, std::pair<bool, Locals> >::iterator iter = mScripts.find (name); std::map<std::string, std::pair<bool, Locals> >::iterator iter =
mScripts.find (Misc::StringUtils::lowerCase (name));
if (iter!=mScripts.end()) if (iter!=mScripts.end())
iter->second.first = false; iter->second.first = false;
@ -55,7 +45,7 @@ namespace MWScript
bool GlobalScripts::isRunning (const std::string& name) const bool GlobalScripts::isRunning (const std::string& name) const
{ {
std::map<std::string, std::pair<bool, Locals> >::const_iterator iter = std::map<std::string, std::pair<bool, Locals> >::const_iterator iter =
mScripts.find (name); mScripts.find (Misc::StringUtils::lowerCase (name));
if (iter==mScripts.end()) if (iter==mScripts.end())
return false; return false;
@ -76,4 +66,21 @@ namespace MWScript
} }
} }
} }
void GlobalScripts::clear()
{
mScripts.clear();
}
void GlobalScripts::addStartup()
{
addScript ("main");
for (MWWorld::Store<ESM::StartScript>::iterator iter =
mStore.get<ESM::StartScript>().begin();
iter != mStore.get<ESM::StartScript>().end(); ++iter)
{
addScript (iter->mScript);
}
}
} }

@ -6,7 +6,7 @@
#include "locals.hpp" #include "locals.hpp"
namespace MWWorld namespace MWWorld
{ {
struct ESMStore; struct ESMStore;
} }
@ -22,8 +22,6 @@ namespace MWScript
GlobalScripts (const MWWorld::ESMStore& store); GlobalScripts (const MWWorld::ESMStore& store);
void reset();
void addScript (const std::string& name); void addScript (const std::string& name);
void removeScript (const std::string& name); void removeScript (const std::string& name);
@ -32,6 +30,11 @@ namespace MWScript
void run(); void run();
///< run all active global scripts ///< run all active global scripts
void clear();
void addStartup();
///< Add startup script
}; };
} }

@ -222,9 +222,4 @@ namespace MWScript
throw std::runtime_error ("unable to access local variable " + variable + " of " + scriptId); throw std::runtime_error ("unable to access local variable " + variable + " of " + scriptId);
} }
void ScriptManager::resetGlobalScripts()
{
mGlobalScripts.reset();
}
} }

@ -61,8 +61,6 @@ namespace MWScript
///< Compile script with the given namen ///< Compile script with the given namen
/// \return Success? /// \return Success?
virtual void resetGlobalScripts();
virtual std::pair<int, int> compileAll(); virtual std::pair<int, int> compileAll();
///< Compile all scripts ///< Compile all scripts
/// \return count, success /// \return count, success

@ -12,19 +12,24 @@
#include "../mwbase/dialoguemanager.hpp" #include "../mwbase/dialoguemanager.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/scriptmanager.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
#include "../mwscript/globalscripts.hpp"
void MWState::StateManager::cleanup() void MWState::StateManager::cleanup()
{ {
if (mState!=State_NoGame) if (mState!=State_NoGame)
{ {
MWBase::Environment::get().getDialogueManager()->clear(); MWBase::Environment::get().getDialogueManager()->clear();
MWBase::Environment::get().getJournal()->clear(); MWBase::Environment::get().getJournal()->clear();
MWBase::Environment::get().getScriptManager()->getGlobalScripts().clear();
MWBase::Environment::get().getWorld()->clear(); MWBase::Environment::get().getWorld()->clear();
mState = State_NoGame; mState = State_NoGame;
mCharacterManager.clearCurrentCharacter(); mCharacterManager.clearCurrentCharacter();
mTimePlayed = 0; mTimePlayed = 0;
@ -64,6 +69,8 @@ void MWState::StateManager::newGame (bool bypass)
else else
MWBase::Environment::get().getWorld()->setGlobalInt ("chargenstate", -1); MWBase::Environment::get().getWorld()->setGlobalInt ("chargenstate", -1);
MWBase::Environment::get().getScriptManager()->getGlobalScripts().addStartup();
mState = State_Running; mState = State_Running;
} }

@ -21,7 +21,6 @@
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/scriptmanager.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/movement.hpp" #include "../mwmechanics/movement.hpp"
@ -262,8 +261,6 @@ namespace MWWorld
delete mWeatherManager; delete mWeatherManager;
mWeatherManager = 0; mWeatherManager = 0;
mWeatherManager = new MWWorld::WeatherManager(mRendering,&mFallback); mWeatherManager = new MWWorld::WeatherManager(mRendering,&mFallback);
MWBase::Environment::get().getScriptManager()->resetGlobalScripts();
} }
void World::clear() void World::clear()

Loading…
Cancel
Save