[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx: [271] branches/fusegl/fuse/fusepb
Brought to you by:
fredm
From: <fr...@us...> - 2006-12-29 15:18:47
|
Revision: 271 http://svn.sourceforge.net/fuse-for-macosx/?rev=271&view=rev Author: fredm Date: 2006-12-29 07:18:45 -0800 (Fri, 29 Dec 2006) Log Message: ----------- Move emulation timer to DisplayController class. Modified Paths: -------------- branches/fusegl/fuse/fusepb/FuseMenus.m branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/classes.nib branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/keyedobjects.nib branches/fusegl/fuse/fusepb/views/DisplayController.h branches/fusegl/fuse/fusepb/views/DisplayController.m branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.m branches/fusegl/fuse/fusepb/views/DisplayScene.h branches/fusegl/fuse/fusepb/views/DisplayScene.m Modified: branches/fusegl/fuse/fusepb/FuseMenus.m =================================================================== --- branches/fusegl/fuse/fusepb/FuseMenus.m 2006-12-29 13:50:18 UTC (rev 270) +++ branches/fusegl/fuse/fusepb/FuseMenus.m 2006-12-29 15:18:45 UTC (rev 271) @@ -27,7 +27,7 @@ */ -#import "DisplayOpenGLView.h" +#import "DisplayController.h" #import "DisplayScene.h" #import "FuseController.h" #import "FuseMenus.h" @@ -49,17 +49,17 @@ void CreateTexture(Cocoa_Texture* new_screen) { - [[[DisplayOpenGLView instance] scene] createTexture:new_screen]; + [[DisplayScene singleton] createTexture:new_screen]; } void DestroyTexture(void) { - [[[DisplayOpenGLView instance] scene] destroyTexture]; + [[DisplayScene singleton] destroyTexture]; } void SetEmulationHz( float hz ) { - [[DisplayOpenGLView instance] setEmulationHz:hz]; + [[DisplayController singleton] setEmulationHz:hz]; } void Hide(void) Modified: branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/classes.nib =================================================================== --- branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/classes.nib 2006-12-29 13:50:18 UTC (rev 270) +++ branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/classes.nib 2006-12-29 15:18:45 UTC (rev 271) @@ -1,7 +1,12 @@ { IBClasses = ( - {CLASS = DisplayController; LANGUAGE = ObjC; SUPERCLASS = NSResponder; }, { + CLASS = DisplayController; + LANGUAGE = ObjC; + OUTLETS = {openGLView = DisplayOpenGLView; }; + SUPERCLASS = NSResponder; + }, + { CLASS = DisplayOpenGLView; LANGUAGE = ObjC; OUTLETS = {controller = NSResponder; }; Modified: branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/keyedobjects.nib =================================================================== (Binary files differ) Modified: branches/fusegl/fuse/fusepb/views/DisplayController.h =================================================================== --- branches/fusegl/fuse/fusepb/views/DisplayController.h 2006-12-29 13:50:18 UTC (rev 270) +++ branches/fusegl/fuse/fusepb/views/DisplayController.h 2006-12-29 15:18:45 UTC (rev 271) @@ -28,8 +28,17 @@ #include "input.h" +@class DisplayOpenGLView; + @interface DisplayController : NSResponder { + /* Model */ + NSTimer* timer; + CFAbsoluteTime time; + + /* Views */ + IBOutlet DisplayOpenGLView *openGLView; + GHashTable *unicode_keysyms_hash; BOOL optDown; @@ -40,7 +49,7 @@ int cocoakeyboard_symbol_shift_pressed; input_key unicode_keysym; } --(void) awakeFromNib; ++(DisplayController *) singleton; -(void) mouseMoved:(NSEvent *)theEvent; -(void) mouseDown:(NSEvent *)theEvent; @@ -57,4 +66,7 @@ -(void) keyDown:(NSEvent *)theEvent; -(void) keyUp:(NSEvent *)theEvent; +-(void) emulationTimerFired:(NSTimer *)timer; +-(void) setEmulationHz:(float)hz; + @end Modified: branches/fusegl/fuse/fusepb/views/DisplayController.m =================================================================== --- branches/fusegl/fuse/fusepb/views/DisplayController.m 2006-12-29 13:50:18 UTC (rev 270) +++ branches/fusegl/fuse/fusepb/views/DisplayController.m 2006-12-29 15:18:45 UTC (rev 271) @@ -23,6 +23,8 @@ */ #import "DisplayController.h" +#import "DisplayOpenGLView.h" +#import "DisplayScene.h" #include "event.h" #include "keyboard.h" @@ -32,17 +34,37 @@ @implementation DisplayController --(void) awakeFromNib +static DisplayController *singleton = nil; + ++ (DisplayController *)singleton { - optDown = NO; - ctrlDown = NO; - shiftDown = NO; + return singleton ? singleton : [[self alloc] init]; +} - cocoakeyboard_caps_shift_pressed = 0; - cocoakeyboard_symbol_shift_pressed = 0; - unicode_keysym = INPUT_KEY_NONE; +-(id) init +{ + if ( singleton ) { + [self dealloc]; + } else { + self = [super init]; + singleton = self; - [self initKeyboard]; + optDown = NO; + ctrlDown = NO; + shiftDown = NO; + + cocoakeyboard_caps_shift_pressed = 0; + cocoakeyboard_symbol_shift_pressed = 0; + unicode_keysym = INPUT_KEY_NONE; + + [self initKeyboard]; + + timer = nil; + + time = CFAbsoluteTimeGetCurrent(); /* set emulation time start time */ + } + + return singleton; } -(void) mouseMoved:(NSEvent *)theEvent @@ -189,4 +211,27 @@ [self keyChange:theEvent type:INPUT_EVENT_KEYRELEASE]; } +-(void) emulationTimerFired:(NSTimer *)timer +{ + CFTimeInterval nowTime = CFAbsoluteTimeGetCurrent(); + CFTimeInterval deltaTime = nowTime - time; + if (deltaTime <= 1.0) { /* skip pauses */ + DisplayScene *scene = [openGLView scene]; + [scene updateEmulationForTimeDelta:deltaTime]; + } + time = nowTime; + + [openGLView setNeedsDisplay:YES]; +} + +-(void) setEmulationHz:(float)hz +{ + [timer invalidate]; + [timer release]; + + timer = [[NSTimer scheduledTimerWithTimeInterval: (1.0f / hz) + target:self selector:@selector(emulationTimerFired:) + userInfo:self repeats:true] retain]; +} + @end Modified: branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h =================================================================== --- branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h 2006-12-29 13:50:18 UTC (rev 270) +++ branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h 2006-12-29 15:18:45 UTC (rev 271) @@ -28,24 +28,16 @@ @interface DisplayOpenGLView : NSOpenGLView { - NSTimer* timer; - CFAbsoluteTime time; - /* Model */ DisplayScene *scene; /* Controller */ IBOutlet NSResponder *controller; } -+(DisplayOpenGLView *) instance; - - (void)dealloc; - (DisplayScene *)scene; --(void) emulationTimerFired:(NSTimer *)timer; --(void) setEmulationHz:(float)hz; - -(id) initWithFrame:(NSRect)frameRect; -(void) awakeFromNib; Modified: branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.m =================================================================== --- branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.m 2006-12-29 13:50:18 UTC (rev 270) +++ branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.m 2006-12-29 15:18:45 UTC (rev 271) @@ -28,13 +28,6 @@ @implementation DisplayOpenGLView -static DisplayOpenGLView *instance = nil; - -+(DisplayOpenGLView *) instance -{ - return instance; -} - -(id) initWithFrame:(NSRect)frameRect { /* Init pixel format attribs */ @@ -52,27 +45,18 @@ exit(1); } - if ( instance ) { - [self dealloc]; - self = instance; - } else { self = [super initWithFrame:frameRect pixelFormat:pixFmt]; if (self) { - scene = [[DisplayScene alloc] init]; + scene = [DisplayScene singleton]; } - instance = self; - } [[self openGLContext] makeCurrentContext]; - timer = nil; - return self; } - (void)dealloc { - [scene release]; [super dealloc]; } @@ -85,22 +69,8 @@ { /* keep the window in the standard aspect ratio if the user resizes */ [[self window] setContentAspectRatio:NSMakeSize(4.0,3.0)]; - - time = CFAbsoluteTimeGetCurrent(); /* set emulation time start time */ } --(void) emulationTimerFired:(NSTimer *)timer -{ - CFTimeInterval nowTime = CFAbsoluteTimeGetCurrent(); - CFTimeInterval deltaTime = nowTime - time; - if (deltaTime <= 1.0) { /* skip pauses */ - [scene updateEmulationForTimeDelta:deltaTime]; - } - time = nowTime; - - [self setNeedsDisplay:YES]; -} - -(void) drawRect:(NSRect)aRect { /* Delegate to our scene object for rendering. */ @@ -117,16 +87,6 @@ [scene setViewportRect:[self bounds]]; } --(void) setEmulationHz:(float)hz -{ - [timer invalidate]; - [timer release]; - - timer = [[NSTimer scheduledTimerWithTimeInterval: (1.0f / hz) - target:self selector:@selector(emulationTimerFired:) - userInfo:self repeats:true] retain]; -} - -(void) mouseMoved:(NSEvent *)theEvent { /* Delegate to our controller object. */ Modified: branches/fusegl/fuse/fusepb/views/DisplayScene.h =================================================================== --- branches/fusegl/fuse/fusepb/views/DisplayScene.h 2006-12-29 13:50:18 UTC (rev 270) +++ branches/fusegl/fuse/fusepb/views/DisplayScene.h 2006-12-29 15:18:45 UTC (rev 271) @@ -33,6 +33,8 @@ BOOL screenTexInitialised; } ++(DisplayScene *) singleton; + -(void) setViewportRect:(NSRect)bounds; -(void) render; Modified: branches/fusegl/fuse/fusepb/views/DisplayScene.m =================================================================== --- branches/fusegl/fuse/fusepb/views/DisplayScene.m 2006-12-29 13:50:18 UTC (rev 270) +++ branches/fusegl/fuse/fusepb/views/DisplayScene.m 2006-12-29 15:18:45 UTC (rev 271) @@ -38,9 +38,29 @@ @implementation DisplayScene +static DisplayScene *singleton = nil; + ++ (DisplayScene *)singleton +{ + return singleton ? singleton : [[self alloc] init]; +} + +- (id)init +{ + if ( singleton ) { + [self dealloc]; + } else { + [super init]; + singleton = self; + } + + return singleton; +} + - (void)dealloc { [self destroyTexture]; + singleton = nil; [super dealloc]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |