1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-31 09:37:56 +00:00

Don't propagate redstone when blink/label changes

Historically, computers tracked whether any world-visible state
(on/off/blinking, label and redstone outputs) had changed with a single
"has changed" flag. While this is simple to use, this has the curious
side effect of that term.setCursorBlink() or os.setComputerLabel() would
cause a block update!

This isn't really a problem in practice - it just means slightly more
block updates. However, the redstone propagation sometimes causes the
computer to invalidate/recheck peripherals, which masks several other
(yet unfixed) bugs.
This commit is contained in:
Jonathan Coates
2024-03-06 18:56:40 +00:00
parent 6e374579a4
commit d38b1da974
12 changed files with 115 additions and 77 deletions

View File

@@ -30,6 +30,7 @@ import org.teavm.jso.typedarrays.ArrayBuffer;
import javax.annotation.Nullable;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Objects;
/**
* Manages the core lifecycle of an emulated {@link Computer}.
@@ -47,6 +48,9 @@ class EmulatedComputer implements ComputerEnvironment, ComputerHandle {
private boolean disposed = false;
private final MemoryMount mount = new MemoryMount();
private @Nullable String oldLabel;
private boolean oldOn;
EmulatedComputer(ComputerContext context, ComputerDisplay computerAccess) {
this.computerAccess = computerAccess;
this.computer = new Computer(context, this, terminal, 0);
@@ -68,8 +72,10 @@ class EmulatedComputer implements ComputerEnvironment, ComputerHandle {
LOG.error("Error when ticking computer", e);
}
if (computer.pollAndResetChanged()) {
computerAccess.setState(computer.getLabel(), computer.isOn());
var newLabel = computer.getLabel();
var newOn = computer.isOn();
if (!Objects.equals(oldLabel, newLabel) || oldOn != newOn) {
computerAccess.setState(oldLabel = newLabel, oldOn = newOn);
}
for (var side : SIDES) {