From 4271d719b68521f91770574b3064525512116670 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 7 Aug 2014 01:07:32 +0200 Subject: Added SetDoDaylightCycle() and IsDaylightCycleEnabled() to cWorld. I need this for a GameRule plugin. --- src/World.cpp | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index d2213d1e5..7ed8bc1e4 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_DoDaylightCycle(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_DoDaylightCycle) { - 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_DoDaylightCycle) + { + 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); } } -- cgit v1.2.3 From 32e1e9a5536f92d074d51cca207f21c372973629 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 8 Aug 2014 18:38:20 +0200 Subject: Renamed m_DoDaylightCycle to m_CycleDaylight. --- src/World.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index 7ed8bc1e4..ab46e886c 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -243,7 +243,7 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin #endif m_Dimension(a_Dimension), m_IsSpawnExplicitlySet(false), - m_DoDaylightCycle(true), + m_CycleDaylight(true), m_WorldAgeSecs(0), m_TimeOfDaySecs(0), m_WorldAge(0), @@ -832,7 +832,7 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec) m_WorldAgeSecs += (double)a_Dt / 1000.0; m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0); - if (m_DoDaylightCycle) + if (m_CycleDaylight) { // 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; @@ -2249,7 +2249,7 @@ 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_DoDaylightCycle) + if (!m_CycleDaylight) { TimeOfDay *= -1; if (TimeOfDay == 0) -- cgit v1.2.3 From cccc321384be18d4ac75e83abf3ce4d19a2a3d56 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 10 Aug 2014 16:46:03 +0200 Subject: Renamed functions. --- src/World.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index ab46e886c..dc1d9fedf 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -243,7 +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_IsDaylightCycleEnabled(true), m_WorldAgeSecs(0), m_TimeOfDaySecs(0), m_WorldAge(0), @@ -832,7 +832,7 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec) m_WorldAgeSecs += (double)a_Dt / 1000.0; m_WorldAge = (Int64)(m_WorldAgeSecs * 20.0); - if (m_CycleDaylight) + if (m_IsDaylightCycleEnabled) { // 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; @@ -2249,7 +2249,7 @@ 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) + if (!m_IsDaylightCycleEnabled) { TimeOfDay *= -1; if (TimeOfDay == 0) -- cgit v1.2.3 From f90078c09ff576d3f8af1554872c53afbdcd6fe0 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 10 Aug 2014 16:48:20 +0200 Subject: Added IsDaylightCycleEnabled saving. --- src/World.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index dc1d9fedf..0ae7f80a6 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -577,6 +577,7 @@ void cWorld::Start(void) m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true); m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true); m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true); + m_IsDaylightCycleEnabled = IniFile.GetValueSetB("General", "IsDaylightCycleEnabled", true); int GameMode = IniFile.GetValueSetI("General", "Gamemode", (int)m_GameMode); int Weather = IniFile.GetValueSetI("General", "Weather", (int)m_Weather); @@ -798,6 +799,7 @@ void cWorld::Stop(void) IniFile.SetValueI("Physics", "TNTShrapnelLevel", (int)m_TNTShrapnelLevel); IniFile.SetValueB("Mechanics", "CommandBlocksEnabled", m_bCommandBlocksEnabled); IniFile.SetValueB("Mechanics", "UseChatPrefixes", m_bUseChatPrefixes); + IniFile.SetValueB("General", "IsDaylightCycleEnabled", m_IsDaylightCycleEnabled); IniFile.SetValueI("General", "Weather", (int)m_Weather); IniFile.SetValueI("General", "TimeInTicks", m_TimeOfDay); IniFile.WriteFile(m_IniFileName); -- cgit v1.2.3 From 42bad0edec58f42e4072360c52870d3be9ced3c5 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 10 Aug 2014 20:06:03 +0200 Subject: Added a comment and simplified code. --- src/World.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index 0ae7f80a6..dcca0519e 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2253,11 +2253,8 @@ void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude) int TimeOfDay = m_TimeOfDay; if (!m_IsDaylightCycleEnabled) { - TimeOfDay *= -1; - if (TimeOfDay == 0) - { - TimeOfDay = -1; - } + // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration. + TimeOfDay = std::min(-TimeOfDay, -1); } cCSLock Lock(m_CSPlayers); -- cgit v1.2.3 From 47c928cab7d1ff73e50925bc7ef50586b6ec9821 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 11 Aug 2014 00:20:28 +0200 Subject: Exported daylight cycle flag to the protocol. --- src/World.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index dcca0519e..5298f3b03 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2250,13 +2250,6 @@ 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_IsDaylightCycleEnabled) - { - // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration. - TimeOfDay = std::min(-TimeOfDay, -1); - } - cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) { @@ -2265,7 +2258,7 @@ void cWorld::BroadcastTimeUpdate(const cClientHandle * a_Exclude) { continue; } - ch->SendTimeUpdate(m_WorldAge, TimeOfDay); + ch->SendTimeUpdate(m_WorldAge, m_TimeOfDay, m_IsDaylightCycleEnabled); } } -- cgit v1.2.3 From 008c1cdaf436dec2d7a4a925c6a600570594d6a2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 14 Aug 2014 01:03:30 +0200 Subject: CheckBasicStyle checks the src folder as well. --- src/World.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index 5298f3b03..b357b8a23 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -3327,7 +3327,7 @@ void cWorld::AddQueuedPlayers(void) cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = PlayersToAdd.begin(), end = PlayersToAdd.end(); itr != end; ++itr) { - ASSERT(std::find(m_Players.begin(), m_Players.end(), *itr) == m_Players.end()); // Is it already in the list? HOW? + ASSERT(std::find(m_Players.begin(), m_Players.end(), *itr) == m_Players.end()); // Is it already in the list? HOW? LOGD("Adding player %s to world \"%s\".", (*itr)->GetName().c_str(), m_WorldName.c_str()); m_Players.push_back(*itr); -- cgit v1.2.3 From b5ffe06f884221f98407910bdd30baf533d84970 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 19 Aug 2014 22:14:37 +0200 Subject: Code formatting fixes. --- src/World.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index b357b8a23..2027e215a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1,3 +1,4 @@ + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "BlockID.h" -- cgit v1.2.3 From 81d238e0805eb8bd5ae3e844129bd11d62e1e8fd Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 21 Aug 2014 21:53:25 +0200 Subject: Added cWorld initializers. --- src/World.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index 2027e215a..d7fa7e0d1 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -251,8 +251,38 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin m_TimeOfDay(0), m_LastTimeUpdate(0), m_SkyDarkness(0), + m_GameMode(gmNotSet), + m_bEnabledPVP(false), + m_IsDeepSnowEnabled(false), + m_ShouldLavaSpawnFire(true), + m_VillagersShouldHarvestCrops(true), + m_SimulatorManager(NULL), + m_SandSimulator(NULL), + m_WaterSimulator(NULL), + m_LavaSimulator(NULL), + m_FireSimulator(NULL), + m_RedstoneSimulator(NULL), + m_MaxPlayers(10), + m_ChunkMap(NULL), + m_bAnimals(true), m_Weather(eWeather_Sunny), m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :) + m_MaxCactusHeight(3), + m_MaxSugarcaneHeight(4), + m_IsCactusBonemealable(false), + m_IsCarrotsBonemealable(true), + m_IsCropsBonemealable(true), + m_IsGrassBonemealable(true), + m_IsMelonStemBonemealable(true), + m_IsMelonBonemealable(true), + m_IsPotatoesBonemealable(true), + m_IsPumpkinStemBonemealable(true), + m_IsPumpkinBonemealable(true), + m_IsSaplingBonemealable(true), + m_IsSugarcaneBonemealable(false), + m_bCommandBlocksEnabled(true), + m_bUseChatPrefixes(false), + m_TNTShrapnelLevel(slNone), m_Scoreboard(this), m_MapManager(this), m_GeneratorCallbacks(*this), -- cgit v1.2.3 From d2d63b8a055409d0d07c57fd69b27469fe1681ac Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 22 Aug 2014 10:35:51 +0200 Subject: World: Report chunk count for the spawn area. --- src/World.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index d7fa7e0d1..69d1217f1 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -437,7 +437,7 @@ void cWorld::InitializeSpawn(void) int ViewDist = IniFile.GetValueSetI("SpawnPosition", "PregenerateDistance", DefaultViewDist); IniFile.WriteFile(m_IniFileName); - LOG("Preparing spawn area in world \"%s\"...", m_WorldName.c_str()); + LOG("Preparing spawn area in world \"%s\", %d x %d chunks, total %d chunks...", m_WorldName.c_str(), ViewDist, ViewDist, ViewDist * ViewDist); for (int x = 0; x < ViewDist; x++) { for (int z = 0; z < ViewDist; z++) -- cgit v1.2.3