From 90369deb5a870674ab02a26a93a71f06eafe9293 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 20 Mar 2021 20:58:19 +0000 Subject: Change TimeOfDay to WorldDate (#5160) * Change TimeOfDay to WorldDate * Do not wrap at 20 minutes, continue incrementing * Fixes #4737 * Fixes #5159 --- src/World.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 17 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index e0f0b6c1c..3be923fff 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -61,14 +61,6 @@ -const int TIME_SUNSET = 12000; -const int TIME_NIGHT_START = 13187; -const int TIME_NIGHT_END = 22812; -const int TIME_SUNRISE = 23999; -const int TIME_SPAWN_DIVISOR = 148; - - - namespace World @@ -167,7 +159,7 @@ cWorld::cWorld( m_BroadcastAchievementMessages(true), m_IsDaylightCycleEnabled(true), m_WorldAge(0), - m_TimeOfDay(0), + m_WorldDate(0), m_WorldTickAge(0), m_LastChunkCheck(0), m_LastSave(0), @@ -483,6 +475,39 @@ void cWorld::CastThunderbolt(Vector3i a_Block) +int cWorld::GetTimeOfDay(void) const +{ + using namespace std::chrono_literals; + + return std::chrono::duration_cast(m_WorldDate % 20min).count(); +} + + + + + +Int64 cWorld::GetWorldAge(void) const +{ + return std::chrono::duration_cast(m_WorldAge).count(); +} + + + + + +void cWorld::SetTimeOfDay(int a_TimeOfDay) +{ + using namespace std::chrono_literals; + + m_WorldDate = (m_WorldDate / 20min) * 20min + cTickTime(a_TimeOfDay); + UpdateSkyDarkness(); + BroadcastTimeUpdate(); +} + + + + + int cWorld::GetDefaultWeatherInterval(eWeather a_Weather) const { auto & Random = GetRandomProvider(); @@ -967,13 +992,7 @@ void cWorld::Tick(std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_La if (m_IsDaylightCycleEnabled) { - m_TimeOfDay += a_Dt; - - // Wrap time of day every 20 minutes (1200 seconds): - if (m_TimeOfDay > std::chrono::minutes(20)) - { - m_TimeOfDay -= std::chrono::minutes(20); - } + m_WorldDate += a_Dt; // Updates the sky darkness based on current time of day: UpdateSkyDarkness(); @@ -1267,7 +1286,13 @@ void cWorld::TickQueuedTasks(void) void cWorld::UpdateSkyDarkness(void) { - int TempTime = std::chrono::duration_cast(m_TimeOfDay).count(); + const int TIME_SUNSET = 12000; + const int TIME_NIGHT_START = 13187; + const int TIME_NIGHT_END = 22812; + const int TIME_SUNRISE = 23999; + const int TIME_SPAWN_DIVISOR = 148; + + const auto TempTime = GetTimeOfDay(); if (TempTime <= TIME_SUNSET) { m_SkyDarkness = 0; -- cgit v1.2.3