mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-11 08:30:55 +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:
parent
fb6fb5d948
commit
902017a962
@ -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)"
|
||||
"{"
|
||||
|
@ -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) {
|
||||
if drawLock.tryLock() {
|
||||
electron.drawViewForPixelSize(view.backingSize, onlyIfDirty: onlyIfDirty)
|
||||
drawLock.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: CSOpenGLViewResponderDelegate
|
||||
|
@ -41,8 +41,13 @@ class MachineDocument: NSDocument, CSOpenGLViewDelegate, CSOpenGLViewResponderDe
|
||||
let cycleCount = cycleCountLow + cycleCountHigh
|
||||
if let lastCycleCount = lastCycleCount {
|
||||
let elapsedTime = cycleCount - lastCycleCount
|
||||
// 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
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,10 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
|
||||
OSAtomicTestAndClear(activityMask, &_updateIsOngoing);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
[self drawViewOnlyIfDirty:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
|
Loading…
x
Reference in New Issue
Block a user