forked from Apple-2-Tools/jace
Issue #28: Optional usage on Disk Drive indicator was causing massive lurch in UI performance.
This commit is contained in:
parent
6515c90856
commit
4c308f997e
@ -95,12 +95,7 @@ public class Configuration implements Reconfigurable {
|
||||
}
|
||||
|
||||
public static Optional<ImageView> getChangedIcon() {
|
||||
Optional<Image> icon = Utility.loadIcon("icon_exclaim.gif");
|
||||
if (icon.isPresent()) {
|
||||
return Optional.of(new ImageView(icon.get()));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Utility.loadIcon("icon_exclaim.gif").map(ImageView::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,7 +81,8 @@ public class CardDiskII extends Card implements Reconfigurable, MediaConsumerPar
|
||||
currentDrive = drive1;
|
||||
drive1.reset();
|
||||
drive2.reset();
|
||||
EmulatorUILogic.removeIndicators(this);
|
||||
EmulatorUILogic.removeIndicators(drive1);
|
||||
EmulatorUILogic.removeIndicators(drive2);
|
||||
// Motherboard.cancelSpeedRequest(this);
|
||||
}
|
||||
|
||||
@ -104,13 +105,13 @@ public class CardDiskII extends Card implements Reconfigurable, MediaConsumerPar
|
||||
case 0x8:
|
||||
// drive off
|
||||
currentDrive.setOn(false);
|
||||
currentDrive.getIcon().ifPresent(icon->EmulatorUILogic.removeIndicator(this, icon));
|
||||
currentDrive.removeIndicator();
|
||||
break;
|
||||
|
||||
case 0x9:
|
||||
// drive on
|
||||
currentDrive.setOn(true);
|
||||
currentDrive.getIcon().ifPresent(icon->EmulatorUILogic.addIndicator(this, icon));
|
||||
currentDrive.addIndicator();
|
||||
break;
|
||||
|
||||
case 0xA:
|
||||
@ -127,9 +128,6 @@ public class CardDiskII extends Card implements Reconfigurable, MediaConsumerPar
|
||||
// read/write latch
|
||||
currentDrive.write();
|
||||
e.setNewValue(currentDrive.readLatch());
|
||||
if (currentDrive.isOn()) {
|
||||
currentDrive.getIcon().ifPresent(icon->EmulatorUILogic.removeIndicator(this, icon));
|
||||
}
|
||||
break;
|
||||
case 0xF:
|
||||
// write mode
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package jace.hardware;
|
||||
|
||||
import jace.EmulatorUILogic;
|
||||
import jace.core.Computer;
|
||||
import jace.library.MediaConsumer;
|
||||
import jace.library.MediaEntry;
|
||||
@ -241,6 +242,25 @@ public class DiskIIDrive implements MediaConsumer {
|
||||
public void setIcon(Optional<Label> 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 MediaFile currentMediaFile;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user