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 : #endif 104 : } 105 : 106 0 : + (GameController *) sharedController; 107 : 108 0 : - (void) applicationDidFinishLaunching:(NSNotification *)notification; 109 : 110 0 : - (BOOL) isGamePaused; 111 0 : - (void) setGamePaused:(BOOL)value; 112 : 113 0 : - (OOMouseInteractionMode) mouseInteractionMode; 114 0 : - (void) setMouseInteractionMode:(OOMouseInteractionMode)mode; 115 0 : - (void) setMouseInteractionModeForFlight; // Chooses mouse control mode appropriately. 116 0 : - (void) setMouseInteractionModeForUIWithMouseInteraction:(BOOL)interaction; 117 : 118 0 : - (void) performGameTick:(id)sender; 119 : 120 : #if OOLITE_MAC_OS_X 121 0 : - (IBAction) showLogAction:(id)sender; 122 0 : - (IBAction) showLogFolderAction:(id)sender; 123 0 : - (IBAction) showSnapshotsAction:(id)sender; 124 0 : - (IBAction) showAddOnsAction:(id)sender; 125 0 : - (void) recenterVirtualJoystick; 126 : #endif 127 : 128 0 : - (void) exitAppWithContext:(NSString *)context; 129 0 : - (void) exitAppCommandQ; 130 : 131 0 : - (NSString *) playerFileToLoad; 132 0 : - (void) setPlayerFileToLoad:(NSString *)filename; 133 : 134 0 : - (NSString *) playerFileDirectory; 135 0 : - (void) setPlayerFileDirectory:(NSString *)filename; 136 : 137 0 : - (void) loadPlayerIfRequired; 138 : 139 0 : - (void) beginSplashScreen; 140 0 : - (void) logProgress:(NSString *)message; 141 : #if OO_DEBUG 142 : - (void) debugLogProgress:(NSString *)format, ... OO_TAKES_FORMAT_STRING(1, 2); 143 : - (void) debugLogProgress:(NSString *)format arguments:(va_list)arguments OO_TAKES_FORMAT_STRING(1, 0); 144 : - (void) debugPushProgressMessage:(NSString *)format, ... OO_TAKES_FORMAT_STRING(1, 2); 145 : - (void) debugPopProgressMessage; 146 : #endif 147 0 : - (void) endSplashScreen; 148 : 149 0 : - (void) startAnimationTimer; 150 0 : - (void) stopAnimationTimer; 151 : 152 0 : - (MyOpenGLView *) gameView; 153 0 : - (void) setGameView:(MyOpenGLView *)view; 154 : 155 0 : - (void)windowDidResize:(NSNotification *)aNotification; 156 : 157 0 : - (void)setUpBasicOpenGLStateWithSize:(NSSize)viewSize; 158 : 159 0 : - (NSURL *) snapshotsURLCreatingIfNeeded:(BOOL)create; 160 : 161 : @end 162 : 163 : 164 : @interface GameController (FullScreen) 165 : 166 : #if OO_USE_FULLSCREEN_CONTROLLER 167 : #if OOLITE_MAC_OS_X 168 0 : - (IBAction) toggleFullScreenAction:(id)sender; 169 : #endif 170 : 171 0 : - (void) setFullScreenMode:(BOOL)value; 172 : #endif 173 : 174 0 : - (void) exitFullScreenMode; // FIXME: should be setFullScreenMode:NO 175 0 : - (BOOL) inFullScreenMode; 176 : 177 0 : - (BOOL) setDisplayWidth:(unsigned int) d_width Height:(unsigned int)d_height Refresh:(unsigned int) d_refresh; 178 0 : - (NSDictionary *) findDisplayModeForWidth:(unsigned int)d_width Height:(unsigned int) d_height Refresh:(unsigned int) d_refresh; 179 0 : - (NSArray *) displayModes; 180 0 : - (NSUInteger) indexOfCurrentDisplayMode; 181 : 182 0 : - (void) pauseFullScreenModeToPerform:(SEL) selector onTarget:(id) target; 183 : 184 : 185 : // Internal use only. 186 0 : - (void) setUpDisplayModes; 187 : 188 : @end 189 : 190 : 191 : #if OO_DEBUG 192 : #define OO_DEBUG_PROGRESS(...) [[GameController sharedController] debugLogProgress:__VA_ARGS__] 193 : #define OO_DEBUG_PUSH_PROGRESS(...) [[GameController sharedController] debugPushProgressMessage:__VA_ARGS__] 194 : #define OO_DEBUG_POP_PROGRESS() [[GameController sharedController] debugPopProgressMessage] 195 : #else 196 0 : #define OO_DEBUG_PROGRESS(...) do {} while (0) 197 0 : #define OO_DEBUG_PUSH_PROGRESS(...) do {} while (0) 198 0 : #define OO_DEBUG_POP_PROGRESS() do {} while (0) 199 : #endif