From e885438363a8a947b3066266eee62dd9e084f4ce Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 6 Apr 2016 19:34:34 -0400 Subject: [PATCH] The penny has finally dropped that I can drive the CPU stuff in a manner completely decoupled from the GPU stuff. For much improved parallelisation. --- .../Documents/MachineDocument.swift | 6 ++---- .../Mac/Clock Signal/Views/CSOpenGLView.m | 19 ++++--------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index 062a69158..cc72a643f 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -41,12 +41,10 @@ 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; + // if the emulation has fallen too far behind then silently limit 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)) - } + runForNumberOfCycles(max(Int32(elapsedTime), Int32(intendedCyclesPerSecond / 25))) } lastCycleCount = cycleCount } diff --git a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m index 3514e9001..5f50e1ec8 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m +++ b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m @@ -13,7 +13,6 @@ @implementation CSOpenGLView { CVDisplayLinkRef _displayLink; uint32_t _updateIsOngoing; - int _missedFrames; } - (void)prepareOpenGL @@ -53,28 +52,18 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt - (void)drawAtTime:(const CVTimeStamp *)now { + // Always post a -didUpdateToTime:. This is the hook upon which the substantial processing occurs. + [self.delegate openGLView:self didUpdateToTime:*now]; + + // Draw the display only if a previous draw is not still ongoing. const uint32_t activityMask = 0x01; if(!OSAtomicTestAndSet(activityMask, &_updateIsOngoing)) { - _missedFrames = 0; - CVTimeStamp time = *now; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ - [self.delegate openGLView:self didUpdateToTime:time]; [self drawViewOnlyIfDirty:YES]; OSAtomicTestAndClear(activityMask, &_updateIsOngoing); }); } - else - { - _missedFrames++; - if(_missedFrames == 10) - { - _missedFrames = 0; - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ - [self drawViewOnlyIfDirty:YES]; - }); - } - } } - (void)invalidate