#import "OGLDisplay.h"
const int Event_Available = 1;
const int Event_NotAvailable = 2;
#define WM_BASE 0x0
const int WM_DRAW = WM_BASE + 1;
const int WM_TIMER = WM_BASE + 2;
const int WM_MOUSE_MOVE = WM_BASE + 3;
const int WM_MOUSE_DOWN = WM_BASE + 4;
const int WM_MOUSE_UP = WM_BASE + 5;
const int WM_MOUSE_DRAG = WM_BASE + 6;
const int WM_MOUSE_SCROLL = WM_BASE + 7;
const int WM_EXIT = WM_BASE + 8;
@implementation OGLDisplay
- (id) init
{
self = [super init];
if (self)
{
event_cond = [[NSConditionLock alloc]
initWithCondition: Event_NotAvailable];
message_cond = [[NSLock alloc] init];
event_list = [[NSMutableArray alloc] initWithCapacity: 10];
messages = [NSMutableArray array];
[messages retain];
[messageTable setDataSource: self];
[self addMessage: @"Hello"];
}
return self;
}
- (id)initWithContentsOfFile:(NSString *)fileName ofType:(NSString *)docType
{
self = [super initWithContentsOfFile: fileName ofType: docType];
if (self)
{
event_cond = [[NSConditionLock alloc]
initWithCondition: Event_NotAvailable];
event_list = [[NSMutableArray alloc] initWithCapacity: 10];
}
return self;
}
- (void) dealloc
{
[message_cond autorelease];
[messages autorelease];
[event_cond autorelease];
[event_list autorelease];
}
- (BOOL)loadDataRepresentation:(NSData *)docData ofType:(NSString *)docType
{
[NSThread detachNewThreadSelector: @selector(eventDispatcher:)
toTarget: self
withObject: nil];
return YES;
}
- (void)windowControllerDidLoadNib:(NSWindowController *)windowController
{
[messageDrawer setParentWindow: [windowController window]];
[self messageDrawerInit];
}
- (void) messageDrawerInit
{
[messageDrawer setMaxContentSize: NSMakeSize(0, 240)];
[messageDrawer setMinContentSize: NSMakeSize(0, 70)];
[messageDrawer setContentSize: NSMakeSize(0, 160)];
[messageDrawer setTrailingOffset: 20];
[messageDrawer setLeadingOffset: 20];
[messageDrawer openOnEdge: NSMinYEdge];
}
- (NSString *)windowNibName
{
return @"OGLDisplay";
}
- (void) addEvent: (struct Event_Type *) event
{
[event_cond lock];
NSData *e = [NSData dataWithBytes: event length: sizeof(struct Event_Type)];
[event_list addObject: e];
[event_cond unlockWithCondition: Event_Available];
}
- (void) getEvent: (struct Event_Type *) event
{
[event_cond lockWhenCondition: Event_Available];
NSData *e = [event_list objectAtIndex: 0];
memcpy(event, [e bytes], sizeof(struct Event_Type));
[event_list removeObjectAtIndex: 0];
[event_cond unlockWithCondition:
[event_list count] == 0 ? Event_NotAvailable : Event_Available];
}
- (void)eventDispatcher:(id)anObject
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
struct Event_Type e;
NSLog(@"Event Thread created!\n");
while (1)
{
[self getEvent: &e];
[self addMessage: [NSString stringWithFormat: @"Event: %d", e.type]];
if (e.type == WM_EXIT)
break;
}
[pool release];
printf("Event Thread stopped!\n");
}
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [messages count];
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
return [[messages objectAtIndex: rowIndex] objectForKey: [aTableColumn identifier]];
}
- (void) addMessage: (NSString*)message
{
if ([message_cond tryLock])
{
id dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSImage imageNamed: @"warning"], @"Icon",
message, @"Message", nil];
[messages addObject: dict];
NSLog([dict objectForKey: @"Message"]);
[messageTable reloadData];
[message_cond unlock];
}
}
- (void) addError: (NSString*)message
{
if ([message_cond tryLock])
{
id dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSImage imageNamed: @"error"], @"Icon",
message, @"Message", nil];
[messages addObject: dict];
[messageTable reloadData];
[message_cond unlock];
}
}
@end
#import "Pedestal.pch"
extern const int WM_DRAW;
extern const int WM_TIMER;
extern const int WM_MOUSE_MOVE;
extern const int WM_MOUSE_DOWN;
extern const int WM_MOUSE_UP;
extern const int WM_MOUSE_DRAG;
extern const int WM_MOUSE_SCROLL;
extern const int WM_EXIT;
struct Event_Type
{
int type;
int x, y;
int flags;
int buttons;
int count;
int dx, dy;
int duration;
};
@interface OGLDisplay : NSDocument
{
IBOutlet NSOpenGLView *view;
IBOutlet id messageDrawer;
IBOutlet id messageTable;
NSConditionLock *event_cond;
NSLock *message_cond;
NSMutableArray *event_list, *messages;
}
- (void) addEvent: (struct Event_Type *) event;
- (void) messageDrawerInit;
- (void) addError: (NSString*)message;
- (void) addMessage: (NSString*)message;
@end
#import "GLView.h"
@implementation GLView
- (id) initWithFrame: (NSRect) frame
{
GLuint attribs[] =
{
NSOpenGLPFANoRecovery,
NSOpenGLPFAWindow,
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAFullScreen,
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFAStencilSize, 8,
NSOpenGLPFAAccumSize, 0,
0
};
NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: (NSOpenGLPixelFormatAttribute*) attribs];
if (!fmt)
NSLog(@"No OpenGL pixel format");
self = [super initWithFrame:frame pixelFormat: [fmt autorelease]];
return self;
}
- (void) awakeFromNib
{
[[self window] makeFirstResponder: self];
}
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (void)windowDidResize:(NSNotification *)aNotification
{
}
- (id) document
{
return [[[self window] windowController] document];
}
- (void) drawRect: (NSRect) rect
{
}
- (NSPoint) windowToView: (NSPoint) p
{
return [self convertPoint: p fromView: nil];
}
- (void)mouseDown:(NSEvent *)theEvent
{
struct Event_Type e;
e.type = WM_MOUSE_DOWN;
[[self document] addEvent: &e];
}
@end
Thread 3 (process 6330 thread 0x4c03):
#0 0x900074c8 in mach_msg_trap ()
#1 0x90007018 in mach_msg ()
#2 0x90d66824 in glcDebugListener ()
#3 0x900246e8 in _pthread_body ()
Thread 2 (process 6330 thread 0x2b3b):
#0 0x90016f48 in semaphore_wait_signal_trap ()
#1 0x9000e790 in _pthread_cond_wait ()
#2 0x90a4bb00 in -[NSConditionLock lockWhenCondition:] ()
#3 0x004b1328 in -[OGLDisplay getEvent:] (self=0x5607d0, _cmd=0x4b1c74, event=0xf002fe20) at /Users/jdrake/Development/Pedestal/OGLDisplay.m:115
#4 0x004b14a8 in -[OGLDisplay eventDispatcher:] (self=0x5607d0, _cmd=0x4b1c60, anObject=0x0) at /Users/jdrake/Development/Pedestal/OGLDisplay.m:138
#5 0x90a39b74 in forkThreadForFunction ()
#6 0x900246e8 in _pthread_body ()
Thread 1 (process 6330 local thread 0x2c07):
#0 -[GLView mouseDown:] (self=0x571980, _cmd=0x90883610, theEvent=0x577f90) at /Users/jdrake/Development/Pedestal/GLView.m:69
#1 0x92e02c60 in -[NSWindow sendEvent:] ()
#2 0x92df5324 in -[NSApplication sendEvent:] ()
#3 0x92dfd73c in -[NSApplication run] ()
#4 0x92eb9b80 in NSApplicationMain ()
#5 0x000ebf74 in main (argc=1, argv=0xbffffd04) at /Users/jdrake/Development/Pedestal/main.m:13
#0 0x900074c8 in mach_msg_trap ()