Fix rounding error in _RyzomDay and _RyzomTime calculation

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

View file

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

View file

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

View file

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

View file

@ -83,4 +83,19 @@ namespace WEEKDAY
}; // 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; _RyzomDay = 0;
_RyzomTime = 0.f; _RyzomTime = 0.f;
_LocalTime = 0.0;
_TickOffset = 0; _TickOffset = 0;
} }
// Update ryzom clock when tick occurs, local time must be given if localUpdateRyzomClock() and getLocalRyzomTime() is used // Update ryzom clock when tick occurs, local time must be given if localUpdateRyzomClock() and getLocalRyzomTime() is used
void updateRyzomClock( uint32 gameCyle, double localTime = 0 ) void updateRyzomClock(uint32 gameCyle);
{
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;
}
// get ryzom time (synchronized with server) // get ryzom time (synchronized with server)
inline float getRyzomTime() const { return _RyzomTime; } inline float getRyzomTime() const { return _RyzomTime; }
@ -202,7 +195,6 @@ private:
uint32 _RyzomDay; uint32 _RyzomDay;
float _RyzomTime; float _RyzomTime;
double _LocalTime;
uint32 _TickOffset; uint32 _TickOffset;
}; };