# HG changeset patch # User John Tsiombikas # Date 1309656812 -10800 # Node ID 124195562f7ebe5244048a7d8c1db8ce0410a0d0 # Parent 6242b03e719126221c47393be6f71be749df2b95 FUCKING AUTORELEASE POOL diff -r 6242b03e7191 -r 124195562f7e README --- a/README Tue Jun 28 13:52:02 2011 +0300 +++ b/README Sun Jul 03 04:33:32 2011 +0300 @@ -12,3 +12,9 @@ Finally the module source code must start by including "config.h", and the rest of it from that point on must be in a big ifdef USE_WSYS_MODULE_WHATEVER block. + +Building on windows +------------------- +If you decide to use the visual studio project files to build sgl, you still +need to run the configure script in order to generate config.h and modules.c. +Msys or cygwin should do the trick. diff -r 6242b03e7191 -r 124195562f7e src/log.c --- a/src/log.c Tue Jun 28 13:52:02 2011 +0300 +++ b/src/log.c Sun Jul 03 04:33:32 2011 +0300 @@ -1,15 +1,27 @@ #include #include +#include +#include #include #include "log.h" void sgl_log(const char *fmt, ...) { + static int first_run = 1; va_list ap; const char *logfile; FILE *fp; - if(!(logfile = getenv("SGL_LOG")) || !(fp = fopen(logfile, "a"))) { + if((logfile = getenv("SGL_LOG"))) { + if(first_run) { + remove(logfile); + first_run = 0; + } + if(!(fp = fopen(logfile, "a"))) { + fprintf(stderr, "failed to open logfile: %s: %s\n", logfile, strerror(errno)); + fp = stderr; + } + } else { fp = stderr; } diff -r 6242b03e7191 -r 124195562f7e src/wsys.c --- a/src/wsys.c Tue Jun 28 13:52:02 2011 +0300 +++ b/src/wsys.c Sun Jul 03 04:33:32 2011 +0300 @@ -2,6 +2,7 @@ #include #include #include "wsys.h" +#include "log.h" static struct wsys_module *merge(struct wsys_module *list1, struct wsys_module *list2); static struct wsys_module *msort(struct wsys_module *list, int count); @@ -27,9 +28,9 @@ { struct wsys_module *ws = wslist; - printf("window system modules:\n"); + sgl_log("window system modules:\n"); while(ws) { - printf("- %s\n", ws->name); + sgl_log("- %s\n", ws->name); ws = ws->next; } } diff -r 6242b03e7191 -r 124195562f7e src/wsys_cocoa.m --- a/src/wsys_cocoa.m Tue Jun 28 13:52:02 2011 +0300 +++ b/src/wsys_cocoa.m Sun Jul 03 04:33:32 2011 +0300 @@ -8,6 +8,9 @@ #import #include "sgl.h" #include "wsys.h" +#include "log.h" + +#define APPLE_SUCKS() sgl_log("%s called\n", __func__) @interface OpenGLView : NSOpenGLView { @@ -38,8 +41,18 @@ { int foo; } + +-(void) applicationWillFinishLaunching: (NSNotification*) notification; +-(void) applicationDidFinishLaunching: (NSNotification*) notification; + +-(void) windowDidExpose: (NSNotification*) notification; +-(void) windowDidResize: (NSNotification*) notification; + -(BOOL) applicationShouldTerminate: (NSApplication*) app; --(BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication*)app; +-(BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication*) app; +-(void) applicationWillTerminate: (NSNotification*) notification; +-(BOOL) windowShouldClose: (id) win; +-(void) windowWillClose: (NSNotification*) notification; @end @@ -103,6 +116,7 @@ static struct window *winlist, *active_win; static int quit_main_loop; +static NSAutoreleasePool *global_pool; void sgl_register_cocoa(void) { @@ -114,12 +128,14 @@ -(id) initWithFrame: (NSRect) frame pixelFormat: (NSOpenGLPixelFormat*) pf { + APPLE_SUCKS(); self = [super initWithFrame: frame pixelFormat: pf]; return self; } -(void) drawRect: (NSRect) rect { + APPLE_SUCKS(); sgl_display_callback_t func = sgl_get_callback(SGL_DISPLAY); if(func) { func(); @@ -128,6 +144,7 @@ -(void) reshape { + APPLE_SUCKS(); NSSize sz; sgl_reshape_callback_t func; @@ -143,41 +160,69 @@ -(BOOL) acceptsFirstResponder { + APPLE_SUCKS(); return YES; } @end @implementation AppDelegate +-(void) applicationWillFinishLaunching: (NSNotification*) notification +{ + APPLE_SUCKS(); +} + +-(void) applicationDidFinishLaunching: (NSNotification*) notification +{ + APPLE_SUCKS(); +} + +-(void) windowDidExpose: (NSNotification*) notification +{ + APPLE_SUCKS(); +} + +-(void) windowDidResize: (NSNotification*) notification +{ + APPLE_SUCKS(); +} + -(BOOL) applicationShouldTerminate: (NSApplication*) app { + APPLE_SUCKS(); return NSTerminateNow; } -(BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication*) app { + APPLE_SUCKS(); return YES; } -(void) applicationWillTerminate: (NSNotification*) notification { - printf("applicationWillTerminate\n"); + APPLE_SUCKS(); } -(BOOL) windowShouldClose: (id) win { + APPLE_SUCKS(); return YES; } -(void) windowWillClose: (NSNotification*) notification { - [NSApp terminate: nil]; + APPLE_SUCKS(); + /*[NSApp terminate: nil];*/ } @end static int init(void) { + APPLE_SUCKS(); AppDelegate *delegate; + global_pool = [[NSAutoreleasePool alloc] init]; + [NSApplication sharedApplication]; delegate = [[AppDelegate alloc] init]; @@ -187,15 +232,14 @@ static void shutdown(void) { + APPLE_SUCKS(); while(winlist) { - struct window *win = winlist; - winlist = winlist->next; - - /* TODO destroy window */ - free(win); + close_window(winlist->wid); } quit_main_loop = 1; + [NSApp setDelegate: nil]; + [global_pool drain]; } @@ -214,6 +258,7 @@ /* create/destroy windows */ static int create_window(int xsz, int ysz, unsigned int flags) { + APPLE_SUCKS(); NSAutoreleasePool *pool; NSWindow *nswin; NSRect rect; @@ -271,6 +316,7 @@ static void close_window(int wid) { + APPLE_SUCKS(); struct window *win, *prev, dummy; sgl_close_callback_t close_func; @@ -284,17 +330,25 @@ } [win->win close]; + prev->next = win->next; + + if(!dummy.next) { + winlist = 0; + } + if(active_win == win) { activate_window(winlist); } - - prev->next = win->next; free(win); - return; + break; } prev = win; win = win->next; } + + if(!winlist) { + shutdown(); + } } @@ -407,6 +461,8 @@ [runloop release]; [pool drain]; + + /*sgl_log("%s returning: %d\n", __func__, quit_main_loop ? -1 : 0);*/ return quit_main_loop ? -1 : 0; } diff -r 6242b03e7191 -r 124195562f7e tests/simple/simple.c --- a/tests/simple/simple.c Tue Jun 28 13:52:02 2011 +0300 +++ b/tests/simple/simple.c Sun Jul 03 04:33:32 2011 +0300 @@ -39,7 +39,7 @@ void disp(void) { - printf("redisplay\n"); + sgl_log("redisplay\n"); glClearColor(0.2, 0.2, 0.2, 1); glClear(GL_COLOR_BUFFER_BIT); @@ -69,9 +69,9 @@ char *ststr = state ? "pressed" : "released"; if(key < 0xff && isprint(key)) { - printf("keyboard: '%c' %s\n", (char)key, ststr); + sgl_log("keyboard: '%c' %s\n", (char)key, ststr); } else { - printf("keyboard: %x %s\n", key, ststr); + sgl_log("keyboard: %x %s\n", key, ststr); } if(key == 27) {