summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChunkMap.cpp26
-rw-r--r--src/ChunkStay.cpp3
2 files changed, 19 insertions, 10 deletions
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index e695f0ab2..83eae2665 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -916,19 +916,21 @@ void cChunkMap::SetChunkData(
}
// Notify relevant ChunkStays:
- for (cChunkStays::iterator itr = m_ChunkStays.begin(); itr != m_ChunkStays.end(); )
+ cChunkStays ToBeDisabled;
+ for (cChunkStays::iterator itr = m_ChunkStays.begin(), end = m_ChunkStays.end(); itr != end; ++itr)
{
if ((*itr)->ChunkAvailable(a_ChunkX, a_ChunkZ))
{
- cChunkStays::iterator cur = itr;
- ++itr;
- m_ChunkStays.erase(cur);
- }
- else
- {
- ++itr;
+ // The chunkstay wants to be disabled, add it to a list of to-be-disabled chunkstays for later processing:
+ ToBeDisabled.push_back(*itr);
}
} // for itr - m_ChunkStays[]
+
+ // Disable (and possibly remove) the chunkstays that chose to get disabled:
+ for (cChunkStays::iterator itr = ToBeDisabled.begin(), end = ToBeDisabled.end(); itr != end; ++itr)
+ {
+ (*itr)->Disable();
+ }
}
// Notify plugins of the chunk becoming available
@@ -2974,7 +2976,12 @@ void cChunkMap::AddChunkStay(cChunkStay & a_ChunkStay)
Chunk->Stay(true);
if (Chunk->IsValid())
{
- a_ChunkStay.ChunkAvailable(itr->m_ChunkX, itr->m_ChunkZ);
+ if (a_ChunkStay.ChunkAvailable(itr->m_ChunkX, itr->m_ChunkZ))
+ {
+ // The chunkstay wants to be deactivated, disable it and bail out:
+ a_ChunkStay.Disable();
+ return;
+ }
}
} // for itr - WantedChunks[]
}
@@ -3017,6 +3024,7 @@ void cChunkMap::DelChunkStay(cChunkStay & a_ChunkStay)
}
Chunk->Stay(false);
} // for itr - Chunks[]
+ a_ChunkStay.OnDisabled();
}
diff --git a/src/ChunkStay.cpp b/src/ChunkStay.cpp
index 6b1d5ee34..a35ccf58c 100644
--- a/src/ChunkStay.cpp
+++ b/src/ChunkStay.cpp
@@ -97,8 +97,9 @@ void cChunkStay::Disable(void)
{
ASSERT(m_ChunkMap != NULL);
- m_ChunkMap->DelChunkStay(*this);
+ cChunkMap * ChunkMap = m_ChunkMap;
m_ChunkMap = NULL;
+ ChunkMap->DelChunkStay(*this);
}