diff --git a/src/main/java/li/cil/oc2/common/bus/CommonDeviceBusController.java b/src/main/java/li/cil/oc2/common/bus/CommonDeviceBusController.java index fbe23046..210f931a 100644 --- a/src/main/java/li/cil/oc2/common/bus/CommonDeviceBusController.java +++ b/src/main/java/li/cil/oc2/common/bus/CommonDeviceBusController.java @@ -34,7 +34,7 @@ public class CommonDeviceBusController implements DeviceBusController { /////////////////////////////////////////////////////////////////// public final Event onAfterBusScan = new Event(); - public final Event onBeforeScan = new Event(); + public final Event onBeforeDeviceScan = new Event(); public final ParameterizedEvent onAfterDeviceScan = new ParameterizedEvent<>(); public final ParameterizedEvent onDevicesAdded = new ParameterizedEvent<>(); public final ParameterizedEvent onDevicesRemoved = new ParameterizedEvent<>(); @@ -90,7 +90,7 @@ public class CommonDeviceBusController implements DeviceBusController { @Override public void scanDevices() { - onBeforeScan(); + onBeforeDeviceScan(); final HashSet newDevices = new HashSet<>(); final HashMap> newDeviceIds = new HashMap<>(); @@ -238,8 +238,8 @@ public class CommonDeviceBusController implements DeviceBusController { onAfterBusScan.run(); } - protected void onBeforeScan() { - onBeforeScan.run(); + protected void onBeforeDeviceScan() { + onBeforeDeviceScan.run(); } protected void onAfterDeviceScan(final boolean didDevicesChange) { diff --git a/src/main/java/li/cil/oc2/common/vm/AbstractVirtualMachine.java b/src/main/java/li/cil/oc2/common/vm/AbstractVirtualMachine.java index bd2f7dfc..11b52b45 100644 --- a/src/main/java/li/cil/oc2/common/vm/AbstractVirtualMachine.java +++ b/src/main/java/li/cil/oc2/common/vm/AbstractVirtualMachine.java @@ -65,7 +65,7 @@ public abstract class AbstractVirtualMachine implements VirtualMachine { public AbstractVirtualMachine(final CommonDeviceBusController busController) { this.busController = busController; - busController.onBeforeScan.add(this::handleBeforeScan); + busController.onBeforeDeviceScan.add(this::handleBeforeDeviceScan); busController.onAfterDeviceScan.add(this::handleAfterDeviceScan); busController.onDevicesAdded.add(this::handleDevicesAdded); busController.onDevicesRemoved.add(this::handleDevicesRemoved); @@ -167,21 +167,6 @@ public abstract class AbstractVirtualMachine implements VirtualMachine { stopRunnerAndReset(); } - public void pauseAndReload() { - state.rpcAdapter.pause(); - - // This is typically called when a device bus starts a scan. Since scans - // can be delayed we must adjust our run state accordingly, to avoid - // running before the scan finishes. - if (runState == VMRunState.RUNNING) { - runState = VMRunState.LOADING_DEVICES; - } - } - - public void resume(final boolean didDevicesChange) { - state.rpcAdapter.resume(busController, didDevicesChange); - } - public void tick() { busController.scan(); setBusState(busController.getState()); @@ -390,12 +375,18 @@ public abstract class AbstractVirtualMachine implements VirtualMachine { handleBootErrorChanged(value); } - private void handleBeforeScan() { - pauseAndReload(); + private void handleBeforeDeviceScan() { + state.rpcAdapter.pause(); + + // Since scans can be delayed we must adjust our run state accordingly, to avoid + // running before the scan finishes. + if (runState == VMRunState.RUNNING) { + runState = VMRunState.LOADING_DEVICES; + } } private void handleAfterDeviceScan(final CommonDeviceBusController.AfterDeviceScanEvent event) { - resume(event.didDevicesChange()); + state.rpcAdapter.resume(busController, event.didDevicesChange()); } private void handleDevicesAdded(final CommonDeviceBusController.DevicesChangedEvent event) {