Oolite
Loading...
Searching...
No Matches
GameController Class Reference

#include <GameController.h>

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

Instance Methods

(void) - applicationDidFinishLaunching:
 
(BOOL) - finishedLaunching
 
(BOOL) - isGamePaused
 
(void) - setGamePaused:
 
(void) - setEcoQoS:
 
(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 479 of file GameController.m.

605 :(NSString *)path
606{
607 if (![self isDirectoryAtPath:path]) return NO;
608
609 NSWorkspace *workspace = NSWorkspace.sharedWorkspace;
610 for (NSString *subPath in [NSFileManager.defaultManager enumeratorAtPath:path]) {
611 subPath = [path stringByAppendingPathComponent:subPath];
612 NSString *type = [workspace typeOfFile:subPath error:NULL];
613 if ([workspace type:type conformsToType:@"org.aegidian.oolite.expansion"]) return YES;
614 }
615
616 return NO;
617}

◆ application:openFile:

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

Definition at line 479 of file GameController.m.

825 :(NSApplication *)theApplication openFile:(NSString *)filename
826{
827 if ([[filename pathExtension] isEqual:@"oolite-save"])
828 {
829 [self setPlayerFileToLoad:filename];
830 [self setPlayerFileDirectory:filename];
831 return YES;
832 }
833 if ([[filename pathExtension] isEqualToString:@"oxp"])
834 {
835 BOOL dir_test;
836 [[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&dir_test];
837 if (dir_test)
838 {
840 {
841 expansionPathsToInclude = [[NSMutableArray alloc] init];
842 }
843 [expansionPathsToInclude addObject:filename];
844 return YES;
845 }
846 }
847 return NO;
848}
return nil
NSMutableArray * expansionPathsToInclude
const char * filename
Definition ioapi.h:133

◆ applicationDidFinishLaunching:

- (void) applicationDidFinishLaunching: (NSNotification *)  notification

Definition at line 1048 of file GameController.m.

234 :(NSNotification *)notification
235{
236 NSAutoreleasePool *pool = nil;
237 unsigned i;
238
239 pool = [[NSAutoreleasePool alloc] init];
240
241 @try
242 {
243 // if not verifying oxps, ensure that gameView is drawn to using beginSplashScreen
244 // OpenGL is initialised and that allows textures to initialise too.
245
246#if OO_OXP_VERIFIER_ENABLED
247
248 if ([OOOXPVerifier runVerificationIfRequested])
249 {
250 [self exitAppWithContext:@"OXP verifier run"];
251 }
252 else
253 {
254 [self beginSplashScreen];
255 }
256
257#else
258 [self beginSplashScreen];
259#endif
260
261#if OOLITE_MAC_OS_X
263 SetUpSparkle();
264#endif
265
266 [self setUpDisplayModes];
267
268 // moved to before the Universe is created
270 {
271 for (i = 0; i < [expansionPathsToInclude count]; i++)
272 {
273 [ResourceManager addExternalPath: (NSString*)[expansionPathsToInclude objectAtIndex: i]];
274 }
275 }
276
277 // initialise OXZ manager
279
280 // moved here to try to avoid initialising this before having an Open GL context
281 //[self logProgress:DESC(@"Initialising universe")]; // DESC expansions only possible after Universe init
282 [[Universe alloc] initWithGameView:gameView];
283
284 [self loadPlayerIfRequired];
285
286 [self logProgress:@""];
287
288 // get the run loop and add the call to performGameTick:
289 [self startAnimationTimer];
290
291 [self endSplashScreen];
292 }
293 @catch (NSException *exception)
294 {
295 [self reportUnhandledStartupException:exception];
296 exit(EXIT_FAILURE);
297 }
298
299 OOLog(@"startup.complete", @"========== Loading complete in %.2f seconds. ==========", -[_splashStart timeIntervalSinceNow]);
300
301#if OO_USE_FULLSCREEN_CONTROLLER
302 [self setFullScreenMode:[[NSUserDefaults standardUserDefaults] boolForKey:@"fullscreen"]];
303#endif
304
305 _finishedLaunching = YES;
306
307 // Release anything allocated above that is not required.
308 [pool release];
309
310#if !OOLITE_MAC_OS_X
311 [[NSRunLoop currentRunLoop] run];
312#endif
313}
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 479 of file GameController.m.

670 :(NSApplication *)sender
671{
672 return dockMenu;
673}
IBOutlet NSMenu * dockMenu

◆ applicationShouldTerminate:

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

Definition at line 479 of file GameController.m.

859 :(NSApplication *)sender
860{
863 return NSTerminateNow;
864}
void OOLoggingTerminate(void)
Definition OOLogging.m:612
OOCacheManager * sharedCache()

◆ awakeFromNib

- (void) awakeFromNib
implementation

Definition at line 479 of file GameController.m.

809{
810 NSString *path = nil;
811
812 // Set contents of Help window
813 path = [[NSBundle mainBundle] pathForResource:@"OoliteReadMe" ofType:@"pdf"];
814 if (path != nil)
815 {
816 PDFDocument *document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]];
817 [helpView setDocument:document];
818 [document release];
819 }
820 [helpView setBackgroundColor:[NSColor whiteColor]];
821}

◆ beginSplashScreen

- (void) beginSplashScreen

Definition at line 1048 of file GameController.m.

337{
338#if !OOLITE_MAC_OS_X
339 if(!gameView)
340 {
341 gameView = [MyOpenGLView alloc];
342 [gameView init];
343 [gameView setGameController:self];
344 [gameView initSplashScreen];
345 }
346#else
347 [gameView updateScreen];
348#endif
349}
IBOutlet MyOpenGLView * gameView

◆ dealloc

- (void) dealloc
implementation

Definition at line 1048 of file GameController.m.

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

◆ 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 1048 of file GameController.m.

376{
377 @try
378 {
379 if (gameIsPaused)
380 delta_t = 0.0; // no movement!
381 else
382 {
383 delta_t = [NSDate timeIntervalSinceReferenceDate] - last_timeInterval;
386 delta_t = MINIMUM_GAME_TICK; // peg the maximum pause (at 0.5->1.0 seconds) to protect against when the machine sleeps
387 }
388
389 [UNIVERSE update:delta_t];
390 if (EXPECT_NOT([PLAYER status] == STATUS_RESTART_GAME))
391 {
392 [UNIVERSE reinitAndShowDemo:YES];
393 }
394 [OOSound update];
395 if (!gameIsPaused)
396 {
398 }
399 }
400 @catch (id exception)
401 {
402 OOLog(@"exception.backtrace",@"%@",[exception callStackSymbols]);
403 }
404
405 @try
406 {
407 [gameView display];
408 }
409 @catch (id exception) {}
410}
#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 479 of file GameController.m.

788{
789 OOLogSetDisplayMessagesInClass(@"startup.progress", NO);
790
791#if OOLITE_MAC_OS_X
792 // These views will be released when we replace the content view.
794 splashView = nil;
795
796 [gameWindow setAcceptsMouseMovedEvents:YES];
797 [gameWindow setContentView:gameView];
798 [gameWindow makeFirstResponder:gameView];
799#elif OOLITE_SDL
800 [gameView endSplashScreen];
801#endif
802}
void OOLogSetDisplayMessagesInClass(NSString *inClass, BOOL inFlag)
Definition OOLogging.m:182
IBOutlet NSTextField * splashProgressTextField
IBOutlet NSView * splashView

◆ exitAppCommandQ

- (void) exitAppCommandQ

Definition at line 479 of file GameController.m.

897{
898 [self exitAppWithContext:@"Command-Q"];
899}

◆ exitAppWithContext:

- (void) exitAppWithContext: (NSString *)  context

Definition at line 479 of file GameController.m.

851 :(NSString *)context
852{
853 [gameView.window orderOut:nil];
854 [(OoliteApp *)NSApp setExitContext:context];
855 [NSApp terminate:self];
856}

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

◆ finishedLaunching

- (BOOL) finishedLaunching

Definition at line 1048 of file GameController.m.

317{
318 return _finishedLaunching;
319}

◆ gameView

- (MyOpenGLView *) gameView

◆ GetPreference

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

Definition at line 464 of file GameController.m.

465{
466 id result = [[NSUserDefaults standardUserDefaults] objectForKey:key];
467 if (expectedClass != Nil && ![result isKindOfClass:expectedClass]) result = nil;
468
469 return result;
470}

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 1048 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 _finishedLaunching = NO;
94 last_timeInterval = [NSDate timeIntervalSinceReferenceDate];
95 delta_t = 0.01; // one hundredth of a second
96 _animationTimerInterval = [[NSUserDefaults standardUserDefaults] oo_doubleForKey:@"animation_timer_interval" defaultValue:MINIMUM_ANIMATION_TICK];
97
98 // rather than seeding this with the date repeatedly, seed it
99 // once here at startup
100 ranrot_srand((uint32_t)[[NSDate date] timeIntervalSince1970]); // reset randomiser with current time
101
102 _splashStart = [[NSDate alloc] init];
103 }
104
105 return self;
106}
static GameController * sSharedController
NSTimeInterval _animationTimerInterval
void ranrot_srand(uint32_t seed)

◆ isDirectoryAtPath:

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

Definition at line 479 of file GameController.m.

598 :(NSString *)path
599{
600 BOOL isDirectory;
601 return [NSFileManager.defaultManager fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory;
602}

◆ isGamePaused

- (BOOL) isGamePaused

Definition at line 1048 of file GameController.m.

128{
129 return gameIsPaused;
130}

◆ loadPlayerIfRequired

- (void) loadPlayerIfRequired

Definition at line 1048 of file GameController.m.

323{
324 if (playerFileToLoad != nil)
325 {
326 [self logProgress:DESC(@"loading-player")];
327 // fix problem with non-shader lighting when starting skips
328 // the splash screen
329 [UNIVERSE useGUILightSource:YES];
330 [UNIVERSE useGUILightSource:NO];
331 [PLAYER loadPlayerFromFile:playerFileToLoad asNew:NO];
332 }
333}
NSString * playerFileToLoad

◆ logProgress:

- (void) logProgress: (NSString *)  message

Definition at line 479 of file GameController.m.

697 :(NSString *)message
698{
699 if (![UNIVERSE doingStartUp]) return;
700
701#if OOLITE_MAC_OS_X
702 [splashProgressTextField setStringValue:message];
703 [splashProgressTextField display];
704#endif
705 if([message length] > 0)
706 {
707 OOLog(@"startup.progress", @"===== [%.2f s] %@", -[_splashStart timeIntervalSinceNow], message);
708 }
709}
#define UNIVERSE
Definition Universe.h:842

Referenced by NoteVerificationStage().

+ Here is the caller graph for this function:

◆ mouseInteractionMode

- (OOMouseInteractionMode) mouseInteractionMode

Definition at line 1048 of file GameController.m.

181{
182 return _mouseMode;
183}
OOMouseInteractionMode _mouseMode

◆ openPath:

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

Definition at line 479 of file GameController.m.

620 :(NSString *)path
621{
622 [NSWorkspace.sharedWorkspace openURL:[NSURL fileURLWithPath:path]];
623}

◆ 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 1048 of file GameController.m.

354 :(id)sender
355{
356 [gameView pollControls];
357 [self doPerformGameTick];
358}

◆ playerFileDirectory

- (NSString *) playerFileDirectory

◆ playerFileToLoad

- (NSString *) playerFileToLoad

◆ recenterVirtualJoystick

- (void) recenterVirtualJoystick

Definition at line 1048 of file GameController.m.

444{
445 // FIXME: does this really need to be spread across GameController and MyOpenGLView? -- Ahruman 2011-01-22
446 my_mouse_x = my_mouse_y = 0; // center mouse
447 [gameView setVirtualJoystick:0.0 :0.0];
448}

◆ RemovePreference

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

Definition at line 479 of file GameController.m.

480{
481 [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
482}

◆ reportUnhandledStartupException:

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

Provided by category GameController(OOPrivate).

Definition at line 479 of file GameController.m.

960 :(NSException *)exception
961{
962 OOLog(@"startup.exception", @"***** Unhandled exception during startup: %@ (%@).", [exception name], [exception reason]);
963
964 #if OOLITE_MAC_OS_X
965 // Display an error alert.
966 // TODO: provide better information on reporting bugs in the manual, and refer to it here.
967 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]);
968 #endif
969}

◆ 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}

◆ setEcoQoS:

- (void) setEcoQoS: (BOOL)  efficiencyModeRequested

Definition at line 1048 of file GameController.m.

153 : (BOOL)efficiencyModeRequested
154{
155#if OOLITE_WINDOWS
156 if ([[NSUserDefaults standardUserDefaults] oo_boolForKey:@"ecoqos" defaultValue:YES])
157 {
158 BOOL setEfficiencyMode = !!efficiencyModeRequested; // yes or no, not 42
159 HANDLE currentProcess = GetCurrentProcess();
160
161 if (EXPECT_NOT(!SetPriorityClass(currentProcess, setEfficiencyMode ? IDLE_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS)))
162 {
163 OOLog(@"gameController.setEcoQos", @"SetPriorityClass failed with error %lu", GetLastError());
164 }
165
166 PROCESS_POWER_THROTTLING_STATE powerThrottling;
167 RtlZeroMemory(&powerThrottling, sizeof(powerThrottling));
168 powerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;
169 powerThrottling.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
170 powerThrottling.StateMask = setEfficiencyMode ? PROCESS_POWER_THROTTLING_EXECUTION_SPEED : 0;
171 if (EXPECT_NOT(!SetProcessInformation(currentProcess, ProcessPowerThrottling, &powerThrottling, sizeof(powerThrottling))))
172 {
173 OOLog(@"gameController.setEcoQos", @"SetProcessInformation failed with error %lu", GetLastError());
174 }
175 }
176#endif
177}

◆ 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 1048 of file GameController.m.

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

Referenced by StationDockPlayer().

+ Here is the caller graph for this function:

◆ setGameView:

- (void) setGameView: (MyOpenGLView *)  view

Definition at line 1048 of file GameController.m.

225 :(MyOpenGLView *)view
226{
227 [gameView release];
228 gameView = [view retain];
229 [gameView setGameController:self];
230 [UNIVERSE setGameView:gameView];
231}

◆ setMouseInteractionMode:

- (void) setMouseInteractionMode: (OOMouseInteractionMode mode

Definition at line 1048 of file GameController.m.

187{
189 if (mode == oldMode) return;
190
192 OOLog(@"input.mouseMode.changed", @"Mouse interaction mode changed from %@ to %@", OOStringFromMouseInteractionMode(oldMode), OOStringFromMouseInteractionMode(mode));
193
194#if OO_USE_FULLSCREEN_CONTROLLER
195 if ([self inFullScreenMode])
196 {
197 [_fullScreenController noteMouseInteractionModeChangedFrom:oldMode to:mode];
198 }
199 else
200#endif
201 {
202 [[self gameView] noteMouseInteractionModeChangedFrom:oldMode to:mode];
203 }
204}
OOMouseInteractionMode
NSString * OOStringFromMouseInteractionMode(OOMouseInteractionMode mode)
const char int mode
Definition ioapi.h:133

◆ setMouseInteractionModeForFlight

- (void) setMouseInteractionModeForFlight

Definition at line 1048 of file GameController.m.

208{
209 [self setMouseInteractionMode:[PLAYER isMouseControlOn] ? MOUSE_MODE_FLIGHT_WITH_MOUSE_CONTROL : MOUSE_MODE_FLIGHT_NO_MOUSE_CONTROL];
210}

◆ setMouseInteractionModeForUIWithMouseInteraction:

- (void) setMouseInteractionModeForUIWithMouseInteraction: (BOOL)  interaction

Definition at line 1048 of file GameController.m.

213 :(BOOL)interaction
214{
215 [self setMouseInteractionMode:interaction ? MOUSE_MODE_UI_SCREEN_WITH_INTERACTION : MOUSE_MODE_UI_SCREEN_NO_INTERACTION];
216}

◆ setPlayerFileDirectory:

- (void) setPlayerFileDirectory: (NSString *)  filename

Definition at line 479 of file GameController.m.

942 :(NSString *)filename
943{
945 {
946 [playerFileDirectory autorelease];
948 }
949
950 if ([[[filename pathExtension] lowercaseString] isEqual:@"oolite-save"])
951 {
953 }
954
955 playerFileDirectory = [filename retain];
956 [[NSUserDefaults standardUserDefaults] setObject:filename forKey:@"save-directory"];
957}
NSString * playerFileDirectory

◆ setPlayerFileToLoad:

- (void) setPlayerFileToLoad: (NSString *)  filename

Definition at line 479 of file GameController.m.

914 :(NSString *)filename
915{
917 [playerFileToLoad autorelease];
919 if ([[[filename pathExtension] lowercaseString] isEqual:@"oolite-save"])
920 playerFileToLoad = [filename copy];
921}

Referenced by main().

+ Here is the caller graph for this function:

◆ SetPreference

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

Definition at line 473 of file GameController.m.

474{
475 [[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
476}

◆ setUpBasicOpenGLStateWithSize:

- (void) setUpBasicOpenGLStateWithSize: (NSSize)  viewSize

Definition at line 479 of file GameController.m.

972 :(NSSize)viewSize
973{
975
976 float ratio = 0.5;
977 float aspect = viewSize.height/viewSize.width;
978
979 OOGL(glClearColor(0.0, 0.0, 0.0, 0.0));
980 OOGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
981
982 OOGL(glClearDepth(1.0));
983 OOGL(glViewport(0, 0, viewSize.width, viewSize.height));
984
985 OOGLResetProjection(); // reset matrix
986 OOGLFrustum(-ratio, ratio, -aspect*ratio, aspect*ratio, 1.0, MAX_CLEAR_DEPTH); // set projection matrix
987
988 OOGL(glDepthFunc(GL_LESS)); // depth buffer
989
990 if (UNIVERSE)
991 {
992 [UNIVERSE setLighting];
993 }
994 else
995 {
996 GLfloat black[4] = {0.0, 0.0, 0.0, 1.0};
997 GLfloat white[] = {1.0, 1.0, 1.0, 1.0};
998 GLfloat stars_ambient[] = {0.25, 0.2, 0.25, 1.0};
999
1000 OOGL(glLightfv(GL_LIGHT1, GL_AMBIENT, black));
1001 OOGL(glLightfv(GL_LIGHT1, GL_SPECULAR, white));
1002 OOGL(glLightfv(GL_LIGHT1, GL_DIFFUSE, white));
1003 OOGL(glLightfv(GL_LIGHT1, GL_POSITION, black));
1004 OOGL(glLightModelfv(GL_LIGHT_MODEL_AMBIENT, stars_ambient));
1005
1006 }
1007
1008 if ([extMgr usePointSmoothing]) OOGL(glEnable(GL_POINT_SMOOTH));
1009 if ([extMgr useLineSmoothing]) OOGL(glEnable(GL_LINE_SMOOTH));
1010
1011 // world's simplest OpenGL optimisations...
1012#if GL_APPLE_transform_hint
1013 if ([extMgr haveExtension:@"GL_APPLE_transform_hint"])
1014 {
1015 OOGL(glHint(GL_TRANSFORM_HINT_APPLE, GL_FASTEST));
1016 }
1017#endif
1018
1019 OOGL(glDisable(GL_NORMALIZE));
1020 OOGL(glDisable(GL_RESCALE_NORMAL));
1021
1022#if GL_VERSION_1_2
1023 // For OpenGL 1.2 or later, we want GL_SEPARATE_SPECULAR_COLOR all the time.
1024 if ([extMgr versionIsAtLeastMajor:1 minor:2])
1025 {
1026 OOGL(glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR));
1027 }
1028#endif
1029}
#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 1048 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 479 of file GameController.m.

569 :sender
570{
571 NSArray *paths = ResourceManager.userRootPaths;
572
573 // Look for an AddOns directory that actually contains some AddOns.
574 for (NSString *path in paths) {
575 if ([self addOnsExistAtPath:path]) {
576 [self openPath:path];
577 return;
578 }
579 }
580
581 // If that failed, look for an AddOns directory that actually exists.
582 for (NSString *path in paths) {
583 if ([self isDirectoryAtPath:path]) {
584 [self openPath:path];
585 return;
586 }
587 }
588
589 // None found, create the default path.
590 [NSFileManager.defaultManager createDirectoryAtPath:[paths objectAtIndex:0]
591 withIntermediateDirectories:YES
592 attributes:nil
593 error:NULL];
594 [self openPath:[paths objectAtIndex:0]];
595}
NSArray * userRootPaths()

◆ showLogAction:

- (IBAction) showLogAction: (id)  sender

Definition at line 1048 of file GameController.m.

451 :sender
452{
453 [[NSWorkspace sharedWorkspace] openFile:[OOLogHandlerGetLogBasePath() stringByAppendingPathComponent:@"Previous.log"]];
454}

◆ showLogFolderAction:

- (IBAction) showLogFolderAction: (id)  sender

Definition at line 1048 of file GameController.m.

457 :sender
458{
459 [[NSWorkspace sharedWorkspace] openFile:OOLogHandlerGetLogBasePath()];
460}

◆ showSnapshotsAction:

- (IBAction) showSnapshotsAction: (id)  sender

Definition at line 479 of file GameController.m.

563 :sender
564{
565 [[NSWorkspace sharedWorkspace] openURL:[self snapshotsURLCreatingIfNeeded:YES]];
566}

◆ snapshotsURLCreatingIfNeeded:

- (NSURL *) snapshotsURLCreatingIfNeeded: (BOOL)  create

Definition at line 479 of file GameController.m.

488 :(BOOL)create
489{
490 BOOL stale = NO;
491 NSDictionary *snapshotDirDict = GetPreference(kSnapshotsDirRefKey, [NSDictionary class]);
492 NSURL *url = nil;
493 NSString *name = DESC(@"snapshots-directory-name-mac");
494
495 if (snapshotDirDict != nil)
496 {
498 if (url != nil)
499 {
500 NSString *existingName = [[url path] lastPathComponent];
501 if ([existingName compare:name options:NSCaseInsensitiveSearch] != 0)
502 {
503 // Check name from previous access, because we might have changed localizations.
504 NSString *originalOldName = GetPreference(kSnapshotsDirNameKey, [NSString class]);
505 if (originalOldName == nil || [existingName compare:originalOldName options:NSCaseInsensitiveSearch] != 0)
506 {
507 url = nil;
508 }
509 }
510
511 // did we put the old directory in the trash?
512 Boolean inTrash = false;
513 const UInt8 *utfPath = (const UInt8 *)[[url path] UTF8String];
514
515 OSStatus err = DetermineIfPathIsEnclosedByFolder(kOnAppropriateDisk, kTrashFolderType, utfPath, false, &inTrash);
516 // if so, create a new directory.
517 if (err == noErr && inTrash == true) url = nil;
518 }
519 }
520
521 if (url == nil)
522 {
523 NSString *path = nil;
524 NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
525 if ([searchPaths count] > 0)
526 {
527 path = [[searchPaths objectAtIndex:0] stringByAppendingPathComponent:name];
528 }
529 url = [NSURL fileURLWithPath:path];
530
531 if (url != nil)
532 {
533 stale = YES;
534 if (create)
535 {
536 NSFileManager *fmgr = [NSFileManager defaultManager];
537 if (![fmgr fileExistsAtPath:path])
538 {
539 [fmgr oo_createDirectoryAtPath:path attributes:nil];
540 }
541 }
542 }
543 }
544
545 if (stale)
546 {
547 snapshotDirDict = JAPersistentFileReferenceFromURL(url);
548 if (snapshotDirDict != nil)
549 {
550 SetPreference(kSnapshotsDirRefKey, snapshotDirDict);
551 SetPreference(kSnapshotsDirNameKey, [[url path] lastPathComponent]);
552 }
553 else
554 {
556 }
557 }
558
559 return url;
560}
#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:848
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 1048 of file GameController.m.

414{
415 if (timer == nil)
416 {
417 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)
418
419 timer = [[NSTimer timerWithTimeInterval:ti target:self selector:@selector(performGameTick:) userInfo:nil repeats:YES] retain];
420
421 [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
422#if OOLITE_MAC_OS_X
423 [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode];
424#endif
425
426 }
427}

◆ stopAnimationTimer

- (void) stopAnimationTimer

Definition at line 1048 of file GameController.m.

431{
432 if (timer != nil)
433 {
434 [timer invalidate];
435 [timer release];
436 timer = nil;
437 }
438}

◆ suppressClangStuff

- (BOOL) suppressClangStuff
implementation

Definition at line 479 of file GameController.m.

1037{
1038 return pauseSelector &&
1040}
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 479 of file GameController.m.

626 :(NSMenuItem *)menuItem
627{
628 SEL action = menuItem.action;
629
630 if (action == @selector(showLogAction:))
631 {
632 // the first path is always Resources
633 return ([[NSFileManager defaultManager] fileExistsAtPath:[OOLogHandlerGetLogBasePath() stringByAppendingPathComponent:@"Previous.log"]]);
634 }
635
636 if (action == @selector(showAddOnsAction:))
637 {
638 // Always enabled in unrestricted mode, to allow users to add OXPs more easily.
639 return [ResourceManager useAddOns] != nil;
640 }
641
642 if (action == @selector(showSnapshotsAction:))
643 {
644 BOOL pathIsDirectory;
645 if(![[NSFileManager defaultManager] fileExistsAtPath:[self snapshotsURLCreatingIfNeeded:NO].path isDirectory:&pathIsDirectory])
646 {
647 return NO;
648 }
649 return pathIsDirectory;
650 }
651
652 if (action == @selector(toggleFullScreenAction:))
653 {
655 {
656 // NOTE: not DESC, because menu titles are not generally localizable.
657 menuItem.title = NSLocalizedString(@"Exit Full Screen", NULL);
658 }
659 else
660 {
661 menuItem.title = NSLocalizedString(@"Enter Full Screen", NULL);
662 }
663 }
664
665 // default
666 return YES;
667}
NSString * OOLogHandlerGetLogBasePath(void)
return self
OOFullScreenController * _fullScreenController
NSString * useAddOns()

◆ windowDidResize:

- (void) windowDidResize: (NSNotification *)  aNotification

Definition at line 479 of file GameController.m.

902 :(NSNotification *)aNotification
903{
904 [gameView updateScreen];
905}

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: