From 41c09f8c3f4c927cc517a266f941509cabfcff57 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 5 Mar 2016 14:45:09 -0500 Subject: [PATCH] Renamed CSCathodeRayView to CSOpenGLView as it no longer has any CRT-related responsibilities. It just does the GL and manages a serial dispatch queue. --- .../Clock Signal.xcodeproj/project.pbxproj | 12 +++--- .../Base.lproj/Atari2600Document.xib | 6 +-- .../Base.lproj/ElectronDocument.xib | 6 +-- .../ClockSignal-Bridging-Header.h | 3 +- .../Documents/ElectronDocument.swift | 2 +- .../Documents/MachineDocument.swift | 8 ++-- .../Mac/Clock Signal/Views/CSCathodeRayView.h | 35 ----------------- .../Mac/Clock Signal/Views/CSOpenGLView.h | 38 +++++++++++++++++++ .../{CSCathodeRayView.m => CSOpenGLView.m} | 8 ++-- .../Mac/Clock Signal/Wrappers/CSElectron.mm | 2 +- .../Mac/Clock Signal/Wrappers/CSMachine.h | 4 +- 11 files changed, 64 insertions(+), 60 deletions(-) delete mode 100644 OSBindings/Mac/Clock Signal/Views/CSCathodeRayView.h create mode 100644 OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h rename OSBindings/Mac/Clock Signal/Views/{CSCathodeRayView.m => CSOpenGLView.m} (96%) diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index f3919ab2c..06a8aad27 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -26,7 +26,7 @@ 4B55CE541C3B7ABF0093A61B /* CSElectron.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B55CE531C3B7ABF0093A61B /* CSElectron.mm */; }; 4B55CE581C3B7D360093A61B /* Atari2600Document.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B55CE561C3B7D360093A61B /* Atari2600Document.swift */; }; 4B55CE591C3B7D360093A61B /* ElectronDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B55CE571C3B7D360093A61B /* ElectronDocument.swift */; }; - 4B55CE5D1C3B7D6F0093A61B /* CSCathodeRayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55CE5C1C3B7D6F0093A61B /* CSCathodeRayView.m */; }; + 4B55CE5D1C3B7D6F0093A61B /* CSOpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55CE5C1C3B7D6F0093A61B /* CSOpenGLView.m */; }; 4B55CE5F1C3B7D960093A61B /* MachineDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B55CE5E1C3B7D960093A61B /* MachineDocument.swift */; }; 4B69FB3D1C4D908A00B5F0AA /* Tape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B69FB3B1C4D908A00B5F0AA /* Tape.cpp */; }; 4B69FB441C4D941400B5F0AA /* TapeUEF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B69FB421C4D941400B5F0AA /* TapeUEF.cpp */; }; @@ -364,8 +364,8 @@ 4B55CE531C3B7ABF0093A61B /* CSElectron.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CSElectron.mm; sourceTree = ""; }; 4B55CE561C3B7D360093A61B /* Atari2600Document.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Atari2600Document.swift; sourceTree = ""; }; 4B55CE571C3B7D360093A61B /* ElectronDocument.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ElectronDocument.swift; sourceTree = ""; }; - 4B55CE5B1C3B7D6F0093A61B /* CSCathodeRayView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSCathodeRayView.h; sourceTree = ""; }; - 4B55CE5C1C3B7D6F0093A61B /* CSCathodeRayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSCathodeRayView.m; sourceTree = ""; }; + 4B55CE5B1C3B7D6F0093A61B /* CSOpenGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSOpenGLView.h; sourceTree = ""; }; + 4B55CE5C1C3B7D6F0093A61B /* CSOpenGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSOpenGLView.m; sourceTree = ""; }; 4B55CE5E1C3B7D960093A61B /* MachineDocument.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MachineDocument.swift; sourceTree = ""; }; 4B69FB3B1C4D908A00B5F0AA /* Tape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Tape.cpp; sourceTree = ""; }; 4B69FB3C1C4D908A00B5F0AA /* Tape.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Tape.hpp; sourceTree = ""; }; @@ -800,8 +800,8 @@ 4B55CE5A1C3B7D6F0093A61B /* Views */ = { isa = PBXGroup; children = ( - 4B55CE5B1C3B7D6F0093A61B /* CSCathodeRayView.h */, - 4B55CE5C1C3B7D6F0093A61B /* CSCathodeRayView.m */, + 4B55CE5B1C3B7D6F0093A61B /* CSOpenGLView.h */, + 4B55CE5C1C3B7D6F0093A61B /* CSOpenGLView.m */, ); path = Views; sourceTree = ""; @@ -1632,7 +1632,7 @@ 4B2E2D9D1C3A070400138695 /* Electron.cpp in Sources */, 4B2039991C67FA92001375C3 /* Shader.cpp in Sources */, 4B69FB3D1C4D908A00B5F0AA /* Tape.cpp in Sources */, - 4B55CE5D1C3B7D6F0093A61B /* CSCathodeRayView.m in Sources */, + 4B55CE5D1C3B7D6F0093A61B /* CSOpenGLView.m in Sources */, 4B2E2D9A1C3A06EC00138695 /* Atari2600.cpp in Sources */, 4B14145B1B58879D00E04248 /* CPU6502.cpp in Sources */, 4BB73EA21B587A5100552FC2 /* AppDelegate.swift in Sources */, diff --git a/OSBindings/Mac/Clock Signal/Base.lproj/Atari2600Document.xib b/OSBindings/Mac/Clock Signal/Base.lproj/Atari2600Document.xib index a98c860c9..b0920d364 100644 --- a/OSBindings/Mac/Clock Signal/Base.lproj/Atari2600Document.xib +++ b/OSBindings/Mac/Clock Signal/Base.lproj/Atari2600Document.xib @@ -1,7 +1,7 @@ - + - + @@ -23,7 +23,7 @@ - + diff --git a/OSBindings/Mac/Clock Signal/Base.lproj/ElectronDocument.xib b/OSBindings/Mac/Clock Signal/Base.lproj/ElectronDocument.xib index a98c860c9..b0920d364 100644 --- a/OSBindings/Mac/Clock Signal/Base.lproj/ElectronDocument.xib +++ b/OSBindings/Mac/Clock Signal/Base.lproj/ElectronDocument.xib @@ -1,7 +1,7 @@ - + - + @@ -23,7 +23,7 @@ - + diff --git a/OSBindings/Mac/Clock Signal/ClockSignal-Bridging-Header.h b/OSBindings/Mac/Clock Signal/ClockSignal-Bridging-Header.h index 1ad92dd77..552a4cbd4 100644 --- a/OSBindings/Mac/Clock Signal/ClockSignal-Bridging-Header.h +++ b/OSBindings/Mac/Clock Signal/ClockSignal-Bridging-Header.h @@ -5,5 +5,6 @@ #import "CSMachine.h" #import "CSAtari2600.h" #import "CSElectron.h" -#import "CSCathodeRayView.h" + +#import "CSOpenGLView.h" #import "AudioQueue.h" diff --git a/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift b/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift index f68fb0019..289032701 100644 --- a/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/ElectronDocument.swift @@ -75,7 +75,7 @@ class ElectronDocument: MachineDocument { } } - override func openGLView(view: CSCathodeRayView, drawViewOnlyIfDirty onlyIfDirty: Bool) { + override func openGLView(view: CSOpenGLView, drawViewOnlyIfDirty onlyIfDirty: Bool) { electron.drawViewForPixelSize(view.backingSize, onlyIfDirty: onlyIfDirty) } diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index e1f14f833..3bb2ebac5 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -9,9 +9,9 @@ import Cocoa import AudioToolbox -class MachineDocument: NSDocument, CSCathodeRayViewDelegate, CSCathodeRayViewResponderDelegate { +class MachineDocument: NSDocument, CSOpenGLViewDelegate, CSOpenGLViewResponderDelegate { - @IBOutlet weak var openGLView: CSCathodeRayView! { + @IBOutlet weak var openGLView: CSOpenGLView! { didSet { openGLView.delegate = self openGLView.responderDelegate = self @@ -29,7 +29,7 @@ class MachineDocument: NSDocument, CSCathodeRayViewDelegate, CSCathodeRayViewRes var intendedCyclesPerSecond: Int64 = 0 private var lastCycleCount: Int64? - final func openGLView(view: CSCathodeRayView, didUpdateToTime time: CVTimeStamp) { + final func openGLView(view: CSOpenGLView, didUpdateToTime time: CVTimeStamp) { // TODO: treat time as a delta from old time, work out how many cycles that is plus error // this slightly elaborate dance is to avoid overflow @@ -46,7 +46,7 @@ class MachineDocument: NSDocument, CSCathodeRayViewDelegate, CSCathodeRayViewRes lastCycleCount = cycleCount } - func openGLView(view: CSCathodeRayView, drawViewOnlyIfDirty onlyIfDirty: Bool) {} + func openGLView(view: CSOpenGLView, drawViewOnlyIfDirty onlyIfDirty: Bool) {} func runForNumberOfCycles(numberOfCycles: Int32) {} // MARK: CSOpenGLViewResponderDelegate diff --git a/OSBindings/Mac/Clock Signal/Views/CSCathodeRayView.h b/OSBindings/Mac/Clock Signal/Views/CSCathodeRayView.h deleted file mode 100644 index a463953d5..000000000 --- a/OSBindings/Mac/Clock Signal/Views/CSCathodeRayView.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// OpenGLView.h -// Clock Signal -// -// Created by Thomas Harte on 16/07/2015. -// Copyright © 2015 Thomas Harte. All rights reserved. -// - -#import -#import - -@class CSCathodeRayView; - -@protocol CSCathodeRayViewDelegate -- (void)openGLView:(nonnull CSCathodeRayView *)view didUpdateToTime:(CVTimeStamp)time; -- (void)openGLView:(nonnull CSCathodeRayView *)view drawViewOnlyIfDirty:(BOOL)onlyIfDirty; -@end - -@protocol CSCathodeRayViewResponderDelegate -- (void)keyDown:(nonnull NSEvent *)event; -- (void)keyUp:(nonnull NSEvent *)event; -- (void)flagsChanged:(nonnull NSEvent *)newModifiers; -@end - - -@interface CSCathodeRayView : NSOpenGLView - -@property (nonatomic, weak) id delegate; -@property (nonatomic, weak) id responderDelegate; - -- (void)invalidate; - -@property (nonatomic, readonly) CGSize backingSize; - -@end diff --git a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h new file mode 100644 index 000000000..78ed6867b --- /dev/null +++ b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h @@ -0,0 +1,38 @@ +// +// CSOpenGLView.h +// Clock Signal +// +// Created by Thomas Harte on 16/07/2015. +// Copyright © 2015 Thomas Harte. All rights reserved. +// + +#import +#import + +@class CSOpenGLView; + +@protocol CSOpenGLViewDelegate +- (void)openGLView:(nonnull CSOpenGLView *)view didUpdateToTime:(CVTimeStamp)time; +- (void)openGLView:(nonnull CSOpenGLView *)view drawViewOnlyIfDirty:(BOOL)onlyIfDirty; +@end + +@protocol CSOpenGLViewResponderDelegate +- (void)keyDown:(nonnull NSEvent *)event; +- (void)keyUp:(nonnull NSEvent *)event; +- (void)flagsChanged:(nonnull NSEvent *)newModifiers; +@end + +/*! + Provides an OpenGL canvas with a refresh-linked update timer and manages a serial dispatch queue + such that a delegate may produce video and respond to keyboard events. +*/ +@interface CSOpenGLView : NSOpenGLView + +@property (nonatomic, weak) id delegate; +@property (nonatomic, weak) id responderDelegate; + +- (void)invalidate; + +@property (nonatomic, readonly) CGSize backingSize; + +@end diff --git a/OSBindings/Mac/Clock Signal/Views/CSCathodeRayView.m b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m similarity index 96% rename from OSBindings/Mac/Clock Signal/Views/CSCathodeRayView.m rename to OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m index f4ddccf97..6097bfb10 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSCathodeRayView.m +++ b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.m @@ -1,12 +1,12 @@ // -// CSCathodeRayView.m +// CSOpenGLView // CLK // // Created by Thomas Harte on 16/07/2015. // Copyright © 2015 Thomas Harte. All rights reserved. // -#import "CSCathodeRayView.h" +#import "CSOpenGLView.h" @import CoreVideo; @import GLKit; @@ -15,7 +15,7 @@ typedef NS_ENUM(NSInteger, CSOpenGLViewCondition) { CSOpenGLViewConditionUpdating }; -@implementation CSCathodeRayView { +@implementation CSOpenGLView { CVDisplayLinkRef _displayLink; NSConditionLock *_runningLock; dispatch_queue_t _dispatchQueue; @@ -55,7 +55,7 @@ typedef NS_ENUM(NSInteger, CSOpenGLViewCondition) { static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *now, const CVTimeStamp *outputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext) { - CSCathodeRayView *view = (__bridge CSCathodeRayView *)displayLinkContext; + CSOpenGLView *view = (__bridge CSOpenGLView *)displayLinkContext; [view drawAtTime:now]; return kCVReturnSuccess; } diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm index cc17d6ae4..a24c5f788 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm @@ -54,7 +54,7 @@ return YES; } -- (void)setView:(CSCathodeRayView *)view { +- (void)setView:(CSOpenGLView *)view { [super setView:view]; } diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h index e75f14bfb..f2f50fd26 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h @@ -7,7 +7,7 @@ // #import -#import "CSCathodeRayView.h" +#import "CSOpenGLView.h" #import "AudioQueue.h" @interface CSMachine : NSObject @@ -15,7 +15,7 @@ - (void)runForNumberOfCycles:(int)numberOfCycles; - (void)sync; -@property (nonatomic, weak) CSCathodeRayView *view; +@property (nonatomic, weak) CSOpenGLView *view; @property (nonatomic, weak) AudioQueue *audioQueue; @end