summaryrefslogtreecommitdiff
path: root/src/video/cocoa
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-08-05 20:36:10 +0000
committermichi_cc <michi_cc@openttd.org>2013-08-05 20:36:10 +0000
commit1ae357e905cd19ba49372775dcd79177b95e25e0 (patch)
tree1b116d502c1d1ff4bb2d1f47ed6f770503776bb4 /src/video/cocoa
parent3569a4fe5a30397add710f90b2eee5ecd953cbab (diff)
downloadopenttd-1ae357e905cd19ba49372775dcd79177b95e25e0.tar.xz
(svn r25664) -Add [FS#4847]: [OSX] Bootstrap downloading of a baseset. (Matthieu)
Diffstat (limited to 'src/video/cocoa')
-rw-r--r--src/video/cocoa/cocoa_v.mm55
1 files changed, 48 insertions, 7 deletions
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index f316a9bb5..f3e68b0ce 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -56,6 +56,7 @@ static bool _cocoa_video_dialog = false;
CocoaSubdriver *_cocoa_subdriver = NULL;
+static const NSString *OTTDMainLaunchGameEngine = @"ottdmain_launch_game_engine";
/**
@@ -63,15 +64,42 @@ CocoaSubdriver *_cocoa_subdriver = NULL;
*/
@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.
*/
- (void) applicationDidFinishLaunching: (NSNotification*) note
{
- /* Hand off to main application code */
- QZ_GameLoop();
+ /* Add a notification observer so we can restart the game loop later on if necessary. */
+ [ [ NSNotificationCenter defaultCenter ] addObserver:self selector:@selector(launchGameEngine:) name:OTTDMainLaunchGameEngine object:nil ];
- /* We're done, thank you for playing */
- [ NSApp stop:_ottd_main ];
+ /* Start game loop. */
+ [ [ NSNotificationCenter defaultCenter ] postNotificationName:OTTDMainLaunchGameEngine object:nil ];
}
/**
@@ -79,11 +107,18 @@ CocoaSubdriver *_cocoa_subdriver = NULL;
*/
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender
{
-
HandleExitGameRequest();
return NSTerminateCancel; // NSTerminateLater ?
}
+
+/**
+ * Remove ourself as a notification observer.
+ */
+- (void)unregisterObserver
+{
+ [ [ NSNotificationCenter defaultCenter ] removeObserver:self ];
+}
@end
/**
@@ -326,6 +361,8 @@ void VideoDriver_Cocoa::Stop()
{
if (!_cocoa_video_started) return;
+ [ _ottd_main unregisterObserver ];
+
delete _cocoa_subdriver;
_cocoa_subdriver = NULL;
@@ -385,7 +422,11 @@ void VideoDriver_Cocoa::MakeDirty(int left, int top, int width, int height)
*/
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 ];
}
@@ -708,7 +749,7 @@ void cocoaReleaseAutoreleasePool()
[ super resetCursorRects ];
[ self clearTrackingRect ];
[ 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