diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2021-03-20 21:58:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-20 21:58:19 +0100 |
commit | 90369deb5a870674ab02a26a93a71f06eafe9293 (patch) | |
tree | e37bb9272ea0265db7dce611120ed63381ca2626 /src/World.cpp | |
parent | Don't send ping updates one packet at a time (diff) | |
download | cuberite-90369deb5a870674ab02a26a93a71f06eafe9293.tar cuberite-90369deb5a870674ab02a26a93a71f06eafe9293.tar.gz cuberite-90369deb5a870674ab02a26a93a71f06eafe9293.tar.bz2 cuberite-90369deb5a870674ab02a26a93a71f06eafe9293.tar.lz cuberite-90369deb5a870674ab02a26a93a71f06eafe9293.tar.xz cuberite-90369deb5a870674ab02a26a93a71f06eafe9293.tar.zst cuberite-90369deb5a870674ab02a26a93a71f06eafe9293.zip |
Diffstat (limited to '')
-rw-r--r-- | src/World.cpp | 59 |
1 files changed, 42 insertions, 17 deletions
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<cTickTime>(m_WorldDate % 20min).count(); +} + + + + + +Int64 cWorld::GetWorldAge(void) const +{ + return std::chrono::duration_cast<cTickTimeLong>(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<cTickTime>(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; |