Issue #28: Optional usage on Disk Drive indicator was causing massive lurch in UI performance.

This commit is contained in:
Brendan Robert 2016-02-25 00:55:48 -06:00
parent 6515c90856
commit 4c308f997e
3 changed files with 25 additions and 12 deletions

View File

@ -95,12 +95,7 @@ public class Configuration implements Reconfigurable {
} }
public static Optional<ImageView> getChangedIcon() { public static Optional<ImageView> getChangedIcon() {
Optional<Image> icon = Utility.loadIcon("icon_exclaim.gif"); return Utility.loadIcon("icon_exclaim.gif").map(ImageView::new);
if (icon.isPresent()) {
return Optional.of(new ImageView(icon.get()));
} else {
return Optional.empty();
}
} }
@Override @Override

View File

@ -81,7 +81,8 @@ public class CardDiskII extends Card implements Reconfigurable, MediaConsumerPar
currentDrive = drive1; currentDrive = drive1;
drive1.reset(); drive1.reset();
drive2.reset(); drive2.reset();
EmulatorUILogic.removeIndicators(this); EmulatorUILogic.removeIndicators(drive1);
EmulatorUILogic.removeIndicators(drive2);
// Motherboard.cancelSpeedRequest(this); // Motherboard.cancelSpeedRequest(this);
} }
@ -104,13 +105,13 @@ public class CardDiskII extends Card implements Reconfigurable, MediaConsumerPar
case 0x8: case 0x8:
// drive off // drive off
currentDrive.setOn(false); currentDrive.setOn(false);
currentDrive.getIcon().ifPresent(icon->EmulatorUILogic.removeIndicator(this, icon)); currentDrive.removeIndicator();
break; break;
case 0x9: case 0x9:
// drive on // drive on
currentDrive.setOn(true); currentDrive.setOn(true);
currentDrive.getIcon().ifPresent(icon->EmulatorUILogic.addIndicator(this, icon)); currentDrive.addIndicator();
break; break;
case 0xA: case 0xA:
@ -127,9 +128,6 @@ public class CardDiskII extends Card implements Reconfigurable, MediaConsumerPar
// read/write latch // read/write latch
currentDrive.write(); currentDrive.write();
e.setNewValue(currentDrive.readLatch()); e.setNewValue(currentDrive.readLatch());
if (currentDrive.isOn()) {
currentDrive.getIcon().ifPresent(icon->EmulatorUILogic.removeIndicator(this, icon));
}
break; break;
case 0xF: case 0xF:
// write mode // write mode

View File

@ -18,6 +18,7 @@
*/ */
package jace.hardware; package jace.hardware;
import jace.EmulatorUILogic;
import jace.core.Computer; import jace.core.Computer;
import jace.library.MediaConsumer; import jace.library.MediaConsumer;
import jace.library.MediaEntry; import jace.library.MediaEntry;
@ -241,6 +242,25 @@ public class DiskIIDrive implements MediaConsumer {
public void setIcon(Optional<Label> i) { public void setIcon(Optional<Label> i) {
icon = i; icon = i;
} }
// Optionals make some things easier, but they slow down things considerably when called a lot
// This reduces the number of Optional checks when rapidly accessing the disk drive.
long lastAdded = 0;
public void addIndicator() {
long now = System.currentTimeMillis();
if (lastAdded == 0 || now - lastAdded >= 500) {
EmulatorUILogic.addIndicator(this, icon.get());
lastAdded = now;
}
}
public void removeIndicator() {
if (lastAdded > 0) {
EmulatorUILogic.removeIndicator(this, icon.get());
lastAdded = 0;
}
}
private MediaEntry currentMediaEntry; private MediaEntry currentMediaEntry;
private MediaFile currentMediaFile; private MediaFile currentMediaFile;