summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-09-05 15:05:54 +0200
committerMattes D <github@xoft.cz>2016-09-05 15:05:54 +0200
commitf7029eddd4120f672c59a4b3a4395832f4de8863 (patch)
tree81c93ca7c5c03ebdde2401e86dd8c02665710384 /src/World.cpp
parentPluginLua: Removed unneeded assignment. (diff)
parentConfigurable dirty unused chunk cap to avoid RAM overuse (#3359) (diff)
downloadcuberite-f7029eddd4120f672c59a4b3a4395832f4de8863.tar
cuberite-f7029eddd4120f672c59a4b3a4395832f4de8863.tar.gz
cuberite-f7029eddd4120f672c59a4b3a4395832f4de8863.tar.bz2
cuberite-f7029eddd4120f672c59a4b3a4395832f4de8863.tar.lz
cuberite-f7029eddd4120f672c59a4b3a4395832f4de8863.tar.xz
cuberite-f7029eddd4120f672c59a4b3a4395832f4de8863.tar.zst
cuberite-f7029eddd4120f672c59a4b3a4395832f4de8863.zip
Diffstat (limited to 'src/World.cpp')
-rw-r--r--src/World.cpp42
1 files changed, 32 insertions, 10 deletions
diff --git a/src/World.cpp b/src/World.cpp
index c10cb52e9..d47d0832a 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -149,7 +149,7 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin
m_WorldAge(0),
m_TimeOfDay(0),
m_LastTimeUpdate(0),
- m_LastUnload(0),
+ m_LastChunkCheck(0),
m_LastSave(0),
m_SkyDarkness(0),
m_GameMode(gmNotSet),
@@ -453,6 +453,13 @@ void cWorld::Start(void)
// The presence of a configuration value overrides everything
// If no configuration value is found, GetDimension() is written to file and the variable is written to again to ensure that cosmic rays haven't sneakily changed its value
m_Dimension = StringToDimension(IniFile.GetValueSet("General", "Dimension", DimensionToString(GetDimension())));
+ int UnusedDirtyChunksCap = IniFile.GetValueSetI("General", "UnusedChunkCap", 1000);
+ if (UnusedDirtyChunksCap < 0)
+ {
+ UnusedDirtyChunksCap *= -1;
+ IniFile.SetValueI("General", "UnusedChunkCap", UnusedDirtyChunksCap);
+ }
+ m_UnusedDirtyChunksCap = static_cast<size_t>(UnusedDirtyChunksCap);
m_BroadcastDeathMessages = IniFile.GetValueSetB("Broadcasting", "BroadcastDeathMessages", true);
m_BroadcastAchievementMessages = IniFile.GetValueSetB("Broadcasting", "BroadcastAchievementMessages", true);
@@ -1057,16 +1064,22 @@ void cWorld::Tick(std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_La
TickWeather(static_cast<float>(a_Dt.count()));
- if (m_WorldAge - m_LastSave > std::chrono::minutes(5)) // Save each 5 minutes
- {
- SaveAllChunks();
- }
-
- if (m_WorldAge - m_LastUnload > std::chrono::seconds(10)) // Unload every 10 seconds
+ if (m_WorldAge - m_LastChunkCheck > std::chrono::seconds(10))
{
+ // Unload every 10 seconds
UnloadUnusedChunks();
- }
+ if (m_WorldAge - m_LastSave > std::chrono::minutes(5))
+ {
+ // Save every 5 minutes
+ SaveAllChunks();
+ }
+ else if (GetNumUnusedDirtyChunks() > m_UnusedDirtyChunksCap)
+ {
+ // Save if we have too many dirty unused chunks
+ SaveAllChunks();
+ }
+ }
}
@@ -2964,7 +2977,7 @@ bool cWorld::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const
void cWorld::UnloadUnusedChunks(void)
{
- m_LastUnload = std::chrono::duration_cast<cTickTimeLong>(m_WorldAge);
+ m_LastChunkCheck = std::chrono::duration_cast<cTickTimeLong>(m_WorldAge);
m_ChunkMap->UnloadUnusedChunks();
}
@@ -3578,7 +3591,7 @@ unsigned int cWorld::GetNumPlayers(void)
-int cWorld::GetNumChunks(void) const
+size_t cWorld::GetNumChunks(void) const
{
return m_ChunkMap->GetNumChunks();
}
@@ -3587,6 +3600,15 @@ int cWorld::GetNumChunks(void) const
+size_t cWorld::GetNumUnusedDirtyChunks(void) const
+{
+ return m_ChunkMap->GetNumUnusedDirtyChunks();
+}
+
+
+
+
+
void cWorld::GetChunkStats(int & a_NumValid, int & a_NumDirty, int & a_NumInLightingQueue)
{
m_ChunkMap->GetChunkStats(a_NumValid, a_NumDirty);