Fix rounding error in _RyzomDay and _RyzomTime calculation

This commit is contained in:
kaetemi 2016-03-10 12:08:48 +01:00
parent 97f6cfe760
commit af0568e131
5 changed files with 24 additions and 17 deletions

View file

@ -1212,10 +1212,10 @@ void CFarTP::sendReady()
else
{
// Set season
RT.updateRyzomClock(NetMngr.getCurrentServerTick(), ryzomGetLocalTime() * 0.001);
RT.updateRyzomClock(NetMngr.getCurrentServerTick());
DayNightCycleHour = (float)RT.getRyzomTime();
CurrSeason = RT.getRyzomSeason();
RT.updateRyzomClock(NetMngr.getCurrentServerTick(), ryzomGetLocalTime() * 0.001);
RT.updateRyzomClock(NetMngr.getCurrentServerTick());
DayNightCycleHour = (float)RT.getRyzomTime();
ManualSeasonValue = RT.getRyzomSeason();

View file

@ -797,10 +797,10 @@ void initMainLoop()
{
// setup good day / season before ig are added.
RT.updateRyzomClock(NetMngr.getCurrentServerTick(), ryzomGetLocalTime() * 0.001);
RT.updateRyzomClock(NetMngr.getCurrentServerTick());
updateDayNightCycleHour();
StartupSeason = CurrSeason = RT.getRyzomSeason();
RT.updateRyzomClock(NetMngr.getCurrentServerTick(), ryzomGetLocalTime() * 0.001);
RT.updateRyzomClock(NetMngr.getCurrentServerTick());
updateDayNightCycleHour();
ManualSeasonValue = RT.getRyzomSeason();

View file

@ -1340,7 +1340,7 @@ bool mainLoop()
if (!ClientCfg.Local)
{
if(NetMngr.getCurrentServerTick() > LastGameCycle)
RT.updateRyzomClock(NetMngr.getCurrentServerTick(), ryzomGetLocalTime() * 0.001);
RT.updateRyzomClock(NetMngr.getCurrentServerTick());
}
else if (ClientCfg.SimulateServerTick)
{
@ -1348,7 +1348,7 @@ bool mainLoop()
uint numTicks = (uint) floor(SimulatedServerDate * 10);
SimulatedServerTick += numTicks;
SimulatedServerDate = (float)((double)SimulatedServerDate - (double) numTicks * 0.1);
RT.updateRyzomClock((uint32)SimulatedServerTick, ryzomGetLocalTime() * 0.001);
RT.updateRyzomClock((uint32)SimulatedServerTick);
}
@ -2092,14 +2092,14 @@ bool mainLoop()
if (Actions.valide ("inc_hour"))
{
RT.increaseTickOffset( (uint32)(2000 * displayHourDelta) );
RT.updateRyzomClock(NetMngr.getCurrentServerTick(), ryzomGetLocalTime() * 0.001);
RT.updateRyzomClock(NetMngr.getCurrentServerTick());
}
// Ctrl-L decrease hour
if (Actions.valide ("dec_hour"))
{
RT.decreaseTickOffset( (uint32)(2000 * displayHourDelta) );
RT.updateRyzomClock(NetMngr.getCurrentServerTick(), ryzomGetLocalTime() * 0.001);
RT.updateRyzomClock(NetMngr.getCurrentServerTick());
CTimedFXManager::getInstance().setDate(CClientDate(RT.getRyzomDay(), (float) RT.getRyzomTime()));
if (IGCallbacks)
{

View file

@ -83,4 +83,19 @@ namespace WEEKDAY
}; // WEEKDAY
void CRyzomTime::updateRyzomClock(uint32 gameCyle)
{
static const uint32 ticksPerDay = (RYZOM_DAY_IN_HOUR * RYZOM_HOURS_IN_TICKS);
static const float ticksPerHour = (float)RYZOM_HOURS_IN_TICKS;
uint32 totalTicks = gameCyle + _TickOffset;
uint32 days = totalTicks / ticksPerDay;
uint32 dayCycle = totalTicks - (days * ticksPerDay);
days -= RYZOM_START_SPRING;
float hours = (float)dayCycle / ticksPerHour;
_RyzomDay = days;
_RyzomTime = hours;
}
/* end of file */

View file

@ -135,18 +135,11 @@ public:
{
_RyzomDay = 0;
_RyzomTime = 0.f;
_LocalTime = 0.0;
_TickOffset = 0;
}
// Update ryzom clock when tick occurs, local time must be given if localUpdateRyzomClock() and getLocalRyzomTime() is used
void updateRyzomClock( uint32 gameCyle, double localTime = 0 )
{
float hours = ( gameCyle + _TickOffset ) / float(RYZOM_HOURS_IN_TICKS);
_RyzomDay = ( (uint)hours / RYZOM_DAY_IN_HOUR ) - RYZOM_START_SPRING;
_RyzomTime = (float) fmod( hours, (float)RYZOM_DAY_IN_HOUR );
_LocalTime = localTime;
}
void updateRyzomClock(uint32 gameCyle);
// get ryzom time (synchronized with server)
inline float getRyzomTime() const { return _RyzomTime; }
@ -202,7 +195,6 @@ private:
uint32 _RyzomDay;
float _RyzomTime;
double _LocalTime;
uint32 _TickOffset;
};