From 34437423c4377e11e7f415fb63363af6f167cfd8 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 10 Jun 2017 19:58:56 +0200 Subject: [PATCH] Implemented block update throttling when network turns on and off, fixes #566 --- CHANGELOG.md | 1 + .../apiimpl/network/node/NetworkNode.java | 27 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 174046767..0de1e639b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - You can now shift click items from the Grid crafting slots to the player inventory when the Grid is disconnected (raoulvdberge) - Added Korean translation (01QueN10) - Fixed error logs when watching a Controller when a network changes (raoulvdberge) +- Implemented block update throttling when network turns on and off (raoulvdberge) ### 1.4.11 - Removed debug log configuration option, as it's no longer needed (raoulvdberge) diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNode.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNode.java index fa8ba5125..40028a6a6 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNode.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNode.java @@ -32,6 +32,8 @@ public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor, private EnumFacing direction; private boolean couldUpdate; + private int ticksSinceUpdateChanged; + private boolean active; public NetworkNode(World world, BlockPos pos) { @@ -94,19 +96,28 @@ public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor, boolean canUpdate = getNetwork() != null && canUpdate(); if (couldUpdate != canUpdate) { - couldUpdate = canUpdate; + ++ticksSinceUpdateChanged; - if (hasConnectivityState()) { - RSUtils.updateBlock(world, pos); - } + // If we go from inactive to active, throttle for 20 ticks + // If we go from active to inactive, throttle for 4 ticks + if (canUpdate ? (ticksSinceUpdateChanged > 20) : (ticksSinceUpdateChanged > 4)) { + ticksSinceUpdateChanged = 0; + couldUpdate = canUpdate; - if (network != null) { - onConnectedStateChange(network, couldUpdate); + if (hasConnectivityState()) { + RSUtils.updateBlock(world, pos); + } - if (shouldRebuildGraphOnChange()) { - network.getNodeGraph().rebuild(); + if (network != null) { + onConnectedStateChange(network, canUpdate); + + if (shouldRebuildGraphOnChange()) { + network.getNodeGraph().rebuild(); + } } } + } else { + ticksSinceUpdateChanged = 0; } }