mirror of
https://github.com/TomHarte/CLK.git
synced 2024-07-05 10:28:58 +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),
|
_audioOutputPositionError(0),
|
||||||
_current_pixel_line(-1),
|
_current_pixel_line(-1),
|
||||||
_use_fast_tape_hack(false),
|
_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(_key_states, 0, sizeof(_key_states));
|
||||||
memset(_palette, 0xf, sizeof(_palette));
|
memset(_palette, 0xf, sizeof(_palette));
|
||||||
@ -57,6 +57,7 @@ Machine::Machine() :
|
|||||||
|
|
||||||
void Machine::setup_output()
|
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(
|
_crt->set_rgb_sampling_function(
|
||||||
"vec4 rgb_sample(vec2 coordinate)"
|
"vec4 rgb_sample(vec2 coordinate)"
|
||||||
"{"
|
"{"
|
||||||
|
@ -58,11 +58,14 @@ class ElectronDocument: MachineDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lazy var actionLock = NSLock()
|
lazy var actionLock = NSLock()
|
||||||
|
lazy var drawLock = NSLock()
|
||||||
override func close() {
|
override func close() {
|
||||||
actionLock.lock()
|
actionLock.lock()
|
||||||
|
drawLock.lock()
|
||||||
openGLView.invalidate()
|
openGLView.invalidate()
|
||||||
openGLView.openGLContext!.makeCurrentContext()
|
openGLView.openGLContext!.makeCurrentContext()
|
||||||
actionLock.unlock()
|
actionLock.unlock()
|
||||||
|
drawLock.unlock()
|
||||||
|
|
||||||
super.close()
|
super.close()
|
||||||
}
|
}
|
||||||
@ -76,7 +79,10 @@ class ElectronDocument: MachineDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func openGLView(view: CSOpenGLView, drawViewOnlyIfDirty onlyIfDirty: Bool) {
|
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
|
// MARK: CSOpenGLViewResponderDelegate
|
||||||
|
@ -41,7 +41,12 @@ class MachineDocument: NSDocument, CSOpenGLViewDelegate, CSOpenGLViewResponderDe
|
|||||||
let cycleCount = cycleCountLow + cycleCountHigh
|
let cycleCount = cycleCountLow + cycleCountHigh
|
||||||
if let lastCycleCount = lastCycleCount {
|
if let lastCycleCount = lastCycleCount {
|
||||||
let elapsedTime = cycleCount - 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
|
lastCycleCount = cycleCount
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,10 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
|
|||||||
OSAtomicTestAndClear(activityMask, &_updateIsOngoing);
|
OSAtomicTestAndClear(activityMask, &_updateIsOngoing);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[self drawViewOnlyIfDirty:YES];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)invalidate
|
- (void)invalidate
|
||||||
|
Loading…
Reference in New Issue
Block a user