2012-05-29 13:31:11 +00:00
|
|
|
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
|
|
|
// Copyright (C) 2010 Winch Gate Property Limited
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include <nel/misc/types_nl.h>
|
|
|
|
#include "game_time.h"
|
|
|
|
|
|
|
|
// STL includes
|
|
|
|
|
|
|
|
// NeL includes
|
|
|
|
// #include <nel/misc/debug.h>
|
|
|
|
#include <nel/misc/value_smoother.h>
|
|
|
|
#include <nel/misc/config_file.h>
|
|
|
|
#include <nel/misc/time_nl.h>
|
|
|
|
|
|
|
|
// Project includes
|
|
|
|
#include "snowballs_client.h"
|
|
|
|
#include "configuration.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace NLMISC;
|
|
|
|
using namespace NL3D;
|
|
|
|
|
|
|
|
namespace SBCLIENT {
|
|
|
|
|
|
|
|
// impl note: at some point animation time can be linked to server as well
|
|
|
|
// see version of time.cpp in snowballs5 experimental code
|
|
|
|
|
|
|
|
static bool _SkipAnimationOnce;
|
|
|
|
static NLMISC::TTime _TimeMs;
|
|
|
|
static CValueSmootherTemplate<float> _FpsSmoother;
|
|
|
|
|
2013-06-16 21:51:33 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
NLMISC::TLocalTime a_LocalTimeDelta;
|
|
|
|
NL3D::TGlobalAnimationTime a_AnimationTimeDelta;
|
|
|
|
|
|
|
|
} /* anonymous namespace */
|
|
|
|
|
2012-05-29 13:31:11 +00:00
|
|
|
static void cbFpsSmoothing(CConfigFile::CVar &var)
|
|
|
|
{
|
|
|
|
_FpsSmoother.init((uint)var.asInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameTime::init()
|
|
|
|
{
|
|
|
|
_SkipAnimationOnce = true; // since we're loading ... ;)
|
|
|
|
_TimeMs = NLMISC::CTime::getLocalTime();
|
|
|
|
LocalTime = ((TLocalTime)_TimeMs) / 1000.0;
|
|
|
|
LocalTimeDelta = 0.0;
|
2013-06-16 21:51:33 +00:00
|
|
|
a_LocalTimeDelta = 0.0;
|
2012-05-29 13:31:11 +00:00
|
|
|
AnimationTime = 0.0;
|
|
|
|
AnimationTimeDelta = 0.f;
|
2013-06-16 21:51:33 +00:00
|
|
|
a_AnimationTimeDelta = 0.0;
|
2012-05-29 13:31:11 +00:00
|
|
|
FramesPerSecond = 0.f;
|
|
|
|
FramesPerSecondSmooth = 0.f;
|
|
|
|
CConfiguration::setAndCallback("FpsSmoothing", cbFpsSmoothing);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameTime::release()
|
|
|
|
{
|
|
|
|
// could also call init again here just for fun but nothing useful otherwise
|
|
|
|
CConfiguration::dropCallback("FpsSmoothing");
|
|
|
|
_FpsSmoother.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameTime::updateTime()
|
|
|
|
{
|
|
|
|
TTime timems = NLMISC::CTime::getLocalTime();
|
|
|
|
TTime deltams = timems - _TimeMs;
|
|
|
|
_TimeMs = timems;
|
|
|
|
|
|
|
|
if (!deltams) // time has not moved
|
|
|
|
{
|
|
|
|
// average of previous fps and this fps should be ok
|
|
|
|
FramesPerSecond *= 3;
|
|
|
|
|
2013-06-16 21:51:33 +00:00
|
|
|
a_LocalTimeDelta = 0.f;
|
|
|
|
a_AnimationTimeDelta = 0.f;
|
2012-05-29 13:31:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FramesPerSecond = 1000.0f / (float)deltams;
|
|
|
|
|
|
|
|
TLocalTime localTime = ((TLocalTime)timems) / 1000.0;
|
2013-06-16 21:51:33 +00:00
|
|
|
a_LocalTimeDelta = localTime - LocalTime;
|
2012-05-29 13:31:11 +00:00
|
|
|
|
|
|
|
if (_SkipAnimationOnce)
|
|
|
|
{
|
2013-06-16 21:51:33 +00:00
|
|
|
a_AnimationTimeDelta = 0.f;
|
2012-05-29 13:31:11 +00:00
|
|
|
_SkipAnimationOnce = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-16 21:51:33 +00:00
|
|
|
a_AnimationTimeDelta = (TGlobalAnimationTime)a_LocalTimeDelta;
|
2012-05-29 13:31:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_FpsSmoother.addValue(FramesPerSecond);
|
|
|
|
FramesPerSecondSmooth = _FpsSmoother.getSmoothValue();
|
|
|
|
}
|
|
|
|
|
2013-06-16 21:51:33 +00:00
|
|
|
void CGameTime::advanceTime(double f)
|
|
|
|
{
|
|
|
|
LocalTimeDelta = a_LocalTimeDelta * f;
|
|
|
|
LocalTime += LocalTimeDelta;
|
|
|
|
TGlobalAnimationTime atd = a_AnimationTimeDelta * f;
|
|
|
|
AnimationTimeDelta = (NL3D::TAnimationTime)atd;
|
|
|
|
AnimationTime += atd;
|
|
|
|
}
|
|
|
|
|
2012-05-29 13:31:11 +00:00
|
|
|
void CGameTime::skipAnimationOnce()
|
|
|
|
{
|
|
|
|
_SkipAnimationOnce = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace SBCLIENT */
|
|
|
|
|
|
|
|
/* end of file */
|