Implemented controller update throttling, should fix lag issues with controllers that constantly turn off and on, fixes #1358

This commit is contained in:
raoulvdberge
2017-07-13 14:52:55 +02:00
parent d1722c5458
commit 7a41c7b0aa
2 changed files with 22 additions and 6 deletions

View File

@@ -2,6 +2,7 @@
### 1.5.10
- Converted Solderer recipes to JSON (raoulvdberge)
- Implemented controller update throttling, should fix lag issues with controllers that constantly turn off and on (raoulvdberge)
### 1.5.9
- Fixed crash relating to MCMP (raoulvdberge)

View File

@@ -108,6 +108,9 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
return nodes;
});
private static final int THROTTLE_INACTIVE_TO_ACTIVE = 20;
private static final int THROTTLE_ACTIVE_TO_INACTIVE = 4;
public static final String NBT_ENERGY = "Energy";
public static final String NBT_ENERGY_CAPACITY = "EnergyCapacity";
@@ -135,6 +138,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
private int lastEnergyDisplay;
private boolean couldRun;
private int ticksSinceUpdateChanged;
private boolean craftingMonitorUpdateRequested;
@@ -216,15 +220,26 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
energy.setEnergyStored(energy.getMaxEnergyStored());
}
if (couldRun != canRun()) {
couldRun = canRun();
boolean canRun = canRun();
if (couldRun != canRun) {
++ticksSinceUpdateChanged;
if (canRun ? (ticksSinceUpdateChanged > THROTTLE_INACTIVE_TO_ACTIVE) : (ticksSinceUpdateChanged > THROTTLE_ACTIVE_TO_INACTIVE)) {
ticksSinceUpdateChanged = 0;
couldRun = canRun;
nodeGraph.rebuild();
securityManager.rebuild();
}
} else {
ticksSinceUpdateChanged = 0;
}
if (getEnergyScaledForDisplay() != lastEnergyDisplay) {
lastEnergyDisplay = getEnergyScaledForDisplay();
int energyDisplay = getEnergyScaledForDisplay();
if (lastEnergyDisplay != energyDisplay) {
lastEnergyDisplay = energyDisplay;
RSUtils.updateBlock(world, pos);
}