mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-30 04:40:53 +00:00
Fix rounding error in _RyzomDay and _RyzomTime calculation
This commit is contained in:
parent
d9e4367716
commit
c576897390
5 changed files with 24 additions and 17 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue