Scans the command line for -nosplash, –nosplash, -splash, –splash- -novsync and –novsync arguments.
174{
175 self = [super init];
176
177 Uint32 colorkey;
178 SDL_Surface *icon=NULL;
179 NSString *imagesDir;
180 NSString *cmdLineArgsStr = @"Startup command: ";
181
182
183
184 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
186 BOOL vSyncPreference = [prefs oo_boolForKey:@"v-sync" defaultValue:YES];
187 int bitsPerColorComponent = [prefs oo_boolForKey:@"hdr" defaultValue:NO] ? 16 : 8;
188 int vSyncValue;
189
190 NSArray *arguments =
nil;
191 NSEnumerator *argEnum =
nil;
193 BOOL noSplashArgFound = NO;
194
195 [self initKeyMappingData];
196
197
199
200 arguments = [[NSProcessInfo processInfo] arguments];
201
202
203
204 for (argEnum = [arguments objectEnumerator]; (arg = [argEnum nextObject]); )
205 {
206 if ([arg isEqual:@"-nosplash"] || [arg isEqual:@"--nosplash"])
207 {
209 noSplashArgFound = YES;
210 }
211 else if (([arg isEqual:@"-splash"] || [arg isEqual:@"--splash"]) && !noSplashArgFound)
212 {
214 }
215
216
217 if ([arg isEqual:@"-novsync"] || [arg isEqual:@"--novsync"]) vSyncPreference = NO;
218
219 if ([arg isEqual: @"-hdr"]) bitsPerColorComponent = 16;
220
221
222 cmdLineArgsStr = [cmdLineArgsStr stringByAppendingFormat:@"%@ ", arg];
223 }
224
225 OOLog(
@"process.args",
@"%@", cmdLineArgsStr);
226
228
229
230
231 OOLog(
@"sdl.init",
@"%@",
@"initialising SDL");
232 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0)
233 {
234 OOLog(
@"sdl.init.failed",
@"Unable to init SDL: %s\n", SDL_GetError());
235 [self dealloc];
237 }
238
239 SDL_putenv ("SDL_VIDEO_WINDOW_POS=center");
240
242
243
245 if (![
OOSound isSoundOK])
OOLog(
@"sound.init",
@"%@",
@"Sound system disabled.");
246
247
248 static char windowCaption[128];
249 NSString *versionString = [NSString stringWithFormat:@"Oolite v%@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]];
250
251 strcpy (windowCaption, [versionString UTF8String]);
252 strcat (windowCaption, " - "__DATE__);
253 SDL_WM_SetCaption (windowCaption, "Oolite");
254
255#if OOLITE_WINDOWS
256
257 SDL_EventState (SDL_SYSWMEVENT, SDL_ENABLE);
258
259
260 static SDL_SysWMinfo wInfo;
261 SDL_VERSION(&wInfo.version);
262 SDL_GetWMInfo(&wInfo);
263 SDL_Window = wInfo.window;
264
265
266 if (![self getCurrentMonitorInfo:&monitorInfo])
267 {
268 OOLogWARN(
@"display.initGL.monitorInfoWarning",
@"Could not get current monitor information.");
269 }
270
271 atDesktopResolution = YES;
272
273#if USE_UNDOCUMENTED_DARKMODE_API
274
275 HMODULE hUxTheme = LoadLibraryExW(L"uxtheme.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
276 if (hUxTheme)
277 {
278
279 pfnSetPreferredAppMode SetPreferredAppMode = (pfnSetPreferredAppMode)GetProcAddress(hUxTheme, MAKEINTRESOURCEA(135));
280 if (SetPreferredAppMode) SetPreferredAppMode(AllowDark);
281 FreeLibrary(hUxTheme);
282 }
283#endif
284#endif
285
287
288 imagesDir = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Images"];
289 icon = SDL_LoadBMP([[imagesDir stringByAppendingPathComponent:@"WMicon.bmp"] UTF8String]);
290
291 if (icon != NULL)
292 {
293 colorkey = SDL_MapRGB(icon->format, 128, 0, 128);
294 SDL_SetColorKey(icon, SDL_SRCCOLORKEY, colorkey);
295 SDL_WM_SetIcon(icon, NULL);
296 }
297 SDL_FreeSurface(icon);
298
299 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, bitsPerColorComponent);
300 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, bitsPerColorComponent);
301 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, bitsPerColorComponent);
302 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, bitsPerColorComponent);
303 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
304 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
305
307
309#if OOLITE_WINDOWS
310 _hdrMaxBrightness = [prefs oo_floatForKey:@"hdr-max-brightness" defaultValue:1000.0f];
311 _hdrPaperWhiteBrightness = [prefs oo_floatForKey:@"hdr-paperwhite-brightness" defaultValue:200.0f];
312 if (bitsPerColorComponent == 16)
313 {
314
315 SDL_GL_SetAttribute(SDL_GL_PIXEL_TYPE_FLOAT, 1);
317 }
318#endif
319
320
321 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, vSyncPreference);
322 OOLog(
@"display.initGL",
@"V-Sync %@requested.", vSyncPreference ?
@"" :
@"not ");
323
324
325
326
327
328
329
330
331 if ([prefs oo_boolForKey:@"anti-aliasing" defaultValue:NO])
332 {
333 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
334 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
335 }
336
337 OOLog(
@"display.mode.list",
@"%@",
@"CREATING MODE LIST");
338 [self populateFullScreenModelist];
340
341
343 [self loadFullscreenSettings];
344 [self loadWindowSize];
345
346
349
350 OOLog(
@"display.initGL",
@"Trying %d-bpcc, 24-bit depth buffer", bitsPerColorComponent);
351 [self createSurface];
352
354 {
355
356 OOLog(
@"display.initGL",
@"%@",
@"Trying 8-bpcc, 32-bit depth buffer");
357 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
358 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
359 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
360 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
361 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
362 [self createSurface];
363
365 {
366
367
368 OOLog(
@"display.initGL",
@"%@",
@"Trying 5-bpcc, 16-bit depth buffer");
369 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
370 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
371 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
372 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
373
374 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
375 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
376
377 [self createSurface];
378
380 {
381 char * errStr = SDL_GetError();
382 OOLogERR(
@"display.mode.error",
@"Could not create display surface: %s", errStr);
383#if OOLITE_WINDOWS
385 {
386 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"splash-screen"];
387 [[NSUserDefaults standardUserDefaults] synchronize];
388 OOLogWARN(
@"display.mode.conflict",
@"Possible incompatibility between the splash screen and video drivers detected.");
389 OOLogWARN(
@"display.mode.conflict",
@"Oolite will start without showing the splash screen from now on. Override with 'oolite.exe -splash'");
390 }
391#endif
392 exit(1);
393 }
394 }
395 }
396
397 int testAttrib = -1;
398 OOLog(
@"display.initGL",
@"%@",
@"Achieved color / depth buffer sizes (bits):");
399 SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &testAttrib);
400 OOLog(
@"display.initGL",
@"Red: %d", testAttrib);
401 SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &testAttrib);
402 OOLog(
@"display.initGL",
@"Green: %d", testAttrib);
403 SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &testAttrib);
404 OOLog(
@"display.initGL",
@"Blue: %d", testAttrib);
405 SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &testAttrib);
406 OOLog(
@"display.initGL",
@"Alpha: %d", testAttrib);
407 SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &testAttrib);
408 OOLog(
@"display.initGL",
@"Depth Buffer: %d", testAttrib);
409#if OOLITE_WINDOWS
410 SDL_GL_GetAttribute(SDL_GL_PIXEL_TYPE_FLOAT, &testAttrib);
411 OOLog(
@"display.initGL",
@"Pixel type is float : %d", testAttrib);
412
413 OOLog(
@"display.initGL",
@"Pixel format index: %d", GetPixelFormat(GetDC(SDL_Window)));
414#endif
415
416
417 if (vSyncPreference && SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &vSyncValue) == -1)
418 {
419 OOLogWARN(
@"display.initGL",
@"Could not enable V-Sync. Please check that your graphics driver supports the %@_swap_control extension.",
421 }
422
425
426 [self autoShowMouse];
427
430
431 typedString = [[NSMutableString alloc] initWithString:@""];
434
436
438
440
441 return self;
442}
#define OOLogWARN(class, format,...)
#define OOLogERR(class, format,...)
BOOL m_glContextInitialized
NSMutableString * typedString
int scancode2Unicode[NUM_KEYS]
NSPoint virtualJoystickPosition
NSTimeInterval timeSinceLastMouseWheel
OOOpenGLMatrixManager * matrixManager
NSTimeInterval timeIntervalAtLastClick
BOOL setStickHandlerClass:(Class aClass)