From af0568e131fe7c2c358e4e3572c44c16c8273627 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Thu, 10 Mar 2016 12:08:48 +0100 Subject: [PATCH] Fix rounding error in _RyzomDay and _RyzomTime calculation --- code/ryzom/client/src/far_tp.cpp | 4 ++-- code/ryzom/client/src/init_main_loop.cpp | 4 ++-- code/ryzom/client/src/main_loop.cpp | 8 ++++---- .../time_weather_season/time_and_season.cpp | 15 +++++++++++++++ .../time_weather_season/time_and_season.h | 10 +--------- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/code/ryzom/client/src/far_tp.cpp b/code/ryzom/client/src/far_tp.cpp index a7a41c628..ba85862b6 100644 --- a/code/ryzom/client/src/far_tp.cpp +++ b/code/ryzom/client/src/far_tp.cpp @@ -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(); diff --git a/code/ryzom/client/src/init_main_loop.cpp b/code/ryzom/client/src/init_main_loop.cpp index dc9a907b7..15a674c2e 100644 --- a/code/ryzom/client/src/init_main_loop.cpp +++ b/code/ryzom/client/src/init_main_loop.cpp @@ -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(); diff --git a/code/ryzom/client/src/main_loop.cpp b/code/ryzom/client/src/main_loop.cpp index c0beba4c1..93842ec3f 100644 --- a/code/ryzom/client/src/main_loop.cpp +++ b/code/ryzom/client/src/main_loop.cpp @@ -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) { diff --git a/code/ryzom/common/src/game_share/time_weather_season/time_and_season.cpp b/code/ryzom/common/src/game_share/time_weather_season/time_and_season.cpp index a24c8a9dd..a71d71be4 100644 --- a/code/ryzom/common/src/game_share/time_weather_season/time_and_season.cpp +++ b/code/ryzom/common/src/game_share/time_weather_season/time_and_season.cpp @@ -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 */ diff --git a/code/ryzom/common/src/game_share/time_weather_season/time_and_season.h b/code/ryzom/common/src/game_share/time_weather_season/time_and_season.h index 92892fd85..62f144119 100644 --- a/code/ryzom/common/src/game_share/time_weather_season/time_and_season.h +++ b/code/ryzom/common/src/game_share/time_weather_season/time_and_season.h @@ -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; };