summaryrefslogtreecommitdiffstats
path: root/src/MapManager.cpp
diff options
context:
space:
mode:
authormjagdis <mjagdis@eris-associates.co.uk>2024-11-01 23:19:34 +0100
committerGitHub <noreply@github.com>2024-11-01 23:19:34 +0100
commit4e3b272af7398df4f9313dda763930658d278aa0 (patch)
tree0612172aa6410c830fde2f52fc7121518c28eecd /src/MapManager.cpp
parentConvert double to ints with floor rather than truncating (#5572) (diff)
downloadcuberite-4e3b272af7398df4f9313dda763930658d278aa0.tar
cuberite-4e3b272af7398df4f9313dda763930658d278aa0.tar.gz
cuberite-4e3b272af7398df4f9313dda763930658d278aa0.tar.bz2
cuberite-4e3b272af7398df4f9313dda763930658d278aa0.tar.lz
cuberite-4e3b272af7398df4f9313dda763930658d278aa0.tar.xz
cuberite-4e3b272af7398df4f9313dda763930658d278aa0.tar.zst
cuberite-4e3b272af7398df4f9313dda763930658d278aa0.zip
Diffstat (limited to 'src/MapManager.cpp')
-rw-r--r--src/MapManager.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/MapManager.cpp b/src/MapManager.cpp
index ae020d800..f7b393648 100644
--- a/src/MapManager.cpp
+++ b/src/MapManager.cpp
@@ -12,8 +12,16 @@
-cMapManager::cMapManager(cWorld * a_World)
- : m_World(a_World)
+// 6000 ticks or 5 minutes
+#define MAP_DATA_SAVE_INTERVAL 6000
+
+
+
+
+
+cMapManager::cMapManager(cWorld * a_World) :
+ m_World(a_World),
+ m_TicksUntilNextSave(MAP_DATA_SAVE_INTERVAL)
{
ASSERT(m_World != nullptr);
}
@@ -49,6 +57,16 @@ void cMapManager::TickMaps()
{
Map.Tick();
}
+
+ if (m_TicksUntilNextSave == 0)
+ {
+ m_TicksUntilNextSave = MAP_DATA_SAVE_INTERVAL;
+ SaveMapData();
+ }
+ else
+ {
+ m_TicksUntilNextSave--;
+ }
}
@@ -149,11 +167,18 @@ void cMapManager::SaveMapData(void)
{
cMap & Map = *it;
- cMapSerializer Serializer(m_World->GetDataPath(), &Map);
-
- if (!Serializer.Save())
+ if (Map.m_Dirty)
{
- LOGWARN("Could not save map #%i", Map.GetID());
+ cMapSerializer Serializer(m_World->GetDataPath(), &Map);
+
+ if (Serializer.Save())
+ {
+ Map.m_Dirty = false;
+ }
+ else
+ {
+ LOGWARN("Could not save map #%i", Map.GetID());
+ }
}
}
}