bsnes/hiro/cocoa/timer.cpp
Tim Allen 653bb378ee Update to v096r03 release.
byuu says:

Changelog:
- fixed icarus to save settings properly
- fixed higan's full screen toggle on OS X
- increased "Add Codes" button width to avoid text clipping
- implemented cocoa/canvas.cpp
- added 1s delay after mapping inputs before re-enabling the window
  (wasn't actually necessary, but already added it)
- fixed setEnabled(false) on Cocoa's ListView and TextEdit widgets
- updated nall::programpath() to use GetModuleFileName on Windows
- GB: system uses open collector logic, so unmapped reads return 0xFF,
  not 0x00 (passes blargg's cpu_instrs again) [gekkio]
2016-01-08 20:23:46 +11:00

67 lines
1.1 KiB
C++

#if defined(Hiro_Timer)
@implementation CocoaTimer : NSObject
-(id) initWith:(hiro::mTimer&)timerReference {
if(self = [super init]) {
timer = &timerReference;
instance = nil;
}
return self;
}
-(NSTimer*) instance {
return instance;
}
-(void) update {
if(instance) {
[instance invalidate];
instance = nil;
}
if(timer->enabled()) {
instance = [NSTimer
scheduledTimerWithTimeInterval:timer->state.interval / 1000.0
target:self selector:@selector(run:) userInfo:nil repeats:YES
];
}
}
-(void) run:(NSTimer*)instance {
if(timer->enabled()) {
timer->doActivate();
}
}
@end
namespace hiro {
auto pTimer::construct() -> void {
@autoreleasepool {
cocoaTimer = [[CocoaTimer alloc] initWith:self()];
}
}
auto pTimer::destruct() -> void {
@autoreleasepool {
if([cocoaTimer instance]) [[cocoaTimer instance] invalidate];
[cocoaTimer release];
}
}
auto pTimer::setEnabled(bool enabled) -> void {
@autoreleasepool {
[cocoaTimer update];
}
}
auto pTimer::setInterval(uint interval) -> void {
@autoreleasepool {
[cocoaTimer update];
}
}
}
#endif