mirror of
https://github.com/badvision/lawless-legends.git
synced 2025-01-18 04:33:00 +00:00
Timed devices lock to parent timing where possible to avoid extra delays
This commit is contained in:
parent
dcf4638e1e
commit
eb04e89708
@ -65,10 +65,16 @@ public abstract class Device implements Reconfigurable {
|
||||
return _ram;
|
||||
}
|
||||
|
||||
Device parentDevice = null;
|
||||
public Device getParent() {
|
||||
return parentDevice;
|
||||
}
|
||||
|
||||
public void addChildDevice(Device d) {
|
||||
if (d == null || children.contains(d) || d.equals(this)) {
|
||||
return;
|
||||
}
|
||||
d.parentDevice = this;
|
||||
children.add(d);
|
||||
d.attach();
|
||||
childrenArray = children.toArray(Device[]::new);
|
||||
|
@ -169,20 +169,33 @@ public abstract class TimedDevice extends Device {
|
||||
return NTSC_1MHZ;
|
||||
}
|
||||
|
||||
private boolean useParentTiming() {
|
||||
if (getParent() != null && getParent() instanceof TimedDevice) {
|
||||
TimedDevice pd = (TimedDevice) getParent();
|
||||
if (pd.useParentTiming() || (!pd.isMaxSpeed() && pd.getSpeedInHz() <= getSpeedInHz())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Long calculateResyncDelay() {
|
||||
if (!isMaxSpeed() && ++cycleTimer >= cyclesPerInterval) {
|
||||
cycleTimer = 0;
|
||||
if (++cycleTimer < cyclesPerInterval) {
|
||||
return null;
|
||||
}
|
||||
cycleTimer = 0;
|
||||
if (isMaxSpeed() || useParentTiming()) {
|
||||
if (tempSpeedDuration > 0) {
|
||||
tempSpeedDuration -= cyclesPerInterval;
|
||||
if (tempSpeedDuration <= 0) {
|
||||
disableTempMaxSpeed();
|
||||
}
|
||||
} else {
|
||||
long retVal = nextSync;
|
||||
nextSync = Math.min(nextSync + nanosPerInterval, System.nanoTime() + nanosPerInterval * 2); // Avoid drift (but not too much!
|
||||
return retVal;
|
||||
}
|
||||
nextSync += nanosPerInterval;
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
long retVal = nextSync;
|
||||
nextSync = Math.min(nextSync + nanosPerInterval, System.nanoTime() + nanosPerInterval * 2); // Avoid drift (but not too much!
|
||||
return retVal;
|
||||
}
|
||||
}
|
@ -276,7 +276,6 @@ public class CardMockingboard extends Card {
|
||||
public void resume() {
|
||||
if (DEBUG) {
|
||||
System.out.println("Resuming Mockingboard");
|
||||
Thread.dumpStack();
|
||||
}
|
||||
if (!activatedAfterReset) {
|
||||
if (DEBUG) {
|
||||
@ -300,7 +299,9 @@ public class CardMockingboard extends Card {
|
||||
}
|
||||
idleTicks = 0;
|
||||
super.resume();
|
||||
System.out.println("Resuming Mockingboard: resume completed");
|
||||
if (DEBUG) {
|
||||
System.out.println("Resuming Mockingboard: resume completed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user