forked from mirror/openmw-tes3mp
changed interface for global variable access
This commit is contained in:
parent
99ea63dc4a
commit
71436b1160
8 changed files with 72 additions and 27 deletions
|
@ -140,9 +140,17 @@ namespace MWBase
|
|||
virtual bool isPositionExplored (float nX, float nY, int x, int y, bool interior) = 0;
|
||||
///< 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;
|
||||
///< Return ' ', if there is no global variable with this name.
|
||||
|
|
|
@ -170,7 +170,7 @@ bool MWDialogue::Filter::testSelectStructNumeric (const SelectWrapper& select) c
|
|||
|
||||
// internally all globals are float :(
|
||||
return select.selectCompare (
|
||||
MWBase::Environment::get().getWorld()->getGlobalVariable (select.getName()).mFloat);
|
||||
MWBase::Environment::get().getWorld()->getGlobalFloat (select.getName()));
|
||||
|
||||
case SelectWrapper::Function_Local:
|
||||
{
|
||||
|
|
|
@ -60,9 +60,9 @@ namespace MWDialogue
|
|||
|
||||
StampedJournalEntry StampedJournalEntry::makeFromQuest (const std::string& topic, int index)
|
||||
{
|
||||
int day = MWBase::Environment::get().getWorld()->getGlobalVariable ("dayspassed").mLong;
|
||||
int month = MWBase::Environment::get().getWorld()->getGlobalVariable ("month").mLong;
|
||||
int dayOfMonth = MWBase::Environment::get().getWorld()->getGlobalVariable ("day").mLong;
|
||||
int day = MWBase::Environment::get().getWorld()->getGlobalInt ("dayspassed");
|
||||
int month = MWBase::Environment::get().getWorld()->getGlobalInt ("month");
|
||||
int dayOfMonth = MWBase::Environment::get().getWorld()->getGlobalInt ("day");
|
||||
|
||||
return StampedJournalEntry (topic, idFromIndex (topic, index), day, month, dayOfMonth);
|
||||
}
|
||||
|
|
|
@ -1238,7 +1238,7 @@ namespace MWGui
|
|||
bool WindowManager::getRestEnabled()
|
||||
{
|
||||
//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;
|
||||
return mRestAllowed;
|
||||
}
|
||||
|
|
|
@ -127,18 +127,18 @@ namespace MWScript
|
|||
|
||||
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
|
||||
{
|
||||
// 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
|
||||
{
|
||||
return MWBase::Environment::get().getWorld()->getGlobalVariable (name).mFloat;
|
||||
return MWBase::Environment::get().getWorld()->getGlobalFloat (name);
|
||||
}
|
||||
|
||||
void InterpreterContext::setGlobalShort (const std::string& name, int value)
|
||||
|
@ -150,7 +150,7 @@ namespace MWScript
|
|||
else if (name=="month")
|
||||
MWBase::Environment::get().getWorld()->setMonth (value);
|
||||
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)
|
||||
|
@ -162,7 +162,7 @@ namespace MWScript
|
|||
else if (name=="month")
|
||||
MWBase::Environment::get().getWorld()->setMonth (value);
|
||||
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)
|
||||
|
@ -174,7 +174,7 @@ namespace MWScript
|
|||
else if (name=="month")
|
||||
MWBase::Environment::get().getWorld()->setMonth (value);
|
||||
else
|
||||
MWBase::Environment::get().getWorld()->getGlobalVariable (name).mFloat = value;
|
||||
MWBase::Environment::get().getWorld()->setGlobalFloat (name, value);
|
||||
}
|
||||
|
||||
std::vector<std::string> InterpreterContext::getGlobals () const
|
||||
|
|
|
@ -657,6 +657,8 @@ namespace MWScript
|
|||
|
||||
void printGlobalVars(Interpreter::Runtime &runtime)
|
||||
{
|
||||
Interpreter::Context& context = runtime.getContext();
|
||||
|
||||
std::stringstream str;
|
||||
str<< "Global variables:";
|
||||
|
||||
|
@ -664,16 +666,33 @@ namespace MWScript
|
|||
std::vector<std::string> names = world->getGlobals();
|
||||
for(size_t i = 0;i < names.size();++i)
|
||||
{
|
||||
char type = world->getGlobalVariableType(names[i]);
|
||||
if(type == 's')
|
||||
str<<std::endl<< " "<<names[i]<<" = "<<world->getGlobalVariable(names[i]).mShort<<" (short)";
|
||||
else if(type == 'l')
|
||||
str<<std::endl<< " "<<names[i]<<" = "<<world->getGlobalVariable(names[i]).mLong<<" (long)";
|
||||
else if(type == 'f')
|
||||
str<<std::endl<< " "<<names[i]<<" = "<<world->getGlobalVariable(names[i]).mFloat<<" (float)";
|
||||
char type = world->getGlobalVariableType (names[i]);
|
||||
str << std::endl << " " << names[i] << " = ";
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 's':
|
||||
|
||||
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:
|
||||
|
|
|
@ -422,14 +422,24 @@ namespace MWWorld
|
|||
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
|
||||
|
|
|
@ -204,9 +204,17 @@ namespace MWWorld
|
|||
virtual bool isPositionExplored (float nX, float nY, int x, int y, bool interior);
|
||||
///< 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;
|
||||
///< Return ' ', if there is no global variable with this name.
|
||||
|
|
Loading…
Reference in a new issue