summaryrefslogtreecommitdiffstats
path: root/src/World.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-06-06 22:31:16 +0200
committerMattes D <github@xoft.cz>2014-06-08 21:58:29 +0200
commitb904223b9dbbe7b696dbd30e748bc131742e11ea (patch)
treed742f036732e34a4c11f72f906c6f90c7d6ba231 /src/World.cpp
parentSmall change for easier understanding. (diff)
downloadcuberite-b904223b9dbbe7b696dbd30e748bc131742e11ea.tar
cuberite-b904223b9dbbe7b696dbd30e748bc131742e11ea.tar.gz
cuberite-b904223b9dbbe7b696dbd30e748bc131742e11ea.tar.bz2
cuberite-b904223b9dbbe7b696dbd30e748bc131742e11ea.tar.lz
cuberite-b904223b9dbbe7b696dbd30e748bc131742e11ea.tar.xz
cuberite-b904223b9dbbe7b696dbd30e748bc131742e11ea.tar.zst
cuberite-b904223b9dbbe7b696dbd30e748bc131742e11ea.zip
Diffstat (limited to 'src/World.cpp')
-rw-r--r--src/World.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/World.cpp b/src/World.cpp
index 88e9c32e6..ccd47d3b0 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -743,6 +743,17 @@ void cWorld::Tick(float a_Dt, int a_LastTickDurationMSec)
m_LastTimeUpdate = m_WorldAge;
}
+ // Add entities waiting in the queue to be added:
+ {
+ cCSLock Lock(m_CSEntitiesToAdd);
+ for (cEntityList::iterator itr = m_EntitiesToAdd.begin(), end = m_EntitiesToAdd.end(); itr != end; ++itr)
+ {
+ (*itr)->SetWorld(this);
+ m_ChunkMap->AddEntity(*itr);
+ }
+ m_EntitiesToAdd.clear();
+ }
+
m_ChunkMap->Tick(a_Dt);
TickClients(a_Dt);
@@ -2808,9 +2819,11 @@ void cWorld::ScheduleTask(int a_DelayTicks, cTask * a_Task)
+
void cWorld::AddEntity(cEntity * a_Entity)
{
- m_ChunkMap->AddEntity(a_Entity);
+ cCSLock Lock(m_CSEntitiesToAdd);
+ m_EntitiesToAdd.push_back(a_Entity);
}
@@ -2819,6 +2832,19 @@ void cWorld::AddEntity(cEntity * a_Entity)
bool cWorld::HasEntity(int a_UniqueID)
{
+ // Check if the entity is in the queue to be added to the world:
+ {
+ cCSLock Lock(m_CSEntitiesToAdd);
+ for (cEntityList::const_iterator itr = m_EntitiesToAdd.begin(), end = m_EntitiesToAdd.end(); itr != end; ++itr)
+ {
+ if ((*itr)->GetUniqueID() == a_UniqueID)
+ {
+ return true;
+ }
+ } // for itr - m_EntitiesToAdd[]
+ }
+
+ // Check if the entity is in the chunkmap:
return m_ChunkMap->HasEntity(a_UniqueID);
}