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.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user