Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
GameController Class Reference

#include <GameController.h>

+ Inheritance diagram for GameController:
+ Collaboration diagram for GameController:

Instance Methods

(void) - applicationDidFinishLaunching:
 
(BOOL) - isGamePaused
 
(void) - setGamePaused:
 
(OOMouseInteractionMode- mouseInteractionMode
 
(void) - setMouseInteractionMode:
 
(void) - setMouseInteractionModeForFlight
 
(void) - setMouseInteractionModeForUIWithMouseInteraction:
 
(void) - performGameTick:
 
(IBAction) - showLogAction:
 
(IBAction) - showLogFolderAction:
 
(IBAction) - showSnapshotsAction:
 
(IBAction) - showAddOnsAction:
 
(void) - recenterVirtualJoystick
 
(void) - exitAppWithContext:
 
(void) - exitAppCommandQ
 
(NSString *) - playerFileToLoad
 
(void) - setPlayerFileToLoad:
 
(NSString *) - playerFileDirectory
 
(void) - setPlayerFileDirectory:
 
(void) - loadPlayerIfRequired
 
(void) - beginSplashScreen
 
(void) - logProgress:
 
(void) - endSplashScreen
 
(void) - startAnimationTimer
 
(void) - stopAnimationTimer
 
(MyOpenGLView *) - gameView
 
(void) - setGameView:
 
(void) - windowDidResize:
 
(void) - setUpBasicOpenGLStateWithSize:
 
(NSURL *) - snapshotsURLCreatingIfNeeded:
 
(id) - init [implementation]
 
(void) - dealloc [implementation]
 
(void) - doPerformGameTick [implementation]
 
(BOOL) - isDirectoryAtPath: [implementation]
 
(BOOL) - addOnsExistAtPath: [implementation]
 
(void) - openPath: [implementation]
 
(BOOL) - validateMenuItem: [implementation]
 
(NSMenu *) - applicationDockMenu: [implementation]
 
(void) - awakeFromNib [implementation]
 
(BOOL) - application:openFile: [implementation]
 
(NSApplicationTerminateReply) - applicationShouldTerminate: [implementation]
 
(void) - reportUnhandledStartupException: [implementation]
 
(BOOL) - suppressClangStuff [implementation]
 
(IBAction) - toggleFullScreenAction: [implementation]
 
(void) - setFullScreenMode: [implementation]
 
(void) - exitFullScreenMode [implementation]
 
(BOOL) - inFullScreenMode [implementation]
 
(BOOL) - setDisplayWidth:Height:Refresh: [implementation]
 
(NSDictionary *) - findDisplayModeForWidth:Height:Refresh: [implementation]
 
(NSArray *) - displayModes [implementation]
 
(NSUInteger) - indexOfCurrentDisplayMode [implementation]
 
(void) - pauseFullScreenModeToPerform:onTarget: [implementation]
 
(void) - setUpDisplayModes [implementation]
 
(void) - toggleFullScreenCalledForWindow:withSender: [implementation]
 

Class Methods

(GameController *) + sharedController
 
(static id) + GetPreference [implementation]
 
(static void) + SetPreference [implementation]
 
(static void) + RemovePreference [implementation]
 

Private Attributes

IBOutlet NSTextField * splashProgressTextField
 
IBOutlet NSView * splashView
 
IBOutlet NSWindow * gameWindow
 
IBOutlet PDFView * helpView
 
IBOutlet NSMenu * dockMenu
 
IBOutlet MyOpenGLViewgameView
 
NSTimeInterval last_timeInterval
 
double delta_t
 
int my_mouse_x
 
int my_mouse_y
 
NSString * playerFileDirectory
 
NSString * playerFileToLoad
 
NSMutableArray * expansionPathsToInclude
 
NSTimer * timer
 
NSTimeInterval _animationTimerInterval
 
NSDate * _splashStart
 
SEL pauseSelector
 
NSObject * pauseTarget
 
BOOL gameIsPaused
 
OOMouseInteractionMode _mouseMode
 
OOMouseInteractionMode _resumeMode
 
OOFullScreenController_fullScreenController
 

Detailed Description

Definition at line 52 of file GameController.h.

Method Documentation

◆ addOnsExistAtPath:

- (BOOL) addOnsExistAtPath: (NSString *) path
implementation

Definition at line 441 of file GameController.m.

567 :(NSString *)path
568{
569 if (![self isDirectoryAtPath:path]) return NO;
570
571 NSWorkspace *workspace = NSWorkspace.sharedWorkspace;
572 for (NSString *subPath in [NSFileManager.defaultManager enumeratorAtPath:path]) {
573 subPath = [path stringByAppendingPathComponent:subPath];
574 NSString *type = [workspace typeOfFile:subPath error:NULL];
575 if ([workspace type:type conformsToType:@"org.aegidian.oolite.expansion"]) return YES;
576 }
577
578 return NO;
579}

◆ application:openFile:

- (BOOL) application: (NSApplication *) theApplication
openFile: (NSString *) filename 
implementation

Definition at line 441 of file GameController.m.

787 :(NSApplication *)theApplication openFile:(NSString *)filename
788{
789 if ([[filename pathExtension] isEqual:@"oolite-save"])
790 {
791 [self setPlayerFileToLoad:filename];
792 [self setPlayerFileDirectory:filename];
793 return YES;
794 }
795 if ([[filename pathExtension] isEqualToString:@"oxp"])
796 {
797 BOOL dir_test;
798 [[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&dir_test];
799 if (dir_test)
800 {
802 {
803 expansionPathsToInclude = [[NSMutableArray alloc] init];
804 }
805 [expansionPathsToInclude addObject:filename];
806 return YES;
807 }
808 }
809 return NO;
810}
return nil
NSMutableArray * expansionPathsToInclude
const char * filename
Definition ioapi.h:133

◆ applicationDidFinishLaunching:

- (void) applicationDidFinishLaunching: (NSNotification *) notification

Definition at line 1010 of file GameController.m.

204 :(NSNotification *)notification
205{
206 NSAutoreleasePool *pool = nil;
207 unsigned i;
208
209 pool = [[NSAutoreleasePool alloc] init];
210
211 @try
212 {
213 // if not verifying oxps, ensure that gameView is drawn to using beginSplashScreen
214 // OpenGL is initialised and that allows textures to initialise too.
215
216#if OO_OXP_VERIFIER_ENABLED
217
218 if ([OOOXPVerifier runVerificationIfRequested])
219 {
220 [self exitAppWithContext:@"OXP verifier run"];
221 }
222 else
223 {
224 [self beginSplashScreen];
225 }
226
227#else
228 [self beginSplashScreen];
229#endif
230
231#if OOLITE_MAC_OS_X
233 SetUpSparkle();
234#endif
235
236 [self setUpDisplayModes];
237
238 // moved to before the Universe is created
240 {
241 for (i = 0; i < [expansionPathsToInclude count]; i++)
242 {
243 [ResourceManager addExternalPath: (NSString*)[expansionPathsToInclude objectAtIndex: i]];
244 }
245 }
246
247 // initialise OXZ manager
249
250 // moved here to try to avoid initialising this before having an Open GL context
251 //[self logProgress:DESC(@"Initialising universe")]; // DESC expansions only possible after Universe init
252 [[Universe alloc] initWithGameView:gameView];
253
254 [self loadPlayerIfRequired];
255
256 [self logProgress:@""];
257
258 // get the run loop and add the call to performGameTick:
259 [self startAnimationTimer];
260
261 [self endSplashScreen];
262 }
263 @catch (NSException *exception)
264 {
265 [self reportUnhandledStartupException:exception];
266 exit(EXIT_FAILURE);
267 }
268
269 OOLog(@"startup.complete", @"========== Loading complete in %.2f seconds. ==========", -[_splashStart timeIntervalSinceNow]);
270
271#if OO_USE_FULLSCREEN_CONTROLLER
272 [self setFullScreenMode:[[NSUserDefaults standardUserDefaults] boolForKey:@"fullscreen"]];
273#endif
274
275 // Release anything allocated above that is not required.
276 [pool release];
277
278#if !OOLITE_MAC_OS_X
279 [[NSRunLoop currentRunLoop] run];
280#endif
281}
static void SetUpSparkle(void)
#define OOLog(class, format,...)
Definition OOLogging.h:88
NSDate * _splashStart
BOOL setStickHandlerClass:(Class aClass)
OOOXZManager * sharedManager()
void addExternalPath:(NSString *fileName)

Referenced by main().

+ Here is the caller graph for this function:

◆ applicationDockMenu:

- (NSMenu *) applicationDockMenu: (NSApplication *) sender
implementation

Definition at line 441 of file GameController.m.

632 :(NSApplication *)sender
633{
634 return dockMenu;
635}
IBOutlet NSMenu * dockMenu

◆ applicationShouldTerminate:

- (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) sender
implementation

Definition at line 441 of file GameController.m.

821 :(NSApplication *)sender
822{
825 return NSTerminateNow;
826}
void OOLoggingTerminate(void)
Definition OOLogging.m:612
OOCacheManager * sharedCache()

◆ awakeFromNib

- (void) awakeFromNib
implementation

Definition at line 441 of file GameController.m.

771{
772 NSString *path = nil;
773
774 // Set contents of Help window
775 path = [[NSBundle mainBundle] pathForResource:@"OoliteReadMe" ofType:@"pdf"];
776 if (path != nil)
777 {
778 PDFDocument *document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]];
779 [helpView setDocument:document];
780 [document release];
781 }
782 [helpView setBackgroundColor:[NSColor whiteColor]];
783}

◆ beginSplashScreen

- (void) beginSplashScreen

Definition at line 1010 of file GameController.m.

299{
300#if !OOLITE_MAC_OS_X
301 if(!gameView)
302 {
303 gameView = [MyOpenGLView alloc];
304 [gameView init];
305 [gameView setGameController:self];
306 [gameView initSplashScreen];
307 }
308#else
309 [gameView updateScreen];
310#endif
311}
IBOutlet MyOpenGLView * gameView

◆ dealloc

- (void) dealloc
implementation

Definition at line 1010 of file GameController.m.

109{
110#if OOLITE_MAC_OS_X
111 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:UNIVERSE];
112#endif
113
114 [timer release];
115 [gameView release];
116 [UNIVERSE release];
117
118 [playerFileToLoad release];
119 [playerFileDirectory release];
120 [expansionPathsToInclude release];
121
122 [super dealloc];
123}

◆ displayModes

- (NSArray *) displayModes
implementation

Provided by category GameController(FullScreen).

Definition at line 1 of file GameController+FullScreen.m.

157{
158 return [_fullScreenController displayModes];
159}

◆ doPerformGameTick

- (void) doPerformGameTick
implementation

Provided by category GameController(OOPrivate).

Definition at line 1010 of file GameController.m.

338{
339 @try
340 {
341 if (gameIsPaused)
342 delta_t = 0.0; // no movement!
343 else
344 {
345 delta_t = [NSDate timeIntervalSinceReferenceDate] - last_timeInterval;
348 delta_t = MINIMUM_GAME_TICK; // peg the maximum pause (at 0.5->1.0 seconds) to protect against when the machine sleeps
349 }
350
351 [UNIVERSE update:delta_t];
352 if (EXPECT_NOT([PLAYER status] == STATUS_RESTART_GAME))
353 {
354 [UNIVERSE reinitAndShowDemo:YES];
355 }
356 [OOSound update];
357 if (!gameIsPaused)
358 {
360 }
361 }
362 @catch (id exception)
363 {
364 OOLog(@"exception.backtrace",@"%@",[exception callStackSymbols]);
365 }
366
367 @try
368 {
369 [gameView display];
370 }
371 @catch (id exception) {}
372}
#define MINIMUM_GAME_TICK
#define EXPECT_NOT(x)
void OOJSFrameCallbacksInvoke(OOTimeDelta delta)
#define PLAYER
NSTimeInterval last_timeInterval
void update()
Definition OOALSound.m:149

◆ endSplashScreen

- (void) endSplashScreen

Definition at line 441 of file GameController.m.

750{
751 OOLogSetDisplayMessagesInClass(@"startup.progress", NO);
752
753#if OOLITE_MAC_OS_X
754 // These views will be released when we replace the content view.
756 splashView = nil;
757
758 [gameWindow setAcceptsMouseMovedEvents:YES];
759 [gameWindow setContentView:gameView];
760 [gameWindow makeFirstResponder:gameView];
761#elif OOLITE_SDL
762 [gameView endSplashScreen];
763#endif
764}
void OOLogSetDisplayMessagesInClass(NSString *inClass, BOOL inFlag)
Definition OOLogging.m:182
IBOutlet NSTextField * splashProgressTextField
IBOutlet NSView * splashView

◆ exitAppCommandQ

- (void) exitAppCommandQ

Definition at line 441 of file GameController.m.

859{
860 [self exitAppWithContext:@"Command-Q"];
861}

◆ exitAppWithContext:

- (void) exitAppWithContext: (NSString *) context

Definition at line 441 of file GameController.m.

813 :(NSString *)context
814{
815 [gameView.window orderOut:nil];
816 [(OoliteApp *)NSApp setExitContext:context];
817 [NSApp terminate:self];
818}

Referenced by OOStandardsInternal().

+ Here is the caller graph for this function:

◆ exitFullScreenMode

- (void) exitFullScreenMode
implementation

Provided by category GameController(FullScreen).

Definition at line 1 of file GameController+FullScreen.m.

124{
125 [self setFullScreenMode:NO];
126}

◆ findDisplayModeForWidth:Height:Refresh:

- (NSDictionary *) findDisplayModeForWidth: (unsigned int) d_width
Height: (unsigned int) d_height
Refresh: (unsigned int) d_refresh 
implementation

Provided by category GameController(FullScreen).

Definition at line 1 of file GameController+FullScreen.m.

150 :(unsigned int)d_width Height:(unsigned int)d_height Refresh:(unsigned int)d_refresh
151{
152 return [_fullScreenController findDisplayModeForWidth:d_width height:d_height refreshRate:d_refresh];
153}
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

◆ gameView

- (MyOpenGLView *) gameView

◆ GetPreference

+ (static id) GetPreference (NSString *) key
(Class) expectedClass 
implementation

Definition at line 426 of file GameController.m.

427{
428 id result = [[NSUserDefaults standardUserDefaults] objectForKey:key];
429 if (expectedClass != Nil && ![result isKindOfClass:expectedClass]) result = nil;
430
431 return result;
432}

References nil.

◆ indexOfCurrentDisplayMode

- (NSUInteger) indexOfCurrentDisplayMode
implementation

Provided by category GameController(FullScreen).

Definition at line 1 of file GameController+FullScreen.m.

163{
164 return [_fullScreenController indexOfCurrentDisplayMode];
165}

◆ inFullScreenMode

- (BOOL) inFullScreenMode
implementation

Provided by category GameController(FullScreen).

Definition at line 1 of file GameController+FullScreen.m.

101{
102 return [_fullScreenController inFullScreenMode];
103}

◆ init

- (id) init
implementation

Definition at line 1010 of file GameController.m.

84{
86 {
87 [self release];
88 [NSException raise:NSInternalInconsistencyException format:@"%s: expected only one GameController to exist at a time.", __PRETTY_FUNCTION__];
89 }
90
91 if ((self = [super init]))
92 {
93 last_timeInterval = [NSDate timeIntervalSinceReferenceDate];
94 delta_t = 0.01; // one hundredth of a second
95 _animationTimerInterval = [[NSUserDefaults standardUserDefaults] oo_doubleForKey:@"animation_timer_interval" defaultValue:MINIMUM_ANIMATION_TICK];
96
97 // rather than seeding this with the date repeatedly, seed it
98 // once here at startup
99 ranrot_srand((uint32_t)[[NSDate date] timeIntervalSince1970]); // reset randomiser with current time
100
101 _splashStart = [[NSDate alloc] init];
102 }
103
104 return self;
105}
static GameController * sSharedController
NSTimeInterval _animationTimerInterval
void ranrot_srand(uint32_t seed)

◆ isDirectoryAtPath:

- (BOOL) isDirectoryAtPath: (NSString *) path
implementation

Definition at line 441 of file GameController.m.

560 :(NSString *)path
561{
562 BOOL isDirectory;
563 return [NSFileManager.defaultManager fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory;
564}

◆ isGamePaused

- (BOOL) isGamePaused

Definition at line 1010 of file GameController.m.

127{
128 return gameIsPaused;
129}

◆ loadPlayerIfRequired

- (void) loadPlayerIfRequired

Definition at line 1010 of file GameController.m.

285{
286 if (playerFileToLoad != nil)
287 {
288 [self logProgress:DESC(@"loading-player")];
289 // fix problem with non-shader lighting when starting skips
290 // the splash screen
291 [UNIVERSE useGUILightSource:YES];
292 [UNIVERSE useGUILightSource:NO];
293 [PLAYER loadPlayerFromFile:playerFileToLoad asNew:NO];
294 }
295}
NSString * playerFileToLoad

◆ logProgress:

- (void) logProgress: (NSString *) message

Definition at line 441 of file GameController.m.

659 :(NSString *)message
660{
661 if (![UNIVERSE doingStartUp]) return;
662
663#if OOLITE_MAC_OS_X
664 [splashProgressTextField setStringValue:message];
665 [splashProgressTextField display];
666#endif
667 if([message length] > 0)
668 {
669 OOLog(@"startup.progress", @"===== [%.2f s] %@", -[_splashStart timeIntervalSinceNow], message);
670 }
671}
#define UNIVERSE
Definition Universe.h:833

Referenced by NoteVerificationStage().

+ Here is the caller graph for this function:

◆ mouseInteractionMode

- (OOMouseInteractionMode) mouseInteractionMode

Definition at line 1010 of file GameController.m.

151{
152 return _mouseMode;
153}
OOMouseInteractionMode _mouseMode

◆ openPath:

- (void) openPath: (NSString *) path
implementation

Definition at line 441 of file GameController.m.

582 :(NSString *)path
583{
584 [NSWorkspace.sharedWorkspace openURL:[NSURL fileURLWithPath:path]];
585}

◆ pauseFullScreenModeToPerform:onTarget:

- (void) pauseFullScreenModeToPerform: (SEL) selector
onTarget: (id) target 
implementation

Provided by category GameController(FullScreen).

Definition at line 1 of file GameController+FullScreen.m.

168 :(SEL)selector onTarget:(id)target
169{
170 [target performSelector:selector];
171}

◆ performGameTick:

- (void) performGameTick: (id) sender

Definition at line 1010 of file GameController.m.

316 :(id)sender
317{
318 [gameView pollControls];
319 [self doPerformGameTick];
320}

◆ playerFileDirectory

- (NSString *) playerFileDirectory

◆ playerFileToLoad

- (NSString *) playerFileToLoad

◆ recenterVirtualJoystick

- (void) recenterVirtualJoystick

Definition at line 1010 of file GameController.m.

406{
407 // FIXME: does this really need to be spread across GameController and MyOpenGLView? -- Ahruman 2011-01-22
408 my_mouse_x = my_mouse_y = 0; // center mouse
409 [gameView setVirtualJoystick:0.0 :0.0];
410}

◆ RemovePreference

+ (static void) RemovePreference (NSString *) key
implementation

Definition at line 441 of file GameController.m.

442{
443 [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
444}

◆ reportUnhandledStartupException:

- (void) reportUnhandledStartupException: (NSException *) exception
implementation

Provided by category GameController(OOPrivate).

Definition at line 441 of file GameController.m.

922 :(NSException *)exception
923{
924 OOLog(@"startup.exception", @"***** Unhandled exception during startup: %@ (%@).", [exception name], [exception reason]);
925
926 #if OOLITE_MAC_OS_X
927 // Display an error alert.
928 // TODO: provide better information on reporting bugs in the manual, and refer to it here.
929 NSRunCriticalAlertPanel(@"Oolite failed to start up, because an unhandled exception occurred.", @"An exception of type %@ occurred. If this problem persists, please file a bug report.", @"OK", NULL, NULL, [exception name]);
930 #endif
931}

◆ setDisplayWidth:Height:Refresh:

- (BOOL) setDisplayWidth: (unsigned int) d_width
Height: (unsigned int) d_height
Refresh: (unsigned int) d_refresh 
implementation

Provided by category GameController(FullScreen).

Definition at line 1 of file GameController+FullScreen.m.

129 :(unsigned int)width Height:(unsigned int)height Refresh:(unsigned int)refreshRate
130{
131 if ([_fullScreenController setDisplayWidth:width height:height refreshRate:refreshRate])
132 {
133 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
134
135 [userDefaults setInteger:width forKey:@"display_width"];
136 [userDefaults setInteger:height forKey:@"display_height"];
137 [userDefaults setInteger:refreshRate forKey:@"display_refresh"];
138
139 [userDefaults synchronize];
140
141 return YES;
142 }
143 else
144 {
145 return NO;
146 }
147}

◆ setFullScreenMode:

- (void) setFullScreenMode: (BOOL) value
implementation

Provided by category GameController(FullScreen).

Definition at line 1 of file GameController+FullScreen.m.

106 :(BOOL)value
107{
108 if (value == [self inFullScreenMode]) return;
109
110 [[NSUserDefaults standardUserDefaults] setBool:value forKey:@"fullscreen"];
111
112 if (value)
113 {
114 [_fullScreenController setFullScreenMode:YES];
115 }
116 else
117 {
118 [_fullScreenController setFullScreenMode:NO];
119 }
120}

◆ setGamePaused:

- (void) setGamePaused: (BOOL) value

Definition at line 1010 of file GameController.m.

132 :(BOOL)value
133{
134 if (value && !gameIsPaused)
135 {
136 _resumeMode = [self mouseInteractionMode];
137 [self setMouseInteractionModeForUIWithMouseInteraction:NO];
138 gameIsPaused = YES;
139 [PLAYER doScriptEvent:OOJSID("gamePaused")];
140 }
141 else if (!value && gameIsPaused)
142 {
143 [self setMouseInteractionMode:_resumeMode];
144 gameIsPaused = NO;
145 [PLAYER doScriptEvent:OOJSID("gameResumed")];
146 }
147}
OOMouseInteractionMode _resumeMode

Referenced by StationDockPlayer().

+ Here is the caller graph for this function:

◆ setGameView:

- (void) setGameView: (MyOpenGLView *) view

Definition at line 1010 of file GameController.m.

195 :(MyOpenGLView *)view
196{
197 [gameView release];
198 gameView = [view retain];
199 [gameView setGameController:self];
200 [UNIVERSE setGameView:gameView];
201}

◆ setMouseInteractionMode:

- (void) setMouseInteractionMode: (OOMouseInteractionMode) mode

Definition at line 1010 of file GameController.m.

157{
159 if (mode == oldMode) return;
160
162 OOLog(@"input.mouseMode.changed", @"Mouse interaction mode changed from %@ to %@", OOStringFromMouseInteractionMode(oldMode), OOStringFromMouseInteractionMode(mode));
163
164#if OO_USE_FULLSCREEN_CONTROLLER
165 if ([self inFullScreenMode])
166 {
167 [_fullScreenController noteMouseInteractionModeChangedFrom:oldMode to:mode];
168 }
169 else
170#endif
171 {
172 [[self gameView] noteMouseInteractionModeChangedFrom:oldMode to:mode];
173 }
174}
OOMouseInteractionMode
NSString * OOStringFromMouseInteractionMode(OOMouseInteractionMode mode)
const char int mode
Definition ioapi.h:133

◆ setMouseInteractionModeForFlight

- (void) setMouseInteractionModeForFlight

Definition at line 1010 of file GameController.m.

178{
179 [self setMouseInteractionMode:[PLAYER isMouseControlOn] ? MOUSE_MODE_FLIGHT_WITH_MOUSE_CONTROL : MOUSE_MODE_FLIGHT_NO_MOUSE_CONTROL];
180}

◆ setMouseInteractionModeForUIWithMouseInteraction:

- (void) setMouseInteractionModeForUIWithMouseInteraction: (BOOL) interaction

Definition at line 1010 of file GameController.m.

183 :(BOOL)interaction
184{
185 [self setMouseInteractionMode:interaction ? MOUSE_MODE_UI_SCREEN_WITH_INTERACTION : MOUSE_MODE_UI_SCREEN_NO_INTERACTION];
186}

◆ setPlayerFileDirectory:

- (void) setPlayerFileDirectory: (NSString *) filename

Definition at line 441 of file GameController.m.

904 :(NSString *)filename
905{
907 {
908 [playerFileDirectory autorelease];
910 }
911
912 if ([[[filename pathExtension] lowercaseString] isEqual:@"oolite-save"])
913 {
915 }
916
917 playerFileDirectory = [filename retain];
918 [[NSUserDefaults standardUserDefaults] setObject:filename forKey:@"save-directory"];
919}
NSString * playerFileDirectory

◆ setPlayerFileToLoad:

- (void) setPlayerFileToLoad: (NSString *) filename

Definition at line 441 of file GameController.m.

876 :(NSString *)filename
877{
879 [playerFileToLoad autorelease];
881 if ([[[filename pathExtension] lowercaseString] isEqual:@"oolite-save"])
882 playerFileToLoad = [filename copy];
883}

Referenced by main().

+ Here is the caller graph for this function:

◆ SetPreference

+ (static void) SetPreference (NSString *) key
(id) value 
implementation

Definition at line 435 of file GameController.m.

436{
437 [[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
438}

◆ setUpBasicOpenGLStateWithSize:

- (void) setUpBasicOpenGLStateWithSize: (NSSize) viewSize

Definition at line 441 of file GameController.m.

934 :(NSSize)viewSize
935{
937
938 float ratio = 0.5;
939 float aspect = viewSize.height/viewSize.width;
940
941 OOGL(glClearColor(0.0, 0.0, 0.0, 0.0));
942 OOGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
943
944 OOGL(glClearDepth(1.0));
945 OOGL(glViewport(0, 0, viewSize.width, viewSize.height));
946
947 OOGLResetProjection(); // reset matrix
948 OOGLFrustum(-ratio, ratio, -aspect*ratio, aspect*ratio, 1.0, MAX_CLEAR_DEPTH); // set projection matrix
949
950 OOGL(glDepthFunc(GL_LESS)); // depth buffer
951
952 if (UNIVERSE)
953 {
954 [UNIVERSE setLighting];
955 }
956 else
957 {
958 GLfloat black[4] = {0.0, 0.0, 0.0, 1.0};
959 GLfloat white[] = {1.0, 1.0, 1.0, 1.0};
960 GLfloat stars_ambient[] = {0.25, 0.2, 0.25, 1.0};
961
962 OOGL(glLightfv(GL_LIGHT1, GL_AMBIENT, black));
963 OOGL(glLightfv(GL_LIGHT1, GL_SPECULAR, white));
964 OOGL(glLightfv(GL_LIGHT1, GL_DIFFUSE, white));
965 OOGL(glLightfv(GL_LIGHT1, GL_POSITION, black));
966 OOGL(glLightModelfv(GL_LIGHT_MODEL_AMBIENT, stars_ambient));
967
968 }
969
970 if ([extMgr usePointSmoothing]) OOGL(glEnable(GL_POINT_SMOOTH));
971 if ([extMgr useLineSmoothing]) OOGL(glEnable(GL_LINE_SMOOTH));
972
973 // world's simplest OpenGL optimisations...
974#if GL_APPLE_transform_hint
975 if ([extMgr haveExtension:@"GL_APPLE_transform_hint"])
976 {
977 OOGL(glHint(GL_TRANSFORM_HINT_APPLE, GL_FASTEST));
978 }
979#endif
980
981 OOGL(glDisable(GL_NORMALIZE));
982 OOGL(glDisable(GL_RESCALE_NORMAL));
983
984#if GL_VERSION_1_2
985 // For OpenGL 1.2 or later, we want GL_SEPARATE_SPECULAR_COLOR all the time.
986 if ([extMgr versionIsAtLeastMajor:1 minor:2])
987 {
988 OOGL(glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR));
989 }
990#endif
991}
#define MAX_CLEAR_DEPTH
void OOGLFrustum(double left, double right, double bottom, double top, double near, double far)
void OOGLResetProjection(void)
#define OOGL(statement)
Definition OOOpenGL.h:251
OOOpenGLExtensionManager * sharedManager()

◆ setUpDisplayModes

- (void) setUpDisplayModes
implementation

Provided by category GameController(FullScreen).

Definition at line 1 of file GameController+FullScreen.m.

50{
51#if OOLITE_MAC_OS_X
52 OOFullScreenController *fullScreenController = nil;
53
54#if OO_MAC_SUPPORT_SYSTEM_STANDARD_FULL_SCREEN
55 if ([OOMacSystemStandardFullScreenController shouldUseSystemStandardFullScreenController])
56 {
57 fullScreenController = [[OOMacSystemStandardFullScreenController alloc] initWithGameView:gameView];
58 }
59#endif
60
61 if (fullScreenController == nil)
62 {
63 fullScreenController = [[OOMacSnowLeopardFullScreenController alloc] initWithGameView:gameView];
64 }
65#endif
66
67 // Load preferred display mode, falling back to current mode if no preferences set.
68 NSDictionary *currentMode = [fullScreenController currentDisplayMode];
69 NSUInteger width = [currentMode oo_unsignedIntegerForKey:kOODisplayWidth];
70 NSUInteger height = [currentMode oo_unsignedIntegerForKey:kOODisplayHeight];
71 NSUInteger refresh = [currentMode oo_unsignedIntegerForKey:kOODisplayRefreshRate];
72
73 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
74 width = [userDefaults oo_unsignedIntegerForKey:@"display_width" defaultValue:width];
75 height = [userDefaults oo_unsignedIntegerForKey:@"display_height" defaultValue:height];
76 refresh = [userDefaults oo_unsignedIntegerForKey:@"display_refresh" defaultValue:refresh];
77
78 [fullScreenController setDisplayWidth:width height:height refreshRate:refresh];
79
80 _fullScreenController = fullScreenController;
81}
BOOL setDisplayWidth:height:refreshRate:(NSUInteger width,[height] NSUInteger height,[refreshRate] NSUInteger refresh)

◆ sharedController

+ (GameController *) sharedController

Definition at line 1010 of file GameController.m.

74{
76 {
77 sSharedController = [[self alloc] init];
78 }
79 return sSharedController;
80}

Referenced by NoteVerificationStage(), and OOStandardsInternal().

+ Here is the caller graph for this function:

◆ showAddOnsAction:

- (IBAction) showAddOnsAction: (id) sender

Definition at line 441 of file GameController.m.

531 :sender
532{
533 NSArray *paths = ResourceManager.userRootPaths;
534
535 // Look for an AddOns directory that actually contains some AddOns.
536 for (NSString *path in paths) {
537 if ([self addOnsExistAtPath:path]) {
538 [self openPath:path];
539 return;
540 }
541 }
542
543 // If that failed, look for an AddOns directory that actually exists.
544 for (NSString *path in paths) {
545 if ([self isDirectoryAtPath:path]) {
546 [self openPath:path];
547 return;
548 }
549 }
550
551 // None found, create the default path.
552 [NSFileManager.defaultManager createDirectoryAtPath:[paths objectAtIndex:0]
553 withIntermediateDirectories:YES
554 attributes:nil
555 error:NULL];
556 [self openPath:[paths objectAtIndex:0]];
557}
NSArray * userRootPaths()

◆ showLogAction:

- (IBAction) showLogAction: (id) sender

Definition at line 1010 of file GameController.m.

413 :sender
414{
415 [[NSWorkspace sharedWorkspace] openFile:[OOLogHandlerGetLogBasePath() stringByAppendingPathComponent:@"Previous.log"]];
416}

◆ showLogFolderAction:

- (IBAction) showLogFolderAction: (id) sender

Definition at line 1010 of file GameController.m.

419 :sender
420{
421 [[NSWorkspace sharedWorkspace] openFile:OOLogHandlerGetLogBasePath()];
422}

◆ showSnapshotsAction:

- (IBAction) showSnapshotsAction: (id) sender

Definition at line 441 of file GameController.m.

525 :sender
526{
527 [[NSWorkspace sharedWorkspace] openURL:[self snapshotsURLCreatingIfNeeded:YES]];
528}

◆ snapshotsURLCreatingIfNeeded:

- (NSURL *) snapshotsURLCreatingIfNeeded: (BOOL) create

Definition at line 441 of file GameController.m.

450 :(BOOL)create
451{
452 BOOL stale = NO;
453 NSDictionary *snapshotDirDict = GetPreference(kSnapshotsDirRefKey, [NSDictionary class]);
454 NSURL *url = nil;
455 NSString *name = DESC(@"snapshots-directory-name-mac");
456
457 if (snapshotDirDict != nil)
458 {
460 if (url != nil)
461 {
462 NSString *existingName = [[url path] lastPathComponent];
463 if ([existingName compare:name options:NSCaseInsensitiveSearch] != 0)
464 {
465 // Check name from previous access, because we might have changed localizations.
466 NSString *originalOldName = GetPreference(kSnapshotsDirNameKey, [NSString class]);
467 if (originalOldName == nil || [existingName compare:originalOldName options:NSCaseInsensitiveSearch] != 0)
468 {
469 url = nil;
470 }
471 }
472
473 // did we put the old directory in the trash?
474 Boolean inTrash = false;
475 const UInt8 *utfPath = (const UInt8 *)[[url path] UTF8String];
476
477 OSStatus err = DetermineIfPathIsEnclosedByFolder(kOnAppropriateDisk, kTrashFolderType, utfPath, false, &inTrash);
478 // if so, create a new directory.
479 if (err == noErr && inTrash == true) url = nil;
480 }
481 }
482
483 if (url == nil)
484 {
485 NSString *path = nil;
486 NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
487 if ([searchPaths count] > 0)
488 {
489 path = [[searchPaths objectAtIndex:0] stringByAppendingPathComponent:name];
490 }
491 url = [NSURL fileURLWithPath:path];
492
493 if (url != nil)
494 {
495 stale = YES;
496 if (create)
497 {
498 NSFileManager *fmgr = [NSFileManager defaultManager];
499 if (![fmgr fileExistsAtPath:path])
500 {
501 [fmgr oo_createDirectoryAtPath:path attributes:nil];
502 }
503 }
504 }
505 }
506
507 if (stale)
508 {
509 snapshotDirDict = JAPersistentFileReferenceFromURL(url);
510 if (snapshotDirDict != nil)
511 {
512 SetPreference(kSnapshotsDirRefKey, snapshotDirDict);
513 SetPreference(kSnapshotsDirNameKey, [[url path] lastPathComponent]);
514 }
515 else
516 {
518 }
519 }
520
521 return url;
522}
#define kSnapshotsDirNameKey
#define kSnapshotsDirRefKey
@ kJAPersistentFileReferenceWithoutUI
@ kJAPersistentFileReferenceWithoutMounting
NSURL * JAURLFromPersistentFileReference(NSDictionary *fileRef, JAPersistentFileReferenceResolveFlags flags, BOOL *isStale)
NSDictionary * JAPersistentFileReferenceFromURL(NSURL *url)
unsigned count
#define DESC(key)
Definition Universe.h:839
static id GetPreference(NSString *key, Class expectedClass)
static void SetPreference(NSString *key, id value)
static void RemovePreference(NSString *key)

◆ startAnimationTimer

- (void) startAnimationTimer

Definition at line 1010 of file GameController.m.

376{
377 if (timer == nil)
378 {
379 NSTimeInterval ti = _animationTimerInterval; // default one two-hundredth of a second (should be a fair bit faster than expected frame rate ~60Hz to avoid problems with phase differences)
380
381 timer = [[NSTimer timerWithTimeInterval:ti target:self selector:@selector(performGameTick:) userInfo:nil repeats:YES] retain];
382
383 [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
384#if OOLITE_MAC_OS_X
385 [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode];
386#endif
387
388 }
389}

◆ stopAnimationTimer

- (void) stopAnimationTimer

Definition at line 1010 of file GameController.m.

393{
394 if (timer != nil)
395 {
396 [timer invalidate];
397 [timer release];
398 timer = nil;
399 }
400}

◆ suppressClangStuff

- (BOOL) suppressClangStuff
implementation

Definition at line 441 of file GameController.m.

999{
1000 return pauseSelector &&
1002}
NSObject * pauseTarget

◆ toggleFullScreenAction:

- (IBAction) toggleFullScreenAction: (id) sender
implementation

Provided by category GameController(FullScreen).

Definition at line 1 of file GameController+FullScreen.m.

86 :(id)sender
87{
88 [self setFullScreenMode:![self inFullScreenMode]];
89}

◆ toggleFullScreenCalledForWindow:withSender:

- (void) toggleFullScreenCalledForWindow: (OOPrimaryWindow *) window
withSender: (id) sender 
implementation

Provided by category GameController(FullScreen).

Definition at line 1 of file GameController+FullScreen.m.

92 :(OOPrimaryWindow *)window withSender:(id)sender
93{
94 [self toggleFullScreenAction:sender];
95}

◆ validateMenuItem:

- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
implementation

Definition at line 441 of file GameController.m.

588 :(NSMenuItem *)menuItem
589{
590 SEL action = menuItem.action;
591
592 if (action == @selector(showLogAction:))
593 {
594 // the first path is always Resources
595 return ([[NSFileManager defaultManager] fileExistsAtPath:[OOLogHandlerGetLogBasePath() stringByAppendingPathComponent:@"Previous.log"]]);
596 }
597
598 if (action == @selector(showAddOnsAction:))
599 {
600 // Always enabled in unrestricted mode, to allow users to add OXPs more easily.
601 return [ResourceManager useAddOns] != nil;
602 }
603
604 if (action == @selector(showSnapshotsAction:))
605 {
606 BOOL pathIsDirectory;
607 if(![[NSFileManager defaultManager] fileExistsAtPath:[self snapshotsURLCreatingIfNeeded:NO].path isDirectory:&pathIsDirectory])
608 {
609 return NO;
610 }
611 return pathIsDirectory;
612 }
613
614 if (action == @selector(toggleFullScreenAction:))
615 {
617 {
618 // NOTE: not DESC, because menu titles are not generally localizable.
619 menuItem.title = NSLocalizedString(@"Exit Full Screen", NULL);
620 }
621 else
622 {
623 menuItem.title = NSLocalizedString(@"Enter Full Screen", NULL);
624 }
625 }
626
627 // default
628 return YES;
629}
NSString * OOLogHandlerGetLogBasePath(void)
OOFullScreenController * _fullScreenController
NSString * useAddOns()

◆ windowDidResize:

- (void) windowDidResize: (NSNotification *) aNotification

Definition at line 441 of file GameController.m.

864 :(NSNotification *)aNotification
865{
866 [gameView updateScreen];
867}

Member Data Documentation

◆ _animationTimerInterval

- (NSTimeInterval) _animationTimerInterval
private

Definition at line 75 of file GameController.h.

◆ _fullScreenController

- (OOFullScreenController*) _fullScreenController
private

Definition at line 89 of file GameController.h.

◆ _mouseMode

- (OOMouseInteractionMode) _mouseMode
private

Definition at line 84 of file GameController.h.

◆ _resumeMode

- (OOMouseInteractionMode) _resumeMode
private

Definition at line 85 of file GameController.h.

◆ _splashStart

- (NSDate*) _splashStart
private

Definition at line 77 of file GameController.h.

◆ delta_t

- (double) delta_t
private

Definition at line 66 of file GameController.h.

◆ dockMenu

- (IBOutlet NSMenu*) dockMenu
private

Definition at line 60 of file GameController.h.

◆ expansionPathsToInclude

- (NSMutableArray*) expansionPathsToInclude
private

Definition at line 72 of file GameController.h.

◆ gameIsPaused

- (BOOL) gameIsPaused
private

Definition at line 82 of file GameController.h.

◆ gameView

- (MyOpenGLView *) gameView
private

Definition at line 63 of file GameController.h.

Referenced by OoliteApp::sendEvent:.

◆ gameWindow

- (IBOutlet NSWindow*) gameWindow
private

Definition at line 58 of file GameController.h.

◆ helpView

- (IBOutlet PDFView*) helpView
private

Definition at line 59 of file GameController.h.

◆ last_timeInterval

- (NSTimeInterval) last_timeInterval
private

Definition at line 65 of file GameController.h.

◆ my_mouse_x

- (int) my_mouse_x
private

Definition at line 68 of file GameController.h.

◆ my_mouse_y

- (int) my_mouse_y
private

Definition at line 68 of file GameController.h.

◆ pauseSelector

- (SEL) pauseSelector
private

Definition at line 79 of file GameController.h.

◆ pauseTarget

- (NSObject*) pauseTarget
private

Definition at line 80 of file GameController.h.

◆ playerFileDirectory

- (NSString *) playerFileDirectory
private

Definition at line 70 of file GameController.h.

◆ playerFileToLoad

- (NSString *) playerFileToLoad
private

Definition at line 71 of file GameController.h.

◆ splashProgressTextField

- (IBOutlet NSTextField*) splashProgressTextField
private

Definition at line 56 of file GameController.h.

◆ splashView

- (IBOutlet NSView*) splashView
private

Definition at line 57 of file GameController.h.

◆ timer

- (NSTimer*) timer
private

Definition at line 74 of file GameController.h.


The documentation for this class was generated from the following files: