From cea3a8e7e8cbf45f709ec63a096cf07b92c87073 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 29 May 2014 16:58:40 +0100 Subject: Cauldrons fill --- src/Chunk.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index ca536e89a..4506cfcc5 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -961,7 +961,6 @@ void cChunk::ApplyWeatherToTop() } break; } // case (snowy biomes) - // TODO: Rainy biomes should check for farmland and cauldrons default: { break; -- cgit v1.2.3 From 8bff3e5af220070ecc789ef551c0b8428b8953ef Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 31 May 2014 22:28:51 +0100 Subject: Implemented end and nether portals --- src/Chunk.cpp | 74 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 36 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 4506cfcc5..7131a26af 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -638,30 +638,22 @@ void cChunk::Tick(float a_Dt) for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr) { // Mobs are tickes inside MobTick (as we don't have to tick them if they are far away from players) - if (!((*itr)->IsMob())) + // Don't tick things queued to be removed + if (!((*itr)->IsMob()) && (std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), (*itr)->GetUniqueID()) == m_EntitiesToRemove.end())) { (*itr)->Tick(a_Dt, *this); } } // for itr - m_Entitites[] - // Remove all entities that were scheduled for removal: for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();) { - if ((*itr)->IsDestroyed()) - { - LOGD("Destroying entity #%i (%s)", (*itr)->GetUniqueID(), (*itr)->GetClass()); - cEntity * ToDelete = *itr; - itr = m_Entities.erase(itr); - delete ToDelete; - continue; - } - ++itr; - } // for itr - m_Entitites[] - - // If any entity moved out of the chunk, move it to the neighbor: - for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();) - { - if ( + auto itr2 = std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), (*itr)->GetUniqueID()); + if (itr2 != m_EntitiesToRemove.end()) + { + itr = m_Entities.erase(itr); + m_EntitiesToRemove.erase(itr2); + } + else if ( // If any entity moved out of the chunk, move it to the neighbor: ((*itr)->GetChunkX() != m_PosX) || ((*itr)->GetChunkZ() != m_PosZ) ) @@ -671,9 +663,19 @@ void cChunk::Tick(float a_Dt) } else { - ++itr; + if ((*itr)->IsDestroyed()) // Remove all entities that were scheduled for removal: + { + LOGD("Destroying entity #%i (%s)", (*itr)->GetUniqueID(), (*itr)->GetClass()); + cEntity * ToDelete = *itr; + itr = m_Entities.erase(itr); + delete ToDelete; + } + else + { + ++itr; + } } - } + } // for itr - m_Entitites[] ApplyWeatherToTop(); } @@ -1847,7 +1849,7 @@ void cChunk::RemoveBlockEntity( cBlockEntity* a_BlockEntity ) -bool cChunk::AddClient(cClientHandle* a_Client) +bool cChunk::AddClient(cClientHandle * a_Client) { for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr) { @@ -1878,7 +1880,7 @@ bool cChunk::AddClient(cClientHandle* a_Client) -void cChunk::RemoveClient( cClientHandle* a_Client ) +void cChunk::RemoveClient(cClientHandle * a_Client) { for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr) { @@ -1886,12 +1888,12 @@ void cChunk::RemoveClient( cClientHandle* a_Client ) { continue; } - + m_LoadedByClient.erase(itr); if (!a_Client->IsDestroyed()) { - for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr ) + for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr) { /* // DEBUG: @@ -1911,7 +1913,7 @@ void cChunk::RemoveClient( cClientHandle* a_Client ) -bool cChunk::HasClient( cClientHandle* a_Client ) +bool cChunk::HasClient(cClientHandle* a_Client) { for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr) { @@ -1942,9 +1944,9 @@ void cChunk::AddEntity(cEntity * a_Entity) { MarkDirty(); } - + ASSERT(std::find(m_Entities.begin(), m_Entities.end(), a_Entity) == m_Entities.end()); // Not there already - + m_Entities.push_back(a_Entity); } @@ -1954,17 +1956,12 @@ void cChunk::AddEntity(cEntity * a_Entity) void cChunk::RemoveEntity(cEntity * a_Entity) { - size_t SizeBefore = m_Entities.size(); - m_Entities.remove(a_Entity); - size_t SizeAfter = m_Entities.size(); - - if (SizeBefore != SizeAfter) + m_EntitiesToRemove.push_back(a_Entity->GetUniqueID()); + + // Mark as dirty if it was a server-generated entity: + if (!a_Entity->IsPlayer()) { - // Mark as dirty if it was a server-generated entity: - if (!a_Entity->IsPlayer()) - { - MarkDirty(); - } + MarkDirty(); } } @@ -1974,6 +1971,11 @@ void cChunk::RemoveEntity(cEntity * a_Entity) bool cChunk::HasEntity(int a_EntityID) { + if (std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), a_EntityID) != m_EntitiesToRemove.end()) + { + return false; // If EntitiesToRemove contains our ID, this chunk doesn't have it, as it should be removed soon + } + for (cEntityList::const_iterator itr = m_Entities.begin(), end = m_Entities.end(); itr != end; ++itr) { if ((*itr)->GetUniqueID() == a_EntityID) -- cgit v1.2.3 From 3278a403b5bc951818ed418c39c64934d55dbd65 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 4 Jun 2014 13:24:43 +0100 Subject: Removed use of auto --- 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 59f4a8507..c6122852a 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -588,7 +588,7 @@ void cChunk::Tick(float a_Dt) for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();) { - auto itr2 = std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), (*itr)->GetUniqueID()); + std::vector::const_iterator itr2 = std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), (*itr)->GetUniqueID()); if (itr2 != m_EntitiesToRemove.end()) { itr = m_Entities.erase(itr); -- cgit v1.2.3 From 156c9851b8a099656fa86ea52d989e35e5b7ebf1 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 5 Jun 2014 17:58:29 +0100 Subject: Suggestions --- src/Chunk.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index c6122852a..2850dd93b 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -580,7 +580,10 @@ void cChunk::Tick(float a_Dt) { // Mobs are tickes inside MobTick (as we don't have to tick them if they are far away from players) // Don't tick things queued to be removed - if (!((*itr)->IsMob()) && (std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), (*itr)->GetUniqueID()) == m_EntitiesToRemove.end())) + if ( + !((*itr)->IsMob()) && + (std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), (*itr)->GetUniqueID()) == m_EntitiesToRemove.end()) + ) { (*itr)->Tick(a_Dt, *this); } @@ -588,7 +591,7 @@ void cChunk::Tick(float a_Dt) for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();) { - std::vector::const_iterator itr2 = std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), (*itr)->GetUniqueID()); + std::vector::iterator itr2 = std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), (*itr)->GetUniqueID()); if (itr2 != m_EntitiesToRemove.end()) { itr = m_Entities.erase(itr); -- cgit v1.2.3 From 35b79e5d710862f957bc494638a8d8906992665d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 10 Jun 2014 20:43:27 +0100 Subject: Portal improvements and suggestions --- src/Chunk.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 2850dd93b..02857ba5a 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1859,7 +1859,20 @@ void cChunk::AddEntity(cEntity * a_Entity) MarkDirty(); } - ASSERT(std::find(m_Entities.begin(), m_Entities.end(), a_Entity) == m_Entities.end()); // Not there already + if (std::find(m_Entities.begin(), m_Entities.end(), a_Entity) != m_Entities.end()) + { + // Not there already + std::vector::iterator itr = std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), a_Entity->GetUniqueID()); + if (itr != m_EntitiesToRemove.end()) + { + m_EntitiesToRemove.erase(itr); + return; + } + else + { + ASSERT(!"Entity already present when AddEntity was called!"); + } + } m_Entities.push_back(a_Entity); } -- cgit v1.2.3 From 29567c56107c86b70da130f995564beb2eaf424c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 12 Jun 2014 15:21:07 +0100 Subject: Portals animate and delay correctly --- src/Chunk.cpp | 74 ++++++++++++++++++++++++++--------------------------------- 1 file changed, 33 insertions(+), 41 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 399c8b9c7..c9e4f5411 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -85,7 +85,8 @@ cChunk::cChunk( m_NeighborZM(a_NeighborZM), m_NeighborZP(a_NeighborZP), m_WaterSimulatorData(a_World->GetWaterSimulator()->CreateChunkData()), - m_LavaSimulatorData (a_World->GetLavaSimulator ()->CreateChunkData()) + m_LavaSimulatorData (a_World->GetLavaSimulator ()->CreateChunkData()), + m_EntityTickIteratorData(std::make_pair(false, &m_Entities.end())) { if (a_NeighborXM != NULL) { @@ -576,26 +577,38 @@ void cChunk::Tick(float a_Dt) } // Tick all entities in this chunk (except mobs): - for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr) + m_EntityTickIteratorData.first = true; + for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();) { - // Mobs are tickes inside MobTick (as we don't have to tick them if they are far away from players) + // Mobs are ticked inside cWorld::TickMobs() (as we don't have to tick them if they are far away from players) // Don't tick things queued to be removed - if ( - !((*itr)->IsMob()) && - (std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), (*itr)->GetUniqueID()) == m_EntitiesToRemove.end()) - ) + if (!((*itr)->IsMob())) { + m_EntityTickIteratorData.second = &itr; (*itr)->Tick(a_Dt, *this); + + if (itr != *m_EntityTickIteratorData.second) + { + itr = *m_EntityTickIteratorData.second; + } + else + { + ++itr; + } + continue; } + ++itr; } // for itr - m_Entitites[] + m_EntityTickIteratorData.first = false; for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();) { - std::vector::iterator itr2 = std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), (*itr)->GetUniqueID()); - if (itr2 != m_EntitiesToRemove.end()) + if ((*itr)->IsDestroyed()) // Remove all entities that were scheduled for removal: { + LOGD("Destroying entity #%i (%s)", (*itr)->GetUniqueID(), (*itr)->GetClass()); + cEntity * ToDelete = *itr; itr = m_Entities.erase(itr); - m_EntitiesToRemove.erase(itr2); + delete ToDelete; } else if ( // If any entity moved out of the chunk, move it to the neighbor: ((*itr)->GetChunkX() != m_PosX) || @@ -607,17 +620,7 @@ void cChunk::Tick(float a_Dt) } else { - if ((*itr)->IsDestroyed()) // Remove all entities that were scheduled for removal: - { - LOGD("Destroying entity #%i (%s)", (*itr)->GetUniqueID(), (*itr)->GetClass()); - cEntity * ToDelete = *itr; - itr = m_Entities.erase(itr); - delete ToDelete; - } - else - { - ++itr; - } + ++itr; } } // for itr - m_Entitites[] @@ -1860,20 +1863,7 @@ void cChunk::AddEntity(cEntity * a_Entity) MarkDirty(); } - if (std::find(m_Entities.begin(), m_Entities.end(), a_Entity) != m_Entities.end()) - { - // Not there already - std::vector::iterator itr = std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), a_Entity->GetUniqueID()); - if (itr != m_EntitiesToRemove.end()) - { - m_EntitiesToRemove.erase(itr); - return; - } - else - { - ASSERT(!"Entity already present when AddEntity was called!"); - } - } + ASSERT(std::find(m_Entities.begin(), m_Entities.end(), a_Entity) == m_Entities.end()); m_Entities.push_back(a_Entity); } @@ -1884,7 +1874,14 @@ void cChunk::AddEntity(cEntity * a_Entity) void cChunk::RemoveEntity(cEntity * a_Entity) { - m_EntitiesToRemove.push_back(a_Entity->GetUniqueID()); + if (m_EntityTickIteratorData.first) + { + *m_EntityTickIteratorData.second = m_Entities.erase(*m_EntityTickIteratorData.second); + } + else + { + m_Entities.remove(a_Entity); + } // Mark as dirty if it was a server-generated entity: if (!a_Entity->IsPlayer()) @@ -1899,11 +1896,6 @@ void cChunk::RemoveEntity(cEntity * a_Entity) bool cChunk::HasEntity(int a_EntityID) { - if (std::find(m_EntitiesToRemove.begin(), m_EntitiesToRemove.end(), a_EntityID) != m_EntitiesToRemove.end()) - { - return false; // If EntitiesToRemove contains our ID, this chunk doesn't have it, as it should be removed soon - } - for (cEntityList::const_iterator itr = m_Entities.begin(), end = m_Entities.end(); itr != end; ++itr) { if ((*itr)->GetUniqueID() == a_EntityID) -- cgit v1.2.3 From 93d4a8aa92af58bb073f18c87167358d18632899 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 12 Jun 2014 18:51:33 +0100 Subject: Removed unnessicary indirection from Entity iterator list --- src/Chunk.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index c9e4f5411..7ca0a4afd 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -86,7 +86,7 @@ cChunk::cChunk( m_NeighborZP(a_NeighborZP), m_WaterSimulatorData(a_World->GetWaterSimulator()->CreateChunkData()), m_LavaSimulatorData (a_World->GetLavaSimulator ()->CreateChunkData()), - m_EntityTickIteratorData(std::make_pair(false, &m_Entities.end())) + m_EntityTickIteratorData(std::make_pair(false, m_Entities.end())) { if (a_NeighborXM != NULL) { @@ -584,12 +584,12 @@ void cChunk::Tick(float a_Dt) // Don't tick things queued to be removed if (!((*itr)->IsMob())) { - m_EntityTickIteratorData.second = &itr; + m_EntityTickIteratorData.second = itr; (*itr)->Tick(a_Dt, *this); - if (itr != *m_EntityTickIteratorData.second) + if (itr != m_EntityTickIteratorData.second) { - itr = *m_EntityTickIteratorData.second; + itr = m_EntityTickIteratorData.second; } else { @@ -1876,7 +1876,7 @@ void cChunk::RemoveEntity(cEntity * a_Entity) { if (m_EntityTickIteratorData.first) { - *m_EntityTickIteratorData.second = m_Entities.erase(*m_EntityTickIteratorData.second); + m_EntityTickIteratorData.second = m_Entities.erase(m_EntityTickIteratorData.second); } else { -- cgit v1.2.3 From c82f4f6309f760186c43b4f32596c3e78a5725b7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 12 Jun 2014 18:56:48 +0100 Subject: Fixed order of initalisation --- 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 7ca0a4afd..8255fdcaf 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -71,6 +71,7 @@ cChunk::cChunk( m_IsDirty(false), m_IsSaving(false), m_HasLoadFailed(false), + m_EntityTickIteratorData(std::make_pair(false, m_Entities.end())), m_StayCount(0), m_PosX(a_ChunkX), m_PosY(a_ChunkY), @@ -85,8 +86,7 @@ cChunk::cChunk( m_NeighborZM(a_NeighborZM), m_NeighborZP(a_NeighborZP), m_WaterSimulatorData(a_World->GetWaterSimulator()->CreateChunkData()), - m_LavaSimulatorData (a_World->GetLavaSimulator ()->CreateChunkData()), - m_EntityTickIteratorData(std::make_pair(false, m_Entities.end())) + m_LavaSimulatorData (a_World->GetLavaSimulator ()->CreateChunkData()) { if (a_NeighborXM != NULL) { -- cgit v1.2.3 From 6e681269d9dfb33b5b73f4f01a61def247b3aee7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 21 Jun 2014 22:07:38 +0100 Subject: Fixed invalid iterators --- src/Chunk.cpp | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 8255fdcaf..727eb451d 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -71,7 +71,6 @@ cChunk::cChunk( m_IsDirty(false), m_IsSaving(false), m_HasLoadFailed(false), - m_EntityTickIteratorData(std::make_pair(false, m_Entities.end())), m_StayCount(0), m_PosX(a_ChunkX), m_PosY(a_ChunkY), @@ -577,44 +576,39 @@ void cChunk::Tick(float a_Dt) } // Tick all entities in this chunk (except mobs): - m_EntityTickIteratorData.first = true; - for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();) + for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr) { // Mobs are ticked inside cWorld::TickMobs() (as we don't have to tick them if they are far away from players) // Don't tick things queued to be removed if (!((*itr)->IsMob())) { - m_EntityTickIteratorData.second = itr; (*itr)->Tick(a_Dt, *this); - - if (itr != m_EntityTickIteratorData.second) - { - itr = m_EntityTickIteratorData.second; - } - else - { - ++itr; - } continue; } - ++itr; } // for itr - m_Entitites[] - m_EntityTickIteratorData.first = false; for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();) { if ((*itr)->IsDestroyed()) // Remove all entities that were scheduled for removal: { LOGD("Destroying entity #%i (%s)", (*itr)->GetUniqueID(), (*itr)->GetClass()); + MarkDirty(); cEntity * ToDelete = *itr; itr = m_Entities.erase(itr); delete ToDelete; } + else if ((*itr)->IsTravellingThroughPortal()) + { + MarkDirty(); + (*itr)->SetIsTravellingThroughPortal(false); + itr = m_Entities.erase(itr); + } else if ( // If any entity moved out of the chunk, move it to the neighbor: ((*itr)->GetChunkX() != m_PosX) || ((*itr)->GetChunkZ() != m_PosZ) ) { + MarkDirty(); MoveEntityToNewChunk(*itr); itr = m_Entities.erase(itr); } @@ -1874,14 +1868,7 @@ void cChunk::AddEntity(cEntity * a_Entity) void cChunk::RemoveEntity(cEntity * a_Entity) { - if (m_EntityTickIteratorData.first) - { - m_EntityTickIteratorData.second = m_Entities.erase(m_EntityTickIteratorData.second); - } - else - { - m_Entities.remove(a_Entity); - } + m_Entities.remove(a_Entity); // Mark as dirty if it was a server-generated entity: if (!a_Entity->IsPlayer()) -- cgit v1.2.3 From 6ab9afd0fd808fad99cd8387c72ce461c37aef80 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 20 Jul 2014 10:46:45 +0100 Subject: Bug and crash fixes * Fixes end portals' solidity * Fixed crashes to do with multithreading and removing an entity from the wrong world * Fixed crashes due to bad merge * Fixed crashes due to an object being deleted twice * Simplified cWorld::Start() and added comments to configuration files --- src/Chunk.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 2f3bdff81..4588de9f3 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -591,7 +591,6 @@ void cChunk::Tick(float a_Dt) if (!((*itr)->IsMob())) { (*itr)->Tick(a_Dt, *this); - continue; } } // for itr - m_Entitites[] @@ -605,10 +604,10 @@ void cChunk::Tick(float a_Dt) itr = m_Entities.erase(itr); delete ToDelete; } - else if ((*itr)->IsTravellingThroughPortal()) // Remove all entities that are travelling to another world + else if ((*itr)->IsWorldTravellingFrom(m_World)) // Remove all entities that are travelling to another world { MarkDirty(); - (*itr)->SetIsTravellingThroughPortal(false); + (*itr)->SetWorldTravellingFrom(NULL); itr = m_Entities.erase(itr); } else if ( // If any entity moved out of the chunk, move it to the neighbor: -- cgit v1.2.3 From 8050a5b98a3003c2a4bed39b896b4a3a4c1068c0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 21 Jul 2014 22:49:06 +0100 Subject: Suggestions --- src/Chunk.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 4588de9f3..7850b7e31 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -596,7 +596,7 @@ void cChunk::Tick(float a_Dt) for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();) { - if ((*itr)->IsDestroyed()) // Remove all entities that were scheduled for removal: + if ((*itr)->IsDestroyed()) // Remove all entities that were scheduled for removal: { LOGD("Destroying entity #%i (%s)", (*itr)->GetUniqueID(), (*itr)->GetClass()); MarkDirty(); @@ -604,13 +604,13 @@ void cChunk::Tick(float a_Dt) itr = m_Entities.erase(itr); delete ToDelete; } - else if ((*itr)->IsWorldTravellingFrom(m_World)) // Remove all entities that are travelling to another world + else if ((*itr)->IsWorldTravellingFrom(m_World)) // Remove all entities that are travelling to another world { MarkDirty(); (*itr)->SetWorldTravellingFrom(NULL); itr = m_Entities.erase(itr); } - else if ( // If any entity moved out of the chunk, move it to the neighbor: + else if ( // If any entity moved out of the chunk, move it to the neighbor: ((*itr)->GetChunkX() != m_PosX) || ((*itr)->GetChunkZ() != m_PosZ) ) -- cgit v1.2.3 From a28b0dc1201dca7c34d9a6c33232157e45a6d4f8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 22 Jul 2014 17:26:48 +0100 Subject: Speed improvements, crash fixes, & self-suggestions --- src/Chunk.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 9b9646b0c..0be61f753 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -583,19 +583,14 @@ void cChunk::Tick(float a_Dt) m_IsDirty = (*itr)->Tick(a_Dt, *this) | m_IsDirty; } - // Tick all entities in this chunk (except mobs): - for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr) - { - // Mobs are ticked inside cWorld::TickMobs() (as we don't have to tick them if they are far away from players) - // Don't tick things queued to be removed - if (!((*itr)->IsMob())) + for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();) + { + if (!((*itr)->IsMob())) // Mobs are ticked inside cWorld::TickMobs() (as we don't have to tick them if they are far away from players) { + // Tick all entities in this chunk (except mobs): (*itr)->Tick(a_Dt, *this); } - } // for itr - m_Entitites[] - - for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end();) - { + if ((*itr)->IsDestroyed()) // Remove all entities that were scheduled for removal: { LOGD("Destroying entity #%i (%s)", (*itr)->GetUniqueID(), (*itr)->GetClass()); @@ -604,7 +599,7 @@ void cChunk::Tick(float a_Dt) itr = m_Entities.erase(itr); delete ToDelete; } - else if ((*itr)->IsWorldTravellingFrom(m_World)) // Remove all entities that are travelling to another world + else if ((*itr)->IsWorldTravellingFrom(m_World)) // Remove all entities that are travelling to another world: { MarkDirty(); (*itr)->SetWorldTravellingFrom(NULL); @@ -1899,7 +1894,7 @@ void cChunk::AddEntity(cEntity * a_Entity) MarkDirty(); } - ASSERT(std::find(m_Entities.begin(), m_Entities.end(), a_Entity) == m_Entities.end()); + ASSERT(std::find(m_Entities.begin(), m_Entities.end(), a_Entity) == m_Entities.end()); // Not there already m_Entities.push_back(a_Entity); } -- cgit v1.2.3