Line data Source code
1 0 : /* 2 : 3 : GameController.h 4 : 5 : Main application controller class. 6 : 7 : Oolite 8 : Copyright (C) 2004-2013 Giles C Williams and contributors 9 : 10 : This program is free software; you can redistribute it and/or 11 : modify it under the terms of the GNU General Public License 12 : as published by the Free Software Foundation; either version 2 13 : of the License, or (at your option) any later version. 14 : 15 : This program is distributed in the hope that it will be useful, 16 : but WITHOUT ANY WARRANTY; without even the implied warranty of 17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 : GNU General Public License for more details. 19 : 20 : You should have received a copy of the GNU General Public License 21 : along with this program; if not, write to the Free Software 22 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 : MA 02110-1301, USA. 24 : 25 : */ 26 : 27 : 28 : #import "OOCocoa.h" 29 : #import "OOFunctionAttributes.h" 30 : #import "OOFullScreenController.h" 31 : #import "OOMouseInteractionMode.h" 32 : 33 : 34 : #if OOLITE_MAC_OS_X 35 : #import <Quartz/Quartz.h> // For PDFKit. 36 : #endif 37 : 38 0 : #define MINIMUM_GAME_TICK 0.25 39 : // * reduced from 0.5s for tgape * // 40 : 41 0 : #define MINIMUM_ANIMATION_TICK 0.0041667 42 : // 1.0 / (desired framerate cap) 43 : 44 : 45 : @class MyOpenGLView, OOFullScreenController; 46 : 47 : 48 : // TEMP: whether to use separate OOFullScreenController object, will hopefully be used for all builds soon. 49 0 : #define OO_USE_FULLSCREEN_CONTROLLER OOLITE_MAC_OS_X 50 : 51 : 52 0 : @interface GameController: NSObject 53 : { 54 : @private 55 : #if OOLITE_MAC_OS_X 56 0 : IBOutlet NSTextField *splashProgressTextField; 57 0 : IBOutlet NSView *splashView; 58 0 : IBOutlet NSWindow *gameWindow; 59 0 : IBOutlet PDFView *helpView; 60 0 : IBOutlet NSMenu *dockMenu; 61 : #endif 62 : 63 0 : IBOutlet MyOpenGLView *gameView; 64 : 65 0 : NSTimeInterval last_timeInterval; 66 0 : double delta_t; 67 : 68 0 : int my_mouse_x, my_mouse_y; 69 : 70 0 : NSString *playerFileDirectory; 71 0 : NSString *playerFileToLoad; 72 0 : NSMutableArray *expansionPathsToInclude; 73 : 74 0 : NSTimer *timer; 75 0 : NSTimeInterval _animationTimerInterval; 76 : 77 0 : NSDate *_splashStart; 78 : 79 0 : SEL pauseSelector; 80 0 : NSObject *pauseTarget; 81 : 82 0 : BOOL gameIsPaused; 83 : 84 0 : OOMouseInteractionMode _mouseMode; 85 0 : OOMouseInteractionMode _resumeMode; 86 : 87 : // Fullscreen mode stuff. 88 : #if OO_USE_FULLSCREEN_CONTROLLER 89 0 : OOFullScreenController *_fullScreenController; 90 : #elif OOLITE_SDL 91 : NSRect fsGeometry; 92 : MyOpenGLView *switchView; 93 : 94 : NSMutableArray *displayModes; 95 : 96 : unsigned int width, height; 97 : unsigned int refresh; 98 : BOOL fullscreen; 99 : NSDictionary *originalDisplayMode; 100 : NSDictionary *fullscreenDisplayMode; 101 : 102 : BOOL stayInFullScreenMode; 103 : BOOL _finishedLaunching; 104 : #endif 105 : } 106 : 107 0 : + (GameController *) sharedController; 108 : 109 0 : - (void) applicationDidFinishLaunching:(NSNotification *)notification; 110 0 : - (BOOL) finishedLaunching; 111 : 112 0 : - (BOOL) isGamePaused; 113 0 : - (void) setGamePaused:(BOOL)value; 114 : 115 0 : - (OOMouseInteractionMode) mouseInteractionMode; 116 0 : - (void) setMouseInteractionMode:(OOMouseInteractionMode)mode; 117 0 : - (void) setMouseInteractionModeForFlight; // Chooses mouse control mode appropriately. 118 0 : - (void) setMouseInteractionModeForUIWithMouseInteraction:(BOOL)interaction; 119 : 120 0 : - (void) performGameTick:(id)sender; 121 : 122 : #if OOLITE_MAC_OS_X 123 0 : - (IBAction) showLogAction:(id)sender; 124 0 : - (IBAction) showLogFolderAction:(id)sender; 125 0 : - (IBAction) showSnapshotsAction:(id)sender; 126 0 : - (IBAction) showAddOnsAction:(id)sender; 127 0 : - (void) recenterVirtualJoystick; 128 : #endif 129 : 130 0 : - (void) exitAppWithContext:(NSString *)context; 131 0 : - (void) exitAppCommandQ; 132 : 133 0 : - (NSString *) playerFileToLoad; 134 0 : - (void) setPlayerFileToLoad:(NSString *)filename; 135 : 136 0 : - (NSString *) playerFileDirectory; 137 0 : - (void) setPlayerFileDirectory:(NSString *)filename; 138 : 139 0 : - (void) loadPlayerIfRequired; 140 : 141 0 : - (void) beginSplashScreen; 142 0 : - (void) logProgress:(NSString *)message; 143 : #if OO_DEBUG 144 : - (void) debugLogProgress:(NSString *)format, ... OO_TAKES_FORMAT_STRING(1, 2); 145 : - (void) debugLogProgress:(NSString *)format arguments:(va_list)arguments OO_TAKES_FORMAT_STRING(1, 0); 146 : - (void) debugPushProgressMessage:(NSString *)format, ... OO_TAKES_FORMAT_STRING(1, 2); 147 : - (void) debugPopProgressMessage; 148 : #endif 149 0 : - (void) endSplashScreen; 150 : 151 0 : - (void) startAnimationTimer; 152 0 : - (void) stopAnimationTimer; 153 : 154 0 : - (MyOpenGLView *) gameView; 155 0 : - (void) setGameView:(MyOpenGLView *)view; 156 : 157 0 : - (void)windowDidResize:(NSNotification *)aNotification; 158 : 159 0 : - (void)setUpBasicOpenGLStateWithSize:(NSSize)viewSize; 160 : 161 0 : - (NSURL *) snapshotsURLCreatingIfNeeded:(BOOL)create; 162 : 163 : @end 164 : 165 : 166 : @interface GameController (FullScreen) 167 : 168 : #if OO_USE_FULLSCREEN_CONTROLLER 169 : #if OOLITE_MAC_OS_X 170 0 : - (IBAction) toggleFullScreenAction:(id)sender; 171 : #endif 172 : 173 0 : - (void) setFullScreenMode:(BOOL)value; 174 : #endif 175 : 176 0 : - (void) exitFullScreenMode; // FIXME: should be setFullScreenMode:NO 177 0 : - (BOOL) inFullScreenMode; 178 : 179 0 : - (BOOL) setDisplayWidth:(unsigned int) d_width Height:(unsigned int)d_height Refresh:(unsigned int) d_refresh; 180 0 : - (NSDictionary *) findDisplayModeForWidth:(unsigned int)d_width Height:(unsigned int) d_height Refresh:(unsigned int) d_refresh; 181 0 : - (NSArray *) displayModes; 182 0 : - (NSUInteger) indexOfCurrentDisplayMode; 183 : 184 0 : - (void) pauseFullScreenModeToPerform:(SEL) selector onTarget:(id) target; 185 : 186 : 187 : // Internal use only. 188 0 : - (void) setUpDisplayModes; 189 : 190 : @end 191 : 192 : 193 : #if OO_DEBUG 194 : #define OO_DEBUG_PROGRESS(...) [[GameController sharedController] debugLogProgress:__VA_ARGS__] 195 : #define OO_DEBUG_PUSH_PROGRESS(...) [[GameController sharedController] debugPushProgressMessage:__VA_ARGS__] 196 : #define OO_DEBUG_POP_PROGRESS() [[GameController sharedController] debugPopProgressMessage] 197 : #else 198 0 : #define OO_DEBUG_PROGRESS(...) do {} while (0) 199 0 : #define OO_DEBUG_PUSH_PROGRESS(...) do {} while (0) 200 0 : #define OO_DEBUG_POP_PROGRESS() do {} while (0) 201 : #endif