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 void resetGlobalScripts() = 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)

@ -3,6 +3,8 @@
#include <cassert>
#include <components/misc/stringops.hpp>
#include "../mwworld/esmstore.hpp"
#include "../mwbase/environment.hpp"
@ -15,25 +17,12 @@ namespace MWScript
GlobalScripts::GlobalScripts (const MWWorld::ESMStore& store)
: mStore (store)
{
reset();
}
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);
}
addStartup();
}
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))
{
Locals locals;
@ -46,7 +35,8 @@ namespace MWScript
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())
iter->second.first = false;
@ -55,7 +45,7 @@ namespace MWScript
bool GlobalScripts::isRunning (const std::string& name) const
{
std::map<std::string, std::pair<bool, Locals> >::const_iterator iter =
mScripts.find (name);
mScripts.find (Misc::StringUtils::lowerCase (name));
if (iter==mScripts.end())
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"
namespace MWWorld
namespace MWWorld
{
struct ESMStore;
}
@ -22,8 +22,6 @@ namespace MWScript
GlobalScripts (const MWWorld::ESMStore& store);
void reset();
void addScript (const std::string& name);
void removeScript (const std::string& name);
@ -32,6 +30,11 @@ namespace MWScript
void run();
///< 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);
}
void ScriptManager::resetGlobalScripts()
{
mGlobalScripts.reset();
}
}

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

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

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

Loading…
Cancel
Save