changed interface for global variable access

This commit is contained in:
Marc Zinnschlag 2013-11-28 09:10:38 +01:00
parent 99ea63dc4a
commit 71436b1160
8 changed files with 72 additions and 27 deletions

View file

@ -140,9 +140,17 @@ namespace MWBase
virtual bool isPositionExplored (float nX, float nY, int x, int y, bool interior) = 0; virtual bool isPositionExplored (float nX, float nY, int x, int y, bool interior) = 0;
///< see MWRender::LocalMap::isPositionExplored ///< see MWRender::LocalMap::isPositionExplored
virtual MWWorld::Globals::Data& getGlobalVariable (const std::string& name) = 0; virtual void setGlobalInt (const std::string& name, int value) = 0;
///< Set value independently from real type.
virtual MWWorld::Globals::Data getGlobalVariable (const std::string& name) const = 0; virtual void setGlobalFloat (const std::string& name, float value) = 0;
///< Set value independently from real type.
virtual int getGlobalInt (const std::string& name) const = 0;
///< Get value independently from real type.
virtual float getGlobalFloat (const std::string& name) const = 0;
///< Get value independently from real type.
virtual char getGlobalVariableType (const std::string& name) const = 0; virtual char getGlobalVariableType (const std::string& name) const = 0;
///< Return ' ', if there is no global variable with this name. ///< Return ' ', if there is no global variable with this name.

View file

@ -170,7 +170,7 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c
// internally all globals are float :( // internally all globals are float :(
return select.selectCompare ( return select.selectCompare (
MWBase::Environment::get().getWorld()->getGlobalVariable (select.getName()).mFloat); MWBase::Environment::get().getWorld()->getGlobalFloat (select.getName()));
case SelectWrapper::Function_Local: case SelectWrapper::Function_Local:
{ {

View file

@ -60,9 +60,9 @@ namespace MWDialogue
StampedJournalEntry StampedJournalEntry::makeFromQuest (const std::string& topic, int index) StampedJournalEntry StampedJournalEntry::makeFromQuest (const std::string& topic, int index)
{ {
int day = MWBase::Environment::get().getWorld()->getGlobalVariable ("dayspassed").mLong; int day = MWBase::Environment::get().getWorld()->getGlobalInt ("dayspassed");
int month = MWBase::Environment::get().getWorld()->getGlobalVariable ("month").mLong; int month = MWBase::Environment::get().getWorld()->getGlobalInt ("month");
int dayOfMonth = MWBase::Environment::get().getWorld()->getGlobalVariable ("day").mLong; int dayOfMonth = MWBase::Environment::get().getWorld()->getGlobalInt ("day");
return StampedJournalEntry (topic, idFromIndex (topic, index), day, month, dayOfMonth); return StampedJournalEntry (topic, idFromIndex (topic, index), day, month, dayOfMonth);
} }

View file

@ -1238,7 +1238,7 @@ namespace MWGui
bool WindowManager::getRestEnabled() bool WindowManager::getRestEnabled()
{ {
//Enable rest dialogue if character creation finished //Enable rest dialogue if character creation finished
if(mRestAllowed==false && MWBase::Environment::get().getWorld()->getGlobalVariable ("chargenstate").mFloat==-1) if(mRestAllowed==false && MWBase::Environment::get().getWorld()->getGlobalFloat ("chargenstate")==-1)
mRestAllowed=true; mRestAllowed=true;
return mRestAllowed; return mRestAllowed;
} }

View file

@ -127,18 +127,18 @@ namespace MWScript
int InterpreterContext::getGlobalShort (const std::string& name) const int InterpreterContext::getGlobalShort (const std::string& name) const
{ {
return MWBase::Environment::get().getWorld()->getGlobalVariable (name).mShort; return MWBase::Environment::get().getWorld()->getGlobalInt (name);
} }
int InterpreterContext::getGlobalLong (const std::string& name) const int InterpreterContext::getGlobalLong (const std::string& name) const
{ {
// a global long is internally a float. // a global long is internally a float.
return MWBase::Environment::get().getWorld()->getGlobalVariable (name).mLong; return MWBase::Environment::get().getWorld()->getGlobalInt (name);
} }
float InterpreterContext::getGlobalFloat (const std::string& name) const float InterpreterContext::getGlobalFloat (const std::string& name) const
{ {
return MWBase::Environment::get().getWorld()->getGlobalVariable (name).mFloat; return MWBase::Environment::get().getWorld()->getGlobalFloat (name);
} }
void InterpreterContext::setGlobalShort (const std::string& name, int value) void InterpreterContext::setGlobalShort (const std::string& name, int value)
@ -150,7 +150,7 @@ namespace MWScript
else if (name=="month") else if (name=="month")
MWBase::Environment::get().getWorld()->setMonth (value); MWBase::Environment::get().getWorld()->setMonth (value);
else else
MWBase::Environment::get().getWorld()->getGlobalVariable (name).mShort = value; MWBase::Environment::get().getWorld()->setGlobalInt (name, value);
} }
void InterpreterContext::setGlobalLong (const std::string& name, int value) void InterpreterContext::setGlobalLong (const std::string& name, int value)
@ -162,7 +162,7 @@ namespace MWScript
else if (name=="month") else if (name=="month")
MWBase::Environment::get().getWorld()->setMonth (value); MWBase::Environment::get().getWorld()->setMonth (value);
else else
MWBase::Environment::get().getWorld()->getGlobalVariable (name).mLong = value; MWBase::Environment::get().getWorld()->setGlobalInt (name, value);
} }
void InterpreterContext::setGlobalFloat (const std::string& name, float value) void InterpreterContext::setGlobalFloat (const std::string& name, float value)
@ -174,7 +174,7 @@ namespace MWScript
else if (name=="month") else if (name=="month")
MWBase::Environment::get().getWorld()->setMonth (value); MWBase::Environment::get().getWorld()->setMonth (value);
else else
MWBase::Environment::get().getWorld()->getGlobalVariable (name).mFloat = value; MWBase::Environment::get().getWorld()->setGlobalFloat (name, value);
} }
std::vector<std::string> InterpreterContext::getGlobals () const std::vector<std::string> InterpreterContext::getGlobals () const

View file

@ -657,6 +657,8 @@ namespace MWScript
void printGlobalVars(Interpreter::Runtime &runtime) void printGlobalVars(Interpreter::Runtime &runtime)
{ {
Interpreter::Context& context = runtime.getContext();
std::stringstream str; std::stringstream str;
str<< "Global variables:"; str<< "Global variables:";
@ -665,15 +667,32 @@ namespace MWScript
for(size_t i = 0;i < names.size();++i) for(size_t i = 0;i < names.size();++i)
{ {
char type = world->getGlobalVariableType (names[i]); char type = world->getGlobalVariableType (names[i]);
if(type == 's') str << std::endl << " " << names[i] << " = ";
str<<std::endl<< " "<<names[i]<<" = "<<world->getGlobalVariable(names[i]).mShort<<" (short)";
else if(type == 'l') switch (type)
str<<std::endl<< " "<<names[i]<<" = "<<world->getGlobalVariable(names[i]).mLong<<" (long)"; {
else if(type == 'f') case 's':
str<<std::endl<< " "<<names[i]<<" = "<<world->getGlobalVariable(names[i]).mFloat<<" (float)";
str << context.getGlobalShort (names[i]) << " (short)";
break;
case 'l':
str << context.getGlobalLong (names[i]) << " (long)";
break;
case 'f':
str << context.getGlobalFloat (names[i]) << " (float)";
break;
default:
str << "<unknown type>";
}
} }
runtime.getContext().report(str.str()); context.report (str.str());
} }
public: public:

View file

@ -422,14 +422,24 @@ namespace MWWorld
return mWorldScene->hasCellChanged(); return mWorldScene->hasCellChanged();
} }
Globals::Data& World::getGlobalVariable (const std::string& name) void World::setGlobalInt (const std::string& name, int value)
{ {
return (*mGlobalVariables)[name]; mGlobalVariables->setInt (name, value);
} }
Globals::Data World::getGlobalVariable (const std::string& name) const void World::setGlobalFloat (const std::string& name, float value)
{ {
return (*mGlobalVariables)[name]; mGlobalVariables->setFloat (name, value);
}
int World::getGlobalInt (const std::string& name) const
{
return mGlobalVariables->getInt (name);
}
float World::getGlobalFloat (const std::string& name) const
{
return mGlobalVariables->getFloat (name);
} }
char World::getGlobalVariableType (const std::string& name) const char World::getGlobalVariableType (const std::string& name) const

View file

@ -204,9 +204,17 @@ namespace MWWorld
virtual bool isPositionExplored (float nX, float nY, int x, int y, bool interior); virtual bool isPositionExplored (float nX, float nY, int x, int y, bool interior);
///< see MWRender::LocalMap::isPositionExplored ///< see MWRender::LocalMap::isPositionExplored
virtual Globals::Data& getGlobalVariable (const std::string& name); virtual void setGlobalInt (const std::string& name, int value);
///< Set value independently from real type.
virtual Globals::Data getGlobalVariable (const std::string& name) const; virtual void setGlobalFloat (const std::string& name, float value);
///< Set value independently from real type.
virtual int getGlobalInt (const std::string& name) const;
///< Get value independently from real type.
virtual float getGlobalFloat (const std::string& name) const;
///< Get value independently from real type.
virtual char getGlobalVariableType (const std::string& name) const; virtual char getGlobalVariableType (const std::string& name) const;
///< Return ' ', if there is no global variable with this name. ///< Return ' ', if there is no global variable with this name.