summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/World.cpp')
-rw-r--r--src/World.cpp49
1 files changed, 32 insertions, 17 deletions
diff --git a/src/World.cpp b/src/World.cpp
index d2213d1e5..ab46e886c 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -243,6 +243,7 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin
#endif
m_Dimension(a_Dimension),
m_IsSpawnExplicitlySet(false),
+ m_CycleDaylight(true),
m_WorldAgeSecs(0),
m_TimeOfDaySecs(0),
m_WorldAge(0),
@@ -827,28 +828,32 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec)
{
SetChunkData(**itr);
} // for itr - SetChunkDataQueue[]
-
- // We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it
+
m_WorldAgeSecs += (double)a_Dt / 1000.0;
- m_TimeOfDaySecs += (double)a_Dt / 1000.0;
+ m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0);
- // Wrap time of day each 20 minutes (1200 seconds)
- if (m_TimeOfDaySecs > 1200.0)
+ if (m_CycleDaylight)
{
- m_TimeOfDaySecs -= 1200.0;
- }
+ // We need sub-tick precision here, that's why we store the time in seconds and calculate ticks off of it
+ m_TimeOfDaySecs += (double)a_Dt / 1000.0;
- m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0);
- m_TimeOfDay = (Int64)(m_TimeOfDaySecs * 20.0);
+ // Wrap time of day each 20 minutes (1200 seconds)
+ if (m_TimeOfDaySecs > 1200.0)
+ {
+ m_TimeOfDaySecs -= 1200.0;
+ }
- // Updates the sky darkness based on current time of day
- UpdateSkyDarkness();
+ m_TimeOfDay = (Int64)(m_TimeOfDaySecs * 20.0);
- // Broadcast time update every 40 ticks (2 seconds)
- if (m_LastTimeUpdate < m_WorldAge - 40)
- {
- BroadcastTimeUpdate();
- m_LastTimeUpdate = m_WorldAge;
+ // Updates the sky darkness based on current time of day
+ UpdateSkyDarkness();
+
+ // Broadcast time update every 40 ticks (2 seconds)
+ if (m_LastTimeUpdate < m_WorldAge - 40)
+ {
+ BroadcastTimeUpdate();
+ m_LastTimeUpdate = m_WorldAge;
+ }
}
// Add entities waiting in the queue to be added:
@@ -2243,6 +2248,16 @@ void cWorld::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, cons
void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
{
+ int TimeOfDay = m_TimeOfDay;
+ if (!m_CycleDaylight)
+ {
+ TimeOfDay *= -1;
+ if (TimeOfDay == 0)
+ {
+ TimeOfDay = -1;
+ }
+ }
+
cCSLock Lock(m_CSPlayers);
for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
{
@@ -2251,7 +2266,7 @@ void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude)
{
continue;
}
- ch->SendTimeUpdate(m_WorldAge, m_TimeOfDay);
+ ch->SendTimeUpdate(m_WorldAge, TimeOfDay);
}
}