summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-07-26 01:02:07 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2020-07-26 01:02:07 +0200
commitb30d70f09d8a068c32a78f85c5208ec637dee19c (patch)
treef7bbeff21abad36a35e3ab20c0c39b3e8266a644 /src
parentReduce unnecessary wakeups (diff)
downloadcuberite-b30d70f09d8a068c32a78f85c5208ec637dee19c.tar
cuberite-b30d70f09d8a068c32a78f85c5208ec637dee19c.tar.gz
cuberite-b30d70f09d8a068c32a78f85c5208ec637dee19c.tar.bz2
cuberite-b30d70f09d8a068c32a78f85c5208ec637dee19c.tar.lz
cuberite-b30d70f09d8a068c32a78f85c5208ec637dee19c.tar.xz
cuberite-b30d70f09d8a068c32a78f85c5208ec637dee19c.tar.zst
cuberite-b30d70f09d8a068c32a78f85c5208ec637dee19c.zip
Diffstat (limited to 'src')
-rw-r--r--src/BlockEntities/BlockEntityWithItems.cpp34
-rw-r--r--src/BlockEntities/ChestEntity.h56
2 files changed, 53 insertions, 37 deletions
diff --git a/src/BlockEntities/BlockEntityWithItems.cpp b/src/BlockEntities/BlockEntityWithItems.cpp
index 8dad08650..1a8ae4342 100644
--- a/src/BlockEntities/BlockEntityWithItems.cpp
+++ b/src/BlockEntities/BlockEntityWithItems.cpp
@@ -41,19 +41,27 @@ void cBlockEntityWithItems::OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum)
{
UNUSED(a_SlotNum);
ASSERT(a_Grid == &m_Contents);
- if (m_World != nullptr)
+
+ if (m_World == nullptr)
+ {
+ return;
+ }
+
+ if (GetWindow() != nullptr)
{
- if (GetWindow() != nullptr)
- {
- GetWindow()->BroadcastWholeWindow();
- }
-
- m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());
- m_World->DoWithChunkAt(m_Pos, [&](cChunk & a_Chunk)
- {
- m_World->GetRedstoneSimulator()->WakeUp(m_Pos, &a_Chunk);
- return true;
- }
- );
+ GetWindow()->BroadcastWholeWindow();
}
+
+ m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());
+ m_World->DoWithChunkAt(m_Pos, [&](cChunk & a_Chunk)
+ {
+ auto & Simulator = *m_World->GetRedstoneSimulator();
+
+ // Notify comparators:
+ Simulator.WakeUp(m_Pos + Vector3i(1, 0, 0), &a_Chunk);
+ Simulator.WakeUp(m_Pos + Vector3i(-1, 0, 0), &a_Chunk);
+ Simulator.WakeUp(m_Pos + Vector3i(0, 0, 1), &a_Chunk);
+ Simulator.WakeUp(m_Pos + Vector3i(0, 0, -1), &a_Chunk);
+ return true;
+ });
}
diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h
index 2ac0c639b..c6d13fa38 100644
--- a/src/BlockEntities/ChestEntity.h
+++ b/src/BlockEntities/ChestEntity.h
@@ -76,33 +76,41 @@ private:
/** cItemGrid::cListener overrides: */
virtual void OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) override
{
- UNUSED(a_SlotNum);
ASSERT(a_Grid == &m_Contents);
- if (m_World != nullptr)
+
+ if (m_World == nullptr)
+ {
+ return;
+ }
+
+ // Have cBlockEntityWithItems update redstone and try to broadcast our window:
+ Super::OnSlotChanged(a_Grid, a_SlotNum);
+
+ cWindow * Window = GetWindow();
+ if ((Window == nullptr) && (m_Neighbour != nullptr))
{
- cWindow * Window = GetWindow();
- if (
- (Window == nullptr) &&
- (m_Neighbour != nullptr)
- )
- {
- // Neighbour might own the window
- Window = m_Neighbour->GetWindow();
- }
-
- if (Window != nullptr)
- {
- Window->BroadcastWholeWindow();
- }
-
- m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());
- m_World->DoWithChunkAt(m_Pos, [&](cChunk & a_Chunk)
- {
- m_World->GetRedstoneSimulator()->WakeUp(m_Pos, &a_Chunk);
- return true;
- }
- );
+ // Window was null, Super will have failed.
+ // Neighbour might own the window:
+ Window = m_Neighbour->GetWindow();
}
+
+ if (Window != nullptr)
+ {
+ Window->BroadcastWholeWindow();
+ }
+
+ m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());
+ m_World->DoWithChunkAt(m_Pos, [&](cChunk & a_Chunk)
+ {
+ auto & Simulator = *m_World->GetRedstoneSimulator();
+
+ // Notify comparators:
+ Simulator.WakeUp(m_Pos + Vector3i(1, 0, 0), &a_Chunk);
+ Simulator.WakeUp(m_Pos + Vector3i(-1, 0, 0), &a_Chunk);
+ Simulator.WakeUp(m_Pos + Vector3i(0, 0, 1), &a_Chunk);
+ Simulator.WakeUp(m_Pos + Vector3i(0, 0, -1), &a_Chunk);
+ return true;
+ });
}
} ; // tolua_export