EmulatorGLView posts an NSNotification rather than calls API method(s)

- Joystick connectivity polling is a consumer
This commit is contained in:
Aaron Culliney 2014-11-30 15:35:21 -08:00
parent 0f25f6d9d1
commit a6935b18c8
4 changed files with 13 additions and 12 deletions

View File

@ -9,7 +9,6 @@
// Based on sample code from https://developer.apple.com/library/mac/samplecode/GLEssentials/Introduction/Intro.html
#import "EmulatorGLView.h"
#import "EmulatorJoystickController.h"
// Apple //e common routines
#import "common.h"
@ -23,9 +22,10 @@
#define USE_DISPLAYLINK 1
#endif
#define SUPPORT_RETINA_RESOLUTION 1
const NSString *kDrawTimerNotification = @"kDrawTimerNotification";
@interface EmulatorGLView ()
#if USE_DISPLAYLINK
@ -280,7 +280,7 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
video_driver_render();
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
CGLUnlockContext([[self openGLContext] CGLContextObj]);
[[EmulatorJoystickController sharedInstance] connectivityPoll];
[[NSNotificationCenter defaultCenter] postNotificationName:(NSString *)kDrawTimerNotification object:nil];
}
- (void)dealloc

View File

@ -10,8 +10,4 @@
@interface EmulatorJoystickController : NSObject
+ (EmulatorJoystickController *)sharedInstance;
- (void)connectivityPoll;
@end

View File

@ -7,17 +7,19 @@
//
#import "EmulatorJoystickController.h"
#import <DDHidLib/DDHidJoystick.h>
#import "EmulatorWindowController.h"
#import "common.h"
#import <DDHidLib/DDHidJoystick.h>
@interface EmulatorJoystickController()
@property (nonatomic, retain) NSDictionary *allJoysticks;
+ (EmulatorJoystickController *)sharedInstance;
- (void)resetJoysticks;
@end
void gldriver_joystick_reset(void) {
EmulatorJoystickController *joystickController = [EmulatorJoystickController sharedInstance];
[joystickController resetJoysticks];
[EmulatorJoystickController sharedInstance];
}
@implementation EmulatorJoystickController
@ -39,13 +41,14 @@ void gldriver_joystick_reset(void) {
self = [super init];
if (self)
{
// ...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(connectivityPoll:) name:(NSString *)kDrawTimerNotification object:nil];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
self.allJoysticks = nil;
[super dealloc];
}
@ -87,7 +90,7 @@ void gldriver_joystick_reset(void) {
#pragma mark -
#pragma mark Joystick connectivity polling
- (void)connectivityPoll
- (void)connectivityPoll:(NSNotification *)notification
{
NSArray *joysticks = [DDHidJoystick allJoysticks];
BOOL changed = ([joysticks count] != [self.allJoysticks count]);

View File

@ -11,6 +11,8 @@
#import <Cocoa/Cocoa.h>
#import "EmulatorGLView.h"
extern const NSString *kDrawTimerNotification;
@interface EmulatorWindowController : NSWindowController
@end