From 49c443896dcac8c4eaf08c4024e8bd2366ad899a Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Sat, 2 Sep 2017 10:45:06 +0300 Subject: Revert "Replace ItemCallbacks with lambdas (#3948)" This reverts commit 496c337cdfa593654018c171f6a74c28272265b5. --- src/Map.cpp | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'src/Map.cpp') diff --git a/src/Map.cpp b/src/Map.cpp index 87cc9bfdf..2fe901d8e 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -120,17 +120,27 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) int RelX = BlockX - (ChunkX * cChunkDef::Width); int RelZ = BlockZ - (ChunkZ * cChunkDef::Width); - ASSERT(m_World != nullptr); + class cCalculatePixelCb : + public cChunkCallback + { + cMap * m_Map; + + int m_RelX, m_RelZ; + + ColorID m_PixelData; + + public: + cCalculatePixelCb(cMap * a_Map, int a_RelX, int a_RelZ) + : m_Map(a_Map), m_RelX(a_RelX), m_RelZ(a_RelZ), m_PixelData(E_BASE_COLOR_TRANSPARENT) {} - ColorID PixelData; - m_World->DoWithChunk(ChunkX, ChunkZ, [&](cChunk & a_Chunk) + virtual bool Item(cChunk * a_Chunk) override { - if (!a_Chunk.IsValid()) + if (!a_Chunk->IsValid()) { return false; } - if (GetDimension() == dimNether) + if (m_Map->GetDimension() == dimNether) { // TODO 2014-02-22 xdot: Nether maps @@ -141,22 +151,22 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) BLOCKTYPE TargetBlock; NIBBLETYPE TargetMeta; - auto Height = a_Chunk.GetHeight(RelX, RelZ); + auto Height = a_Chunk->GetHeight(m_RelX, m_RelZ); auto ChunkHeight = cChunkDef::Height; - a_Chunk.GetBlockTypeMeta(RelX, Height, RelZ, TargetBlock, TargetMeta); + a_Chunk->GetBlockTypeMeta(m_RelX, Height, m_RelZ, TargetBlock, TargetMeta); auto ColourID = BlockHandler(TargetBlock)->GetMapBaseColourID(TargetMeta); if (IsBlockWater(TargetBlock)) { ChunkHeight /= 4; - while (((--Height) != -1) && IsBlockWater(a_Chunk.GetBlock(RelX, Height, RelZ))) + while (((--Height) != -1) && IsBlockWater(a_Chunk->GetBlock(m_RelX, Height, m_RelZ))) { continue; } } else if (ColourID == 0) { - while (((--Height) != -1) && ((ColourID = BlockHandler(a_Chunk.GetBlock(RelX, Height, RelZ))->GetMapBaseColourID(a_Chunk.GetMeta(RelX, Height, RelZ))) == 0)) + while (((--Height) != -1) && ((ColourID = BlockHandler(a_Chunk->GetBlock(m_RelX, Height, m_RelZ))->GetMapBaseColourID(a_Chunk->GetMeta(m_RelX, Height, m_RelZ))) == 0)) { continue; } @@ -164,12 +174,20 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) // Multiply base color ID by 4 and add brightness ID const int BrightnessIDSize = static_cast(BrightnessID.size()); - PixelData = ColourID * 4 + BrightnessID[static_cast(Clamp((BrightnessIDSize * Height) / ChunkHeight, 0, BrightnessIDSize - 1))]; + m_PixelData = ColourID * 4 + BrightnessID[static_cast(Clamp((BrightnessIDSize * Height) / ChunkHeight, 0, BrightnessIDSize - 1))]; return false; } - ); - SetPixel(a_X, a_Z, PixelData); + ColorID GetPixelData(void) const + { + return m_PixelData; + } + } CalculatePixelCb(this, RelX, RelZ); + + ASSERT(m_World != nullptr); + m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb); + + SetPixel(a_X, a_Z, CalculatePixelCb.GetPixelData()); return true; } -- cgit v1.2.3