mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-19 16:39:41 +00:00
implemented passing of time
This commit is contained in:
parent
083b11c740
commit
d27c548710
4 changed files with 71 additions and 4 deletions
|
@ -51,6 +51,9 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
|
|||
// global scripts
|
||||
mEnvironment.mGlobalScripts->run (mEnvironment);
|
||||
|
||||
// passing of time (30 times as fast as RL time)
|
||||
mEnvironment.mWorld->advanceTime ((mEnvironment.mFrameDuration*30)/3600);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -133,18 +133,32 @@ namespace MWScript
|
|||
|
||||
void InterpreterContext::setGlobalShort (const std::string& name, int value)
|
||||
{
|
||||
mEnvironment.mWorld->getGlobalVariable (name).mShort = value;
|
||||
if (name=="gamehour")
|
||||
mEnvironment.mWorld->setHour (value);
|
||||
else if (name=="day")
|
||||
mEnvironment.mWorld->setDay (value);
|
||||
else
|
||||
mEnvironment.mWorld->getGlobalVariable (name).mShort = value;
|
||||
}
|
||||
|
||||
void InterpreterContext::setGlobalLong (const std::string& name, int value)
|
||||
{
|
||||
// a global long is internally a float.
|
||||
mEnvironment.mWorld->getGlobalVariable (name).mLong = value;
|
||||
if (name=="gamehour")
|
||||
mEnvironment.mWorld->setHour (value);
|
||||
else if (name=="day")
|
||||
mEnvironment.mWorld->setDay (value);
|
||||
else
|
||||
mEnvironment.mWorld->getGlobalVariable (name).mLong = value;
|
||||
}
|
||||
|
||||
void InterpreterContext::setGlobalFloat (const std::string& name, float value)
|
||||
{
|
||||
mEnvironment.mWorld->getGlobalVariable (name).mFloat = value;
|
||||
if (name=="gamehour")
|
||||
mEnvironment.mWorld->setHour (value);
|
||||
else if (name=="day")
|
||||
mEnvironment.mWorld->setDay (value);
|
||||
else
|
||||
mEnvironment.mWorld->getGlobalVariable (name).mFloat = value;
|
||||
}
|
||||
|
||||
bool InterpreterContext::isScriptRunning (const std::string& name) const
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include "world.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
#include "components/bsa/bsa_archive.hpp"
|
||||
|
@ -278,4 +279,47 @@ namespace MWWorld
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void World::advanceTime (double hours)
|
||||
{
|
||||
hours += mGlobalVariables->getFloat ("gamehour");
|
||||
setHour (hours);
|
||||
}
|
||||
|
||||
void World::setHour (double hour)
|
||||
{
|
||||
if (hour<0)
|
||||
hour = 0;
|
||||
|
||||
int days = hour / 24;
|
||||
|
||||
hour = std::fmod (hour, 24);
|
||||
|
||||
mGlobalVariables->setFloat ("gamehour", hour);
|
||||
|
||||
if (days>0)
|
||||
{
|
||||
setDay (days + mGlobalVariables->getInt ("year"));
|
||||
|
||||
days += mGlobalVariables->getInt ("dayspassed");
|
||||
mGlobalVariables->setInt ("dayspassed", days);
|
||||
}
|
||||
}
|
||||
|
||||
void World::setDay (int day)
|
||||
{
|
||||
if (day<0)
|
||||
day = 0;
|
||||
|
||||
int year = day / 365;
|
||||
day = day % 365;
|
||||
|
||||
mGlobalVariables->setInt ("day", day);
|
||||
|
||||
if (year>0)
|
||||
{
|
||||
year += mGlobalVariables->getInt ("year");
|
||||
mGlobalVariables->setInt ("year", year);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,6 +88,12 @@ namespace MWWorld
|
|||
void enable (Ptr reference);
|
||||
|
||||
void disable (Ptr reference);
|
||||
|
||||
void advanceTime (double hours);
|
||||
|
||||
void setHour (double hour);
|
||||
|
||||
void setDay (int day);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue