1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-03 11:30:02 +00:00

Fixes: drop any processing backlog, try not to allow an Electron document to close mid-draw, perform a frame grab even if the emulated machine is over-processing, really really don't create a CRT until it's safe.

This commit is contained in:
Thomas Harte 2016-03-20 18:42:37 -04:00
parent fb6fb5d948
commit 902017a962
4 changed files with 19 additions and 3 deletions

View File

@ -45,7 +45,7 @@ Machine::Machine() :
_audioOutputPositionError(0),
_current_pixel_line(-1),
_use_fast_tape_hack(false),
_crt(std::unique_ptr<Outputs::CRT::CRT>(new Outputs::CRT::CRT(crt_cycles_per_line, 8, Outputs::CRT::DisplayType::PAL50, 1)))
_crt(nullptr)
{
memset(_key_states, 0, sizeof(_key_states));
memset(_palette, 0xf, sizeof(_palette));
@ -57,6 +57,7 @@ Machine::Machine() :
void Machine::setup_output()
{
_crt = std::unique_ptr<Outputs::CRT::CRT>(new Outputs::CRT::CRT(crt_cycles_per_line, 8, Outputs::CRT::DisplayType::PAL50, 1));
_crt->set_rgb_sampling_function(
"vec4 rgb_sample(vec2 coordinate)"
"{"

View File

@ -58,11 +58,14 @@ class ElectronDocument: MachineDocument {
}
lazy var actionLock = NSLock()
lazy var drawLock = NSLock()
override func close() {
actionLock.lock()
drawLock.lock()
openGLView.invalidate()
openGLView.openGLContext!.makeCurrentContext()
actionLock.unlock()
drawLock.unlock()
super.close()
}
@ -76,7 +79,10 @@ class ElectronDocument: MachineDocument {
}
override func openGLView(view: CSOpenGLView, drawViewOnlyIfDirty onlyIfDirty: Bool) {
electron.drawViewForPixelSize(view.backingSize, onlyIfDirty: onlyIfDirty)
if drawLock.tryLock() {
electron.drawViewForPixelSize(view.backingSize, onlyIfDirty: onlyIfDirty)
drawLock.unlock()
}
}
// MARK: CSOpenGLViewResponderDelegate

View File

@ -41,7 +41,12 @@ class MachineDocument: NSDocument, CSOpenGLViewDelegate, CSOpenGLViewResponderDe
let cycleCount = cycleCountLow + cycleCountHigh
if let lastCycleCount = lastCycleCount {
let elapsedTime = cycleCount - lastCycleCount
runForNumberOfCycles(Int32(elapsedTime))
// if the emulation has fallen too far behind then silently swallow the request;
// some actions e.g. the host computer waking after sleep may give us a
// prohibitive backlog
if elapsedTime < intendedCyclesPerSecond / 25 {
runForNumberOfCycles(Int32(elapsedTime))
}
}
lastCycleCount = cycleCount
}

View File

@ -62,6 +62,10 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
OSAtomicTestAndClear(activityMask, &_updateIsOngoing);
});
}
else
{
[self drawViewOnlyIfDirty:YES];
}
}
- (void)invalidate