Implemented block update throttling when network turns on and off, fixes #566

This commit is contained in:
raoulvdberge
2017-06-10 19:58:56 +02:00
parent 575855a2c8
commit 34437423c4
2 changed files with 20 additions and 8 deletions

View File

@@ -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)

View File

@@ -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;
}
}