Allow stepping through the time delta in multiple passes in snowballs

--HG--
branch : multipass-stereo
This commit is contained in:
kaetemi 2013-06-16 23:51:33 +02:00
parent c7a9edd495
commit 4a7f58938d
3 changed files with 28 additions and 7 deletions

View file

@ -42,6 +42,14 @@ static bool _SkipAnimationOnce;
static NLMISC::TTime _TimeMs; static NLMISC::TTime _TimeMs;
static CValueSmootherTemplate<float> _FpsSmoother; static CValueSmootherTemplate<float> _FpsSmoother;
namespace
{
NLMISC::TLocalTime a_LocalTimeDelta;
NL3D::TGlobalAnimationTime a_AnimationTimeDelta;
} /* anonymous namespace */
static void cbFpsSmoothing(CConfigFile::CVar &var) static void cbFpsSmoothing(CConfigFile::CVar &var)
{ {
_FpsSmoother.init((uint)var.asInt()); _FpsSmoother.init((uint)var.asInt());
@ -53,8 +61,10 @@ void CGameTime::init()
_TimeMs = NLMISC::CTime::getLocalTime(); _TimeMs = NLMISC::CTime::getLocalTime();
LocalTime = ((TLocalTime)_TimeMs) / 1000.0; LocalTime = ((TLocalTime)_TimeMs) / 1000.0;
LocalTimeDelta = 0.0; LocalTimeDelta = 0.0;
a_LocalTimeDelta = 0.0;
AnimationTime = 0.0; AnimationTime = 0.0;
AnimationTimeDelta = 0.f; AnimationTimeDelta = 0.f;
a_AnimationTimeDelta = 0.0;
FramesPerSecond = 0.f; FramesPerSecond = 0.f;
FramesPerSecondSmooth = 0.f; FramesPerSecondSmooth = 0.f;
CConfiguration::setAndCallback("FpsSmoothing", cbFpsSmoothing); CConfiguration::setAndCallback("FpsSmoothing", cbFpsSmoothing);
@ -78,26 +88,24 @@ void CGameTime::updateTime()
// average of previous fps and this fps should be ok // average of previous fps and this fps should be ok
FramesPerSecond *= 3; FramesPerSecond *= 3;
LocalTimeDelta = 0.f; a_LocalTimeDelta = 0.f;
AnimationTimeDelta = 0.f; a_AnimationTimeDelta = 0.f;
} }
else else
{ {
FramesPerSecond = 1000.0f / (float)deltams; FramesPerSecond = 1000.0f / (float)deltams;
TLocalTime localTime = ((TLocalTime)timems) / 1000.0; TLocalTime localTime = ((TLocalTime)timems) / 1000.0;
LocalTimeDelta = localTime - LocalTime; a_LocalTimeDelta = localTime - LocalTime;
LocalTime = localTime;
if (_SkipAnimationOnce) if (_SkipAnimationOnce)
{ {
AnimationTimeDelta = 0.f; a_AnimationTimeDelta = 0.f;
_SkipAnimationOnce = false; _SkipAnimationOnce = false;
} }
else else
{ {
AnimationTimeDelta = (TAnimationTime)LocalTimeDelta; a_AnimationTimeDelta = (TGlobalAnimationTime)a_LocalTimeDelta;
AnimationTime += (TGlobalAnimationTime)LocalTimeDelta;
} }
} }
@ -105,6 +113,15 @@ void CGameTime::updateTime()
FramesPerSecondSmooth = _FpsSmoother.getSmoothValue(); FramesPerSecondSmooth = _FpsSmoother.getSmoothValue();
} }
void CGameTime::advanceTime(double f)
{
LocalTimeDelta = a_LocalTimeDelta * f;
LocalTime += LocalTimeDelta;
TGlobalAnimationTime atd = a_AnimationTimeDelta * f;
AnimationTimeDelta = (NL3D::TAnimationTime)atd;
AnimationTime += atd;
}
void CGameTime::skipAnimationOnce() void CGameTime::skipAnimationOnce()
{ {
_SkipAnimationOnce = true; _SkipAnimationOnce = true;

View file

@ -40,6 +40,9 @@ public:
static void updateTime(); static void updateTime();
/// Advance time to target time by factor f.
static void advanceTime(double f);
/// Used when loading, this will skip changing animation time on the next update /// Used when loading, this will skip changing animation time on the next update
/// (updates aren't called during loading) /// (updates aren't called during loading)
static void skipAnimationOnce(); static void skipAnimationOnce();

View file

@ -679,6 +679,7 @@ void loopIngame()
// 02. Update Time (deltas) // 02. Update Time (deltas)
CGameTime::updateTime(); CGameTime::updateTime();
CGameTime::advanceTime(1.0);
// 03. Update Input (keyboard controls, etc) // 03. Update Input (keyboard controls, etc)
Driver->EventServer.pump(); // Pump user input messages Driver->EventServer.pump(); // Pump user input messages