mirror of
https://github.com/TomHarte/CLK.git
synced 2024-10-11 08:23:43 +00:00
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.
This commit is contained in:
parent
5aa6da221f
commit
e885438363
@ -41,12 +41,10 @@ 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
|
||||||
// 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
|
// some actions — e.g. the host computer waking after sleep — may give us a
|
||||||
// prohibitive backlog
|
// prohibitive backlog
|
||||||
if elapsedTime < intendedCyclesPerSecond / 25 {
|
runForNumberOfCycles(max(Int32(elapsedTime), Int32(intendedCyclesPerSecond / 25)))
|
||||||
runForNumberOfCycles(Int32(elapsedTime))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lastCycleCount = cycleCount
|
lastCycleCount = cycleCount
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
@implementation CSOpenGLView {
|
@implementation CSOpenGLView {
|
||||||
CVDisplayLinkRef _displayLink;
|
CVDisplayLinkRef _displayLink;
|
||||||
uint32_t _updateIsOngoing;
|
uint32_t _updateIsOngoing;
|
||||||
int _missedFrames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)prepareOpenGL
|
- (void)prepareOpenGL
|
||||||
@ -53,28 +52,18 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
|
|||||||
|
|
||||||
- (void)drawAtTime:(const CVTimeStamp *)now
|
- (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;
|
const uint32_t activityMask = 0x01;
|
||||||
if(!OSAtomicTestAndSet(activityMask, &_updateIsOngoing))
|
if(!OSAtomicTestAndSet(activityMask, &_updateIsOngoing))
|
||||||
{
|
{
|
||||||
_missedFrames = 0;
|
|
||||||
CVTimeStamp time = *now;
|
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
|
||||||
[self.delegate openGLView:self didUpdateToTime:time];
|
|
||||||
[self drawViewOnlyIfDirty:YES];
|
[self drawViewOnlyIfDirty:YES];
|
||||||
OSAtomicTestAndClear(activityMask, &_updateIsOngoing);
|
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
|
- (void)invalidate
|
||||||
|
Loading…
Reference in New Issue
Block a user