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:
(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:
(void) - setFullScreenMode:
(void) - exitFullScreenMode
(BOOL) - inFullScreenMode
(BOOL) - setDisplayWidth:Height:Refresh:
(NSDictionary *) - findDisplayModeForWidth:Height:Refresh:
(NSArray *) - displayModes
(NSUInteger) - indexOfCurrentDisplayMode
(void) - pauseFullScreenModeToPerform:onTarget:
(void) - setUpDisplayModes

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 MyOpenGLView * gameView
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 47 of file GameController.h.

Method Documentation

◆ addOnsExistAtPath:

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

Definition at line 539 of file GameController.m.

539 :(NSString*)path
540{
541 if (![self isDirectoryAtPath:path])
542 return NO;
543
544 NSWorkspace* workspace = NSWorkspace.sharedWorkspace;
545 for (NSString* subPath in [NSFileManager.defaultManager enumeratorAtPath:path]) {
546 subPath = [path stringByAppendingPathComponent:subPath];
547 NSString* type = [workspace typeOfFile:subPath error:NULL];
548 if ([workspace type:type conformsToType:@"org.aegidian.oolite.expansion"])
549 return YES;
550 }
551
552 return NO;
553}

◆ application:openFile:

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

Definition at line 738 of file GameController.m.

738 :(NSApplication*)theApplication openFile:(NSString*)filename
739{
740 if ([[filename pathExtension] isEqual:@"oolite-save"]) {
741 [self setPlayerFileToLoad:filename];
742 [self setPlayerFileDirectory:filename];
743 return YES;
744 }
745 if ([[filename pathExtension] isEqualToString:@"oxp"]) {
746 BOOL dir_test;
747 [[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&dir_test];
748 if (dir_test) {
750 expansionPathsToInclude = [[NSMutableArray alloc] init];
751 }
752 [expansionPathsToInclude addObject:filename];
753 return YES;
754 }
755 }
756 return NO;
757}
return nil
NSMutableArray * expansionPathsToInclude
const char * filename
Definition ioapi.h:125

References expansionPathsToInclude, nil, setPlayerFileDirectory:, and setPlayerFileToLoad:.

Here is the call graph for this function:

◆ applicationDidFinishLaunching:

- (void) applicationDidFinishLaunching: (NSNotification*) notification

Definition at line 212 of file GameController.m.

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

References _splashStart, ResourceManager::addExternalPath:, beginSplashScreen, endSplashScreen, exitAppWithContext:, expansionPathsToInclude, loadPlayerIfRequired, logProgress:, nil, OOLog, reportUnhandledStartupException:, setFullScreenMode:, OOJoystickManager::setStickHandlerClass:, setUpDisplayModes, SetUpSparkle(), OOOXZManager::sharedManager, and startAnimationTimer.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ applicationDockMenu:

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

Definition at line 595 of file GameController.m.

595 :(NSApplication*)sender
596{
597 return dockMenu;
598}
IBOutlet NSMenu * dockMenu

References dockMenu.

◆ applicationShouldTerminate:

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

Definition at line 766 of file GameController.m.

766 :(NSApplication*)sender
767{
770 return NSTerminateNow;
771}
void OOLoggingTerminate(void)
Definition OOLogging.m:562
OOCacheManager * sharedCache()

References OOCacheManager::finishOngoingFlush, OOLoggingTerminate(), and OOCacheManager::sharedCache.

Here is the call graph for this function:

◆ awakeFromNib

- (void) awakeFromNib
implementation

Definition at line 723 of file GameController.m.

724{
725 NSString* path = nil;
726
727 // Set contents of Help window
728 path = [[NSBundle mainBundle] pathForResource:@"OoliteReadMe" ofType:@"pdf"];
729 if (path != nil) {
730 PDFDocument* document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:path]];
731 [helpView setDocument:document];
732 [document release];
733 }
734 [helpView setBackgroundColor:[NSColor whiteColor]];
735}

References awakeFromNib, and nil.

Referenced by awakeFromNib.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginSplashScreen

- (void) beginSplashScreen

Definition at line 303 of file GameController.m.

304{
305#if !OOLITE_MAC_COCOA_UI
306 if (!gameView) {
307 gameView = [MyOpenGLView alloc];
308 [gameView init];
309 [gameView setGameController:self];
310 [gameView initSplashScreen];
311 }
312#else
313 [gameView updateScreen];
314#endif
315}
IBOutlet MyOpenGLView * gameView

References beginSplashScreen, gameView, MyOpenGLView::init, MyOpenGLView::initSplashScreen, MyOpenGLView::setGameController:, and MyOpenGLView::updateScreen.

Referenced by applicationDidFinishLaunching:, beginSplashScreen, and playerFileDirectory.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dealloc

- (void) dealloc
implementation

Definition at line 104 of file GameController.m.

105{
106#if OOLITE_MAC_COCOA_UI
107 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:UNIVERSE];
108#endif
109
110 [timer release];
111 [gameView release];
112 [UNIVERSE release];
113
114 [playerFileToLoad release];
115 [playerFileDirectory release];
116 [expansionPathsToInclude release];
117
118 [super dealloc];
119}

References dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ displayModes

- (NSArray *) displayModes

Provided by category GameController(FullScreen).

Referenced by PlayerEntity(OOControlsPrivate)::handleGameOptionsScreenKeys, and PlayerEntity::setGuiToGameOptionsScreen.

Here is the caller graph for this function:

◆ doPerformGameTick

- (void) doPerformGameTick
implementation

Provided by category GameController(OOPrivate).

Definition at line 339 of file GameController.m.

340{
341 @try {
342 if (gameIsPaused)
343 delta_t = 0.0; // no movement!
344 else {
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 [UNIVERSE reinitAndShowDemo:YES];
354 }
355 [OOSound update];
356 if (!gameIsPaused) {
358 }
359 }
360 @catch (id exception) {
361 OOLog(@"exception.backtrace", @"%@", [exception callStackSymbols]);
362 }
363
364 @
365 try {
366 [gameView updateScreen];
367 }
368 @catch (id exception) {
369 }
370}
#define MINIMUM_GAME_TICK
#define EXPECT_NOT(x)
void OOJSFrameCallbacksInvoke(OOTimeDelta delta)
#define PLAYER
NSTimeInterval last_timeInterval
void update()
Definition OOALSound.m:136

References GameController(OOPrivate)::doPerformGameTick, EXPECT_NOT, MINIMUM_GAME_TICK, OOJSFrameCallbacksInvoke(), OOLog, PLAYER, and OOSound::update.

Referenced by GameController(OOPrivate)::doPerformGameTick, and performGameTick:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endSplashScreen

- (void) endSplashScreen

Definition at line 703 of file GameController.m.

704{
705 OOLogSetDisplayMessagesInClass(@"startup.progress", NO);
706
707#if OOLITE_MAC_COCOA_UI
708 // These views will be released when we replace the content view.
710 splashView = nil;
711
712 [gameWindow setAcceptsMouseMovedEvents:YES];
713 [gameWindow setContentView:gameView];
714 [gameWindow makeFirstResponder:gameView];
715#elif OOLITE_SDL
716 [gameView endSplashScreen];
717#endif
718}
void OOLogSetDisplayMessagesInClass(NSString *inClass, BOOL inFlag)
Definition OOLogging.m:172
IBOutlet NSTextField * splashProgressTextField
IBOutlet NSView * splashView

References endSplashScreen, MyOpenGLView::endSplashScreen, nil, OOLogSetDisplayMessagesInClass(), splashProgressTextField, and splashView.

Referenced by applicationDidFinishLaunching:, endSplashScreen, and playerFileDirectory.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exitAppCommandQ

- (void) exitAppCommandQ

Definition at line 806 of file GameController.m.

807{
808 [self exitAppWithContext:@"Command-Q"];
809}

References exitAppCommandQ, and exitAppWithContext:.

Referenced by exitAppCommandQ.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exitAppWithContext:

- (void) exitAppWithContext: (NSString*) context

Definition at line 759 of file GameController.m.

759 :(NSString*)context
760{
761 [gameView.window orderOut:nil];
762 [(OoliteApp*)NSApp setExitContext:context];
763 [NSApp terminate:self];
764}

Referenced by applicationDidFinishLaunching:, MyOpenGLView::endSplashScreen, exitAppCommandQ, PlayerEntity(OOControlsPrivate)::pollApplicationControls, and Universe::quitGame.

Here is the caller graph for this function:

◆ exitFullScreenMode

- (void) exitFullScreenMode

Provided by category GameController(FullScreen).

Referenced by PlayerEntity(OOControlsPrivate)::pollApplicationControls.

Here is the caller graph for this function:

◆ findDisplayModeForWidth:Height:Refresh:

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

Provided by category GameController(FullScreen).

◆ finishedLaunching

- (BOOL) finishedLaunching

Definition at line 286 of file GameController.m.

287{
288 return _finishedLaunching;
289}

References finishedLaunching.

Referenced by finishedLaunching.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gameView

References gameView.

◆ GetPreference

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

Definition at line 416 of file GameController.m.

417{
418 id result = [[NSUserDefaults standardUserDefaults] objectForKey:key];
419 if (expectedClass != Nil && ![result isKindOfClass:expectedClass])
420 result = nil;
421
422 return result;
423}

References nil.

Referenced by snapshotsURLCreatingIfNeeded:.

Here is the caller graph for this function:

◆ indexOfCurrentDisplayMode

- (NSUInteger) indexOfCurrentDisplayMode

Provided by category GameController(FullScreen).

Referenced by PlayerEntity(OOControlsPrivate)::handleGameOptionsScreenKeys, and PlayerEntity::setGuiToGameOptionsScreen.

Here is the caller graph for this function:

◆ inFullScreenMode

- (BOOL) inFullScreenMode

Provided by category GameController(FullScreen).

Referenced by Universe::gameSettings, PlayerEntity(OOControlsPrivate)::pollApplicationControls, and setMouseInteractionMode:.

Here is the caller graph for this function:

◆ init

- (id) init
implementation

Definition at line 81 of file GameController.m.

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

References _animationTimerInterval, _splashStart, delta_t, init, last_timeInterval, nil, ranrot_srand(), and sSharedController.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDirectoryAtPath:

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

Definition at line 533 of file GameController.m.

533 :(NSString*)path
534{
535 BOOL isDirectory;
536 return [NSFileManager.defaultManager fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory;
537}

◆ isGamePaused

- (BOOL) isGamePaused

Definition at line 121 of file GameController.m.

122{
123 return gameIsPaused;
124}

References gameIsPaused, and isGamePaused.

Referenced by isGamePaused, and Universe::setViewDirection:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadPlayerIfRequired

- (void) loadPlayerIfRequired

Definition at line 291 of file GameController.m.

292{
293 if (playerFileToLoad != nil) {
294 [self logProgress:DESC(@"loading-player")];
295 // fix problem with non-shader lighting when starting skips
296 // the splash screen
297 [UNIVERSE useGUILightSource:YES];
298 [UNIVERSE useGUILightSource:NO];
299 [PLAYER loadPlayerFromFile:playerFileToLoad asNew:NO];
300 }
301}
NSString * playerFileToLoad

References loadPlayerIfRequired, logProgress:, nil, and playerFileToLoad.

Referenced by applicationDidFinishLaunching:, Universe::handleGameOver, loadPlayerIfRequired, and playerFileDirectory.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logProgress:

- (void) logProgress: (NSString*) message

Definition at line 620 of file GameController.m.

620 :(NSString*)message
621{
622 if (![UNIVERSE doingStartUp])
623 return;
624
625#if OOLITE_MAC_COCOA_UI
626 [splashProgressTextField setStringValue:message];
627 [splashProgressTextField display];
628#endif
629 if ([message length] > 0) {
630 OOLog(@"startup.progress", @"===== [%.2f s] %@", -[_splashStart timeIntervalSinceNow], message);
631 }
632}
#define UNIVERSE
Definition Universe.h:827

References _splashStart, OOLog, and UNIVERSE.

Referenced by applicationDidFinishLaunching:, Universe::initWithGameView:, loadPlayerIfRequired, NoteVerificationStage(), PlayerEntity::setUpAndConfirmOK:saveGame:, and Universe::setUpSpace.

Here is the caller graph for this function:

◆ mouseInteractionMode

- (OOMouseInteractionMode) mouseInteractionMode

Definition at line 165 of file GameController.m.

166{
167 return _mouseMode;
168}
OOMouseInteractionMode _mouseMode

References _mouseMode, and mouseInteractionMode.

Referenced by mouseInteractionMode, and setGamePaused:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openPath:

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

Definition at line 555 of file GameController.m.

555 :(NSString*)path
556{
557 [NSWorkspace.sharedWorkspace openURL:[NSURL fileURLWithPath:path]];
558}

Referenced by showAddOnsAction:.

Here is the caller graph for this function:

◆ pauseFullScreenModeToPerform:onTarget:

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

Provided by category GameController(FullScreen).

Referenced by PlayerEntity(OOControlsPrivate)::pollApplicationControls, and PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:.

Here is the caller graph for this function:

◆ performGameTick:

- (void) performGameTick: (id) sender

Definition at line 319 of file GameController.m.

319 :(id)sender
320{
321 [gameView pollControls];
322 [self doPerformGameTick];
323}

References doPerformGameTick, and MyOpenGLView::pollControls.

Here is the call graph for this function:

◆ playerFileDirectory

- (NSString *) playerFileDirectory

References beginSplashScreen, endSplashScreen, loadPlayerIfRequired, playerFileDirectory, startAnimationTimer, and stopAnimationTimer.

Here is the call graph for this function:

◆ playerFileToLoad

- (NSString *) playerFileToLoad

References playerFileToLoad.

◆ recenterVirtualJoystick

- (void) recenterVirtualJoystick

Definition at line 398 of file GameController.m.

399{
400 // FIXME: does this really need to be spread across GameController and MyOpenGLView? -- Ahruman 2011-01-22
401 my_mouse_x = my_mouse_y = 0; // center mouse
402 [gameView setVirtualJoystick:0.0:0.0];
403}

References my_mouse_x, my_mouse_y, and recenterVirtualJoystick.

Referenced by recenterVirtualJoystick.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemovePreference

+ (void) RemovePreference (NSString *) key
implementation

Definition at line 430 of file GameController.m.

431{
432 [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
433}

Referenced by snapshotsURLCreatingIfNeeded:.

Here is the caller graph for this function:

◆ reportUnhandledStartupException:

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

Provided by category GameController(OOPrivate).

Definition at line 861 of file GameController.m.

861 :(NSException*)exception
862{
863 OOLog(@"startup.exception", @"***** Unhandled exception during startup: %@ (%@).", [exception name], [exception reason]);
864
865#if OOLITE_MAC_COCOA_UI
866 // Display an error alert.
867 // TODO: provide better information on reporting bugs in the manual, and refer to it here.
868 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]);
869#endif
870}

References OOLog.

Referenced by applicationDidFinishLaunching:.

Here is the caller graph for this function:

◆ setDisplayWidth:Height:Refresh:

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

Provided by category GameController(FullScreen).

Referenced by PlayerEntity(OOControlsPrivate)::handleGameOptionsScreenKeys.

Here is the caller graph for this function:

◆ setEcoQoS:

- (void) setEcoQoS: (BOOL) efficiencyModeRequested

Definition at line 142 of file GameController.m.

142 :(BOOL)efficiencyModeRequested
143{
144#if OOLITE_WINDOWS
145 if ([[NSUserDefaults standardUserDefaults] oo_boolForKey:@"ecoqos" defaultValue:YES]) {
146 BOOL setEfficiencyMode = !!efficiencyModeRequested; // yes or no, not 42
147 HANDLE currentProcess = GetCurrentProcess();
148
149 if (EXPECT_NOT(!SetPriorityClass(currentProcess, setEfficiencyMode ? IDLE_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS))) {
150 OOLog(@"gameController.setEcoQos", @"SetPriorityClass failed with error %lu", GetLastError());
151 }
152
153 PROCESS_POWER_THROTTLING_STATE powerThrottling;
154 RtlZeroMemory(&powerThrottling, sizeof(powerThrottling));
155 powerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;
156 powerThrottling.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
157 powerThrottling.StateMask = setEfficiencyMode ? PROCESS_POWER_THROTTLING_EXECUTION_SPEED : 0;
158 if (EXPECT_NOT(!SetProcessInformation(currentProcess, ProcessPowerThrottling, &powerThrottling, sizeof(powerThrottling)))) {
159 OOLog(@"gameController.setEcoQos", @"SetProcessInformation failed with error %lu", GetLastError());
160 }
161 }
162#endif
163}

References EXPECT_NOT, and OOLog.

Referenced by setGamePaused:.

Here is the caller graph for this function:

◆ setFullScreenMode:

- (void) setFullScreenMode: (BOOL) value

Provided by category GameController(FullScreen).

Referenced by applicationDidFinishLaunching:.

Here is the caller graph for this function:

◆ setGamePaused:

- (void) setGamePaused: (BOOL) value

Definition at line 126 of file GameController.m.

126 :(BOOL)value
127{
128 if (value && !gameIsPaused) {
129 _resumeMode = [self mouseInteractionMode];
130 [self setMouseInteractionModeForUIWithMouseInteraction:NO];
131 [self setEcoQoS:YES];
132 gameIsPaused = YES;
133 [PLAYER doScriptEvent:OOJSID("gamePaused")];
134 } else if (!value && gameIsPaused) {
135 [self setMouseInteractionMode:_resumeMode];
136 [self setEcoQoS:NO];
137 gameIsPaused = NO;
138 [PLAYER doScriptEvent:OOJSID("gameResumed")];
139 }
140}
OOMouseInteractionMode _resumeMode

References _resumeMode, gameIsPaused, mouseInteractionMode, setEcoQoS:, setMouseInteractionMode:, and setMouseInteractionModeForUIWithMouseInteraction:.

Referenced by Universe::handleOoliteException:, Universe::pauseGame, PlayerEntity(OOControlsPrivate)::pollApplicationControls, PlayerEntity(OOControlsPrivate)::pollDockedControls:, Universe::reinitAndShowDemo:, StationDockPlayer(), and StationDockPlayer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setGameView:

- (void) setGameView: (MyOpenGLView*) view

Definition at line 204 of file GameController.m.

204 :(MyOpenGLView*)view
205{
206 [gameView release];
207 gameView = [view retain];
208 [gameView setGameController:self];
209 [UNIVERSE setGameView:gameView];
210}

References gameView, and MyOpenGLView::setGameController:.

Here is the call graph for this function:

◆ setMouseInteractionMode:

- (void) setMouseInteractionMode: (OOMouseInteractionMode) mode

Definition at line 170 of file GameController.m.

171{
173 if (mode == oldMode)
174 return;
175
177 OOLog(@"input.mouseMode.changed", @"Mouse interaction mode changed from %@ to %@", OOStringFromMouseInteractionMode(oldMode), OOStringFromMouseInteractionMode(mode));
178
179#if OO_USE_FULLSCREEN_CONTROLLER
180 if ([self inFullScreenMode]) {
181 [_fullScreenController noteMouseInteractionModeChangedFrom:oldMode to:mode];
182 } else
183#endif
184 {
185 [[self gameView] noteMouseInteractionModeChangedFrom:oldMode to:mode];
186 }
187}
OOMouseInteractionMode
NSString * OOStringFromMouseInteractionMode(OOMouseInteractionMode mode)
BOOL inFullScreenMode()
const char int mode
Definition ioapi.h:125

References _mouseMode, gameView, inFullScreenMode, MyOpenGLView::noteMouseInteractionModeChangedFrom:to:, OOFullScreenController::noteMouseInteractionModeChangedFrom:to:, OOLog, and OOStringFromMouseInteractionMode().

Referenced by setGamePaused:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMouseInteractionModeForFlight

- (void) setMouseInteractionModeForFlight

Definition at line 189 of file GameController.m.

190{
191 [self setMouseInteractionMode:[PLAYER isMouseControlOn] ? MOUSE_MODE_FLIGHT_WITH_MOUSE_CONTROL : MOUSE_MODE_FLIGHT_NO_MOUSE_CONTROL];
192}

References setMouseInteractionModeForFlight.

Referenced by PlayerEntity(OOControlsPrivate)::pollApplicationControls, setMouseInteractionModeForFlight, and Universe::setViewDirection:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMouseInteractionModeForUIWithMouseInteraction:

- (void) setMouseInteractionModeForUIWithMouseInteraction: (BOOL) interaction

Definition at line 194 of file GameController.m.

194 :(BOOL)interaction
195{
196 [self setMouseInteractionMode:interaction ? MOUSE_MODE_UI_SCREEN_WITH_INTERACTION : MOUSE_MODE_UI_SCREEN_NO_INTERACTION];
197}

Referenced by Universe::enterGUIViewModeWithMouseInteraction:, Universe::reinitAndShowDemo:, setGamePaused:, and Universe::setViewDirection:.

Here is the caller graph for this function:

◆ setPlayerFileDirectory:

- (void) setPlayerFileDirectory: (NSString*) filename

Definition at line 846 of file GameController.m.

846 :(NSString*)filename
847{
848 if (playerFileDirectory != nil) {
849 [playerFileDirectory autorelease];
851 }
852
853 if ([[[filename pathExtension] lowercaseString] isEqual:@"oolite-save"]) {
854 filename = [filename stringByDeletingLastPathComponent];
855 }
856
857 playerFileDirectory = [filename retain];
858 [[NSUserDefaults standardUserDefaults] setObject:filename forKey:@"save-directory"];
859}
NSString * playerFileDirectory

References nil, and playerFileDirectory.

Referenced by application:openFile:.

Here is the caller graph for this function:

◆ setPlayerFileToLoad:

- (void) setPlayerFileToLoad: (NSString*) filename

Definition at line 821 of file GameController.m.

821 :(NSString*)filename
822{
824 [playerFileToLoad autorelease];
826 if ([[[filename pathExtension] lowercaseString] isEqual:@"oolite-save"])
827 playerFileToLoad = [filename copy];
828}

References nil, and playerFileToLoad.

Referenced by application:openFile:, main(), and Universe::reinitAndShowDemo:.

Here is the caller graph for this function:

◆ SetPreference

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

Definition at line 425 of file GameController.m.

426{
427 [[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
428}

Referenced by snapshotsURLCreatingIfNeeded:.

Here is the caller graph for this function:

◆ setUpDisplayModes

- (void) setUpDisplayModes

Provided by category GameController(FullScreen).

Referenced by applicationDidFinishLaunching:.

Here is the caller graph for this function:

◆ sharedController

+ (GameController *) sharedController

Definition at line 73 of file GameController.m.

74{
75 if (sSharedController == nil) {
76 sSharedController = [[self alloc] init];
77 }
78 return sSharedController;
79}

References nil, sharedController, and sSharedController.

Referenced by Universe::initWithGameView:, NoteVerificationStage(), PlayerEntity::setUpAndConfirmOK:saveGame:, Universe::setUpSpace, and sharedController.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showAddOnsAction:

- (IBAction) showAddOnsAction: (id) sender

Definition at line 505 of file GameController.m.

505 :sender
506{
507 NSArray* paths = ResourceManager.userRootPaths;
508
509 // Look for an AddOns directory that actually contains some AddOns.
510 for (NSString* path in paths) {
511 if ([self addOnsExistAtPath:path]) {
512 [self openPath:path];
513 return;
514 }
515 }
516
517 // If that failed, look for an AddOns directory that actually exists.
518 for (NSString* path in paths) {
519 if ([self isDirectoryAtPath:path]) {
520 [self openPath:path];
521 return;
522 }
523 }
524
525 // None found, create the default path.
526 [NSFileManager.defaultManager createDirectoryAtPath:[paths objectAtIndex:0]
527 withIntermediateDirectories:YES
528 attributes:nil
529 error:NULL];
530 [self openPath:[paths objectAtIndex:0]];
531}

References openPath:, and ResourceManager::userRootPaths.

Here is the call graph for this function:

◆ showLogAction:

- (IBAction) showLogAction: (id) sender

Definition at line 405 of file GameController.m.

405 :sender
406{
407 [[NSWorkspace sharedWorkspace] openFile:[OOLogHandlerGetLogBasePath() stringByAppendingPathComponent:@"Previous.log"]];
408}

◆ showLogFolderAction:

- (IBAction) showLogFolderAction: (id) sender

Definition at line 410 of file GameController.m.

410 :sender
411{
412 [[NSWorkspace sharedWorkspace] openFile:OOLogHandlerGetLogBasePath()];
413}

◆ showSnapshotsAction:

- (IBAction) showSnapshotsAction: (id) sender

Definition at line 500 of file GameController.m.

500 :sender
501{
502 [[NSWorkspace sharedWorkspace] openURL:[self snapshotsURLCreatingIfNeeded:YES]];
503}

References snapshotsURLCreatingIfNeeded:.

Here is the call graph for this function:

◆ snapshotsURLCreatingIfNeeded:

- (NSURL *) snapshotsURLCreatingIfNeeded: (BOOL) create

Definition at line 438 of file GameController.m.

438 :(BOOL)create
439{
440 BOOL stale = NO;
441 NSDictionary* snapshotDirDict = GetPreference(kSnapshotsDirRefKey, [NSDictionary class]);
442 NSURL* url = nil;
443 NSString* name = DESC(@"snapshots-directory-name-mac");
444
445 if (snapshotDirDict != nil) {
446 url = JAURLFromPersistentFileReference(snapshotDirDict, kJAPersistentFileReferenceWithoutUI | kJAPersistentFileReferenceWithoutMounting, &stale);
447 if (url != nil) {
448 NSString* existingName = [[url path] lastPathComponent];
449 if ([existingName compare:name options:NSCaseInsensitiveSearch] != 0) {
450 // Check name from previous access, because we might have changed localizations.
451 NSString* originalOldName = GetPreference(kSnapshotsDirNameKey, [NSString class]);
452 if (originalOldName == nil || [existingName compare:originalOldName options:NSCaseInsensitiveSearch] != 0) {
453 url = nil;
454 }
455 }
456
457 // did we put the old directory in the trash?
458 Boolean inTrash = false;
459 const UInt8* utfPath = (const UInt8*)[[url path] UTF8String];
460
461 OSStatus err = DetermineIfPathIsEnclosedByFolder(kOnAppropriateDisk, kTrashFolderType, utfPath, false, &inTrash);
462 // if so, create a new directory.
463 if (err == noErr && inTrash == true)
464 url = nil;
465 }
466 }
467
468 if (url == nil) {
469 NSString* path = nil;
470 NSArray* searchPaths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
471 if ([searchPaths count] > 0) {
472 path = [[searchPaths objectAtIndex:0] stringByAppendingPathComponent:name];
473 }
474 url = [NSURL fileURLWithPath:path];
475
476 if (url != nil) {
477 stale = YES;
478 if (create) {
479 NSFileManager* fmgr = [NSFileManager defaultManager];
480 if (![fmgr fileExistsAtPath:path]) {
481 [fmgr oo_createDirectoryAtPath:path attributes:nil];
482 }
483 }
484 }
485 }
486
487 if (stale) {
488 snapshotDirDict = JAPersistentFileReferenceFromURL(url);
489 if (snapshotDirDict != nil) {
490 SetPreference(kSnapshotsDirRefKey, snapshotDirDict);
491 SetPreference(kSnapshotsDirNameKey, [[url path] lastPathComponent]);
492 } else {
494 }
495 }
496
497 return url;
498}
#define kSnapshotsDirNameKey
#define kSnapshotsDirRefKey
unsigned count
#define DESC(key)
Definition Universe.h:832
static id GetPreference(NSString *key, Class expectedClass)
static void SetPreference(NSString *key, id value)
static void RemovePreference(NSString *key)

References count, DESC, GetPreference, kSnapshotsDirNameKey, kSnapshotsDirRefKey, nil, RemovePreference, and SetPreference.

Referenced by showSnapshotsAction:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startAnimationTimer

- (void) startAnimationTimer

Definition at line 372 of file GameController.m.

373{
374 if (timer == nil) {
375 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)
376
377 timer = [[NSTimer timerWithTimeInterval:ti target:self selector:@selector(performGameTick:) userInfo:nil repeats:YES] retain];
378
379 [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
380#if OOLITE_MAC_COCOA_UI
381 [[NSRunLoop currentRunLoop] addTimer:timer
382 forMode:NSEventTrackingRunLoopMode];
383#endif
384 }
385}

References _animationTimerInterval, nil, startAnimationTimer, and timer.

Referenced by applicationDidFinishLaunching:, playerFileDirectory, PlayerEntity::setUpAndConfirmOK:saveGame:, and startAnimationTimer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopAnimationTimer

- (void) stopAnimationTimer

Definition at line 387 of file GameController.m.

388{
389 if (timer != nil) {
390 [timer invalidate];
391 [timer release];
392 timer = nil;
393 }
394}

References nil, stopAnimationTimer, and timer.

Referenced by playerFileDirectory, PlayerEntity::setUpAndConfirmOK:saveGame:, and stopAnimationTimer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ suppressClangStuff

- (BOOL) suppressClangStuff
implementation

Definition at line 876 of file GameController.m.

877{
878 return pauseSelector && pauseTarget;
879}
NSObject * pauseTarget

References pauseSelector, pauseTarget, and suppressClangStuff.

Referenced by suppressClangStuff.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toggleFullScreenAction:

- (IBAction) toggleFullScreenAction: (id) sender

Provided by category GameController(FullScreen).

◆ validateMenuItem:

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

Definition at line 560 of file GameController.m.

560 :(NSMenuItem*)menuItem
561{
562 SEL action = menuItem.action;
563
564 if (action == @selector(showLogAction:)) {
565 // the first path is always Resources
566 return ([[NSFileManager defaultManager] fileExistsAtPath:[OOLogHandlerGetLogBasePath() stringByAppendingPathComponent:@"Previous.log"]]);
567 }
568
569 if (action == @selector(showAddOnsAction:)) {
570 // Always enabled in unrestricted mode, to allow users to add OXPs more easily.
571 return [ResourceManager useAddOns] != nil;
572 }
573
574 if (action == @selector(showSnapshotsAction:)) {
575 BOOL pathIsDirectory;
576 if (![[NSFileManager defaultManager] fileExistsAtPath:[self snapshotsURLCreatingIfNeeded:NO].path isDirectory:&pathIsDirectory]) {
577 return NO;
578 }
579 return pathIsDirectory;
580 }
581
582 if (action == @selector(toggleFullScreenAction:)) {
583 if (_fullScreenController.fullScreenMode) {
584 // NOTE: not DESC, because menu titles are not generally localizable.
585 menuItem.title = NSLocalizedString(@"Exit Full Screen", NULL);
586 } else {
587 menuItem.title = NSLocalizedString(@"Enter Full Screen", NULL);
588 }
589 }
590
591 // default
592 return YES;
593}
NSString * OOLogHandlerGetLogBasePath(void)
OOFullScreenController * _fullScreenController
NSString * useAddOns()

References _fullScreenController, nil, OOLogHandlerGetLogBasePath(), and ResourceManager::useAddOns.

Here is the call graph for this function:

◆ windowDidResize:

- (void) windowDidResize: (NSNotification*) aNotification

Definition at line 811 of file GameController.m.

811 :(NSNotification*)aNotification
812{
813 [gameView updateScreen];
814}

References MyOpenGLView::updateScreen.

Here is the call graph for this function:

Member Data Documentation

◆ _animationTimerInterval

- (NSTimeInterval) _animationTimerInterval
private

Definition at line 69 of file GameController.h.

Referenced by init, and startAnimationTimer.

◆ _fullScreenController

- (OOFullScreenController*) _fullScreenController
private

Definition at line 83 of file GameController.h.

Referenced by validateMenuItem:.

◆ _mouseMode

- (OOMouseInteractionMode) _mouseMode
private

Definition at line 78 of file GameController.h.

Referenced by mouseInteractionMode, and setMouseInteractionMode:.

◆ _resumeMode

- (OOMouseInteractionMode) _resumeMode
private

Definition at line 79 of file GameController.h.

Referenced by setGamePaused:.

◆ _splashStart

- (NSDate*) _splashStart
private

Definition at line 71 of file GameController.h.

Referenced by applicationDidFinishLaunching:, init, and logProgress:.

◆ delta_t

- (double) delta_t
private

Definition at line 60 of file GameController.h.

Referenced by init.

◆ dockMenu

- (IBOutlet NSMenu*) dockMenu
private

Definition at line 54 of file GameController.h.

Referenced by applicationDockMenu:.

◆ expansionPathsToInclude

- (NSMutableArray*) expansionPathsToInclude
private

Definition at line 66 of file GameController.h.

Referenced by application:openFile:, and applicationDidFinishLaunching:.

◆ gameIsPaused

- (BOOL) gameIsPaused
private

Definition at line 76 of file GameController.h.

Referenced by isGamePaused, and setGamePaused:.

◆ gameView

- (MyOpenGLView *) gameView
private

Definition at line 199 of file GameController.m.

200{
201 return gameView;
202}

Referenced by beginSplashScreen, gameView, setGameView:, and setMouseInteractionMode:.

◆ gameWindow

- (IBOutlet NSWindow*) gameWindow
private

Definition at line 52 of file GameController.h.

◆ helpView

- (IBOutlet PDFView*) helpView
private

Definition at line 53 of file GameController.h.

◆ last_timeInterval

- (NSTimeInterval) last_timeInterval
private

Definition at line 59 of file GameController.h.

Referenced by init.

◆ my_mouse_x

- (int) my_mouse_x
private

Definition at line 62 of file GameController.h.

Referenced by recenterVirtualJoystick.

◆ my_mouse_y

- (int) my_mouse_y
private

Definition at line 62 of file GameController.h.

Referenced by recenterVirtualJoystick.

◆ pauseSelector

- (SEL) pauseSelector
private

Definition at line 73 of file GameController.h.

Referenced by suppressClangStuff.

◆ pauseTarget

- (NSObject*) pauseTarget
private

Definition at line 74 of file GameController.h.

Referenced by suppressClangStuff.

◆ playerFileDirectory

- (NSString *) playerFileDirectory
private

Definition at line 830 of file GameController.m.

831{
832 if (playerFileDirectory == nil) {
833 playerFileDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"save-directory"];
834 if (playerFileDirectory != nil && ![[NSFileManager defaultManager] fileExistsAtPath:playerFileDirectory]) {
836 }
838 playerFileDirectory = [[NSFileManager defaultManager] defaultCommanderPath];
839
840 [playerFileDirectory retain];
841 }
842
843 return playerFileDirectory;
844}

Referenced by playerFileDirectory, and setPlayerFileDirectory:.

◆ playerFileToLoad

- (NSString *) playerFileToLoad
private

◆ splashProgressTextField

- (IBOutlet NSTextField*) splashProgressTextField
private

Definition at line 50 of file GameController.h.

Referenced by endSplashScreen.

◆ splashView

- (IBOutlet NSView*) splashView
private

Definition at line 51 of file GameController.h.

Referenced by endSplashScreen.

◆ timer

- (NSTimer*) timer
private

Definition at line 68 of file GameController.h.

Referenced by startAnimationTimer, and stopAnimationTimer.


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