1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-16 11:30:22 +00:00

Prevents an endless queue of backlogged updates.

This commit is contained in:
Thomas Harte 2020-02-03 22:08:07 -05:00
parent cf9729c74f
commit 96769c52f6

View File

@ -25,6 +25,7 @@
#import "NSBundle+DataResource.h" #import "NSBundle+DataResource.h"
#import "NSData+StdVector.h" #import "NSData+StdVector.h"
#include <atomic>
#include <bitset> #include <bitset>
#import <OpenGL/OpenGL.h> #import <OpenGL/OpenGL.h>
@ -152,6 +153,7 @@ struct ActivityObserver: public Activity::Observer {
CSHighPrecisionTimer *_timer; CSHighPrecisionTimer *_timer;
CGSize _pixelSize; CGSize _pixelSize;
std::atomic_flag is_updating;
std::unique_ptr<Outputs::Display::OpenGL::ScanTarget> _scanTarget; std::unique_ptr<Outputs::Display::OpenGL::ScanTarget> _scanTarget;
} }
@ -205,6 +207,7 @@ struct ActivityObserver: public Activity::Observer {
_speakerDelegate.machineAccessLock = _delegateMachineAccessLock; _speakerDelegate.machineAccessLock = _delegateMachineAccessLock;
_joystickMachine = _machine->joystick_machine(); _joystickMachine = _machine->joystick_machine();
is_updating.clear();
} }
return self; return self;
} }
@ -705,11 +708,12 @@ struct ActivityObserver: public Activity::Observer {
} }
- (void)openGLViewDisplayLinkDidFire:(CSOpenGLView *)view { - (void)openGLViewDisplayLinkDidFire:(CSOpenGLView *)view {
CGSize pixelSize = view.backingSize;
@synchronized(self) { @synchronized(self) {
_pixelSize = view.backingSize; _pixelSize = pixelSize;
} }
[self.view performWithGLContext:^{ [self.view performWithGLContext:^{
self->_scanTarget->draw((int)self->_pixelSize.width, (int)self->_pixelSize.height); self->_scanTarget->draw((int)pixelSize.width, (int)pixelSize.height);
} flushDrawable:YES]; } flushDrawable:YES];
} }
@ -721,11 +725,14 @@ struct ActivityObserver: public Activity::Observer {
pixelSize = self->_pixelSize; pixelSize = self->_pixelSize;
} }
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ if(!self->is_updating.test_and_set()) {
[self.view performWithGLContext:^{ dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
self->_scanTarget->update((int)pixelSize.width, (int)pixelSize.height); [self.view performWithGLContext:^{
} flushDrawable:NO]; self->_scanTarget->update((int)pixelSize.width, (int)pixelSize.height);
}); } flushDrawable:NO];
self->is_updating.clear();
});
}
} interval:2500000]; } interval:2500000];
} }