summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/World.cpp59
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;