summaryrefslogtreecommitdiffstats
path: root/src/Chunk.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-09-22 22:21:47 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2020-09-25 15:51:16 +0200
commit4519469547c0f8befe74e3e80a94efb0e076ba34 (patch)
treeb2e020631d1fbbfe0225d1c6a6a88dbc6eab124b /src/Chunk.cpp
parentGrass spread: check chunk & light validity correctly (diff)
downloadcuberite-4519469547c0f8befe74e3e80a94efb0e076ba34.tar
cuberite-4519469547c0f8befe74e3e80a94efb0e076ba34.tar.gz
cuberite-4519469547c0f8befe74e3e80a94efb0e076ba34.tar.bz2
cuberite-4519469547c0f8befe74e3e80a94efb0e076ba34.tar.lz
cuberite-4519469547c0f8befe74e3e80a94efb0e076ba34.tar.xz
cuberite-4519469547c0f8befe74e3e80a94efb0e076ba34.tar.zst
cuberite-4519469547c0f8befe74e3e80a94efb0e076ba34.zip
Diffstat (limited to '')
-rw-r--r--src/Chunk.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index 8f72d7c0f..df9292fae 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -103,24 +103,9 @@ cChunk::cChunk(
cChunk::~cChunk()
{
- cPluginManager::Get()->CallHookChunkUnloaded(*m_World, m_PosX, m_PosZ);
-
// LOGINFO("### delete cChunk() (%i, %i) from %p, thread 0x%x ###", m_PosX, m_PosZ, this, GetCurrentThreadId());
- m_BlockEntities.clear();
-
- // Remove and destroy all entities that are not players:
- cEntityList Entities;
- std::swap(Entities, m_Entities); // Need another list because cEntity destructors check if they've been removed from chunk
- for (auto & Entity : Entities)
- {
- if (!Entity->IsPlayer())
- {
- // Scheduling a normal destruction is neither possible (Since this chunk will be gone till the schedule occurs) nor necessary.
- Entity->DestroyNoScheduling(false); // No point in broadcasting in an unloading chunk. Chunks unload when no one is nearby.
- }
- }
-
+ // Inform our neighbours that we're no longer valid:
if (m_NeighborXM != nullptr)
{
m_NeighborXM->m_NeighborXP = nullptr;
@@ -137,6 +122,7 @@ cChunk::~cChunk()
{
m_NeighborZP->m_NeighborZM = nullptr;
}
+
delete m_WaterSimulatorData;
m_WaterSimulatorData = nullptr;
delete m_LavaSimulatorData;
@@ -221,6 +207,25 @@ bool cChunk::CanUnloadAfterSaving(void) const
+void cChunk::OnUnload()
+{
+ // Note: this is only called during normal operation, not during shutdown
+
+ // Notify all entities of imminent unload:
+ for (auto & Entity : m_Entities)
+ {
+ // Chunks cannot be unloaded when they still contain players:
+ ASSERT(!Entity->IsPlayer());
+
+ // Notify the entity:
+ Entity->OnRemoveFromWorld(*Entity->GetWorld());
+ }
+}
+
+
+
+
+
void cChunk::MarkSaving(void)
{
m_IsSaving = true;