Skip to content

Commit

Permalink
#35 added mode to try spent less cpu resources for emulation (deactiv…
Browse files Browse the repository at this point in the history
…ated by default)
  • Loading branch information
raydac committed Feb 25, 2023
1 parent d68e6c7 commit ef6d8c0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
10 changes: 9 additions & 1 deletion zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/MainForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public String getDescription() {
private final AtomicReference<AnimationEncoder> currentAnimationEncoder = new AtomicReference<>();
private final Motherboard board;
private final ZxVideoStreamer videoStreamer;
private final Timer wallClock = new Timer(TIMER_INT_DELAY_MILLISECONDS, Duration.ofNanos(50000L));
private final Timer wallClock;
private final Runnable traceWindowsUpdater = new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -386,6 +386,14 @@ public void run() {

public MainForm(final MainFormParameters parameters) {
super(parameters.getTitle());

if (AppOptions.getInstance().isTryLessResources()) {
LOGGER.info("Less resources mode is active");
this.wallClock = new Timer(TIMER_INT_DELAY_MILLISECONDS, Duration.ofNanos(50000L));
} else {
this.wallClock = new Timer(TIMER_INT_DELAY_MILLISECONDS);
}

this.setUndecorated(parameters.isUndecorated());
Runtime.getRuntime().addShutdownHook(new Thread(this::doOnShutdown));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ public class OptionsPanel extends JTabbedPane {
private JLabel labelCustomRomPath;
private JLabel labelMacroCursorKeys;
private JLabel labelTimingProfile;
private JLabel labelTryLessResources;
private JLabel labelBorderWidth;
private JLabel labelEmulateFFport;
private JCheckBox checkGrabSound;
private JCheckBox checkTryLessResources;
private JCheckBox checkInterlacedScan;
private JCheckBox checkSoundSchemeACB;
private JCheckBox checkSyncPaint;
Expand Down Expand Up @@ -198,6 +200,7 @@ private void initComponents() {
labelInterlacedScan = new JLabel();
labelOldTvFilter = new JLabel();
labelTimingProfile = new JLabel();
labelTryLessResources = new JLabel();
labelBorderWidth = new JLabel();
checkInterlacedScan = new JCheckBox();
labelFfMpegPath = new JLabel();
Expand Down Expand Up @@ -235,6 +238,7 @@ private void initComponents() {
checkAutoiCsForCursorKeys = new JCheckBox();
checkSyncPaint = new JCheckBox();
checkOldTvFilter = new JCheckBox();
checkTryLessResources = new JCheckBox();
checkVkbdApart = new JCheckBox();
comboKeyboardLook = new JComboBox<>(VirtualKeyboardLook.values());
comboVolumeProfile = new JComboBox<>(VolumeProfile.values());
Expand Down Expand Up @@ -623,6 +627,20 @@ private void initComponents() {
gridBagConstraints.anchor = GridBagConstraints.WEST;
panelGeneral.add(comboTimingProfile, gridBagConstraints);

labelTryLessResources.setHorizontalAlignment(RIGHT);
labelTryLessResources.setText("Try use less resources:");
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 12;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
panelGeneral.add(labelTryLessResources, gridBagConstraints);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 12;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = GridBagConstraints.WEST;
panelGeneral.add(checkTryLessResources, gridBagConstraints);

final JPanel panelKempston = new JPanel(new GridBagLayout());
panelKempston.setBorder(createTitledBorder("Kempston joystick"));

Expand Down Expand Up @@ -753,6 +771,7 @@ public static final class DataContainer {
public final boolean vkdApart;
public final boolean autoCsForCursorKeys;
public final boolean interlacedScan;
public final boolean tryLessResources;
public final boolean syncPaint;
public final boolean oldTvFilter;
public final boolean emulateFFport;
Expand All @@ -779,6 +798,7 @@ public DataContainer() {
this.timingProfile = AppOptions.getInstance().getTimingProfile();
this.customRomPath = customRomPath == null ? "" : customRomPath;
this.interlacedScan = AppOptions.getInstance().isInterlacedScan();
this.tryLessResources = AppOptions.getInstance().isTryLessResources();
this.oldTvFilter = AppOptions.getInstance().isOldColorTvOnStart();
this.soundSchemeAcb = AppOptions.getInstance().isSoundChannelsACB();
this.autoCsForCursorKeys = AppOptions.getInstance().getAutoCsForCursorKeys();
Expand Down Expand Up @@ -820,6 +840,7 @@ public DataContainer(final OptionsPanel optionsPanel) {
this.customRomPath = optionsPanel.textCustomRomPath.getText();

this.interlacedScan = optionsPanel.checkInterlacedScan.isSelected();
this.tryLessResources = optionsPanel.checkTryLessResources.isSelected();
this.oldTvFilter = optionsPanel.checkOldTvFilter.isSelected();

this.syncPaint = optionsPanel.checkSyncPaint.isSelected();
Expand Down Expand Up @@ -860,6 +881,7 @@ public void store() {
AppOptions.getInstance().setTimingProfile(this.timingProfile);
AppOptions.getInstance().setBorderWidth(this.borderWidth);
AppOptions.getInstance().setInterlacedScan(this.interlacedScan);
AppOptions.getInstance().setTryLessResources(this.tryLessResources);
AppOptions.getInstance().setOldColorTvOnStart(this.oldTvFilter);
AppOptions.getInstance().setAutoCsForCursorKeys(this.autoCsForCursorKeys);
AppOptions.getInstance().setCustomRomPath(this.customRomPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,18 @@ public synchronized boolean isInterlacedScan() {
return preferences.getBoolean(Option.INTERLACED_SCAN.name(), true);
}

public synchronized boolean isTryLessResources() {
return preferences.getBoolean(Option.TRY_LESS_RESOURCES.name(), false);
}

public synchronized void setInterlacedScan(final boolean value) {
preferences.putBoolean(Option.INTERLACED_SCAN.name(), value);
}

public synchronized void setTryLessResources(final boolean value) {
preferences.putBoolean(Option.TRY_LESS_RESOURCES.name(), value);
}

public synchronized int getFrameRate() {
return preferences.getInt(Option.STREAM_FRAMERATE.name(), 25);
}
Expand Down Expand Up @@ -537,7 +545,8 @@ public enum Option {
PROTEK_JOYSTICK_VK_DOWN,
PROTEK_JOYSTICK_VK_FIRE,
ATTRIBUTE_PORT_FF,
ULAPLUS
ULAPLUS,
TRY_LESS_RESOURCES;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public void next(final Duration delay) {
}

public void sleep() {
if (this.sleepDelay < 0L) {
Thread.onSpinWait();
} else {
if (this.sleepDelay > 0L) {
final long nanos = this.timeout - System.nanoTime();
if (nanos > this.sleepDelay) {
LockSupport.parkNanos(this.sleepDelay);
Expand Down

0 comments on commit ef6d8c0

Please sign in to comment.