From b12f4ef7d58cfe4d815feb2db1f88f223c7f2a61 Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Thu, 7 Sep 2017 07:41:16 -0500 Subject: Made world data paths adjustable, and added API to temporarily disable saving chunks to disk. (#3912) --- src/World.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index f610d4d2e..e2ac24e71 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -120,16 +120,18 @@ void cWorld::cTickThread::Execute(void) //////////////////////////////////////////////////////////////////////////////// // cWorld: -cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AString & a_LinkedOverworldName) : +cWorld::cWorld(const AString & a_WorldName, const AString & a_DataPath, eDimension a_Dimension, const AString & a_LinkedOverworldName) : m_WorldName(a_WorldName), + m_DataPath(a_DataPath), m_LinkedOverworldName(a_LinkedOverworldName), - m_IniFileName(m_WorldName + "/world.ini"), + m_IniFileName(m_DataPath + "/world.ini"), m_StorageSchema("Default"), #ifdef __arm__ m_StorageCompressionFactor(0), #else m_StorageCompressionFactor(6), #endif + m_IsSavingEnabled(true), m_Dimension(a_Dimension), m_IsSpawnExplicitlySet(false), m_SpawnX(0), @@ -194,10 +196,10 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin { LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str()); - cFile::CreateFolder(FILE_IO_PREFIX + m_WorldName); + cFile::CreateFolderRecursive(FILE_IO_PREFIX + m_DataPath); // Load the scoreboard - cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard); + cScoreboardSerializer Serializer(m_DataPath, &m_Scoreboard); Serializer.Load(); } @@ -213,11 +215,14 @@ cWorld::~cWorld() m_Storage.WaitForFinish(); - // Unload the scoreboard - cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard); - Serializer.Save(); + if (IsSavingEnabled()) + { + // Unload the scoreboard + cScoreboardSerializer Serializer(m_DataPath, &m_Scoreboard); + Serializer.Save(); - m_MapManager.SaveMapData(); + m_MapManager.SaveMapData(); + } // Explicitly destroy the chunkmap, so that it's guaranteed to be destroyed before the other internals // This fixes crashes on stopping the server, because chunk destructor deletes entities and those access the world. @@ -2965,7 +2970,9 @@ void cWorld::SetChunkData(cSetChunkData & a_SetChunkData) ); // Save the chunk right after generating, so that we don't have to generate it again on next run - if (a_SetChunkData.ShouldMarkDirty()) + // If saving is disabled, then the chunk was marked dirty so it will get + // saved if saving is later enabled. + if (a_SetChunkData.ShouldMarkDirty() && IsSavingEnabled()) { m_Storage.QueueSaveChunk(ChunkX, ChunkZ); } @@ -3629,8 +3636,11 @@ bool cWorld::ForEachLoadedChunk(std::function a_Callback) void cWorld::SaveAllChunks(void) { - m_LastSave = std::chrono::duration_cast(m_WorldAge); - m_ChunkMap->SaveAllChunks(); + if (IsSavingEnabled()) + { + m_LastSave = std::chrono::duration_cast(m_WorldAge); + m_ChunkMap->SaveAllChunks(); + } } -- cgit v1.2.3