From 18793ca568ed1d26d56ba2afc26ae7b8316159f7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 8 Apr 2014 08:57:35 -0700 Subject: Fixed missing - that caused all neighbour lookups to go to the chunkmap --- src/Chunk.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 22b33c595..fe9cd9b31 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -2511,7 +2511,7 @@ cChunk * cChunk::GetNeighborChunk(int a_BlockX, int a_BlockZ) cChunk * cChunk::GetRelNeighborChunk(int a_RelX, int a_RelZ) { // If the relative coords are too far away, use the parent's chunk lookup instead: - if ((a_RelX < 128) || (a_RelX > 128) || (a_RelZ < -128) || (a_RelZ > 128)) + if ((a_RelX < -128) || (a_RelX > 128) || (a_RelZ < -128) || (a_RelZ > 128)) { int BlockX = m_PosX * cChunkDef::Width + a_RelX; int BlockZ = m_PosZ * cChunkDef::Width + a_RelZ; -- cgit v1.2.3 From 875c2557c30aa5254c2ec3f4062ec463418c7d09 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 12 Apr 2014 00:01:15 +0200 Subject: Implemented the skeleton code for the beacon. There is no handling for the GUI. It can now check how big the pyramid is under the beacon. --- src/Chunk.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index fe9cd9b31..4366111ef 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1299,6 +1299,7 @@ void cChunk::CreateBlockEntities(void) BLOCKTYPE BlockType = cChunkDef::GetBlock(m_BlockTypes, x, y, z); switch (BlockType) { + case E_BLOCK_BEACON: case E_BLOCK_CHEST: case E_BLOCK_COMMAND_BLOCK: case E_BLOCK_DISPENSER: @@ -1429,6 +1430,7 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, // If the new block is a block entity, create the entity object: switch (a_BlockType) { + case E_BLOCK_BEACON: case E_BLOCK_CHEST: case E_BLOCK_COMMAND_BLOCK: case E_BLOCK_DISPENSER: -- cgit v1.2.3 From 013da806ec20b62a742aded9a9d2b8131193f30d Mon Sep 17 00:00:00 2001 From: jfhumann Date: Fri, 18 Apr 2014 21:09:44 +0200 Subject: Did some static analysis, fixed some bugs and optimized a lot of code --- src/Chunk.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index fe9cd9b31..acefd98ed 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -452,7 +452,7 @@ void cChunk::CollectMobCensus(cMobCensus& toFill) { cMonster& Monster = (cMonster&)(**itr); currentPosition = Monster.GetPosition(); - for (std::list::const_iterator itr2 = playerPositions.begin(); itr2 != playerPositions.end(); itr2 ++) + for (std::list::const_iterator itr2 = playerPositions.begin(); itr2 != playerPositions.end(); ++itr2) { toFill.CollectMob(Monster,*this,(currentPosition-**itr2).SqrLength()); } @@ -600,7 +600,7 @@ void cChunk::Tick(float a_Dt) delete ToDelete; continue; } - itr++; + ++itr; } // for itr - m_Entitites[] // If any entity moved out of the chunk, move it to the neighbor: -- cgit v1.2.3 From ffce8d6907b8b93a2764a67766a40901bcad0835 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 24 Apr 2014 21:49:56 +0100 Subject: Implemented suggestions --- src/Chunk.cpp | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index ee1531b5c..6c35f7f47 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -378,16 +378,14 @@ void cChunk::SetLight( // TODO: We might get cases of wrong lighting when a chunk changes in the middle of a lighting calculation. // Postponing until we see how bad it is :) + int IdxWhereNonEmptyStarts = 0; { // Compress blocklight - bool FoundNonEmpty = false; - int IdxWhereNonEmptyStarts = 0; m_BlockLight.clear(); for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) { if (a_BlockLight[Idx] != 0) { - FoundNonEmpty = true; IdxWhereNonEmptyStarts = Idx; break; } @@ -396,19 +394,7 @@ void cChunk::SetLight( } { // Compress skylight - bool FoundNonEmpty = false; - int IdxWhereNonEmptyStarts = 0; m_BlockSkyLight.clear(); - - for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) - { - if (a_SkyLight[Idx] != 0xff) - { - FoundNonEmpty = true; - IdxWhereNonEmptyStarts = Idx; - break; - } - } m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[IdxWhereNonEmptyStarts + 1]); } @@ -421,10 +407,8 @@ void cChunk::SetLight( void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) { - std::vector Blocks = m_BlockTypes; - Blocks.resize(NumBlocks); - - memcpy(a_BlockTypes, &Blocks[0], NumBlocks); + std::copy(m_BlockTypes.begin(), m_BlockTypes.end(), a_BlockTypes); + std::fill_n(&a_BlockTypes[m_BlockTypes.size()], NumBlocks - m_BlockTypes.size(), E_BLOCK_AIR); } @@ -832,7 +816,7 @@ void cChunk::BroadcastPendingBlockChanges(void) void cChunk::CheckBlocks() { - if (m_ToTickBlocks.size() == 0) + if (m_ToTickBlocks.empty()) { return; } @@ -1605,7 +1589,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT MarkDirty(); - if (m_BlockTypes.empty() || ((size_t)index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || ((size_t)index >= m_BlockTypes.size())) { m_BlockTypes.resize(index + 1); } @@ -2550,7 +2534,7 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const return 0; } - if (m_BlockTypes.empty() || ((size_t)a_BlockIdx > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || ((size_t)a_BlockIdx >= m_BlockTypes.size())) { return E_BLOCK_AIR; } -- cgit v1.2.3 From acbd4e6503a8da6645c97dbe010eed7f37386194 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 24 Apr 2014 21:52:01 +0100 Subject: Another small speed improvement? --- src/Chunk.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 6c35f7f47..7af1820d2 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -378,24 +378,14 @@ void cChunk::SetLight( // TODO: We might get cases of wrong lighting when a chunk changes in the middle of a lighting calculation. // Postponing until we see how bad it is :) - int IdxWhereNonEmptyStarts = 0; { // Compress blocklight m_BlockLight.clear(); - - for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) - { - if (a_BlockLight[Idx] != 0) - { - IdxWhereNonEmptyStarts = Idx; - break; - } - } - m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts + 1]); + m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[m_BlockTypes.size()]); } { // Compress skylight m_BlockSkyLight.clear(); - m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[IdxWhereNonEmptyStarts + 1]); + m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[m_BlockTypes.size()]); } m_IsLightValid = true; -- cgit v1.2.3 From 3397f9faec43ac288fa9e7f1f555a1309a4e47a5 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 24 Apr 2014 22:07:20 +0100 Subject: Fixed indent --- src/Chunk.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 7af1820d2..97a8ba88b 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -282,7 +282,7 @@ void cChunk::SetAllData( const HeightMap * a_HeightMap, const BiomeMap & a_BiomeMap, cBlockEntityList & a_BlockEntities - ) +) { memcpy(m_BiomeMap, a_BiomeMap, sizeof(m_BiomeMap)); -- cgit v1.2.3 From 05f52192c9389f0c28cc6d772f3625c9588273a1 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 25 Apr 2014 21:22:43 +0100 Subject: Implemented comments --- src/Chunk.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 97a8ba88b..652f56905 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -241,21 +241,21 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) a_Callback.HeightMap (&m_HeightMap); a_Callback.BiomeData (&m_BiomeMap); - std::vector Blocks = m_BlockTypes; + COMPRESSED_BLOCKTYPE Blocks = m_BlockTypes; Blocks.resize(NumBlocks); a_Callback.BlockTypes (&Blocks[0]); - std::vector Metas = m_BlockMeta; + COMPRESSED_NIBBLETYPE Metas = m_BlockMeta; Metas.resize(NumBlocks / 2); a_Callback.BlockMeta (&Metas[0]); a_Callback.LightIsValid (m_IsLightValid); - std::vector BlockLights = m_BlockLight; + COMPRESSED_NIBBLETYPE BlockLights = m_BlockLight; BlockLights.resize(NumBlocks / 2); a_Callback.BlockLight (&BlockLights[0]); - std::vector BlockSkyLights = m_BlockSkyLight; + COMPRESSED_NIBBLETYPE BlockSkyLights = m_BlockSkyLight; BlockSkyLights.resize(NumBlocks / 2, 0xff); a_Callback.BlockSkyLight(&BlockSkyLights[0]); @@ -1579,7 +1579,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT MarkDirty(); - if (m_BlockTypes.empty() || ((size_t)index >= m_BlockTypes.size())) + if ((size_t)index >= m_BlockTypes.size()) { m_BlockTypes.resize(index + 1); } @@ -2524,7 +2524,7 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const return 0; } - if (m_BlockTypes.empty() || ((size_t)a_BlockIdx >= m_BlockTypes.size())) + if ((size_t)a_BlockIdx >= m_BlockTypes.size()) { return E_BLOCK_AIR; } -- cgit v1.2.3