summaryrefslogtreecommitdiffstats
path: root/source/World.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-11 21:05:44 +0200
committermadmaxoft <github@xoft.cz>2013-08-11 21:05:44 +0200
commit829cc866cd63c50ebff4dac2f942a0df93d269fc (patch)
treef3f414cd6f3825c7fb345d52cd802ccb9a10c9e3 /source/World.cpp
parentcIsThread threads get a window identification on Win. (diff)
downloadcuberite-829cc866cd63c50ebff4dac2f942a0df93d269fc.tar
cuberite-829cc866cd63c50ebff4dac2f942a0df93d269fc.tar.gz
cuberite-829cc866cd63c50ebff4dac2f942a0df93d269fc.tar.bz2
cuberite-829cc866cd63c50ebff4dac2f942a0df93d269fc.tar.lz
cuberite-829cc866cd63c50ebff4dac2f942a0df93d269fc.tar.xz
cuberite-829cc866cd63c50ebff4dac2f942a0df93d269fc.tar.zst
cuberite-829cc866cd63c50ebff4dac2f942a0df93d269fc.zip
Diffstat (limited to 'source/World.cpp')
-rw-r--r--source/World.cpp56
1 files changed, 55 insertions, 1 deletions
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();
+}
+
+
+
+