summaryrefslogtreecommitdiffstats
path: root/src/ChunkMap.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-02-02 23:09:03 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-02-02 23:09:03 +0100
commit2d0b31e7b671447ca49988d14c13b6eb6bad4cf2 (patch)
treea0b28406e9c9f561fed241a47f3a51ef4db791a1 /src/ChunkMap.cpp
parentFixed #624 (diff)
parentMerge pull request #622 from worktycho/registerfix (diff)
downloadcuberite-2d0b31e7b671447ca49988d14c13b6eb6bad4cf2.tar
cuberite-2d0b31e7b671447ca49988d14c13b6eb6bad4cf2.tar.gz
cuberite-2d0b31e7b671447ca49988d14c13b6eb6bad4cf2.tar.bz2
cuberite-2d0b31e7b671447ca49988d14c13b6eb6bad4cf2.tar.lz
cuberite-2d0b31e7b671447ca49988d14c13b6eb6bad4cf2.tar.xz
cuberite-2d0b31e7b671447ca49988d14c13b6eb6bad4cf2.tar.zst
cuberite-2d0b31e7b671447ca49988d14c13b6eb6bad4cf2.zip
Diffstat (limited to 'src/ChunkMap.cpp')
-rw-r--r--src/ChunkMap.cpp58
1 files changed, 56 insertions, 2 deletions
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index 5797eb453..049bb5fb2 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -1117,6 +1117,21 @@ void cChunkMap::CollectPickupsByPlayer(cPlayer * a_Player)
BLOCKTYPE cChunkMap::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
{
+ // First check if it isn't queued in the m_FastSetBlockQueue:
+ {
+ int X = a_BlockX, Y = a_BlockY, Z = a_BlockZ;
+ int ChunkX, ChunkY, ChunkZ;
+ cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
+ ChunkY = 0;
+ cCSLock Lock(m_CSFastSetBlock);
+ for (sSetBlockList::iterator itr = m_FastSetBlockQueue.begin(); itr != m_FastSetBlockQueue.end(); ++itr)
+ {
+ if ((itr->x == X) && (itr->y == Y) && (itr->z == Z) && (itr->ChunkX == ChunkX) && (itr->ChunkZ == ChunkZ))
+ {
+ return itr->BlockType;
+ }
+ } // for itr - m_FastSetBlockQueue[]
+ }
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ );
@@ -1135,6 +1150,17 @@ BLOCKTYPE cChunkMap::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
NIBBLETYPE cChunkMap::GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ)
{
+ // First check if it isn't queued in the m_FastSetBlockQueue:
+ {
+ cCSLock Lock(m_CSFastSetBlock);
+ for (sSetBlockList::iterator itr = m_FastSetBlockQueue.begin(); itr != m_FastSetBlockQueue.end(); ++itr)
+ {
+ if ((itr->x == a_BlockX) && (itr->y == a_BlockY) && (itr->z == a_BlockZ))
+ {
+ return itr->BlockMeta;
+ }
+ } // for itr - m_FastSetBlockQueue[]
+ }
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ );
@@ -1207,8 +1233,14 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP
-void cChunkMap::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta)
+void cChunkMap::SetBlock(cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta)
{
+ cChunkInterface ChunkInterface(this);
+ if (a_BlockType == E_BLOCK_AIR)
+ {
+ BlockHandler(GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnDestroyed(ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ);
+ }
+
int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ;
cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ );
@@ -1219,6 +1251,7 @@ void cChunkMap::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_B
Chunk->SetBlock(X, Y, Z, a_BlockType, a_BlockMeta );
m_World->GetSimulatorManager()->WakeUp(a_BlockX, a_BlockY, a_BlockZ, Chunk);
}
+ BlockHandler(a_BlockType)->OnPlaced(ChunkInterface, a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta);
}
@@ -2692,6 +2725,28 @@ void cChunkMap::cChunkLayer::UnloadUnusedChunks(void)
+void cChunkMap::FastSetBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
+{
+ cCSLock Lock(m_CSFastSetBlock);
+ m_FastSetBlockQueue.push_back(sSetBlock(a_X, a_Y, a_Z, a_BlockType, a_BlockMeta));
+}
+
+void cChunkMap::FastSetQueuedBlocks()
+{
+ // Asynchronously set blocks:
+ sSetBlockList FastSetBlockQueueCopy;
+ {
+ cCSLock Lock(m_CSFastSetBlock);
+ std::swap(FastSetBlockQueueCopy, m_FastSetBlockQueue);
+ }
+ this->FastSetBlocks(FastSetBlockQueueCopy);
+ if (!FastSetBlockQueueCopy.empty())
+ {
+ // Some blocks failed, store them for next tick:
+ cCSLock Lock(m_CSFastSetBlock);
+ m_FastSetBlockQueue.splice(m_FastSetBlockQueue.end(), FastSetBlockQueueCopy);
+ }
+}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -2801,4 +2856,3 @@ void cChunkStay::Disable(void)
-