(svn r25664) -Add [FS#4847]: [OSX] Bootstrap downloading of a baseset. (Matthieu)

pull/155/head
michi_cc 11 years ago
parent 3cd7eeb160
commit 84c4f8bbdc

@ -218,7 +218,7 @@ bool HandleBootstrap()
if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure; if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure;
/* If there is no network or no freetype, then there is nothing we can do. Go straight to failure. */ /* If there is no network or no freetype, then there is nothing we can do. Go straight to failure. */
#if defined(ENABLE_NETWORK) && defined(WITH_FREETYPE) && !defined(__APPLE__) && (defined(WITH_FONTCONFIG) || defined(WIN32)) #if defined(ENABLE_NETWORK) && defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(WIN32) || defined(__APPLE__))
if (!_network_available) goto failure; if (!_network_available) goto failure;
/* First tell the game we're bootstrapping. */ /* First tell the game we're bootstrapping. */

@ -56,22 +56,50 @@ static bool _cocoa_video_dialog = false;
CocoaSubdriver *_cocoa_subdriver = NULL; CocoaSubdriver *_cocoa_subdriver = NULL;
static const NSString *OTTDMainLaunchGameEngine = @"ottdmain_launch_game_engine";
/** /**
* The main class of the application, the application's delegate. * The main class of the application, the application's delegate.
*/ */
@implementation OTTDMain @implementation OTTDMain
/**
* Stop the game engine. Must be called on main thread.
*/
- (void)stopEngine
{
[ NSApp stop:self ];
/* Send an empty event to return from the run loop. Without that, application is stuck waiting for an event. */
NSEvent *event = [ NSEvent otherEventWithType:NSApplicationDefined location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0.0 windowNumber:0 context:nil subtype:0 data1:0 data2:0 ];
[ NSApp postEvent:event atStart:YES ];
}
/**
* Start the game loop.
*/
- (void)launchGameEngine: (NSNotification*) note
{
/* Setup cursor for the current _game_mode. */
[ _cocoa_subdriver->cocoaview resetCursorRects ];
/* Hand off to main application code. */
QZ_GameLoop();
/* We are done, thank you for playing. */
[ self performSelectorOnMainThread:@selector(stopEngine) withObject:nil waitUntilDone:FALSE ];
}
/** /**
* Called when the internal event loop has just started running. * Called when the internal event loop has just started running.
*/ */
- (void) applicationDidFinishLaunching: (NSNotification*) note - (void) applicationDidFinishLaunching: (NSNotification*) note
{ {
/* Hand off to main application code */ /* Add a notification observer so we can restart the game loop later on if necessary. */
QZ_GameLoop(); [ [ NSNotificationCenter defaultCenter ] addObserver:self selector:@selector(launchGameEngine:) name:OTTDMainLaunchGameEngine object:nil ];
/* We're done, thank you for playing */ /* Start game loop. */
[ NSApp stop:_ottd_main ]; [ [ NSNotificationCenter defaultCenter ] postNotificationName:OTTDMainLaunchGameEngine object:nil ];
} }
/** /**
@ -79,11 +107,18 @@ CocoaSubdriver *_cocoa_subdriver = NULL;
*/ */
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender
{ {
HandleExitGameRequest(); HandleExitGameRequest();
return NSTerminateCancel; // NSTerminateLater ? return NSTerminateCancel; // NSTerminateLater ?
} }
/**
* Remove ourself as a notification observer.
*/
- (void)unregisterObserver
{
[ [ NSNotificationCenter defaultCenter ] removeObserver:self ];
}
@end @end
/** /**
@ -326,6 +361,8 @@ void VideoDriver_Cocoa::Stop()
{ {
if (!_cocoa_video_started) return; if (!_cocoa_video_started) return;
[ _ottd_main unregisterObserver ];
delete _cocoa_subdriver; delete _cocoa_subdriver;
_cocoa_subdriver = NULL; _cocoa_subdriver = NULL;
@ -385,7 +422,11 @@ void VideoDriver_Cocoa::MakeDirty(int left, int top, int width, int height)
*/ */
void VideoDriver_Cocoa::MainLoop() void VideoDriver_Cocoa::MainLoop()
{ {
/* Start the main event loop */ /* Restart game loop if it was already running (e.g. after bootstrapping),
* otherwise this call is a no-op. */
[ [ NSNotificationCenter defaultCenter ] postNotificationName:OTTDMainLaunchGameEngine object:nil ];
/* Start the main event loop. */
[ NSApp run ]; [ NSApp run ];
} }
@ -708,7 +749,7 @@ void cocoaReleaseAutoreleasePool()
[ super resetCursorRects ]; [ super resetCursorRects ];
[ self clearTrackingRect ]; [ self clearTrackingRect ];
[ self setTrackingRect ]; [ self setTrackingRect ];
[ self addCursorRect:[ self bounds ] cursor:[ NSCursor clearCocoaCursor ] ]; [ self addCursorRect:[ self bounds ] cursor:(_game_mode == GM_BOOTSTRAP ? [ NSCursor arrowCursor ] : [ NSCursor clearCocoaCursor ]) ];
} }
/** /**
* Prepare for moving the application window * Prepare for moving the application window

Loading…
Cancel
Save