mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-16 18:30:32 +00:00
Adds a flags parameter to the BestEffortUpdater delegate.
On the Cocoa side, cuts Swift out of the update loop, as that seems merely to add code.
This commit is contained in:
parent
3c760e585a
commit
4de121142b
@ -80,7 +80,7 @@ void BestEffortUpdater::update_loop() {
|
||||
// Cap running at 1/5th of a second, to avoid doing a huge amount of work after any
|
||||
// brief system interruption.
|
||||
const double duration = std::min(double(integer_duration) / 1e9, 0.2);
|
||||
delegate->update(this, duration, has_skipped_);
|
||||
delegate->update(this, duration, has_skipped_, 0);
|
||||
has_skipped_ = false;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class BestEffortUpdater {
|
||||
|
||||
/// A delegate receives timing cues.
|
||||
struct Delegate {
|
||||
virtual void update(BestEffortUpdater *updater, Time::Seconds duration, bool did_skip_previous_update) = 0;
|
||||
virtual void update(BestEffortUpdater *updater, Time::Seconds duration, bool did_skip_previous_update, int flags) = 0;
|
||||
};
|
||||
|
||||
/// Sets the current delegate.
|
||||
|
@ -67,7 +67,7 @@
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
buildConfiguration = "Release"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
enableASanStackUseAfterReturn = "YES"
|
||||
|
@ -15,7 +15,6 @@ class MachineDocument:
|
||||
CSMachineDelegate,
|
||||
CSOpenGLViewDelegate,
|
||||
CSOpenGLViewResponderDelegate,
|
||||
CSBestEffortUpdaterDelegate,
|
||||
CSAudioQueueDelegate,
|
||||
CSROMReciverViewDelegate
|
||||
{
|
||||
@ -98,7 +97,6 @@ class MachineDocument:
|
||||
|
||||
bestEffortLock.lock()
|
||||
if let bestEffortUpdater = bestEffortUpdater {
|
||||
bestEffortUpdater.delegate = nil
|
||||
bestEffortUpdater.flush()
|
||||
self.bestEffortUpdater = nil
|
||||
}
|
||||
@ -221,8 +219,8 @@ class MachineDocument:
|
||||
openGLView.window!.makeKeyAndOrderFront(self)
|
||||
openGLView.window!.makeFirstResponder(openGLView)
|
||||
|
||||
// Start accepting best effort updates.
|
||||
self.bestEffortUpdater!.delegate = self
|
||||
// Start forwarding best-effort updates.
|
||||
self.bestEffortUpdater!.setMachine(machine)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,20 +9,12 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreVideo/CoreVideo.h>
|
||||
|
||||
@class CSBestEffortUpdater;
|
||||
|
||||
@protocol CSBestEffortUpdaterDelegate <NSObject>
|
||||
|
||||
- (void)bestEffortUpdater:(CSBestEffortUpdater *)bestEffortUpdater runForInterval:(NSTimeInterval)interval didSkipPreviousUpdate:(BOOL)didSkipPreviousUpdate;
|
||||
|
||||
@end
|
||||
|
||||
#import "CSMachine.h"
|
||||
|
||||
@interface CSBestEffortUpdater : NSObject
|
||||
|
||||
@property (nonatomic, weak) id<CSBestEffortUpdaterDelegate> delegate;
|
||||
|
||||
- (void)update;
|
||||
- (void)flush;
|
||||
- (void)setMachine:(CSMachine *)machine;
|
||||
|
||||
@end
|
||||
|
@ -11,38 +11,26 @@
|
||||
#include "BestEffortUpdater.hpp"
|
||||
|
||||
struct UpdaterDelegate: public Concurrency::BestEffortUpdater::Delegate {
|
||||
__weak id<CSBestEffortUpdaterDelegate> delegate;
|
||||
NSLock *delegateLock;
|
||||
__weak CSMachine *machine;
|
||||
|
||||
void update(Concurrency::BestEffortUpdater *updater, Time::Seconds cycles, bool did_skip_previous_update) {
|
||||
[delegateLock lock];
|
||||
__weak id<CSBestEffortUpdaterDelegate> delegateCopy = delegate;
|
||||
[delegateLock unlock];
|
||||
|
||||
[delegateCopy bestEffortUpdater:nil runForInterval:(NSTimeInterval)cycles didSkipPreviousUpdate:did_skip_previous_update];
|
||||
void update(Concurrency::BestEffortUpdater *updater, Time::Seconds seconds, bool did_skip_previous_update, int flags) {
|
||||
[machine runForInterval:seconds];
|
||||
}
|
||||
};
|
||||
|
||||
@implementation CSBestEffortUpdater {
|
||||
Concurrency::BestEffortUpdater _updater;
|
||||
UpdaterDelegate _updaterDelegate;
|
||||
NSLock *_delegateLock;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_delegateLock = [[NSLock alloc] init];
|
||||
_updaterDelegate.delegateLock = _delegateLock;
|
||||
_updater.set_delegate(&_updaterDelegate);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
//- (void)dealloc {
|
||||
// _updater.flush();
|
||||
//}
|
||||
|
||||
- (void)update {
|
||||
_updater.update();
|
||||
}
|
||||
@ -51,20 +39,9 @@ struct UpdaterDelegate: public Concurrency::BestEffortUpdater::Delegate {
|
||||
_updater.flush();
|
||||
}
|
||||
|
||||
- (void)setDelegate:(id<CSBestEffortUpdaterDelegate>)delegate {
|
||||
[_delegateLock lock];
|
||||
_updaterDelegate.delegate = delegate;
|
||||
[_delegateLock unlock];
|
||||
}
|
||||
|
||||
- (id<CSBestEffortUpdaterDelegate>)delegate {
|
||||
id<CSBestEffortUpdaterDelegate> delegate;
|
||||
|
||||
[_delegateLock lock];
|
||||
delegate = _updaterDelegate.delegate;
|
||||
[_delegateLock unlock];
|
||||
|
||||
return delegate;
|
||||
- (void)setMachine:(CSMachine *)machine {
|
||||
_updater.flush();
|
||||
_updaterDelegate.machine = machine;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -34,8 +34,8 @@
|
||||
namespace {
|
||||
|
||||
struct BestEffortUpdaterDelegate: public Concurrency::BestEffortUpdater::Delegate {
|
||||
void update(Concurrency::BestEffortUpdater *updater, Time::Seconds duration, bool did_skip_previous_update) override {
|
||||
machine->crt_machine()->run_for(duration);
|
||||
void update(Concurrency::BestEffortUpdater *updater, Time::Seconds duration, bool did_skip_previous_update, int flags) override {
|
||||
machine->crt_machine()->run_until(duration);
|
||||
}
|
||||
|
||||
Machine::DynamicMachine *machine;
|
||||
|
Loading…
x
Reference in New Issue
Block a user