From c93dbcaa535691e737f9ea58fab3ce7b151aae1f Mon Sep 17 00:00:00 2001 From: Joel de Vahl Date: Wed, 19 Dec 2007 18:47:47 +0000 Subject: Initial server launcher for osx. --- default.bam | 19 ++++++++- scripts/make_release.py | 4 +- src/osxlaunch/main.m | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 src/osxlaunch/main.m diff --git a/default.bam b/default.bam index 39ad6b22..d1ecbc02 100644 --- a/default.bam +++ b/default.bam @@ -232,6 +232,7 @@ function build(settings) client_settings.linker.frameworks:add("OpenGL") client_settings.linker.frameworks:add("AGL") client_settings.linker.frameworks:add("Carbon") + client_settings.linker.frameworks:add("Cocoa") client_settings.linker.frameworks:add("CoreAudio") client_settings.linker.frameworks:add("AudioToolbox") client_settings.linker.frameworks:add("AudioUnit") @@ -263,6 +264,10 @@ function build(settings) game_server = Compile(settings, Collect("src/game/server/*.cpp"), serverdata.source, serverdata.cdata) editor = Compile(settings, Collect("src/editor/*.cpp")) + if platform == "macosx" then + osxlaunch = Compile(settings, Collect("src/osxlaunch/*.m")) + end + -- build tools (TODO: fix this so we don't get double _d_d stuff) tools_src = Collect("src/tools/*.cpp", "src/tools/*.c") @@ -284,16 +289,28 @@ function build(settings) masterserver_exe = Link(server_settings, "mastersrv", masterserver, engine, zlib) + if platform == "macosx" then + osxlaunch_exe = Link(client_settings, "TeeLaunch", osxlaunch) + end + -- make targets c = PseudoTarget("client".."_"..settings.config_name, client_exe) s = PseudoTarget("server".."_"..settings.config_name, server_exe) m = PseudoTarget("masterserver".."_"..settings.config_name, masterserver_exe) t = PseudoTarget("tools".."_"..settings.config_name, tools) + + if platform == "macosx" then + o = PseudoTarget("TeeLaunch".."_"..settings.config_name, osxlaunch_exe) + else + o = { } + end + Target(c) Target(s) Target(m) Target(t) - all = PseudoTarget(settings.config_name, c, s, m, t) + Target(o) + all = PseudoTarget(settings.config_name, c, s, m, t, o) Target(all) return all end diff --git a/scripts/make_release.py b/scripts/make_release.py index fa8766b4..dcb9b459 100644 --- a/scripts/make_release.py +++ b/scripts/make_release.py @@ -89,6 +89,8 @@ if use_bundle: copydir("data", bundle_resource_dir) shutil.copy("other/icons/Teewars.icns", bundle_resource_dir) shutil.copy("teewars"+exe_ext, bundle_bin_dir) + shutil.copy("teewars_srv"+exe_ext, bundle_bin_dir) + shutil.copy("TeeLaunch"+exe_ext, bundle_bin_dir) file(os.path.join(bundle_content_dir, "Info.plist"), "w").write(""" @@ -97,7 +99,7 @@ if use_bundle: CFBundleDevelopmentRegion English CFBundleExecutable - teewars + TeeLaunch CFBundleIconFile Teewars CFBundleInfoDictionaryVersion diff --git a/src/osxlaunch/main.m b/src/osxlaunch/main.m new file mode 100644 index 00000000..5f3d6ab6 --- /dev/null +++ b/src/osxlaunch/main.m @@ -0,0 +1,104 @@ +#import +#include + +@interface ServerView : NSTextView +{ + NSFileHandle *file; +} +- (void)listenTo: (NSFileHandle*)f; +@end + +@implementation ServerView +- (void)listenTo: (NSFileHandle*)f; +{ + file = f; + + [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(outputNotification:) name: NSFileHandleReadCompletionNotification object: file]; + + [file readInBackgroundAndNotify]; +} + +- (void) outputNotification: (NSNotification *) notification +{ + NSData *data = [[[notification userInfo] objectForKey: NSFileHandleNotificationDataItem] retain]; + NSString *string = [[NSString alloc] initWithData: data encoding: NSASCIIStringEncoding]; + + NSRange end = NSMakeRange([[self string] length], 0); + + [self replaceCharactersInRange: end withString: string]; + end.location += [string length]; + [self scrollRangeToVisible: end]; + + [string release]; + [file readInBackgroundAndNotify]; +} + +-(void)windowWillClose:(NSNotification *)notification +{ + [NSApp terminate:self]; +} +@end + +int main(int argc, char **argv) +{ + UInt32 mod = GetCurrentKeyModifiers(); + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSApp = [NSApplication sharedApplication]; + NSBundle* mainBundle = [NSBundle mainBundle]; + NSTask *task; + task = [[NSTask alloc] init]; + [task setCurrentDirectoryPath: [mainBundle resourcePath]]; + NSPipe *pipe; + NSFileHandle *file; + pipe = [NSPipe pipe]; + [task setStandardOutput: pipe]; + file = [pipe fileHandleForReading]; + + + if(mod & optionKey) + { + // run server + NSWindow *window; + ServerView *view; + NSRect graphicsRect; + + graphicsRect = NSMakeRect(100.0, 1000.0, 600.0, 400.0); + + window = [[NSWindow alloc] + initWithContentRect: graphicsRect + styleMask: NSTitledWindowMask + | NSClosableWindowMask + | NSMiniaturizableWindowMask + backing: NSBackingStoreBuffered + defer: NO]; + + [window setTitle: @"Teewars Server"]; + + view = [[[ServerView alloc] initWithFrame: graphicsRect] autorelease]; + [view setEditable: NO]; + + [window setContentView: view]; + [window setDelegate: view]; + [window makeKeyAndOrderFront: nil]; + + [view listenTo: file]; + [task setLaunchPath: [mainBundle pathForAuxiliaryExecutable: @"teewars_srv"]]; + [task launch]; + [NSApp run]; + [task terminate]; + } + else + { + // run client + [task setLaunchPath: [mainBundle pathForAuxiliaryExecutable: @"teewars"]]; + [task launch]; + [task waitUntilExit]; + } + + + + [NSApp release]; + [pool release]; + return(EXIT_SUCCESS); +} -- cgit 1.4.1