From 829cc866cd63c50ebff4dac2f942a0df93d269fc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 11 Aug 2013 21:05:44 +0200 Subject: Added cWorld:QueueSaveAllChunks() function for saving chunks asynchronously. The cWorld:SaveAllChunks() is therefore deprecated in the API and will be removed soon, use QueueSaveAllChunks() instead. --- source/World.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'source/World.cpp') diff --git a/source/World.cpp b/source/World.cpp index af66d1ead..9212202e9 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -1,3 +1,4 @@ + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "BlockID.h" @@ -242,7 +243,7 @@ cWorld::cWorld(const AString & a_WorldName) : m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :) m_TickThread(*this) { - LOGD("cWorld::cWorld(%s)", a_WorldName.c_str()); + LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str()); cMakeDir::MakeDir(m_WorldName.c_str()); } @@ -587,6 +588,7 @@ void cWorld::Tick(float a_Dt) m_ChunkMap->Tick(a_Dt); TickQueuedBlocks(a_Dt); + TickQueuedTasks(); GetSimulatorManager()->Simulate(a_Dt); @@ -781,6 +783,27 @@ void cWorld::TickSpawnMobs(float a_Dt) +void cWorld::TickQueuedTasks(void) +{ + // Make a copy of the tasks to avoid deadlocks on accessing m_Tasks + cTasks Tasks; + { + cCSLock Lock(m_CSTasks); + std::swap(Tasks, m_Tasks); + } + + // Execute and delete each task: + for (cTasks::iterator itr = m_Tasks.begin(), end = m_Tasks.end(); itr != end; ++itr) + { + (*itr)->Run(*this); + delete *itr; + } // for itr - m_Tasks[] +} + + + + + void cWorld::WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ) { return m_ChunkMap->WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); @@ -2307,6 +2330,25 @@ void cWorld::SaveAllChunks(void) +void cWorld::QueueSaveAllChunks(void) +{ + QueueTask(new cWorld::cTaskSaveAllChunks); +} + + + + + +void cWorld::QueueTask(cTask * a_Task) +{ + cCSLock Lock(m_CSTasks); + m_Tasks.push_back(a_Task); +} + + + + + void cWorld::AddEntity(cEntity * a_Entity) { m_ChunkMap->AddEntity(a_Entity); @@ -2552,3 +2594,15 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cWorld::cTaskSaveAllChunks: + +void cWorld::cTaskSaveAllChunks::Run(cWorld & a_World) +{ + a_World.SaveAllChunks(); +} + + + + -- cgit v1.2.3