From 931900fbd31a82aaab5f1aa8a5d3067565717a14 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 11 Sep 2010 19:03:41 +0900 Subject: [PATCH] Pass .m files through indent. The result isn't perfect, but it cleans up the whitespace and makes the code more consistent with the rest of the project. --- tools/Forge/Bundles/MapEdit/CameraView.m | 835 ++++----- tools/Forge/Bundles/MapEdit/Clipper.m | 174 +- tools/Forge/Bundles/MapEdit/Dict.m | 615 +++--- tools/Forge/Bundles/MapEdit/DictList.m | 62 +- tools/Forge/Bundles/MapEdit/Entity.m | 413 ++--- tools/Forge/Bundles/MapEdit/EntityClass.m | 145 +- .../Forge/Bundles/MapEdit/InspectorControl.m | 70 +- tools/Forge/Bundles/MapEdit/KeypairView.m | 97 +- tools/Forge/Bundles/MapEdit/Map.m | 1001 +++++----- tools/Forge/Bundles/MapEdit/PopScrollView.m | 49 +- tools/Forge/Bundles/MapEdit/Preferences.m | 226 +-- tools/Forge/Bundles/MapEdit/Project.m | 487 +++-- tools/Forge/Bundles/MapEdit/QuakeEd.m | 941 +++++----- tools/Forge/Bundles/MapEdit/QuakeEd_main.m | 4 +- tools/Forge/Bundles/MapEdit/SetBrush.m | 1652 ++++++++--------- tools/Forge/Bundles/MapEdit/Storage.m | 343 ++-- tools/Forge/Bundles/MapEdit/TexturePalette.m | 791 ++++---- tools/Forge/Bundles/MapEdit/TextureView.m | 163 +- tools/Forge/Bundles/MapEdit/Things.m | 285 ++- tools/Forge/Bundles/MapEdit/UserPath.m | 238 +-- tools/Forge/Bundles/MapEdit/XYView.m | 1200 ++++++------ tools/Forge/Bundles/MapEdit/ZScrollView.m | 40 +- tools/Forge/Bundles/MapEdit/ZView.m | 727 ++++---- tools/Forge/Bundles/MapEdit/misc.m | 218 ++- tools/Forge/Bundles/MapEdit/render.m | 591 +++--- 25 files changed, 5481 insertions(+), 5886 deletions(-) diff --git a/tools/Forge/Bundles/MapEdit/CameraView.m b/tools/Forge/Bundles/MapEdit/CameraView.m index 8772c6a35..4ace84b59 100644 --- a/tools/Forge/Bundles/MapEdit/CameraView.m +++ b/tools/Forge/Bundles/MapEdit/CameraView.m @@ -6,13 +6,12 @@ #include "XYView.h" #include "ZView.h" -id cameraview_i; +id cameraview_i; extern NSBezierPath *path; -BOOL timedrawing = 0; +BOOL timedrawing = 0; @implementation CameraView - /* ================== initWithFrame: @@ -20,43 +19,43 @@ initWithFrame: */ - initWithFrame:(NSRect)frameRect { - int size; - + int size; + [super initWithFrame: frameRect]; - + cameraview_i = self; - + xa = ya = za = 0; - + [self matrixFromAngles]; - + origin[0] = 64; origin[1] = 64; origin[2] = 48; - + move = 16; - + size = _bounds.size.width * _bounds.size.height; - zbuffer = malloc (size*4); - imagebuffer = malloc (size*4); - + zbuffer = malloc (size * 4); + imagebuffer = malloc (size * 4); + return self; } -- setXYOrigin: (NSPoint *)pt +-setXYOrigin:(NSPoint *)pt { origin[0] = pt->x; origin[1] = pt->y; return self; } -- setZOrigin: (float)pt +-setZOrigin:(float)pt { origin[2] = pt; return self; } -- setOrigin: (vec3_t)org angle: (float)angle +-setOrigin:(vec3_t)org angle:(float)angle { VectorCopy (org, origin); ya = angle; @@ -64,24 +63,23 @@ initWithFrame: return self; } -- getOrigin: (vec3_t)org +-getOrigin:(vec3_t)org { VectorCopy (origin, org); return self; } -- (float)yawAngle +-(float)yawAngle { return ya; } -- upFloor:sender +-upFloor:sender { sb_floor_dir = 1; sb_floor_dist = 99999; - [map_i makeAllPerform: @selector(feetToFloor)]; - if (sb_floor_dist == 99999) - { + [map_i makeAllPerform: @selector (feetToFloor)]; + if (sb_floor_dist == 99999) { Sys_Printf ("already on top floor"); return self; } @@ -91,13 +89,12 @@ initWithFrame: return self; } -- downFloor: sender +-downFloor:sender { sb_floor_dir = -1; sb_floor_dist = -99999; - [map_i makeAllPerform: @selector(feetToFloor)]; - if (sb_floor_dist == -99999) - { + [map_i makeAllPerform: @selector (feetToFloor)]; + if (sb_floor_dist == -99999) { Sys_Printf ("already on bottom floor"); return self; } @@ -120,30 +117,30 @@ UI TARGETS homeView ============ */ -- homeView: sender +-homeView:sender { xa = za = 0; - + [self matrixFromAngles]; [quakeed_i updateAll]; Sys_Printf ("homed view angle"); - + return self; } -- drawMode: sender +-drawMode:sender { - drawmode = [sender selectedColumn]; + drawmode =[sender selectedColumn]; [quakeed_i updateCamera]; return self; } -- setDrawMode: (drawmode_t)mode +-setDrawMode:(drawmode_t)mode { drawmode = mode; - //XXX[mode_radio_i selectCellAt:0: mode]; + [mode_radio_i selectCellAtRow: 0 column: mode]; [quakeed_i updateCamera]; return self; } @@ -156,22 +153,22 @@ TRANSFORMATION METHODS =============================================================================== */ -- matrixFromAngles +-matrixFromAngles { - if (xa > M_PI*0.4) - xa = M_PI*0.4; - if (xa < -M_PI*0.4) - xa = -M_PI*0.4; - -// vpn - matrix[2][0] = cos(xa)*cos(ya); - matrix[2][1] = cos(xa)*sin(ya); - matrix[2][2] = sin(xa); + if (xa > M_PI * 0.4) + xa = M_PI * 0.4; + if (xa < -M_PI * 0.4) + xa = -M_PI * 0.4; -// vup - matrix[1][0] = cos(xa+M_PI/2)*cos(ya); - matrix[1][1] = cos(xa+M_PI/2)*sin(ya); - matrix[1][2] = sin(xa+M_PI/2); +// vpn + matrix[2][0] = cos (xa) * cos (ya); + matrix[2][1] = cos (xa) * sin (ya); + matrix[2][2] = sin (xa); + +// vup + matrix[1][0] = cos (xa + M_PI / 2) * cos (ya); + matrix[1][1] = cos (xa + M_PI / 2) * sin (ya); + matrix[1][2] = sin (xa + M_PI / 2); // vright CrossProduct (matrix[2], matrix[1], matrix[0]); @@ -180,19 +177,19 @@ TRANSFORMATION METHODS } -- inverseTransform: (vec_t *)invec to:(vec_t *)outvec +-inverseTransform:(vec_t *)invec to:(vec_t *)outvec { - vec3_t inverse[3]; - vec3_t temp; - int i,j; - - for (i=0 ; i<3 ; i++) - for (j=0 ; j<3 ; j++) + vec3_t inverse[3]; + vec3_t temp; + int i, j; + + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) inverse[i][j] = matrix[j][i]; - - temp[0] = DotProduct(invec, inverse[0]); - temp[1] = DotProduct(invec, inverse[1]); - temp[2] = DotProduct(invec, inverse[2]); + + temp[0] = DotProduct (invec, inverse[0]); + temp[1] = DotProduct (invec, inverse[1]); + temp[2] = DotProduct (invec, inverse[2]); VectorAdd (temp, origin, outvec); @@ -209,42 +206,43 @@ TRANSFORMATION METHODS =============================================================================== */ -typedef struct -{ - vec3_t trans; - int clipflags; - vec3_t screen; // valid only if clipflags == 0 +typedef struct { + vec3_t trans; + int clipflags; + vec3_t screen; // valid only if clipflags == 0 } campt_t; + #define CLIP_RIGHT 1 #define CLIP_LEFT 2 #define CLIP_TOP 4 #define CLIP_BOTTOM 8 #define CLIP_FRONT 16 -int cam_cur; -campt_t campts[2]; +int cam_cur; +campt_t campts[2]; -vec3_t r_matrix[3]; -vec3_t r_origin; -float mid_x, mid_y; -float topscale = (240.0/3)/160; -float bottomscale = (240.0*2/3)/160; +vec3_t r_matrix[3]; +vec3_t r_origin; +float mid_x, mid_y; +float topscale = (240.0 / 3) / 160; +float bottomscale = (240.0 * 2 / 3) / 160; -extern plane_t rfrustum[5]; +extern plane_t rfrustum[5]; -void MakeCampt (vec3_t in, campt_t *pt) +void +MakeCampt (vec3_t in, campt_t * pt) { - vec3_t temp; - float scale; - + vec3_t temp; + float scale; + // transform the points VectorSubtract (in, r_origin, temp); - - pt->trans[0] = DotProduct(temp, r_matrix[0]); - pt->trans[1] = DotProduct(temp, r_matrix[1]); - pt->trans[2] = DotProduct(temp, r_matrix[2]); -// check clip flags + pt->trans[0] = DotProduct (temp, r_matrix[0]); + pt->trans[1] = DotProduct (temp, r_matrix[1]); + pt->trans[2] = DotProduct (temp, r_matrix[2]); + +// check clip flags if (pt->trans[2] < 1) pt->clipflags = CLIP_FRONT; else @@ -254,117 +252,115 @@ void MakeCampt (vec3_t in, campt_t *pt) pt->clipflags |= CLIP_RIGHT; else if (-pt->trans[0] > pt->trans[2]) pt->clipflags |= CLIP_LEFT; - - if (pt->trans[1] > pt->trans[2]*topscale ) + + if (pt->trans[1] > pt->trans[2] * topscale) pt->clipflags |= CLIP_TOP; - else if (-pt->trans[1] > pt->trans[2]*bottomscale ) + else if (-pt->trans[1] > pt->trans[2] * bottomscale) pt->clipflags |= CLIP_BOTTOM; - + if (pt->clipflags) return; - + // project - scale = mid_x/pt->trans[2]; - pt->screen[0] = mid_x + pt->trans[0]*scale; - pt->screen[1] = mid_y + pt->trans[1]*scale; + scale = mid_x / pt->trans[2]; + pt->screen[0] = mid_x + pt->trans[0] * scale; + pt->screen[1] = mid_y + pt->trans[1] * scale; } -void CameraMoveto(vec3_t p) +void +CameraMoveto (vec3_t p) { - campt_t *pt; - + campt_t *pt; + if ([path elementCount] > 2048) lineflush (); - + pt = &campts[cam_cur]; cam_cur ^= 1; - MakeCampt (p,pt); + MakeCampt (p, pt); if (!pt->clipflags) { // onscreen, so move there immediately - NSPoint point = {pt->screen[0], pt->screen[1]}; + NSPoint point = { pt->screen[0], pt->screen[1] }; [path moveToPoint: point]; } } -void ClipLine (vec3_t p1, vec3_t p2, int planenum) +void +ClipLine (vec3_t p1, vec3_t p2, int planenum) { - float d, d2, frac; - vec3_t new; - plane_t *pl; - float scale; - NSPoint point; - + float d, d2, frac; + vec3_t new; + plane_t *pl; + float scale; + NSPoint point; + if (planenum == 5) { // draw it! - scale = mid_x/p1[2]; - point.x = mid_x + p1[0]*scale; - point.y = mid_y + p1[1]*scale; + scale = mid_x / p1[2]; + point.x = mid_x + p1[0] * scale; + point.y = mid_y + p1[1] * scale; [path moveToPoint: point]; - - scale = mid_x/p2[2]; - point.x = mid_x + p2[0]*scale; - point.y = mid_y + p2[1]*scale; + + scale = mid_x / p2[2]; + point.x = mid_x + p2[0] * scale; + point.y = mid_y + p2[1] * scale; [path lineToPoint: point]; return; } pl = &rfrustum[planenum]; - - d = DotProduct (p1, pl->normal) - pl->dist; + + d = DotProduct (p1, pl->normal) - pl->dist; d2 = DotProduct (p2, pl->normal) - pl->dist; - if (d <= ON_EPSILON && d2 <= ON_EPSILON) - { // off screen + if (d <= ON_EPSILON && d2 <= ON_EPSILON) { // off screen return; } - - if (d >= 0 && d2 >= 0) - { // on front - ClipLine (p1, p2, planenum+1); + + if (d >= 0 && d2 >= 0) { // on front + ClipLine (p1, p2, planenum + 1); return; } - - frac = d/(d-d2); - new[0] = p1[0] + frac*(p2[0]-p1[0]); - new[1] = p1[1] + frac*(p2[1]-p1[1]); - new[2] = p1[2] + frac*(p2[2]-p1[2]); - + + frac = d / (d - d2); + new[0] = p1[0] + frac * (p2[0] - p1[0]); + new[1] = p1[1] + frac * (p2[1] - p1[1]); + new[2] = p1[2] + frac * (p2[2] - p1[2]); + if (d > 0) - ClipLine (p1, new, planenum+1); + ClipLine (p1, new, planenum + 1); else - ClipLine (new, p2, planenum+1); + ClipLine (new, p2, planenum + 1); } -int c_off, c_on, c_clip; +int c_off, c_on, c_clip; -void CameraLineto(vec3_t p) +void +CameraLineto (vec3_t p) { - campt_t *p1, *p2; - int bits; - + campt_t *p1, *p2; + int bits; + p2 = &campts[cam_cur]; cam_cur ^= 1; p1 = &campts[cam_cur]; MakeCampt (p, p2); - if (p1->clipflags & p2->clipflags) - { + if (p1->clipflags & p2->clipflags) { c_off++; - return; // entirely off screen + return; // entirely off screen } - + bits = p1->clipflags | p2->clipflags; - - if (! bits ) - { - NSPoint point1 = {p1->screen[0], p1->screen[1]}; - NSPoint point2 = {p2->screen[0], p2->screen[1]}; + + if (!bits) { + NSPoint point1 = { p1->screen[0], p1->screen[1] }; + NSPoint point2 = { p2->screen[0], p2->screen[1] }; c_on++; - [path moveToPoint: point1]; + [path moveToPoint: point1]; [path lineToPoint: point2]; - return; // entirely on screen + return; // entirely on screen } - // needs to be clipped c_clip++; @@ -377,10 +373,10 @@ void CameraLineto(vec3_t p) drawSolid ============= */ -- drawSolid +-drawSolid { - unsigned char *planes[5]; - + unsigned char *planes[5]; + // // draw it // @@ -388,47 +384,40 @@ drawSolid VectorCopy (matrix[0], r_matrix[0]); VectorCopy (matrix[1], r_matrix[1]); VectorCopy (matrix[2], r_matrix[2]); - + r_width = _bounds.size.width; r_height = _bounds.size.height; r_picbuffer = imagebuffer; r_zbuffer = zbuffer; r_drawflat = (drawmode == dr_flat); - + REN_BeginCamera (); REN_ClearBuffers (); // // render the setbrushes -// - [map_i makeAllPerform: @selector(CameraRenderSelf)]; +// + [map_i makeAllPerform: @selector (CameraRenderSelf)]; // // display the output // - [[self window] setBackingType:NSBackingStoreRetained]; - - planes[0] = (unsigned char *)imagebuffer; - NSDrawBitmap( - _bounds, - r_width, - r_height, - 8, - 3, - 32, - r_width*4, - NO, - NO, - @"RGB", //FIXME what should this be? - (const unsigned char **const)planes - ); + [[self window] setBackingType: NSBackingStoreRetained]; + + planes[0] = (unsigned char *) imagebuffer; + NSDrawBitmap (_bounds, r_width, r_height, 8, 3, 32, r_width * 4, NO, NO, @"RGB", // FIXME + // what + // should + // this + // be? + (const unsigned char **const) planes); + + // XXX NSPing (); + [[self window] setBackingType: NSBackingStoreBuffered]; + + - //XXX NSPing (); - [[self window] setBackingType:NSBackingStoreBuffered]; - - - return self; } @@ -438,9 +427,9 @@ drawSolid drawWire =================== */ -- drawWire: (NSRect)rect +-drawWire:(NSRect)rect { -// copy current info to globals for the C callbacks +// copy current info to globals for the C callbacks mid_x = _bounds.size.width / 2; mid_y = 2 * _bounds.size.height / 3; @@ -448,20 +437,20 @@ drawWire VectorCopy (matrix[0], r_matrix[0]); VectorCopy (matrix[1], r_matrix[1]); VectorCopy (matrix[2], r_matrix[2]); - + r_width = _bounds.size.width; r_height = _bounds.size.height; r_picbuffer = imagebuffer; r_zbuffer = zbuffer; REN_BeginCamera (); - + // erase window NSEraseRect (rect); - + // draw all entities - linestart (0,0,0); - [map_i makeUnselectedPerform: @selector(CameraDrawSelf)]; + linestart (0, 0, 0); + [map_i makeUnselectedPerform: @selector (CameraDrawSelf)]; lineflush (); return self; @@ -472,21 +461,20 @@ drawWire drawSelf =================== */ -- drawSelf:(NSRect)rects :(int)rectCount +-drawSelf:(NSRect)rects :(int)rectCount { float drawtime = 0; if (timedrawing) - drawtime = Sys_DoubleTime (); + drawtime = Sys_DoubleTime (); if (drawmode == dr_texture || drawmode == dr_flat) [self drawSolid]; else [self drawWire: rects]; - if (timedrawing) - { - //XXX NSPing (); + if (timedrawing) { + // XXX NSPing (); drawtime = Sys_DoubleTime () - drawtime; printf ("CameraView drawtime: %5.3f\n", drawtime); } @@ -500,25 +488,25 @@ drawSelf XYDrawSelf ============= */ -- XYDrawSelf +-XYDrawSelf { - - PSsetrgbcolor (0,0,1.0); + + PSsetrgbcolor (0, 0, 1.0); PSsetlinewidth (0.15); - PSmoveto (origin[0]-16,origin[1]); - PSrlineto (16,8); - PSrlineto (16,-8); - PSrlineto (-16,-8); - PSrlineto (-16,8); - PSrlineto (32,0); - - PSmoveto (origin[0],origin[1]); - PSrlineto (64*cos(ya+M_PI/4), 64*sin(ya+M_PI/4)); - PSmoveto (origin[0],origin[1]); - PSrlineto (64*cos(ya-M_PI/4), 64*sin(ya-M_PI/4)); - + PSmoveto (origin[0] - 16, origin[1]); + PSrlineto (16, 8); + PSrlineto (16, -8); + PSrlineto (-16, -8); + PSrlineto (-16, 8); + PSrlineto (32, 0); + + PSmoveto (origin[0], origin[1]); + PSrlineto (64 * cos (ya + M_PI / 4), 64 * sin (ya + M_PI / 4)); + PSmoveto (origin[0], origin[1]); + PSrlineto (64 * cos (ya - M_PI / 4), 64 * sin (ya - M_PI / 4)); + PSstroke (); - + return self; } @@ -527,23 +515,23 @@ XYDrawSelf ZDrawSelf ============= */ -- ZDrawSelf +-ZDrawSelf { - PSsetrgbcolor (0,0,1.0); + PSsetrgbcolor (0, 0, 1.0); PSsetlinewidth (0.15); - - PSmoveto (-16,origin[2]); - PSrlineto (16,8); - PSrlineto (16,-8); - PSrlineto (-16,-8); - PSrlineto (-16,8); - PSrlineto (32,0); - - PSmoveto (-15,origin[2]-47); - PSrlineto (29,0); - PSrlineto (0,54); - PSrlineto (-29,0); - PSrlineto (0,-54); + + PSmoveto (-16, origin[2]); + PSrlineto (16, 8); + PSrlineto (16, -8); + PSrlineto (-16, -8); + PSrlineto (-16, 8); + PSrlineto (32, 0); + + PSmoveto (-15, origin[2] - 47); + PSrlineto (29, 0); + PSrlineto (0, 54); + PSrlineto (-29, 0); + PSrlineto (0, -54); PSstroke (); @@ -564,79 +552,77 @@ ZDrawSelf modalMoveLoop ================ */ -- modalMoveLoop: (NSPoint *)basept :(vec3_t)movemod : converter +-modalMoveLoop:(NSPoint *)basept :(vec3_t)movemod :converter { - vec3_t originbase; - NSEvent *event = 0; //XXX - NSPoint newpt; -// NSPoint brushpt; - vec3_t delta; -// id ent; - int i; -// vec3_t temp; - + vec3_t originbase; + NSEvent *event = 0; // XXX + NSPoint newpt; + +// NSPoint brushpt; + vec3_t delta; + +// id ent; + int i; + +// vec3_t temp; + Sys_Printf ("moving camera position"); - VectorCopy (origin, originbase); - + VectorCopy (origin, originbase); + // // modal event loop using instance drawing // goto drawentry; - while ([event type] != NSLeftMouseUp && [event type] != NSRightMouseUp) - { - // + while ([event type] != NSLeftMouseUp &&[event type] != NSRightMouseUp) { + // // calculate new point - // - newpt = [event locationInWindow]; - newpt = [converter convertPoint:newpt fromView:NULL]; - - delta[0] = newpt.x-basept->x; - delta[1] = newpt.y-basept->y; - delta[2] = delta[1]; // height change - - for (i=0 ; i<3 ; i++) - origin[i] = originbase[i]+movemod[i]*delta[i]; - -#if 0 // FIXME - // + // + newpt =[event locationInWindow]; + newpt =[converter convertPoint: newpt fromView: NULL]; + + delta[0] = newpt.x - basept->x; + delta[1] = newpt.y - basept->y; + delta[2] = delta[1]; // height change + + for (i = 0; i < 3; i++) + origin[i] = originbase[i] + movemod[i] * delta[i]; + +#if 0 // FIXME + // // if command is down, look towards brush or entity - // - if (event->flags & NS_SHIFTMASK) - { - ent = [quakemap_i selectedEntity]; - if (ent) - { + // + if (event->flags & NS_SHIFTMASK) { + ent =[quakemap_i selectedEntity]; + if (ent) { [ent origin: temp]; brushpt.x = temp[0]; brushpt.y = temp[1]; - } - else - brushpt = [brush_i centerPoint]; + } else + brushpt =[brush_i centerPoint]; ya = atan2 (brushpt.y - newpt.y, brushpt.x - newpt.x); [self matrixFromAngles]; } #endif - -drawentry: - // + + drawentry: + // // instance draw new frame - // + // [quakeed_i newinstance]; [self display]; -/*XXX event = [NSApp nextEventMatchingMask: NSLeftMouseUpMask | NSLeftMouseDraggedMask | NSRightMouseUpMask - | NSRightMouseDraggedMask | NSApplicationDefinedMask]; -*/ - if ([event type] == NSKeyDown) - { + | NSRightMouseDraggedMask | NSApplicationDefinedMask + untilDate: [NSDate distantFuture] + inMode: NSEventTrackingRunLoopMode dequeue: YES]; + if ([event type] == NSKeyDown) { [self _keyDown: event]; [self display]; goto drawentry; } - + } return self; @@ -649,31 +635,29 @@ drawentry: XYmouseDown =============== */ -- (BOOL)XYmouseDown: (NSPoint *)pt flags:(int)flags // return YES if brush handled -{ - vec3_t movemod; - - if (fabs(pt->x - origin[0]) > 16 - || fabs(pt->y - origin[1]) > 16 ) +-(BOOL) XYmouseDown:(NSPoint *)pt flags:(int)flags +// return YES if brush handled +{ + vec3_t movemod; + + if (fabs (pt->x - origin[0]) > 16 || fabs (pt->y - origin[1]) > 16) return NO; - -#if 0 - if (flags & NSAlternateKeyMask) - { // up / down drag + +#if 0 + if (flags & NSAlternateKeyMask) { // up / down drag movemod[0] = 0; movemod[1] = 0; movemod[2] = 1; - } - else + } else #endif - { + { movemod[0] = 1; movemod[1] = 1; movemod[2] = 0; } - + [self modalMoveLoop: pt : movemod : xyview_i]; - + return YES; } @@ -683,18 +667,18 @@ XYmouseDown ZmouseDown =============== */ -- (BOOL)ZmouseDown: (NSPoint *)pt flags:(int)flags // return YES if brush handled -{ - vec3_t movemod; - - if (fabs(pt->y - origin[2]) > 16 - || pt->x < -8 || pt->x > 8 ) +-(BOOL) ZmouseDown:(NSPoint *)pt flags:(int)flags +// return YES if brush handled +{ + vec3_t movemod; + + if (fabs (pt->y - origin[2]) > 16 || pt->x < -8 || pt->x > 8) return NO; - + movemod[0] = 0; movemod[1] = 0; movemod[2] = 1; - + [self modalMoveLoop: pt : movemod : zview_i]; return YES; @@ -708,48 +692,46 @@ ZmouseDown viewDrag: =================== */ -- viewDrag:(NSPoint *)pt +-viewDrag:(NSPoint *)pt { - float dx,dy; - NSEvent *event = 0; //XXX - NSPoint newpt; - + float dx, dy; + NSEvent *event = 0; // XXX + NSPoint newpt; + // // modal event loop using instance drawing // goto drawentry; - while ([event type] != NSRightMouseUp) - { - // + while ([event type] != NSRightMouseUp) { + // // calculate new point - // - newpt = [event locationInWindow]; - newpt = [self convertPoint:newpt fromView:NULL]; + // + newpt =[event locationInWindow]; + newpt =[self convertPoint: newpt fromView: NULL]; dx = newpt.x - pt->x; dy = newpt.y - pt->y; *pt = newpt; - - ya -= dx/_bounds.size.width*M_PI/2 * 4; - xa += dy/_bounds.size.width*M_PI/2 * 4; - + + ya -= dx / _bounds.size.width * M_PI / 2 * 4; + xa += dy / _bounds.size.width * M_PI / 2 * 4; + [self matrixFromAngles]; - -drawentry: + + drawentry: [quakeed_i newinstance]; [self display]; -/*XXX - event = [NSApp getNextEvent: - NSKeyDownMask | NSRightMouseUpMask | NSRightMouseDraggedMask]; -*/ - if ([event type] == NSKeyDown) - { - [self _keyDown: event]; + event = [NSApp nextEventMatchingMask: NSRightMouseUpMask + | NSRightMouseDraggedMask + untilDate: [NSDate distantFuture] + inMode: NSEventTrackingRunLoopMode dequeue: YES]; + if ([event type] == NSKeyDown) { + [self _keyDown:event]; [self display]; goto drawentry; } - + } return self; @@ -763,80 +745,72 @@ drawentry: mouseDown =================== */ -- (void) mouseDown:(NSEvent *)theEvent +-(void) mouseDown:(NSEvent *)theEvent { - NSPoint pt; - int i; - vec3_t p1, p2; - float forward, right, up; - int flags; - - pt = [theEvent locationInWindow]; - - pt = [self convertPoint:pt fromView:NULL]; + NSPoint pt; + int i; + vec3_t p1, p2; + float forward, right, up; + int flags; + + pt =[theEvent locationInWindow]; + + pt =[self convertPoint: pt fromView: NULL]; VectorCopy (origin, p1); forward = 160; right = pt.x - 160; - up = pt.y - 240*2/3; - for (i=0 ; i<3 ; i++) - p2[i] = forward*matrix[2][i] + up*matrix[1][i] + right*matrix[0][i]; - for (i=0 ; i<3 ; i++) - p2[i] = p1[i] + 100*p2[i]; + up = pt.y - 240 * 2 / 3; + for (i = 0; i < 3; i++) + p2[i] = + forward * matrix[2][i] + up * matrix[1][i] + right * matrix[0][i]; + for (i = 0; i < 3; i++) + p2[i] = p1[i] + 100 * p2[i]; - flags = [theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask); + flags = + [theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask | + NSAlternateKeyMask | NSCommandKeyMask); // // bare click to select a texture // - if (flags == 0) - { + if (flags == 0) { [map_i getTextureRay: p1 : p2]; return; } - // // shift click to select / deselect a brush from the world // - if (flags == NSShiftKeyMask) - { + if (flags == NSShiftKeyMask) { [map_i selectRay: p1 : p2 : NO]; return; } - // // cmd-shift click to set a target/targetname entity connection // - if (flags == (NSShiftKeyMask|NSCommandKeyMask) ) - { + if (flags == (NSShiftKeyMask | NSCommandKeyMask)) { [map_i entityConnect: p1 : p2]; return; } - // // alt click = set entire brush texture // - if (flags == NSAlternateKeyMask) - { - if (drawmode != dr_texture) - { + if (flags == NSAlternateKeyMask) { + if (drawmode != dr_texture) { Sys_Printf ("No texture setting except in texture mode!\n"); NopSound (); return; - } + } [map_i setTextureRay: p1 : p2 : YES]; [quakeed_i updateAll]; return; } - // // ctrl-alt click = set single face texture // - if (flags == (NSControlKeyMask | NSAlternateKeyMask) ) - { - if (drawmode != dr_texture) - { + if (flags == (NSControlKeyMask | NSAlternateKeyMask)) { + if (drawmode != dr_texture) { Sys_Printf ("No texture setting except in texture mode!\n"); NopSound (); return; @@ -845,11 +819,11 @@ mouseDown [quakeed_i updateAll]; return; } - + Sys_Printf ("bad flags for click"); NopSound (); - + return; } @@ -860,29 +834,30 @@ rightMouseDown */ -(void) rightMouseDown:(NSEvent *)theEvent { - NSPoint pt; - int flags; - - pt = [theEvent locationInWindow]; - - [self convertPoint:pt fromView:NULL]; + NSPoint pt; + int flags; - flags = [theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask); + pt =[theEvent locationInWindow]; + + [self convertPoint: pt fromView: NULL]; + + flags = + [theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask | + NSAlternateKeyMask | NSCommandKeyMask); // // click = drag camera // - if (flags == 0) - { + if (flags == 0) { Sys_Printf ("looking"); [self viewDrag: &pt]; Sys_Printf ("%s", ""); return; - } + } Sys_Printf ("bad flags for click"); NopSound (); - + return; } @@ -898,85 +873,83 @@ keyDown #define KEY_DOWNARROW 0xaf -- _keyDown: (NSEvent *)theEvent +-_keyDown:(NSEvent *)theEvent { - int ch; - - ch = tolower([[theEvent characters] characterAtIndex: 0]); - - switch (ch) - { - case 13: - return self; - - case 'a': - case 'A': - xa += M_PI/8; - [self matrixFromAngles]; - [quakeed_i updateCamera]; - return self; - - case 'z': - case 'Z': - xa -= M_PI/8; - [self matrixFromAngles]; - [quakeed_i updateCamera]; - return self; - - case KEY_RIGHTARROW: - ya -= M_PI*move/(64*2); - [self matrixFromAngles]; - [quakeed_i updateCamera]; - break; - - case KEY_LEFTARROW: - ya += M_PI*move/(64*2); - [self matrixFromAngles]; - [quakeed_i updateCamera]; - break; - - case KEY_UPARROW: - origin[0] += move*cos(ya); - origin[1] += move*sin(ya); - [quakeed_i updateCamera]; - break; - - case KEY_DOWNARROW: - origin[0] -= move*cos(ya); - origin[1] -= move*sin(ya); - [quakeed_i updateCamera]; - break; - - case '.': - origin[0] += move*cos(ya-M_PI_2); - origin[1] += move*sin(ya-M_PI_2); - [quakeed_i updateCamera]; - break; - - case ',': - origin[0] -= move*cos(ya-M_PI_2); - origin[1] -= move*sin(ya-M_PI_2); - [quakeed_i updateCamera]; - break; - - case 'd': - case 'D': - origin[2] += move; - [quakeed_i updateCamera]; - break; - - case 'c': - case 'C': - origin[2] -= move; - [quakeed_i updateCamera]; - break; - + int ch; + + ch = tolower ([[theEvent characters] characterAtIndex: 0]); + + switch (ch) { + case 13: + return self; + + case 'a': + case 'A': + xa += M_PI / 8; + [self matrixFromAngles]; + [quakeed_i updateCamera]; + return self; + + case 'z': + case 'Z': + xa -= M_PI / 8; + [self matrixFromAngles]; + [quakeed_i updateCamera]; + return self; + + case KEY_RIGHTARROW: + ya -= M_PI * move / (64 * 2); + [self matrixFromAngles]; + [quakeed_i updateCamera]; + break; + + case KEY_LEFTARROW: + ya += M_PI * move / (64 * 2); + [self matrixFromAngles]; + [quakeed_i updateCamera]; + break; + + case KEY_UPARROW: + origin[0] += move * cos (ya); + origin[1] += move * sin (ya); + [quakeed_i updateCamera]; + break; + + case KEY_DOWNARROW: + origin[0] -= move * cos (ya); + origin[1] -= move * sin (ya); + [quakeed_i updateCamera]; + break; + + case '.': + origin[0] += move * cos (ya - M_PI_2); + origin[1] += move * sin (ya - M_PI_2); + [quakeed_i updateCamera]; + break; + + case ',': + origin[0] -= move * cos (ya - M_PI_2); + origin[1] -= move * sin (ya - M_PI_2); + [quakeed_i updateCamera]; + break; + + case 'd': + case 'D': + origin[2] += move; + [quakeed_i updateCamera]; + break; + + case 'c': + case 'C': + origin[2] -= move; + [quakeed_i updateCamera]; + break; + } - - return self; + + return self; } @end - diff --git a/tools/Forge/Bundles/MapEdit/Clipper.m b/tools/Forge/Bundles/MapEdit/Clipper.m index 4b24e6f48..2bd0086a0 100644 --- a/tools/Forge/Bundles/MapEdit/Clipper.m +++ b/tools/Forge/Bundles/MapEdit/Clipper.m @@ -10,79 +10,73 @@ #include "CameraView.h" #include "QuakeEd.h" -id clipper_i; +id clipper_i; @implementation Clipper -- init +-init { [super init]; clipper_i = self; - return self; + return self; } -- (BOOL)hide +-(BOOL) hide { - int oldnum; - + int oldnum; + oldnum = num; num = 0; return (oldnum > 0); } -- flipNormal +-flipNormal { - vec3_t temp; - - if (num == 2) - { + vec3_t temp; + + if (num == 2) { VectorCopy (pos[0], temp); VectorCopy (pos[1], pos[0]); VectorCopy (temp, pos[1]); - } - else if (num == 3) - { + } else if (num == 3) { VectorCopy (pos[0], temp); VectorCopy (pos[2], pos[0]); VectorCopy (temp, pos[2]); - } - else - { + } else { Sys_Printf ("no clipplane"); NSBeep (); } - + return self; } -- (BOOL)getFace: (face_t *)f +-(BOOL) getFace:(face_t *) f { - vec3_t v1, v2, norm; - int i; - + vec3_t v1, v2, norm; + int i; + VectorCopy (vec3_origin, plane.normal); plane.dist = 0; if (num < 2) return NO; - if (num == 2) - { + if (num == 2) { VectorCopy (pos[0], pos[2]); pos[2][2] += 16; } - - for (i=0 ; i<3 ; i++) + + for (i = 0; i < 3; i++) VectorCopy (pos[i], f->planepts[i]); - + VectorSubtract (pos[2], pos[0], v1); VectorSubtract (pos[1], pos[0], v2); - + CrossProduct (v1, v2, norm); VectorNormalize (norm); - - if ( !norm[0] && !norm[1] && !norm[2] ) + + if (!norm[0] && !norm[1] && !norm[2]) return NO; - - [texturepalette_i getTextureDef: &f->texture]; + + [texturepalette_i getTextureDef:&f->texture]; return YES; } @@ -92,38 +86,36 @@ id clipper_i; XYClick ================ */ -- XYClick: (NSPoint)pt +-XYClick:(NSPoint) pt { - int i; - vec3_t new; - - new[0] = [xyview_i snapToGrid: pt.x]; - new[1] = [xyview_i snapToGrid: pt.y]; - new[2] = [map_i currentMinZ]; + int i; + vec3_t new; + + new[0] =[xyview_i snapToGrid:pt.x]; + new[1] =[xyview_i snapToGrid:pt.y]; + new[2] =[map_i currentMinZ]; // see if a point is allready there - for (i=0 ; ix - pos[i][0] > 10) || fabs(pt->y - pos[i][1] > 10) ) + int i; + + for (i = 0; i < 3; i++) { + if (fabs (pt->x - pos[i][0] > 10) || fabs (pt->y - pos[i][1] > 10)) continue; - // drag this point - + // drag this point + } - + return NO; } -- ZClick: (NSPoint)pt +-ZClick:(NSPoint) pt { return self; } //============================================================================= -- carve +-carve { - [map_i makeSelectedPerform: @selector(carveByClipper)]; + [map_i makeSelectedPerform:@selector (carveByClipper)]; num = 0; return self; } -- cameraDrawSelf +-cameraDrawSelf { - vec3_t mid; - int i; - - linecolor (1,0.5,0); + vec3_t mid; + int i; - for (i=0 ; ikey, d->value); + int i; + dict_t *d; + + for (i = 0; i < numElements; i++) { + d =[self elementAt:i]; + printf ("%s : %s\n", d->key, d->value); } return self; } @@ -31,80 +29,75 @@ copyFromZone JDC =========== */ -- copy +-copy { - id new; - int i; - dict_t *d; - char *old; - - new = [super copy]; - for (i=0 ; ikey; - d->key = malloc(strlen(old)+1); + d->key = malloc (strlen (old) + 1); strcpy (d->key, old); - + old = d->value; - d->value = malloc(strlen(old)+1); + d->value = malloc (strlen (old) + 1); strcpy (d->value, old); } - + return new; } -- initFromFile:(FILE *)fp +-initFromFile:(FILE *) fp { [self init]; - return [self parseBraceBlock:fp]; + return[self parseBraceBlock:fp]; } //=============================================== // -// Dictionary pair functions +// Dictionary pair functions // //=============================================== // -// Write a { } block out to a FILE* +// Write a { } block out to a FILE* // -- writeBlockTo:(FILE *)fp +-writeBlockTo:(FILE *) fp { - int max; - int i; - dict_t *d; - - fprintf(fp,"{\n"); - max = [super count]; - for (i = 0;i < max;i++) - { - d = [super elementAt:i]; - fprintf(fp,"\t{\"%s\"\t\"%s\"}\n",d->key,d->value); + int max; + int i; + dict_t *d; + + fprintf (fp, "{\n"); + max =[super count]; + for (i = 0; i < max; i++) { + d =[super elementAt:i]; + fprintf (fp, "\t{\"%s\"\t\"%s\"}\n", d->key, d->value); } - fprintf(fp,"}\n"); - + fprintf (fp, "}\n"); + return self; } // -// Write a single { } block out +// Write a single { } block out // -- writeFile:(char *)path +-writeFile:(char *) path { - FILE *fp; - - fp = fopen(path,"w+t"); - if (fp != NULL) - { - printf("Writing dictionary file %s.\n",path); - fprintf(fp,"// QE_Project file %s\n",path); + FILE *fp; + + fp = fopen (path, "w+t"); + if (fp != NULL) { + printf ("Writing dictionary file %s.\n", path); + fprintf (fp, "// QE_Project file %s\n", path); [self writeBlockTo:fp]; - fclose(fp); - } - else - { - printf("Error writing %s!\n",path); + fclose (fp); + } else { + printf ("Error writing %s!\n", path); return NULL; } @@ -113,165 +106,160 @@ JDC //=============================================== // -// Utility methods +// Utility methods // //=============================================== // -// Find a keyword in storage -// Returns * to dict_t, otherwise NULL +// Find a keyword in storage +// Returns * to dict_t, otherwise NULL // -- (dict_t *) findKeyword:(char *)key -{ - int max; - int i; - dict_t *d; - - max = [super count]; - for (i = 0;i < max;i++) - { - d = [super elementAt:i]; - if (!strcmp(d->key,key)) +-(dict_t *) findKeyword:(char *) key +{ + int max; + int i; + dict_t *d; + + max =[super count]; + for (i = 0; i < max; i++) { + d =[super elementAt:i]; + if (!strcmp (d->key, key)) return d; } - + return NULL; } // -// Change a keyword's string +// Change a keyword's string // -- changeStringFor:(char *)key to:(char *)value +-changeStringFor:(char *) +key to:(char *) value { - dict_t *d; - dict_t newd; - - d = [self findKeyword:key]; - if (d != NULL) - { - free(d->value); - d->value = malloc(strlen(value)+1); - strcpy(d->value,value); - } - else - { - newd.key = malloc(strlen(key)+1); - strcpy(newd.key,key); - newd.value = malloc(strlen(value)+1); - strcpy(newd.value,value); + dict_t *d; + dict_t newd; + + d =[self findKeyword:key]; + if (d != NULL) { + free (d->value); + d->value = malloc (strlen (value) + 1); + strcpy (d->value, value); + } else { + newd.key = malloc (strlen (key) + 1); + strcpy (newd.key, key); + newd.value = malloc (strlen (value) + 1); + strcpy (newd.value, value); [self addElement:&newd]; } return self; } // -// Search for keyword, return the string * +// Search for keyword, return the string * // -- (char *)getStringFor:(char *)name +-(char *) getStringFor:(char *) name { - dict_t *d; - - d = [self findKeyword:name]; + dict_t *d; + + d =[self findKeyword:name]; if (d != NULL) return d->value; - + return ""; } // -// Search for keyword, return the value +// Search for keyword, return the value // -- (unsigned int)getValueFor:(char *)name +-(unsigned int) getValueFor:(char *) name { - dict_t *d; - - d = [self findKeyword:name]; + dict_t *d; + + d =[self findKeyword:name]; if (d != NULL) - return atol(d->value); - + return atol (d->value); + return 0; } // -// Return # of units in keyword's value +// Return # of units in keyword's value // -- (int) getValueUnits:(char *)key +-(int) getValueUnits:(char *) key { - id temp; - int count; - - temp = [self parseMultipleFrom:key]; - count = [temp count]; + id temp; + int count; + + temp =[self parseMultipleFrom:key]; + count =[temp count]; [temp release]; - + return count; } // -// Convert List to string +// Convert List to string // -- (char *)convertListToString:(id)list +-(char *) convertListToString:(id) list { - int i; - int max; - char tempstr[4096]; - char *s; - char *newstr; - - max = [list count]; + int i; + int max; + char tempstr[4096]; + char *s; + char *newstr; + + max =[list count]; tempstr[0] = 0; - for (i = 0;i < max;i++) - { - s = [list elementAt:i]; - strcat(tempstr,s); - strcat(tempstr," "); + for (i = 0; i < max; i++) { + s =[list elementAt:i]; + strcat (tempstr, s); + strcat (tempstr, " "); } - newstr = malloc(strlen(tempstr)+1); - strcpy(newstr,tempstr); - + newstr = malloc (strlen (tempstr) + 1); + strcpy (newstr, tempstr); + return newstr; } // // JDC: I wrote this to simplify removing vectors // -- removeKeyword:(char *)key +-removeKeyword:(char *) key { - dict_t *d; + dict_t *d; - d = [self findKeyword:key]; + d =[self findKeyword:key]; if (d == NULL) return self; - [self removeElementAt:d - (dict_t*)dataPtr]; + [self removeElementAt:d - (dict_t *) dataPtr]; return self; } // -// Delete string from keyword's value +// Delete string from keyword's value // -- delString:(char *)string fromValue:(char *)key +-delString:(char *) +string fromValue:(char *) key { - id temp; - int count; - int i; - char *s; - dict_t *d; - - d = [self findKeyword:key]; + id temp; + int count; + int i; + char *s; + dict_t *d; + + d =[self findKeyword:key]; if (d == NULL) return NULL; - temp = [self parseMultipleFrom:key]; - count = [temp count]; - for (i = 0;i < count;i++) - { - s = [temp elementAt:i]; - if (!strcmp(s,string)) - { + temp =[self parseMultipleFrom:key]; + count =[temp count]; + for (i = 0; i < count; i++) { + s =[temp elementAt:i]; + if (!strcmp (s, string)) { [temp removeElementAt:i]; - free(d->value); - d->value = [self convertListToString:temp]; + free (d->value); + d->value =[self convertListToString:temp]; [temp release]; - + break; } } @@ -279,186 +267,179 @@ JDC } // -// Add string to keyword's value +// Add string to keyword's value // -- addString:(char *)string toValue:(char *)key +-addString:(char *) +string toValue:(char *) key { - char *newstr; - char spacing[] = "\t"; - dict_t *d; - - d = [self findKeyword:key]; + char *newstr; + char spacing[] = "\t"; + dict_t *d; + + d =[self findKeyword:key]; if (d == NULL) return NULL; - newstr = malloc(strlen(string) + strlen(d->value) + strlen(spacing) + 1); - strcpy(newstr,d->value); - strcat(newstr,spacing); - strcat(newstr,string); - free(d->value); + newstr = + malloc (strlen (string) + strlen (d->value) + strlen (spacing) + 1); + strcpy (newstr, d->value); + strcat (newstr, spacing); + strcat (newstr, string); + free (d->value); d->value = newstr; - + return self; } //=============================================== // -// Use these for multiple parameters in a keyword value +// Use these for multiple parameters in a keyword value // //=============================================== -char *searchStr; -char item[4096]; +char *searchStr; +char item[4096]; -- setupMultiple:(char *)value +-setupMultiple:(char *) value { searchStr = value; return self; } -- (char *)getNextParameter +-(char *) getNextParameter { - char *s; - + char *s; + if (!searchStr) return NULL; - strcpy(item,searchStr); - s = FindWhitespcInBuffer(item); + strcpy (item, searchStr); + s = FindWhitespcInBuffer (item); if (!*s) searchStr = NULL; - else - { + else { *s = 0; - searchStr = FindNonwhitespcInBuffer(s+1); + searchStr = FindNonwhitespcInBuffer (s + 1); } return item; } // -// Parses a keyvalue string & returns a Storage full of those items +// Parses a keyvalue string & returns a Storage full of those items // -- (id) parseMultipleFrom:(char *)key +-(id) parseMultipleFrom:(char *) key { - #define ITEMSIZE 128 - id stuff; - char string[ITEMSIZE]; - char *s; - - s = [self getStringFor:key]; +#define ITEMSIZE 128 + id stuff; + char string[ITEMSIZE]; + char *s; + + s =[self getStringFor:key]; if (s == NULL) return NULL; - - stuff = [[Storage alloc] - initCount:0 - elementSize:ITEMSIZE - description:NULL]; - + + stuff =[[Storage alloc] + initCount: 0 elementSize: ITEMSIZE description:NULL]; + [self setupMultiple:s]; - while((s = [self getNextParameter])) - { - bzero(string,ITEMSIZE); - strcpy(string,s); + while ((s =[self getNextParameter])) { + bzero (string, ITEMSIZE); + strcpy (string, s); [stuff addElement:string]; } - + return stuff; } //=============================================== // -// Dictionary pair parsing +// Dictionary pair parsing // //=============================================== // -// parse all keyword/value pairs within { } 's +// parse all keyword/value pairs within { } 's // -- (id) parseBraceBlock:(FILE *)fp +-(id) parseBraceBlock:(FILE *) fp { - int c; - dict_t pair; - char string[1024]; - - c = FindBrace(fp); + int c; + dict_t pair; + char string[1024]; + + c = FindBrace (fp); if (c == -1) return NULL; - - while((c = FindBrace(fp)) != '}') - { + + while ((c = FindBrace (fp)) != '}') { if (c == -1) return NULL; -// c = FindNonwhitespc(fp); -// if (c == -1) -// return NULL; -// CopyUntilWhitespc(fp,string); +// c = FindNonwhitespc(fp); +// if (c == -1) +// return NULL; +// CopyUntilWhitespc(fp,string); // JDC: fixed to allow quoted keys - c = FindNonwhitespc(fp); + c = FindNonwhitespc (fp); if (c == -1) return NULL; - c = fgetc(fp); - if ( c == '\"') - CopyUntilQuote(fp,string); - else - { - ungetc (c,fp); - CopyUntilWhitespc(fp,string); + c = fgetc (fp); + if (c == '\"') + CopyUntilQuote (fp, string); + else { + ungetc (c, fp); + CopyUntilWhitespc (fp, string); } - pair.key = malloc(strlen(string)+1); - strcpy(pair.key,string); - - c = FindQuote(fp); - CopyUntilQuote(fp,string); - pair.value = malloc(strlen(string)+1); - strcpy(pair.value,string); - + pair.key = malloc (strlen (string) + 1); + strcpy (pair.key, string); + + c = FindQuote (fp); + CopyUntilQuote (fp, string); + pair.value = malloc (strlen (string) + 1); + strcpy (pair.value, string); + [super addElement:&pair]; - c = FindBrace(fp); + c = FindBrace (fp); } - + return self; } @end - //=============================================== // -// C routines for string parsing +// C routines for string parsing // //=============================================== -int GetNextChar(FILE *fp) + int +GetNextChar (FILE * fp) { - int c; - int c2; - - c = getc(fp); + int c; + int c2; + + c = getc (fp); if (c == EOF) return -1; - if (c == '/') // parse comments + if (c == '/') // parse comments { - c2 = getc(fp); - if (c2 == '/') - { - while((c2 = getc(fp)) != '\n'); - c = getc(fp); - } - else - ungetc(c2,fp); + c2 = getc (fp); + if (c2 == '/') { + while ((c2 = getc (fp)) != '\n'); + c = getc (fp); + } else + ungetc (c2, fp); } return c; } -void CopyUntilWhitespc(FILE *fp,char *buffer) +void +CopyUntilWhitespc (FILE * fp, char *buffer) { - int count = 800; - int c; - - while(count--) - { - c = GetNextChar(fp); + int count = 800; + int c; + + while (count--) { + c = GetNextChar (fp); if (c == EOF) return; - if (c <= ' ') - { + if (c <= ' ') { *buffer = 0; return; } @@ -466,18 +447,17 @@ void CopyUntilWhitespc(FILE *fp,char *buffer) } } -void CopyUntilQuote(FILE *fp,char *buffer) +void +CopyUntilQuote (FILE * fp, char *buffer) { - int count = 800; - int c; - - while(count--) - { - c = GetNextChar(fp); + int count = 800; + int c; + + while (count--) { + c = GetNextChar (fp); if (c == EOF) return; - if (c == '\"') - { + if (c == '\"') { *buffer = 0; return; } @@ -485,31 +465,30 @@ void CopyUntilQuote(FILE *fp,char *buffer) } } -int FindBrace(FILE *fp) +int +FindBrace (FILE * fp) { - int count = 800; - int c; - - while(count--) - { - c = GetNextChar(fp); + int count = 800; + int c; + + while (count--) { + c = GetNextChar (fp); if (c == EOF) return -1; - if (c == '{' || - c == '}') + if (c == '{' || c == '}') return c; } return -1; } -int FindQuote(FILE *fp) +int +FindQuote (FILE * fp) { - int count = 800; - int c; - - while(count--) - { - c = GetNextChar(fp); + int count = 800; + int c; + + while (count--) { + c = GetNextChar (fp); if (c == EOF) return -1; if (c == '\"') @@ -518,63 +497,63 @@ int FindQuote(FILE *fp) return -1; } -int FindWhitespc(FILE *fp) +int +FindWhitespc (FILE * fp) { - int count = 800; - int c; - - while(count--) - { - c = GetNextChar(fp); - if (c == EOF) - return -1; - if (c <= ' ') - { - ungetc(c,fp); - return c; - } - } - return -1; -} + int count = 800; + int c; -int FindNonwhitespc(FILE *fp) -{ - int count = 800; - int c; - - while(count--) - { - c = GetNextChar(fp); + while (count--) { + c = GetNextChar (fp); if (c == EOF) return -1; - if (c > ' ') - { - ungetc(c,fp); + if (c <= ' ') { + ungetc (c, fp); return c; } } return -1; } -char *FindWhitespcInBuffer(char *buffer) +int +FindNonwhitespc (FILE * fp) { - int count = 1000; - char *b = buffer; - - while(count--) + int count = 800; + int c; + + while (count--) { + c = GetNextChar (fp); + if (c == EOF) + return -1; + if (c > ' ') { + ungetc (c, fp); + return c; + } + } + return -1; +} + +char * +FindWhitespcInBuffer (char *buffer) +{ + int count = 1000; + char *b = buffer; + + while (count--) if (*b <= ' ') return b; else b++; - return NULL; + return NULL; } -char *FindNonwhitespcInBuffer(char *buffer) +char * +FindNonwhitespcInBuffer (char *buffer) { - int count = 1000; - char *b = buffer; - - while(count--) + int count = 1000; + char *b = buffer; + + while (count--) if (*b > ' ') return b; else diff --git a/tools/Forge/Bundles/MapEdit/DictList.m b/tools/Forge/Bundles/MapEdit/DictList.m index 00ae27b66..2724be7c9 100644 --- a/tools/Forge/Bundles/MapEdit/DictList.m +++ b/tools/Forge/Bundles/MapEdit/DictList.m @@ -3,64 +3,60 @@ #include "Dict.h" @implementation DictList - // -// Read in variable # of objects from FILE * +// Read in variable # of objects from FILE * // -- initListFromFile:(FILE *)fp +- initListFromFile:(FILE *) fp { - id d; - + id d; + [super init]; - do - { - d = [(Dict *)[Dict alloc] initFromFile:fp]; + do { + d =[(Dict *)[Dict alloc] initFromFile:fp]; if (d != NULL) [self addObject:d]; - } while(d != NULL); + } while (d != NULL); [d release]; - + return self; } // -// Write out list file +// Write out list file // -- writeListFile:(char *)filename +-writeListFile:(char *) filename { - FILE *fp; - int i; - id obj; - - fp = fopen(filename,"w+t"); + FILE *fp; + int i; + id obj; + + fp = fopen (filename, "w+t"); if (fp == NULL) return NULL; - - fprintf(fp,"// Object List written by QuakeEd\n"); - for (i = 0;i < [self count];i++) - { - obj = [self objectAtIndex:i]; + fprintf (fp, "// Object List written by QuakeEd\n"); + + for (i = 0; i <[self count]; i++) { + obj =[self objectAtIndex:i]; [obj writeBlockTo:fp]; } - fclose(fp); - + fclose (fp); + return self; } // -// Find the keyword in all the Dict objects +// Find the keyword in all the Dict objects // -- (id) findDictKeyword:(char *)key +-(id) findDictKeyword:(char *) key { - int i; - dict_t *d; - id dict; + int i; + dict_t *d; + id dict; - for (i = 0;i < [self count];i++) - { - dict = [self objectAtIndex:i]; - d = [(Dict *)dict findKeyword:key]; + for (i = 0; i <[self count]; i++) { + dict =[self objectAtIndex:i]; + d =[(Dict *) dict findKeyword:key]; if (d != NULL) return dict; } diff --git a/tools/Forge/Bundles/MapEdit/Entity.m b/tools/Forge/Bundles/MapEdit/Entity.m index 0d4d5a20f..891fc2b0f 100644 --- a/tools/Forge/Bundles/MapEdit/Entity.m +++ b/tools/Forge/Bundles/MapEdit/Entity.m @@ -12,89 +12,85 @@ @implementation Entity -vec3_t bad_mins = {-8, -8, -8}; -vec3_t bad_maxs = {8, 8, 8}; +vec3_t bad_mins = { -8, -8, -8 }; +vec3_t bad_maxs = { 8, 8, 8 }; -- createFixedBrush: (vec3_t)org +-createFixedBrush:(vec3_t) org { - vec3_t emins, emaxs; - float *v, *v2, *color; - id new; - texturedef_t td; - + vec3_t emins, emaxs; + float *v, *v2, *color; + id new; + texturedef_t td; + // get class - new = [entity_classes_i classForName: [self valueForQKey: "classname"]]; + new =[entity_classes_i classForName: [self valueForQKey:"classname"]]; if (new) { - v = [new mins]; - v2 = [new maxs]; + v =[new mins]; + v2 =[new maxs]; } else { v = bad_mins; v2 = bad_maxs; } - color = [new drawColor]; + color =[new drawColor]; modifiable = NO; - memset(&td,0,sizeof(td)); - strcpy (td.texture,"entity"); + memset (&td, 0, sizeof (td)); + strcpy (td.texture, "entity"); VectorAdd (org, v, emins); VectorAdd (org, v2, emaxs); - new = [[SetBrush alloc] initOwner: self mins:emins maxs:emaxs - texture: &td]; - [new setEntityColor: color]; + new =[[SetBrush alloc] initOwner: self mins: emins maxs: emaxs texture:&td]; + [new setEntityColor:color]; + + [self addObject:new]; - [self addObject: new]; - return self; } -- initClass: (char *)classname +-initClass:(char *) classname { - id new; - esize_t esize; - char value[80]; - vec3_t min, max; - float *v; - + id new; + esize_t esize; + char value[80]; + vec3_t min, max; + float *v; + [super init]; - + modifiable = YES; [self setKey: "classname" toValue:classname]; // get class - new = [entity_classes_i classForName: [self valueForQKey: "classname"]]; + new =[entity_classes_i classForName: [self valueForQKey:"classname"]]; if (!new) esize = esize_model; else - esize = [new esize]; - -// create a brush if needed - if (esize == esize_fixed) - { - v = [new mins]; - [[map_i selectedBrush] getMins: min maxs: max]; - VectorSubtract (min, v, min); - - sprintf (value, "%i %i %i",(int)min[0], (int)min[1], (int)min[2]); - [self setKey:"origin" toValue: value]; + esize =[new esize]; - [self createFixedBrush: min]; - } - else +// create a brush if needed + if (esize == esize_fixed) { + v =[new mins]; + [[map_i selectedBrush] getMins: min maxs:max]; + VectorSubtract (min, v, min); + + sprintf (value, "%i %i %i", (int) min[0], (int) min[1], (int) min[2]); + [self setKey: "origin" toValue:value]; + + [self createFixedBrush:min]; + } else modifiable = YES; - + return self; } -- (void)dealloc +-(void) dealloc { - epair_t *e, *n; - - for (e=epairs ; e ; e=n) - { + epair_t *e, *n; + + for (e = epairs; e; e = n) { n = e->next; free (e->key); free (e->value); @@ -103,78 +99,79 @@ vec3_t bad_maxs = {8, 8, 8}; [super dealloc]; } -- (BOOL)modifiable +-(BOOL) modifiable { return modifiable; } -- setModifiable: (BOOL)m +-setModifiable:(BOOL) m { modifiable = m; return self; } -- (void)removeObject: o +-(void) removeObject:o { - [super removeObject: o]; + [super removeObject:o]; if ([self count]) return; // the entity is empty, so remove the entire thing - if ( self == [map_i objectAtIndex: 0]) - return; // never remove the world - - [map_i removeObject: self]; + if (self ==[map_i objectAtIndex:0]) + return; // never remove the world + + [map_i removeObject:self]; [self release]; } -- (char *)valueForQKey: (char *)k +-(char *) valueForQKey:(char *) k { - epair_t *e; - static char ret[64]; - - for (e=epairs ; e ; e=e->next) - if (!strcmp(k,e->key)) - { + epair_t *e; + static char ret[64]; + + for (e = epairs; e; e = e->next) + if (!strcmp (k, e->key)) { strcpy (ret, e->value); return ret; } return ""; } -- getVector: (vec3_t)v forKey: (char *)k +-getVector:(vec3_t) +v forKey:(char *) k { - char *c; - - c = [self valueForQKey: k]; + char *c; + + c =[self valueForQKey:k]; v[0] = v[1] = v[2] = 0; - + sscanf (c, "%f %f %f", &v[0], &v[1], &v[2]); return self; } -- print +-print { - epair_t *e; - - for (e=epairs ; e ; e=e->next) - printf ("%20s : %20s\n",e->key, e->value); + epair_t *e; + + for (e = epairs; e; e = e->next) + printf ("%20s : %20s\n", e->key, e->value); return self; } -- setKey:(const char *)k toValue:(const char *)v +-setKey:(const char *) +k toValue:(const char *) v { - epair_t *e; + epair_t *e; while (*k && *k <= ' ') k++; if (!*k) - return self; // don't set NULL values - - for (e=epairs ; e ; e=e->next) { + return self; // don't set NULL values + + for (e = epairs; e; e = e->next) { if (!strcmp (k, e->key)) { free (e->value); e->value = strdup (v); @@ -182,59 +179,56 @@ vec3_t bad_maxs = {8, 8, 8}; } } - e = malloc (sizeof(epair_t)); + e = malloc (sizeof (epair_t)); e->key = strdup (k); e->value = strdup (v); e->next = epairs; epairs = e; - + return self; } -- (int)numPairs +-(int) numPairs { - int i; - epair_t *e; - - i=0; - for (e=epairs ; e ; e=e->next) + int i; + epair_t *e; + + i = 0; + for (e = epairs; e; e = e->next) i++; return i; } -- (epair_t *)epairs +-(epair_t *) epairs { return epairs; } -- removeKeyPair: (char *)key +-removeKeyPair:(char *) key { - epair_t *e, *e2; - + epair_t *e, *e2; + if (!epairs) return self; e = epairs; - if (!strcmp(e->key, key)) - { + if (!strcmp (e->key, key)) { epairs = e->next; free (e); return self; } - - for (; e ; e=e->next) - { - if (e->next && !strcmp(e->next->key, key)) - { + + for (; e; e = e->next) { + if (e->next && !strcmp (e->next->key, key)) { e2 = e->next; e->next = e2->next; free (e2); return self; } } - + printf ("WARNING: removeKeyPair: %s not found\n", key); - return self; + return self; } @@ -245,37 +239,37 @@ targetname If the entity does not have a "targetname" key, a unique one is generated ============= */ -- (char *)targetname +-(char *) targetname { - char *t; - int i, count; - id ent; - int tval, maxt; - char name[20]; - - t = [self valueForQKey: "targetname"]; + char *t; + int i, count; + id ent; + int tval, maxt; + char name[20]; + + t =[self valueForQKey:"targetname"]; if (t && t[0]) return t; - + // make a unique name of the form t - count = [map_i count]; + count =[map_i count]; maxt = 0; - for (i=1 ; i maxt) maxt = tval; } - - sprintf (name,"t%i",maxt+1); - - [self setKey: "targetname" toValue: name]; - - return [self valueForQKey: "targetname"]; // so it's not on the stack + + sprintf (name, "t%i", maxt + 1); + + [self setKey: "targetname" toValue:name]; + + return[self valueForQKey:"targetname"]; + // so it's not on the stack } /* @@ -286,40 +280,39 @@ FILE METHODS ============================================================================== */ -int nument; +int nument; -- initFromScript: (script_t *) script +-initFromScript:(script_t *) script { - char *key; - id eclass, brush; - char *spawn; - vec3_t emins, emaxs; - vec3_t org; - texturedef_t td; - esize_t esize; - int i, c; - float *color; - + char *key; + id eclass, brush; + char *spawn; + vec3_t emins, emaxs; + vec3_t org; + texturedef_t td; + esize_t esize; + int i, c; + float *color; + [self init]; - if (!Script_GetToken (script, true)) - { + if (!Script_GetToken (script, true)) { [self dealloc]; return nil; } - if (strcmp (Script_Token (script), "{") ) + if (strcmp (Script_Token (script), "{")) Sys_Error ("initFromFileP: { not found"); - + do { if (!Script_GetToken (script, true)) break; - if (!strcmp (Script_Token (script), "}") ) + if (!strcmp (Script_Token (script), "}")) break; - if (!strcmp (Script_Token (script), "{") ) { + if (!strcmp (Script_Token (script), "{")) { // read a brush - brush = [[SetBrush alloc] initFromScript: script owner:self]; - [self addObject: brush]; + brush =[[SetBrush alloc] initFromScript: script owner:self]; + [self addObject:brush]; } else { // read a key / value pair key = strdup (Script_Token (script)); @@ -328,122 +321,114 @@ int nument; free (key); } } while (1); - + nument++; // get class - spawn = [self valueForQKey: "classname"]; - eclass = [entity_classes_i classForName: spawn]; + spawn =[self valueForQKey:"classname"]; + eclass =[entity_classes_i classForName:spawn]; - esize = [eclass esize]; + esize =[eclass esize]; - [self getVector: org forKey: "origin"]; - - if ([self count] && esize != esize_model) - { - printf ("WARNING:Entity with brushes and wrong model type\n"); + [self getVector: org forKey:"origin"]; + + if ([self count] && esize != esize_model) { + printf ("WARNING:Entity with brushes and wrong model type\n"); [self removeAllObjects]; } - - if (![self count] && esize == esize_model) - { - printf ("WARNING:Entity with no brushes and esize_model\n"); - [texturepalette_i getTextureDef: &td]; - for (i=0 ; i<3 ; i++) - { + + if (![self count] && esize == esize_model) { + printf ("WARNING:Entity with no brushes and esize_model\n"); + [texturepalette_i getTextureDef:&td]; + for (i = 0; i < 3; i++) { emins[i] = org[i] - 8; emaxs[i] = org[i] + 8; } - brush = [[SetBrush alloc] initOwner: self mins:emins maxs:emaxs - texture: &td]; - [self addObject: brush]; + brush =[[SetBrush alloc] initOwner: self mins: emins maxs: emaxs texture:&td]; + [self addObject:brush]; } - // create a brush if needed if (esize == esize_fixed) - [self createFixedBrush: org]; + [self createFixedBrush:org]; else modifiable = YES; // set all the brush colors - color = [eclass drawColor]; + color =[eclass drawColor]; - c = [self count]; - for (i=0 ; inext) - fprintf (f,"\"%s\"\t\"%s\"\n", e->key, e->value); - + + for (e = epairs; e; e = e->next) + fprintf (f, "\"%s\"\t\"%s\"\n", e->key, e->value); + // fixed size entities don't save out brushes - if ( modifiable ) - { - for (i = 0 ; i < [self count]; i++) - [[self objectAtIndex: i] writeToFILE: f region: reg]; + if (modifiable) { + for (i = 0; i <[self count]; i++) + [[self objectAtIndex: i] writeToFILE: f region:reg]; } - - fprintf (f,"}\n"); - + + fprintf (f, "}\n"); + if (temporg) - [self setKey: "angle" toValue: oldang]; + [self setKey: "angle" toValue:oldang]; return self; } diff --git a/tools/Forge/Bundles/MapEdit/EntityClass.m b/tools/Forge/Bundles/MapEdit/EntityClass.m index c20f73d9b..a4fee235d 100644 --- a/tools/Forge/Bundles/MapEdit/EntityClass.m +++ b/tools/Forge/Bundles/MapEdit/EntityClass.m @@ -11,7 +11,7 @@ @implementation EntityClass static int -parse_vector (script_t *script, vec3_t vec) +parse_vector (script_t * script, vec3_t vec) { int r; @@ -23,7 +23,7 @@ parse_vector (script_t *script, vec3_t vec) r = sscanf (script->p, "%f %f %f)", &vec[0], &vec[1], &vec[2]); if (r != 3) return 0; - + while (strcmp (script->token->str, ")")) { if (!Script_GetToken (script, 0)) return 0; @@ -41,16 +41,17 @@ parse_vector (script_t *script, vec3_t vec) // // /*QUAKED func_door (0 .5 .8) ? START_OPEN STONE_SOUND DOOR_DONT_LINK GOLD_KEY SILVER_KEY -- initFromText: (const char *)text source: (const char *)filename +-initFromText:(const char *) +text source:(const char *) filename { const char *t; size_t len; int i; script_t *script; - + [super init]; - - text += strlen("/*QUAKED "); + + text += strlen ("/*QUAKED "); script = Script_New (); Script_Start (script, filename, text); @@ -65,8 +66,8 @@ parse_vector (script_t *script, vec3_t vec) // grab the color if (!parse_vector (script, color)) return 0; - - // get the size + + // get the size if (!strcmp (script->token->str, "(")) { Script_UngetToken (script); if (!parse_vector (script, mins)) @@ -80,7 +81,7 @@ parse_vector (script_t *script, vec3_t vec) } else { return 0; } - + // get the flags // any remaining words on the line are parm flags for (i = 0; i < MAX_FLAGS; i++) { @@ -93,50 +94,49 @@ parse_vector (script_t *script, vec3_t vec) Script_GetToken (script, 0); // find the length until close comment - for (t = script->p; t[0] && !(t[0] == '*' && t[1] == '/'); t++) - ; - + for (t = script->p; t[0] && !(t[0] == '*' && t[1] == '/'); t++); + // copy the comment block out len = t - text; comments = malloc (len + 1); memcpy (comments, text, len); comments[len] = 0; - + return self; } -- (esize_t)esize +-(esize_t) esize { return esize; } -- (char *)classname +-(char *) classname { return name; } -- (float *)mins +-(float *) mins { return mins; } -- (float *)maxs +-(float *) maxs { return maxs; } -- (float *)drawColor +-(float *) drawColor { return color; } -- (char *)comments +-(char *) comments { return comments; } -- (char *)flagName: (unsigned)flagnum +-(char *) flagName:(unsigned) flagnum { if (flagnum >= MAX_FLAGS) Sys_Error ("EntityClass flagName: bad number"); @@ -144,31 +144,27 @@ parse_vector (script_t *script, vec3_t vec) } @end - //=========================================================================== @implementation EntityClassList - /* ================= insertEC: ================= */ -- (void)insertEC: ec +- (void) insertEC:ec { - char *name; - int i; - - name = [ec classname]; - for (i=0 ; i<[self count] ; i++) - { - if (strcasecmp (name, [[self objectAtIndex: i] classname]) < 0) - { + char *name; + int i; + + name =[ec classname]; + for (i = 0; i <[self count]; i++) { + if (strcasecmp (name,[[self objectAtIndex:i] classname]) < 0) { [self insertObject: ec atIndex:i]; return; } } - [self addObject: ec]; + [self addObject:ec]; } @@ -177,16 +173,16 @@ insertEC: scanFile ================= */ -- (void)scanFile: (char *)filename +-(void) scanFile:(char *) filename { - int size, line; - char *data; - id cl; - int i; - char path[1024]; - QFile *file; + int size, line; + char *data; + id cl; + int i; + char path[1024]; + QFile *file; - sprintf (path,"%s/%s", source_path, filename); + sprintf (path, "%s/%s", source_path, filename); file = Qopen (path, "rt"); if (!file) @@ -198,12 +194,12 @@ scanFile Qclose (file); line = 1; - for (i=0 ; id_name); if (len <= 3) continue; - if (!strcmp (ent->d_name+len-3,".qc")) - [self scanFile: ent->d_name]; + if (!strcmp (ent->d_name + len - 3, ".qc")) + [self scanFile:ent->d_name]; } } -id entity_classes_i; +id entity_classes_i; -- initForSourceDirectory: (char *)path +-initForSourceDirectory:(char *) path { [super init]; - - source_path = path; + + source_path = path; [self scanDirectory]; - + entity_classes_i = self; - - nullclass = [[EntityClass alloc] - initFromText: "/*QUAKED UNKNOWN_CLASS (0 0.5 0) ?*/" - source: va ("%s:%d", __FILE__, __LINE__ - 1)]; + + nullclass =[[EntityClass alloc] + initFromText: "/*QUAKED UNKNOWN_CLASS (0 0.5 0) ?*/" source:va ("%s:%d", __FILE__, + __LINE__ - + 1)]; return self; } -- (id)classForName: (char *)name +-(id) classForName:(char *) name { - int i; - id o; - - for (i=0 ; i<[self count] ; i++) - { - o = [self objectAtIndex: i]; - if (!strcmp (name,[o classname]) ) + int i; + id o; + + for (i = 0; i <[self count]; i++) { + o =[self objectAtIndex:i]; + if (!strcmp (name,[o classname])) return o; } - + return nullclass; } @end - diff --git a/tools/Forge/Bundles/MapEdit/InspectorControl.m b/tools/Forge/Bundles/MapEdit/InspectorControl.m index 66aa8da2b..cc7076897 100644 --- a/tools/Forge/Bundles/MapEdit/InspectorControl.m +++ b/tools/Forge/Bundles/MapEdit/InspectorControl.m @@ -6,19 +6,18 @@ #include "TexturePalette.h" #include "Preferences.h" -id inspcontrol_i; +id inspcontrol_i; @implementation InspectorControl -- awakeFromNib -{ +-awakeFromNib { inspcontrol_i = self; - + currentInspectorType = -1; - contentList = [[NSArray alloc] init]; - windowList = [[NSArray alloc] init]; - itemList = [[NSArray alloc] init]; + contentList =[[NSArray alloc] init]; + windowList =[[NSArray alloc] init]; + itemList =[[NSArray alloc] init]; // ADD NEW INSPECTORS HERE... @@ -36,7 +35,7 @@ id inspcontrol_i; [contentList addObject:[win_things_i contentView]]; [itemThings_i setKeyEquivalent:@"3"]; [itemList addObject:itemThings_i]; - + [windowList addObject:win_prefs_i]; [contentList addObject:[win_prefs_i contentView]]; [itemPrefs_i setKeyEquivalent:@"4"]; @@ -61,7 +60,7 @@ id inspcontrol_i; [inspectorView_i setAutoresizesSubviews:YES]; - inspectorSubview_i = [contentList objectAtIndex:i_project]; + inspectorSubview_i =[contentList objectAtIndex:i_project]; [inspectorView_i addSubview:inspectorSubview_i]; currentInspectorType = -1; @@ -72,56 +71,57 @@ id inspcontrol_i; // -// Sent by the PopUpList in the Inspector -// Each cell in the PopUpList must have the correct tag +// Sent by the PopUpList in the Inspector +// Each cell in the PopUpList must have the correct tag // -- changeInspector:sender +-changeInspector:sender { - id cell; + id cell; - cell = [sender selectedCell]; + cell =[sender selectedCell]; [self changeInspectorTo:[cell tag]]; return self; } // -// Change to specific Inspector +// Change to specific Inspector // -- changeInspectorTo:(insp_e)which +-changeInspectorTo:(insp_e) which { - id newView; - NSRect r; - id cell; - NSRect f; - + id newView; + NSRect r; + id cell; + NSRect f; + if (which == currentInspectorType) return self; - + currentInspectorType = which; - newView = [contentList objectAtIndex:which]; - - cell = [itemList objectAtIndex:which]; // set PopUpButton title + newView =[contentList objectAtIndex:which]; + + cell =[itemList objectAtIndex:which];// set PopUpButton title [popUpButton_i setTitle:[cell title]]; - - [inspectorView_i replaceSubview:inspectorSubview_i with:newView]; - r = [inspectorView_i frame]; + + [inspectorView_i replaceSubview: inspectorSubview_i with:newView]; + r =[inspectorView_i frame]; inspectorSubview_i = newView; - [inspectorSubview_i setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + [inspectorSubview_i setAutoresizingMask:NSViewWidthSizable | + NSViewHeightSizable]; r.size.width -= 4; r.size.height -= 4; [inspectorSubview_i setFrameSize:r.size]; - + [inspectorSubview_i lockFocus]; - f = [inspectorSubview_i bounds]; - PSsetgray(NSLightGray); - NSRectFill(f); + f =[inspectorSubview_i bounds]; + PSsetgray (NSLightGray); + NSRectFill (f); [inspectorSubview_i unlockFocus]; [inspectorView_i display]; - + return self; } -- (insp_e)getCurrentInspector +-(insp_e) getCurrentInspector { return currentInspectorType; } diff --git a/tools/Forge/Bundles/MapEdit/KeypairView.m b/tools/Forge/Bundles/MapEdit/KeypairView.m index 30d0d01bd..4990307dc 100644 --- a/tools/Forge/Bundles/MapEdit/KeypairView.m +++ b/tools/Forge/Bundles/MapEdit/KeypairView.m @@ -4,16 +4,15 @@ #include "Entity.h" #include "Things.h" -id keypairview_i; +id keypairview_i; @implementation KeypairView - /* ================== initWithFrame: ================== */ -- initWithFrame:(NSRect)frameRect +- initWithFrame:(NSRect) frameRect { [super initWithFrame:frameRect]; keypairview_i = self; @@ -21,75 +20,73 @@ initWithFrame: } -- calcViewSize +-calcViewSize { - NSRect b; - NSPoint pt; - int count; - id ent; - - ent = [map_i currentEntity]; - count = [ent numPairs]; + NSRect b; + NSPoint pt; + int count; + id ent; - //XXX[_super_view setFlipped: YES]; - - b = [_super_view bounds]; - b.size.height = LINEHEIGHT*count + SPACING; - [self setBounds: b]; + ent =[map_i currentEntity]; + count =[ent numPairs]; + + // XXX[_super_view setFlipped: YES]; + + b =[_super_view bounds]; + b.size.height = LINEHEIGHT * count + SPACING; + [self setBounds:b]; pt.x = pt.y = 0; - [self scrollPoint: pt]; + [self scrollPoint:pt]; return self; } -- drawSelf:(const NSRect *)rects :(int)rectCount +-drawSelf: (const NSRect *) rects:(int) rectCount { - epair_t *pair; - int y; - - //XXX PSsetgray(NSGrayComponent(NS_COLORLTGRAY)); - PSrectfill(0,0,_bounds.size.width,_bounds.size.height); - - //XXX PSselectfont("Helvetica-Bold",FONTSIZE); - PSrotate(0); - PSsetgray(0); - - pair = [[map_i currentEntity] epairs]; + epair_t *pair; + int y; + + // XXX PSsetgray(NSGrayComponent(NS_COLORLTGRAY)); + PSrectfill (0, 0, _bounds.size.width, _bounds.size.height); + + // XXX PSselectfont("Helvetica-Bold",FONTSIZE); + PSrotate (0); + PSsetgray (0); + + pair =[[map_i currentEntity] epairs]; y = _bounds.size.height - LINEHEIGHT; - for ( ; pair ; pair=pair->next) - { - PSmoveto(SPACING, y); - PSshow(pair->key); - PSmoveto(100, y); - PSshow(pair->value); + for (; pair; pair = pair->next) { + PSmoveto (SPACING, y); + PSshow (pair->key); + PSmoveto (100, y); + PSshow (pair->value); y -= LINEHEIGHT; } - PSstroke(); - + PSstroke (); + return self; } -- (void)mouseDown:(NSEvent *)theEvent +-(void) mouseDown:(NSEvent *) theEvent { - NSPoint loc; - int i; - epair_t *p; + NSPoint loc; + int i; + epair_t *p; + + loc =[theEvent locationInWindow]; + loc =[self convertPoint: loc fromView:NULL]; - loc = [theEvent locationInWindow]; - loc = [self convertPoint:loc fromView:NULL]; - i = (_bounds.size.height - loc.y - 4) / LINEHEIGHT; - p = [[map_i currentEntity] epairs]; - while ( i ) - { - p=p->next; + p =[[map_i currentEntity] epairs]; + while (i) { + p = p->next; if (!p) return; i--; } if (p) - [things_i setSelectedKey: p]; - + [things_i setSelectedKey:p]; + return; } diff --git a/tools/Forge/Bundles/MapEdit/Map.m b/tools/Forge/Bundles/MapEdit/Map.m index b897581fa..a7253ed2d 100644 --- a/tools/Forge/Bundles/MapEdit/Map.m +++ b/tools/Forge/Bundles/MapEdit/Map.m @@ -18,10 +18,9 @@ #include "Project.h" -id map_i; +id map_i; @implementation Map - /* =============================================================================== @@ -29,45 +28,40 @@ FILE METHODS =============================================================================== */ - -- init -{ + - init { [super init]; map_i = self; minz = 0; maxz = 80; - - oldselection = [[NSMutableArray alloc] init]; - + + oldselection =[[NSMutableArray alloc] init]; + return self; } -- saveSelected +-saveSelected { - int i, c; - id o, w; - + int i, c; + id o, w; + [oldselection removeAllObjects]; - w = [self objectAtIndex: 0]; - c = [w count]; + w =[self objectAtIndex:0]; + c =[w count]; sb_newowner = oldselection; - for (i=0 ; i -2048) minz = m; return self; } -- (float)currentMaxZ +-(float) currentMaxZ { - float grid; - - [self currentMinZ]; // grid align - - grid = [xyview_i gridsize]; - maxz = grid * rint(maxz/grid); + float grid; + + [self currentMinZ]; // grid align + + grid =[xyview_i gridsize]; + maxz = grid * rint (maxz / grid); if (maxz <= minz) maxz = minz + grid; return maxz; } -- setCurrentMaxZ: (float)m +-setCurrentMaxZ:(float) m { if (m < 2048) maxz = m; return self; } -- (void) removeObject: o +-(void) removeObject:o { - [super removeObject: o]; - - if (o == currentEntity) - { // select the world - [self setCurrentEntity: [self objectAtIndex: 0]]; + [super removeObject:o]; + + if (o == currentEntity) { // select the world + [self setCurrentEntity: [self objectAtIndex:0]]; } return; } -- writeStats +-writeStats { /*XXX FILE *f; @@ -198,29 +189,29 @@ FILE METHODS return self; } -- (int)numSelected +-(int) numSelected { - int i, c; - int num; - + int i, c; + int num; + num = 0; - c = [currentEntity count]; - for (i=0 ; i=0 ; i--) - { - ent = [self objectAtIndex: i]; - c2 = [ent count]; - for (j=0 ; jbesttime) + + c =[self count]; + for (i = c - 1; i >= 0; i--) { + ent =[self objectAtIndex:i]; + c2 =[ent count]; + for (j = 0; j < c2; j++) { + brush =[ent objectAtIndex:j]; + [brush hitByRay: p1: p2: &time:&face]; + if (time < 0 || time > besttime) continue; bestent = ent; besttime = time; @@ -441,48 +423,43 @@ to intervening world brushes bestface = face; } if (i == 1 && ef && bestbrush) - break; // found an entity, so don't check the world + break; // found an entity, so don't check the + // world } - - if (besttime == 99999) - { + + if (besttime == 99999) { Sys_Printf ("trace missed"); return self; } - if ( [bestbrush regioned] ) - { + if ([bestbrush regioned]) { Sys_Printf ("WANRING: clicked on regioned brush"); return self; } - - if (bestent != currentEntity) - { - [self makeSelectedPerform: @selector(deselect)]; - [self setCurrentEntity: bestent]; + + if (bestent != currentEntity) { + [self makeSelectedPerform:@selector (deselect)]; + [self setCurrentEntity:bestent]; } - + [quakeed_i disableFlushWindow]; - if ( ![bestbrush selected] ) - { - if ( [map_i numSelected] == 0) - { // don't grab texture if others are selected - td = [bestbrush texturedefForFace: bestface]; - [texturepalette_i setTextureDef: td]; + if (![bestbrush selected]) { + if ([map_i numSelected] == 0) { // don't grab texture if others are + // selected + td =[bestbrush texturedefForFace:bestface]; + [texturepalette_i setTextureDef:td]; } - [bestbrush setSelected: YES]; - Sys_Printf ("selected entity %i brush %i face %i", (int) [self indexOfObject:bestent], (int) [bestent indexOfObject: bestbrush], bestface); - } - else - { - [bestbrush setSelected: NO]; - Sys_Printf ("deselected entity %i brush %i face %i", (int) [self indexOfObject:bestent], (int) [bestent indexOfObject: bestbrush], bestface); + [bestbrush setSelected:YES]; + Sys_Printf ("selected entity %i brush %i face %i", (int)[self indexOfObject: bestent], (int)[bestent indexOfObject:bestbrush], bestface); + } else { + [bestbrush setSelected:NO]; + Sys_Printf ("deselected entity %i brush %i face %i", (int)[self indexOfObject: bestent], (int)[bestent indexOfObject:bestbrush], bestface); } [quakeed_i enableFlushWindow]; [quakeed_i updateAll]; - + return self; } @@ -494,38 +471,36 @@ checks only the selected brushes Returns the brush hit, or nil if missed. ================= */ -- grabRay: (vec3_t)p1 : (vec3_t)p2 +-grabRay: (vec3_t) p1:(vec3_t) p2 { - int i, j, c, c2; - id ent; - id brush, bestbrush; - int face; - float time, besttime; - + int i, j, c, c2; + id ent; + id brush, bestbrush; + int face; + float time, besttime; + bestbrush = nil; besttime = 99999; - - c = [self count]; - for (i=0 ; ibesttime) + [brush hitByRay: p1: p2: &time:&face]; + if (time < 0 || time > besttime) continue; besttime = time; bestbrush = brush; } } - + if (besttime == 99999) return nil; - + return bestbrush; } @@ -534,31 +509,29 @@ Returns the brush hit, or nil if missed. getTextureRay ================= */ -- getTextureRay: (vec3_t)p1 : (vec3_t)p2 +-getTextureRay: (vec3_t) p1:(vec3_t) p2 { - int i, j, c, c2; - id ent, bestent; - id brush, bestbrush; - int face, bestface; - float time, besttime; - texturedef_t *td; - vec3_t mins, maxs; + int i, j, c, c2; + id ent, bestent; + id brush, bestbrush; + int face, bestface; + float time, besttime; + texturedef_t *td; + vec3_t mins, maxs; bestbrush = nil; bestent = nil; besttime = 99999; bestface = -1; - c = [self count]; - for (i=0 ; ibesttime) + c =[self count]; + for (i = 0; i < c; i++) { + ent =[self objectAtIndex:i]; + c2 =[ent count]; + for (j = 0; j < c2; j++) { + brush =[ent objectAtIndex:j]; + [brush hitByRay: p1: p2: &time:&face]; + if (time < 0 || time > besttime) continue; bestent = ent; bestface = face; @@ -566,26 +539,25 @@ getTextureRay bestbrush = brush; } } - + if (besttime == 99999) return nil; - if ( ![bestent modifiable]) - { + if (![bestent modifiable]) { Sys_Printf ("can't modify spawned entities"); return self; } - - td = [bestbrush texturedefForFace: bestface]; - [texturepalette_i setTextureDef: td]; - + + td =[bestbrush texturedefForFace:bestface]; + [texturepalette_i setTextureDef:td]; + Sys_Printf ("grabbed texturedef and sizes"); - - [bestbrush getMins: mins maxs: maxs]; - + + [bestbrush getMins: mins maxs:maxs]; + minz = mins[2]; maxz = maxs[2]; - + return bestbrush; } @@ -594,30 +566,28 @@ getTextureRay setTextureRay ================= */ -- setTextureRay: (vec3_t)p1 : (vec3_t)p2 : (BOOL)allsides; +-setTextureRay: (vec3_t) p1: (vec3_t) p2:(BOOL) allsides; { - int i, j, c, c2; - id ent, bestent; - id brush, bestbrush; - int face, bestface; - float time, besttime; - texturedef_t td; - + int i, j, c, c2; + id ent, bestent; + id brush, bestbrush; + int face, bestface; + float time, besttime; + texturedef_t td; + bestent = nil; bestface = -1; bestbrush = nil; besttime = 99999; - - c = [self count]; - for (i=0 ; ibesttime) + + c =[self count]; + for (i = 0; i < c; i++) { + ent =[self objectAtIndex:i]; + c2 =[ent count]; + for (j = 0; j < c2; j++) { + brush =[ent objectAtIndex:j]; + [brush hitByRay: p1: p2: &time:&face]; + if (time < 0 || time > besttime) continue; bestent = ent; besttime = time; @@ -625,42 +595,36 @@ setTextureRay bestface = face; } } - - if (besttime == 99999) - { + + if (besttime == 99999) { Sys_Printf ("trace missed"); return self; } - if ( ![bestent modifiable]) - { + if (![bestent modifiable]) { Sys_Printf ("can't modify spawned entities"); return self; } - - if ( [bestbrush regioned] ) - { + + if ([bestbrush regioned]) { Sys_Printf ("WANRING: clicked on regioned brush"); return self; } - - [texturepalette_i getTextureDef: &td]; - + + [texturepalette_i getTextureDef:&td]; + [quakeed_i disableFlushWindow]; - if (allsides) - { - [bestbrush setTexturedef: &td]; - Sys_Printf ("textured entity %i brush %i", (int) [self indexOfObject:bestent], (int) [bestent indexOfObject: bestbrush]); - } - else - { - [bestbrush setTexturedef: &td forFace: bestface]; - Sys_Printf ("deselected entity %i brush %i face %i", (int) [self indexOfObject:bestent], (int) [bestent indexOfObject: bestbrush], bestface); + if (allsides) { + [bestbrush setTexturedef:&td]; + Sys_Printf ("textured entity %i brush %i", (int)[self indexOfObject: bestent], (int)[bestent indexOfObject:bestbrush]); + } else { + [bestbrush setTexturedef: &td forFace:bestface]; + Sys_Printf ("deselected entity %i brush %i face %i", (int)[self indexOfObject: bestent], (int)[bestent indexOfObject:bestbrush], bestface); } [quakeed_i enableFlushWindow]; - + [quakeed_i updateAll]; - + return self; } @@ -673,22 +637,20 @@ OPERATIONS ON SELECTIONS ============================================================================== */ -- makeSelectedPerform: (SEL)sel +-makeSelectedPerform:(SEL) sel { - int i,j, c, c2; - id ent, brush; - int total; - + int i, j, c, c2; + id ent, brush; + int total; + total = 0; - c = [self count]; - for (i=c-1 ; i>=0 ; i--) - { - ent = [self objectAtIndex: i]; - c2 = [ent count]; - for (j = c2-1 ; j >=0 ; j--) - { - brush = [ent objectAtIndex: j]; - if (! [brush selected] ) + c =[self count]; + for (i = c - 1; i >= 0; i--) { + ent =[self objectAtIndex:i]; + c2 =[ent count]; + for (j = c2 - 1; j >= 0; j--) { + brush =[ent objectAtIndex:j]; + if (![brush selected]) continue; if ([brush regioned]) continue; @@ -697,26 +659,24 @@ OPERATIONS ON SELECTIONS } } -// if (!total) -// Sys_Printf ("nothing selected"); - - return self; +// if (!total) +// Sys_Printf ("nothing selected"); + + return self; } -- makeUnselectedPerform: (SEL)sel +-makeUnselectedPerform:(SEL) sel { - int i,j, c, c2; - id ent, brush; - - c = [self count]; - for (i=c-1 ; i>=0 ; i--) - { - ent = [self objectAtIndex: i]; - c2 = [ent count]; - for (j = c2-1 ; j >=0 ; j--) - { - brush = [ent objectAtIndex: j]; - if ( [brush selected] ) + int i, j, c, c2; + id ent, brush; + + c =[self count]; + for (i = c - 1; i >= 0; i--) { + ent =[self objectAtIndex:i]; + c2 =[ent count]; + for (j = c2 - 1; j >= 0; j--) { + brush =[ent objectAtIndex:j]; + if ([brush selected]) continue; if ([brush regioned]) continue; @@ -724,87 +684,89 @@ OPERATIONS ON SELECTIONS } } - return self; + return self; } -- makeAllPerform: (SEL)sel +-makeAllPerform:(SEL) sel { - int i,j, c, c2; - id ent, brush; - - c = [self count]; - for (i=c-1 ; i>=0 ; i--) - { - ent = [self objectAtIndex: i]; - c2 = [ent count]; - for (j = c2-1 ; j >=0 ; j--) - { - brush = [ent objectAtIndex: j]; + int i, j, c, c2; + id ent, brush; + + c =[self count]; + for (i = c - 1; i >= 0; i--) { + ent =[self objectAtIndex:i]; + c2 =[ent count]; + for (j = c2 - 1; j >= 0; j--) { + brush =[ent objectAtIndex:j]; if ([brush regioned]) continue; [brush performSelector:sel]; } } - return self; + return self; } -- makeGlobalPerform: (SEL)sel // in and out of region +-makeGlobalPerform:(SEL) sel // in and out of region { - int i,j, c, c2; - id ent, brush; - - c = [self count]; - for (i=c-1 ; i>=0 ; i--) - { - ent = [self objectAtIndex: i]; - c2 = [ent count]; - for (j = c2-1 ; j >=0 ; j--) - { - brush = [ent objectAtIndex: j]; + int i, j, c, c2; + id ent, brush; + + c =[self count]; + for (i = c - 1; i >= 0; i--) { + ent =[self objectAtIndex:i]; + c2 =[ent count]; + for (j = c2 - 1; j >= 0; j--) { + brush =[ent objectAtIndex:j]; [brush performSelector:sel]; } } - return self; + return self; } -void sel_identity (void) +void +sel_identity (void) { - sel_x[0]=1; sel_x[1]=0; sel_x[2]=0; - sel_y[0]=0; sel_y[1]=1; sel_y[2]=0; - sel_z[0]=0; sel_z[1]=0; sel_z[2]=1; + sel_x[0] = 1; + sel_x[1] = 0; + sel_x[2] = 0; + sel_y[0] = 0; + sel_y[1] = 1; + sel_y[2] = 0; + sel_z[0] = 0; + sel_z[1] = 0; + sel_z[2] = 1; } -- transformSelection +-transformSelection { - if ( ![currentEntity modifiable]) - { + if (![currentEntity modifiable]) { Sys_Printf ("can't modify spawned entities"); return self; } - // find an origin to apply the transformation to sb_mins[0] = sb_mins[1] = sb_mins[2] = 99999; sb_maxs[0] = sb_maxs[1] = sb_maxs[2] = -99999; - [self makeSelectedPerform: @selector(addToBBox)]; - sel_org[0] = [xyview_i snapToGrid: (sb_mins[0] + sb_maxs[0])/2]; - sel_org[1] = [xyview_i snapToGrid: (sb_mins[1] + sb_maxs[1])/2]; - sel_org[2] = [xyview_i snapToGrid: (sb_mins[2] + sb_maxs[2])/2]; - + [self makeSelectedPerform:@selector (addToBBox)]; + sel_org[0] =[xyview_i snapToGrid:(sb_mins[0] + sb_maxs[0]) / 2]; + sel_org[1] =[xyview_i snapToGrid:(sb_mins[1] + sb_maxs[1]) / 2]; + sel_org[2] =[xyview_i snapToGrid:(sb_mins[2] + sb_maxs[2]) / 2]; + // do it! - [self makeSelectedPerform: @selector(transform)]; + [self makeSelectedPerform:@selector (transform)]; [quakeed_i updateAll]; return self; } -void swapvectors (vec3_t a, vec3_t b) +void +swapvectors (vec3_t a, vec3_t b) { - vec3_t temp; - + vec3_t temp; + VectorCopy (a, temp); VectorCopy (b, a); VectorSubtract (vec3_origin, temp, b); @@ -818,107 +780,104 @@ UI operations =============================================================================== */ -- rotate_x: sender +-rotate_x:sender { sel_identity (); - swapvectors(sel_y, sel_z); + swapvectors (sel_y, sel_z); [self transformSelection]; return self; } -- rotate_y: sender +-rotate_y:sender { sel_identity (); - swapvectors(sel_x, sel_z); + swapvectors (sel_x, sel_z); [self transformSelection]; return self; } -- rotate_z: sender +-rotate_z:sender { sel_identity (); - swapvectors(sel_x, sel_y); + swapvectors (sel_x, sel_y); [self transformSelection]; return self; } -- flip_x: sender +-flip_x:sender { sel_identity (); sel_x[0] = -1; [self transformSelection]; - [map_i makeSelectedPerform: @selector(flipNormals)]; + [map_i makeSelectedPerform:@selector (flipNormals)]; return self; } -- flip_y: sender +-flip_y:sender { sel_identity (); sel_y[1] = -1; [self transformSelection]; - [map_i makeSelectedPerform: @selector(flipNormals)]; + [map_i makeSelectedPerform:@selector (flipNormals)]; return self; } -- flip_z: sender +-flip_z:sender { sel_identity (); sel_z[2] = -1; [self transformSelection]; - [map_i makeSelectedPerform: @selector(flipNormals)]; + [map_i makeSelectedPerform:@selector (flipNormals)]; return self; } -- cloneSelection: sender +-cloneSelection:sender { - int i,j , c, originalElements; - id o, b; - id new; - - sb_translate[0] = sb_translate[1] = [xyview_i gridsize]; + int i, j, c, originalElements; + id o, b; + id new; + + sb_translate[0] = sb_translate[1] =[xyview_i gridsize]; sb_translate[2] = 0; // copy individual brushes in the world entity - o = [self objectAtIndex: 0]; - c = [o count]; - for (i=0 ; i2) + if (startwad < 0 || startwad > 2) startwad = 0; - - [startwad_i selectCellAtRow:startwad column: 0]; + + [startwad_i selectCellAtRow: startwad column:0]; WriteNumericDefault ("StartWad", value); return self; } -- (int)getStartWad +-(int) getStartWad { return startwad; } //=============================================== -// X,Y,Z light values +// X,Y,Z light values //=============================================== // -// Set the state +// Set the state // -- setXlight:(float)value +-setXlight:(float) value { xlight = value; if (xlight < 0.25 || xlight > 1) @@ -264,7 +268,8 @@ void WriteStringDefault (char *name, char *value) WriteNumericDefault ("Xlight", xlight); return self; } -- setYlight:(float)value + +-setYlight:(float) value { ylight = value; if (ylight < 0.25 || ylight > 1) @@ -274,7 +279,8 @@ void WriteStringDefault (char *name, char *value) WriteNumericDefault ("Ylight", ylight); return self; } -- setZlight:(float)value + +-setZlight:(float) value { zlight = value; if (zlight < 0.25 || zlight > 1) @@ -286,19 +292,21 @@ void WriteStringDefault (char *name, char *value) } // -// Get the state +// Get the state // -- (float)getXlight +-(float) getXlight { - return [xlight_i floatValue]; + return[xlight_i floatValue]; } -- (float)getYlight + +-(float) getYlight { - return [ylight_i floatValue]; + return[ylight_i floatValue]; } -- (float)getZlight + +-(float) getZlight { - return [zlight_i floatValue]; + return[zlight_i floatValue]; } @@ -310,22 +318,22 @@ UIChanged Grab all the current UI state ============ */ --UIChanged: sender +-UIChanged:sender { qprintf ("defaults updated"); - - [self setProjectPath: (char *)[startproject_i stringValue]]; - [self setBspSoundPath: (char *)[bspSoundField_i stringValue]]; - [self setShowBSP: [showBSP_i intValue]]; - [self setBrushOffset: [brushOffset_i intValue]]; - [self setStartWad: [startwad_i selectedRow]]; - [self setXlight: [xlight_i floatValue]]; - [self setYlight: [ylight_i floatValue]]; - [self setZlight: [zlight_i floatValue]]; - [map_i makeGlobalPerform: @selector(flushTextures)]; + [self setProjectPath:(char *)[startproject_i stringValue]]; + [self setBspSoundPath:(char *)[bspSoundField_i stringValue]]; + [self setShowBSP:[showBSP_i intValue]]; + [self setBrushOffset:[brushOffset_i intValue]]; + [self setStartWad:[startwad_i selectedRow]]; + [self setXlight:[xlight_i floatValue]]; + [self setYlight:[ylight_i floatValue]]; + [self setZlight:[zlight_i floatValue]]; + + [map_i makeGlobalPerform:@selector (flushTextures)]; [quakeed_i updateAll]; - + return self; } diff --git a/tools/Forge/Bundles/MapEdit/Project.m b/tools/Forge/Bundles/MapEdit/Project.m index ff18170a8..6b1208163 100644 --- a/tools/Forge/Bundles/MapEdit/Project.m +++ b/tools/Forge/Bundles/MapEdit/Project.m @@ -17,11 +17,11 @@ #include "TexturePalette.h" -id project_i; +id project_i; @implementation Project -- init +-init { project_i = self; @@ -30,145 +30,139 @@ id project_i; //=========================================================== // -// Project code +// Project code // //=========================================================== -- initVars +-initVars { - char *s; - - s = [preferences_i getProjectPath]; - //XXX StripFilename(s); - strcpy(path_basepath,s); - - strcpy(path_progdir,s); - strcat(path_progdir,"/"SUBDIR_ENT); - - strcpy(path_mapdirectory,s); - strcat(path_mapdirectory,"/"SUBDIR_MAPS); // source dir + char *s; - strcpy(path_finalmapdir,s); - strcat(path_finalmapdir,"/"SUBDIR_MAPS); // dest dir - - [basepathinfo_i setStringValue:[NSString stringWithCString:s]]; // in Project Inspector - - #if 0 - if ((s = [projectInfo getStringFor:BASEPATHKEY])) - { - strcpy(path_basepath,s); - - strcpy(path_progdir,s); - strcat(path_progdir,"/"SUBDIR_ENT); - - strcpy(path_mapdirectory,s); - strcat(path_mapdirectory,"/"SUBDIR_MAPS); // source dir + s =[preferences_i getProjectPath]; + // XXX StripFilename(s); + strcpy (path_basepath, s); - strcpy(path_finalmapdir,s); - strcat(path_finalmapdir,"/"SUBDIR_MAPS); // dest dir - - [basepathinfo_i setStringValue:s]; // in Project Inspector + strcpy (path_progdir, s); + strcat (path_progdir, "/" SUBDIR_ENT); + + strcpy (path_mapdirectory, s); + strcat (path_mapdirectory, "/" SUBDIR_MAPS); // source dir + + strcpy (path_finalmapdir, s); + strcat (path_finalmapdir, "/" SUBDIR_MAPS); // dest dir + + [basepathinfo_i setStringValue: [NSString stringWithCString:s]]; + // in Project Inspector + +#if 0 + if ((s =[projectInfo getStringFor:BASEPATHKEY])) { + strcpy (path_basepath, s); + + strcpy (path_progdir, s); + strcat (path_progdir, "/" SUBDIR_ENT); + + strcpy (path_mapdirectory, s); + strcat (path_mapdirectory, "/" SUBDIR_MAPS); // source dir + + strcpy (path_finalmapdir, s); + strcat (path_finalmapdir, "/" SUBDIR_MAPS); // dest dir + + [basepathinfo_i setStringValue:s]; + // in Project Inspector } - #endif - - if ((s = [projectInfo getStringFor:BSPFULLVIS])) - { - strcpy(string_fullvis,s); - changeString('@','\"',string_fullvis); - } - - if ((s = [projectInfo getStringFor:BSPFASTVIS])) - { - strcpy(string_fastvis,s); - changeString('@','\"',string_fastvis); - } - - if ((s = [projectInfo getStringFor:BSPNOVIS])) - { - strcpy(string_novis,s); - changeString('@','\"',string_novis); - } - - if ((s = [projectInfo getStringFor:BSPRELIGHT])) - { - strcpy(string_relight,s); - changeString('@','\"',string_relight); - } - - if ((s = [projectInfo getStringFor:BSPLEAKTEST])) - { - strcpy(string_leaktest,s); - changeString('@','\"',string_leaktest); +#endif + + if ((s =[projectInfo getStringFor:BSPFULLVIS])) { + strcpy (string_fullvis, s); + changeString ('@', '\"', string_fullvis); } - if ((s = [projectInfo getStringFor:BSPENTITIES])) - { - strcpy(string_entities,s); - changeString('@','\"', string_entities); + if ((s =[projectInfo getStringFor:BSPFASTVIS])) { + strcpy (string_fastvis, s); + changeString ('@', '\"', string_fastvis); } - // Build list of wads - wadList = [projectInfo parseMultipleFrom:WADSKEY]; + if ((s =[projectInfo getStringFor:BSPNOVIS])) { + strcpy (string_novis, s); + changeString ('@', '\"', string_novis); + } + + if ((s =[projectInfo getStringFor:BSPRELIGHT])) { + strcpy (string_relight, s); + changeString ('@', '\"', string_relight); + } + + if ((s =[projectInfo getStringFor:BSPLEAKTEST])) { + strcpy (string_leaktest, s); + changeString ('@', '\"', string_leaktest); + } + + if ((s =[projectInfo getStringFor:BSPENTITIES])) { + strcpy (string_entities, s); + changeString ('@', '\"', string_entities); + } + // Build list of wads + wadList =[projectInfo parseMultipleFrom:WADSKEY]; + + // Build list of maps & descriptions + mapList =[projectInfo parseMultipleFrom:MAPNAMESKEY]; + descList =[projectInfo parseMultipleFrom:DESCKEY]; + [self changeChar: '_' to: ' ' in:descList]; - // Build list of maps & descriptions - mapList = [projectInfo parseMultipleFrom:MAPNAMESKEY]; - descList = [projectInfo parseMultipleFrom:DESCKEY]; - [self changeChar:'_' to:' ' in:descList]; - [self initProjSettings]; return self; } // -// Init Project Settings fields +// Init Project Settings fields // -- initProjSettings +-initProjSettings { - [pis_basepath_i setStringValue:[NSString stringWithCString:path_basepath]]; - [pis_fullvis_i setStringValue:[NSString stringWithCString:string_fullvis]]; - [pis_fastvis_i setStringValue:[NSString stringWithCString:string_fastvis]]; - [pis_novis_i setStringValue:[NSString stringWithCString:string_novis]]; - [pis_relight_i setStringValue:[NSString stringWithCString:string_relight]]; - [pis_leaktest_i setStringValue:[NSString stringWithCString:string_leaktest]]; - + [pis_basepath_i setStringValue: [NSString stringWithCString:path_basepath]]; + [pis_fullvis_i setStringValue: [NSString stringWithCString:string_fullvis]]; + [pis_fastvis_i setStringValue: [NSString stringWithCString:string_fastvis]]; + [pis_novis_i setStringValue: [NSString stringWithCString:string_novis]]; + [pis_relight_i setStringValue: [NSString stringWithCString:string_relight]]; + [pis_leaktest_i setStringValue: [NSString stringWithCString:string_leaktest]]; + return self; } // -// Add text to the BSP Output window +// Add text to the BSP Output window // -- addToOutput:(char *)string +-addToOutput:(char *) string { - int end; - - end = [BSPoutput_i textLength]; - [BSPoutput_i replaceCharactersInRange:NSMakeRange (end, 0) withString:[NSString stringWithCString:string]]; - - end = [BSPoutput_i textLength]; + int end; + + end =[BSPoutput_i textLength]; + [BSPoutput_i replaceCharactersInRange: NSMakeRange (end, 0) withString: [NSString stringWithCString:string]]; + + end =[BSPoutput_i textLength]; [BSPoutput_i setSelectedRange:NSMakeRange (end, 0)]; - //XXX [BSPoutput_i scrollSelToVisible]; - + // XXX [BSPoutput_i scrollSelToVisible]; + return self; } -- clearBspOutput:sender +-clearBspOutput:sender { - int end; - - end = [BSPoutput_i textLength]; - [BSPoutput_i replaceCharactersInRange:NSMakeRange (0, end) withString:@""]; - + int end; + + end =[BSPoutput_i textLength]; + [BSPoutput_i replaceCharactersInRange: NSMakeRange (0, end) withString:@""]; + return self; } -- print +-print { - //XXX [BSPoutput_i printPSCode:self]; + // XXX [BSPoutput_i printPSCode:self]; return self; } -- initProject +-initProject { [self parseProjectFile]; if (projectInfo == NULL) @@ -179,57 +173,56 @@ id project_i; [pis_wads_i setReusesColumns:YES]; [pis_wads_i loadColumnZero]; - [things_i initEntities]; - + [things_i initEntities]; + return self; } // -// Change a character to another in a Storage list of strings +// Change a character to another in a Storage list of strings // -- changeChar:(char)f to:(char)t in:(id)obj +-changeChar:(char) +f to:(char) +t in:(id) obj { - int i; - int max; - char *string; + int i; + int max; + char *string; - max = [obj count]; - for (i = 0;i < max;i++) - { - string = [obj elementAt:i]; - changeString(f,t,string); + max =[obj count]; + for (i = 0; i < max; i++) { + string =[obj elementAt:i]; + changeString (f, t, string); } return self; } // -// Fill the QuakeEd Maps or wads browser -// (Delegate method - delegated in Interface Builder) +// Fill the QuakeEd Maps or wads browser +// (Delegate method - delegated in Interface Builder) // -- (int)browser:sender fillMatrix:matrix inColumn:(int)column +-(int) browser: sender fillMatrix: matrix inColumn:(int) column { - id cell, list; - int max; - char *name; - int i; + id cell, list; + int max; + char *name; + int i; if (sender == mapbrowse_i) list = mapList; else if (sender == pis_wads_i) list = wadList; - else - { + else { list = nil; Sys_Error ("Project: unknown browser to fill"); } - - max = [list count]; - for (i = 0 ; i.QE_Project file +// Read in the .QE_Project file // -- parseProjectFile +-parseProjectFile { - char *path; - int rtn; - - path = [preferences_i getProjectPath]; - if (!path || !path[0] || access(path,0)) - { - rtn = NSRunAlertPanel(@"Project Error!", - @"A default project has not been found.\n" - , @"Open Project", NULL, NULL); + char *path; + int rtn; + + path =[preferences_i getProjectPath]; + if (!path || !path[0] || access (path, 0)) { + rtn = NSRunAlertPanel (@"Project Error!", + @"A default project has not been found.\n", + @"Open Project", NULL, NULL); if ([self openProject] == nil) - while (1) // can't run without a project - [NSApp terminate: self]; - return self; + while (1) // can't run without a project + [NSApp terminate:self]; + return self; } [self openProjectFile:path]; @@ -336,103 +325,102 @@ id project_i; } // -// Loads and parses a project file +// Loads and parses a project file // -- openProjectFile:(char *)path -{ - FILE *fp; - struct stat s; +-openProjectFile:(char *) path +{ + FILE *fp; + struct stat s; - strcpy(path_projectinfo,path); + strcpy (path_projectinfo, path); projectInfo = NULL; - fp = fopen(path,"r+t"); + fp = fopen (path, "r+t"); if (fp == NULL) return self; - stat(path,&s); + stat (path, &s); lastModified = s.st_mtime; - projectInfo = [(Dict *)[Dict alloc] initFromFile:fp]; - fclose(fp); - + projectInfo =[(Dict *)[Dict alloc] initFromFile:fp]; + fclose (fp); + return self; } -- (char *)currentProjectFile +-(char *) currentProjectFile { return path_projectinfo; } // -// Open a project file +// Open a project file // -- openProject +-openProject { - char path[128]; - id openpanel; - int rtn; - NSString *projtypes[] ={ @"qpr"}; + char path[128]; + id openpanel; + int rtn; + NSString *projtypes[] = { @"qpr" }; NSArray *filenames; const char *dir; - - openpanel = [NSOpenPanel new]; - //[openpanel allowMultipleFiles:NO]; - //[openpanel chooseDirectories:NO]; - rtn = [openpanel runModalForTypes:[NSArray arrayWithObjects: projtypes count:1]]; - if (rtn == NSOKButton) - { - filenames = [openpanel filenames]; - dir = [[openpanel directory] cString]; - sprintf (path, "%s/%s", dir, [[filenames objectAtIndex:0] cString]); - strcpy(path_projectinfo,path); - [self openProjectFile:path]; - return self; + + openpanel =[NSOpenPanel new]; + // [openpanel allowMultipleFiles:NO]; + // [openpanel chooseDirectories:NO]; + rtn =[openpanel runModalForTypes: [NSArray arrayWithObjects: projtypes count:1]]; + if (rtn == NSOKButton) { + filenames =[openpanel filenames]; + dir =[[openpanel directory] cString]; + sprintf (path, "%s/%s", dir,[[filenames objectAtIndex:0] cString]); + strcpy (path_projectinfo, path); + [self openProjectFile:path]; + return self; } - + return nil; } // -// Search for a string in a List of strings +// Search for a string in a List of strings // -- (int)searchForString:(char *)str in:(id)obj +-(int) searchForString:(char *) +str in:(id) obj { - int i; - int max; - char *s; + int i; + int max; + char *s; - max = [obj count]; - for (i = 0;i < max; i++) - { + max =[obj count]; + for (i = 0; i < max; i++) { s = (char *)[obj elementAt:i]; - if (!strcmp(s,str)) + if (!strcmp (s, str)) return 1; } return 0; } -- (char *)getMapDirectory +-(char *) getMapDirectory { return path_mapdirectory; } -- (char *)getFinalMapDirectory +-(char *) getFinalMapDirectory { return path_finalmapdir; } -- (char *)getProgDirectory +-(char *) getProgDirectory { return path_progdir; } // -// Return the WAD name for cmd-8 +// Return the WAD name for cmd-8 // -- (char *)getWAD8 +-(char *) getWAD8 { if (!path_wad8[0]) return NULL; @@ -440,9 +428,9 @@ id project_i; } // -// Return the WAD name for cmd-9 +// Return the WAD name for cmd-9 // -- (char *)getWAD9 +-(char *) getWAD9 { if (!path_wad9[0]) return NULL; @@ -450,9 +438,9 @@ id project_i; } // -// Return the WAD name for cmd-0 +// Return the WAD name for cmd-0 // -- (char *)getWAD0 +-(char *) getWAD0 { if (!path_wad0[0]) return NULL; @@ -460,9 +448,9 @@ id project_i; } // -// Return the FULLVIS cmd string +// Return the FULLVIS cmd string // -- (char *)getFullVisCmd +-(char *) getFullVisCmd { if (!string_fullvis[0]) return NULL; @@ -470,9 +458,9 @@ id project_i; } // -// Return the FASTVIS cmd string +// Return the FASTVIS cmd string // -- (char *)getFastVisCmd +-(char *) getFastVisCmd { if (!string_fastvis[0]) return NULL; @@ -480,9 +468,9 @@ id project_i; } // -// Return the NOVIS cmd string +// Return the NOVIS cmd string // -- (char *)getNoVisCmd +-(char *) getNoVisCmd { if (!string_novis[0]) return NULL; @@ -490,9 +478,9 @@ id project_i; } // -// Return the RELIGHT cmd string +// Return the RELIGHT cmd string // -- (char *)getRelightCmd +-(char *) getRelightCmd { if (!string_relight[0]) return NULL; @@ -500,16 +488,16 @@ id project_i; } // -// Return the LEAKTEST cmd string +// Return the LEAKTEST cmd string // -- (char *)getLeaktestCmd +-(char *) getLeaktestCmd { if (!string_leaktest[0]) return NULL; return string_leaktest; } -- (char *)getEntitiesCmd +-(char *) getEntitiesCmd { if (!string_entities[0]) return NULL; @@ -517,21 +505,18 @@ id project_i; } @end - //==================================================== // C Functions //==================================================== - // // Change a character to a different char in a string // -void changeString(char cf,char ct,char *string) + void +changeString (char cf, char ct, char *string) { - int j; + int j; - for (j = 0;j < strlen(string);j++) + for (j = 0; j < strlen (string); j++) if (string[j] == cf) string[j] = ct; } - - diff --git a/tools/Forge/Bundles/MapEdit/QuakeEd.m b/tools/Forge/Bundles/MapEdit/QuakeEd.m index 9daae1085..ba57d02e8 100644 --- a/tools/Forge/Bundles/MapEdit/QuakeEd.m +++ b/tools/Forge/Bundles/MapEdit/QuakeEd.m @@ -16,46 +16,52 @@ #include "InspectorControl.h" #include "Project.h" -id quakeed_i; -id entclasses_i; +id quakeed_i; +id entclasses_i; extern NSBezierPath *path; -id g_cmd_out_i; +id g_cmd_out_i; -BOOL autodirty; -BOOL filter_light, filter_path, filter_entities; -BOOL filter_clip_brushes, filter_water_brushes, filter_world; +BOOL autodirty; +BOOL filter_light, filter_path, filter_entities; +BOOL filter_clip_brushes, filter_water_brushes, filter_world; -BOOL running; +BOOL running; -int bsppid; +int bsppid; #if 0 // example command strings -char *fullviscmd = "rsh satan \"/LocalApps/qbsp $1 $2 ; /LocalApps/light $2 ; /LocalApps/vis $2\""; -char *fastviscmd = "rsh satan \"/LocalApps/qbsp $1 $2 ; /LocalApps/light $2 ; /LocalApps/vis -fast $2\""; -char *noviscmd = "rsh satan \"/LocalApps/qbsp $1 $2 ; /LocalApps/light $2\""; -char *relightcmd = "rsh satan \"/LocalApps/light $2\""; -char *leakcmd = "rsh satan \"/LocalApps/qbsp -mark -notjunc $1 $2\""; +char *fullviscmd = + "rsh satan \"/LocalApps/qbsp $1 $2 ; /LocalApps/light $2 ; /LocalApps/vis $2\""; +char *fastviscmd = + "rsh satan \"/LocalApps/qbsp $1 $2 ; /LocalApps/light $2 ; /LocalApps/vis -fast $2\""; +char *noviscmd = + "rsh satan \"/LocalApps/qbsp $1 $2 ; /LocalApps/light $2\""; +char *relightcmd = "rsh satan \"/LocalApps/light $2\""; +char *leakcmd = "rsh satan \"/LocalApps/qbsp -mark -notjunc $1 $2\""; #endif -void NopSound (void) +void +NopSound (void) { NSBeep (); } -void My_Malloc_Error (int code) +void +My_Malloc_Error (int code) { -// recursive toast Error ("Malloc error: %i\n", code); - write (1, "malloc error!\n", strlen("malloc error!\n")+1); +// recursive toast Error ("Malloc error: %i\n", code); + write (1, "malloc error!\n", strlen ("malloc error!\n") + 1); } #define FN_CMDOUT "/tmp/QuakeEdCmd.txt" -void DisplayCmdOutput (void) +void +DisplayCmdOutput (void) { - char *buffer; + char *buffer; QFile *file; int size; @@ -71,8 +77,8 @@ void DisplayCmdOutput (void) if ([preferences_i getShowBSP]) [inspcontrol_i changeInspectorTo:i_output]; - [preferences_i playBspSound]; - + [preferences_i playBspSound]; + } /* @@ -82,23 +88,23 @@ CheckCmdDone See if the BSP is done =============== */ -//DPSTimedEntry cmdte; -void CheckCmdDone(/*DPSTimedEntry tag,*/ double now, void *userData) +//DPSTimedEntry cmdte; +void +CheckCmdDone ( /* DPSTimedEntry tag, */ double now, void *userData) { - union wait statusp; - struct rusage rusage; - - if (!wait4(bsppid, &statusp, WNOHANG, &rusage)) + union wait statusp; + struct rusage rusage; + + if (!wait4 (bsppid, &statusp, WNOHANG, &rusage)) return; DisplayCmdOutput (); bsppid = 0; -// DPSRemoveTimedEntry( cmdte ); +// DPSRemoveTimedEntry( cmdte ); } //============================================================================ @implementation QuakeEd - /* =============== AutoSave @@ -106,14 +112,12 @@ AutoSave Every five minutes, save a modified map =============== */ --(void) AutoSave -{ + - (void) AutoSave { // automatic backup - if (autodirty) - { + if (autodirty) { autodirty = NO; - #define FN_AUTOSAVE "/qcache/AutoSaveMap.map" - [map_i writeMapFile: FN_AUTOSAVE useRegion: NO]; +#define FN_AUTOSAVE "/qcache/AutoSaveMap.map" + [map_i writeMapFile: FN_AUTOSAVE useRegion:NO]; } [map_i writeStats]; } @@ -123,46 +127,38 @@ Every five minutes, save a modified map init =============== */ -- initContent:(NSRect)contentRect -style:(int)aStyle -backing:(int)backingType -buttonMask:(int)mask -defer:(BOOL)flag +-initContent: (NSRect) contentRect style: (int) aStyle backing: (int) backingType buttonMask: (int) mask defer:(BOOL) flag { - [super initWithContentRect:contentRect - styleMask:aStyle - backing:backingType - defer:flag]; + [super initWithContentRect: contentRect styleMask: aStyle backing: backingType defer:flag]; + + // XXX [self addToEventMask: + // XXX NSRightMouseDragged|NSLeftMouseDragged]; + + // XXX malloc_error(My_Malloc_Error); - //XXX [self addToEventMask: - //XXX NSRightMouseDragged|NSLeftMouseDragged]; - - //XXX malloc_error(My_Malloc_Error); - quakeed_i = self; dirty = autodirty = NO; - [NSTimer timerWithTimeInterval: 5 * 60 - target: self - selector: @selector(AutoSave) - userInfo: nil - repeats: YES]; + [NSTimer timerWithTimeInterval: 5 * 60 target: self selector:@selector + (AutoSave) + userInfo: nil repeats:YES]; - path = [NSBezierPath new]; + path =[NSBezierPath new]; return self; } + #define FN_TEMPSAVE "/qcache/temp.map" -- setDefaultFilename -{ +-setDefaultFilename +{ strcpy (filename, FN_TEMPSAVE); - [self setTitleWithRepresentedFilename:[NSString stringWithCString:filename]]; - + [self setTitleWithRepresentedFilename: [NSString stringWithCString:filename]]; + return self; } -- (BOOL)dirty +-(BOOL) dirty { return dirty; } @@ -175,39 +171,36 @@ defer:(BOOL)flag =============================================================================== */ -BOOL updateinflight; +BOOL updateinflight; -BOOL clearinstance; +BOOL clearinstance; -BOOL updatexy; -BOOL updatez; -BOOL updatecamera; +BOOL updatexy; +BOOL updatez; +BOOL updatecamera; -void postappdefined (void) +void +postappdefined (void) { - NSEvent *ev; + NSEvent *ev; if (updateinflight) return; - + // post an event at the end of the que - ev = [NSEvent otherEventWithType: NSApplicationDefined - location: NSZeroPoint - modifierFlags: 0 - timestamp: [[NSDate date] timeIntervalSinceReferenceDate] - windowNumber: 0 - context: [NSApp context] - subtype: 0 - data1: 0 - data2: 0]; - [NSApp postEvent: ev atStart: NO]; + ev =[NSEvent otherEventWithType: NSApplicationDefined location: NSZeroPoint modifierFlags: 0 timestamp:[[NSDate date] + timeIntervalSinceReferenceDate] + windowNumber: 0 context:[NSApp context] + subtype: 0 data1: 0 data2:0]; + [NSApp postEvent: ev atStart:NO]; //printf ("posted\n"); updateinflight = YES; } -int c_updateall; -- updateAll // when a model has been changed +int c_updateall; + +-updateAll // when a model has been changed { updatecamera = updatexy = updatez = YES; c_updateall++; @@ -215,29 +208,29 @@ int c_updateall; return self; } -- updateAll:sender +-updateAll:sender { [self updateAll]; return self; } -- updateCamera // when the camera has moved +-updateCamera // when the camera has moved { updatecamera = YES; clearinstance = YES; - + postappdefined (); return self; } -- updateXY +-updateXY { updatexy = YES; postappdefined (); return self; } -- updateZ +-updateZ { updatez = YES; postappdefined (); @@ -245,13 +238,13 @@ int c_updateall; } -- newinstance +-newinstance { clearinstance = YES; return self; } -- redrawInstance +-redrawInstance { clearinstance = YES; [self flushWindow]; @@ -268,45 +261,44 @@ instance draw the brush after each flush -flushWindow { [super flushWindow]; - + if (!running) - return self; // don't lock focus before nib is finished loading - - //if (_flushDisabled) - // return self; - - [cameraview_i lockFocus]; - if (clearinstance) - { - //XXX PSnewinstance (); + return self; // don't lock focus before nib is + // finished loading + + // if (_flushDisabled) + // return self; + + [cameraview_i lockFocus]; + if (clearinstance) { + // XXX PSnewinstance (); clearinstance = NO; } - - //XXX PSsetinstance (1); - linestart (0,0,0); - [map_i makeSelectedPerform: @selector(CameraDrawSelf)]; + // XXX PSsetinstance (1); + linestart (0, 0, 0); + [map_i makeSelectedPerform:@selector (CameraDrawSelf)]; [clipper_i cameraDrawSelf]; lineflush (); - //XXX PSsetinstance (0); - [cameraview_i unlockFocus]; + // XXX PSsetinstance (0); + [cameraview_i unlockFocus]; [xyview_i lockFocus]; - //XXX PSsetinstance (1); - linestart (0,0,0); - [map_i makeSelectedPerform: @selector(XYDrawSelf)]; + // XXX PSsetinstance (1); + linestart (0, 0, 0); + [map_i makeSelectedPerform:@selector (XYDrawSelf)]; lineflush (); [cameraview_i XYDrawSelf]; [zview_i XYDrawSelf]; [clipper_i XYDrawSelf]; - //XXX PSsetinstance (0); + // XXX PSsetinstance (0); [xyview_i unlockFocus]; [zview_i lockFocus]; - //XXX PSsetinstance (1); - [map_i makeSelectedPerform: @selector(ZDrawSelf)]; + // XXX PSsetinstance (1); + [map_i makeSelectedPerform:@selector (ZDrawSelf)]; [cameraview_i ZDrawSelf]; [clipper_i ZDrawSelf]; - //XXX PSsetinstance (0); + // XXX PSsetinstance (0); [zview_i unlockFocus]; return self; @@ -321,33 +313,31 @@ App delegate methods ============================================================================== */ -- applicationDefined:(NSEvent *)theEvent +-applicationDefined:(NSEvent *) theEvent { NSEvent *evp; - + updateinflight = NO; //printf ("serviced\n"); - -// update screen - evp = [NSApp nextEventMatchingMask: NSAnyEventMask - untilDate: [NSDate distantPast] - inMode: NSEventTrackingRunLoopMode - dequeue: NO]; - if (evp) - { - postappdefined(); + +// update screen + evp =[NSApp nextEventMatchingMask: NSAnyEventMask untilDate:[NSDate + distantPast] + inMode: NSEventTrackingRunLoopMode dequeue:NO]; + if (evp) { + postappdefined (); return self; } - - [self disableFlushWindow]; - if ([map_i count] != [entitycount_i intValue]) - [entitycount_i setIntValue: [map_i count]]; - if ([[map_i currentEntity] count] != [brushcount_i intValue]) - [brushcount_i setIntValue: [[map_i currentEntity] count]]; - + [self disableFlushWindow]; + + if ([map_i count] !=[entitycount_i intValue]) + [entitycount_i setIntValue:[map_i count]]; + if ([[map_i currentEntity] count] !=[brushcount_i intValue]) + [brushcount_i setIntValue:[[map_i currentEntity] count]]; + if (updatecamera) [cameraview_i display]; if (updatexy) @@ -359,51 +349,52 @@ App delegate methods [self enableFlushWindow]; [self flushWindow]; - -// NSPing (); - + +// NSPing (); + return self; } -- appDidInit:sender +-appDidInit:sender { NSArray *screens; NSScreen *scrn; - + running = YES; - g_cmd_out_i = cmd_out_i; // for qprintf + g_cmd_out_i = cmd_out_i; // for qprintf - [preferences_i readDefaults]; - [project_i initProject]; + [preferences_i readDefaults]; + [project_i initProject]; + + [xyview_i setModeRadio:xy_drawmode_i]; + // because xy view is inside + // scrollview and can't be + // connected directly in IB - [xyview_i setModeRadio: xy_drawmode_i]; // because xy view is inside - // scrollview and can't be - // connected directly in IB - [self setFrameAutosaveName:@"EditorWinFrame"]; - [self clear: self]; + [self clear:self]; // go to my second monitor - screens = [NSScreen screens]; + screens =[NSScreen screens]; if ([screens count] == 2) { - scrn = [screens objectAtIndex: 1]; - //XXX [self moveTopLeftTo:0 : [scrn frame].size.height - //XXX screen:scrn]; + scrn =[screens objectAtIndex:1]; + // XXX [self moveTopLeftTo:0 : [scrn frame].size.height + // XXX screen:scrn]; } - - [self makeKeyAndOrderFront: self]; -//[self doOpen: "/raid/quake/id1_/maps/amlev1.map"]; // DEBUG + [self makeKeyAndOrderFront:self]; + +//[self doOpen: "/raid/quake/id1_/maps/amlev1.map"]; // DEBUG [map_i newMap]; - + qprintf ("ready."); -//malloc_debug(-1); // DEBUG - +//malloc_debug(-1); // DEBUG + return self; } -- appWillTerminate:sender +-appWillTerminate:sender { // FIXME: save dialog if dirty return self; @@ -412,90 +403,84 @@ App delegate methods //=========================================================================== -- textCommand: sender +-textCommand:sender { - char const *t; - - t = [[sender stringValue] cString]; - - if (!strcmp (t, "texname")) - { - texturedef_t *td; - id b; - - b = [map_i selectedBrush]; - if (!b) - { + char const *t; + + t =[[sender stringValue] cString]; + + if (!strcmp (t, "texname")) { + texturedef_t *td; + id b; + + b =[map_i selectedBrush]; + if (!b) { qprintf ("nothing selected"); return self; } - td = [b texturedef]; + td =[b texturedef]; qprintf (td->texture); return self; - } - else + } else qprintf ("Unknown command\n"); return self; } -- openProject:sender +-openProject:sender { - [project_i openProject]; + [project_i openProject]; return self; } -- clear: sender -{ +-clear:sender +{ [map_i newMap]; [self updateAll]; - [regionbutton_i setIntValue: 0]; + [regionbutton_i setIntValue:0]; [self setDefaultFilename]; return self; } -- centerCamera: sender +-centerCamera:sender { - NSRect sbounds; - - sbounds = [[xyview_i superview] bounds]; - - sbounds.origin.x += sbounds.size.width/2; - sbounds.origin.y += sbounds.size.height/2; - - [cameraview_i setXYOrigin: &sbounds.origin]; + NSRect sbounds; + + sbounds =[[xyview_i superview] bounds]; + + sbounds.origin.x += sbounds.size.width / 2; + sbounds.origin.y += sbounds.size.height / 2; + + [cameraview_i setXYOrigin:&sbounds.origin]; [self updateAll]; - + return self; } -- centerZChecker: sender +-centerZChecker:sender { - NSRect sbounds; - - sbounds = [[xyview_i superview] bounds]; - - sbounds.origin.x += sbounds.size.width/2; - sbounds.origin.y += sbounds.size.height/2; - - [zview_i setPoint: &sbounds.origin]; + NSRect sbounds; + + sbounds =[[xyview_i superview] bounds]; + + sbounds.origin.x += sbounds.size.width / 2; + sbounds.origin.y += sbounds.size.height / 2; + + [zview_i setPoint:&sbounds.origin]; [self updateAll]; - + return self; } -- changeXYLookUp: sender +-changeXYLookUp:sender { - if ([sender intValue]) - { + if ([sender intValue]) { xy_viewnormal[2] = 1; - } - else - { + } else { xy_viewnormal[2] = -1; } [self updateAll]; @@ -516,57 +501,55 @@ REGION MODIFICATION applyRegion: ================== */ -- applyRegion: sender +-applyRegion:sender { - filter_clip_brushes = [filter_clip_i intValue]; - filter_water_brushes = [filter_water_i intValue]; - filter_light = [filter_light_i intValue]; - filter_path = [filter_path_i intValue]; - filter_entities = [filter_entities_i intValue]; - filter_world = [filter_world_i intValue]; + filter_clip_brushes =[filter_clip_i intValue]; + filter_water_brushes =[filter_water_i intValue]; + filter_light =[filter_light_i intValue]; + filter_path =[filter_path_i intValue]; + filter_entities =[filter_entities_i intValue]; + filter_world =[filter_world_i intValue]; - if (![regionbutton_i intValue]) - { + if (![regionbutton_i intValue]) { region_min[0] = region_min[1] = region_min[2] = -9999; region_max[0] = region_max[1] = region_max[2] = 9999; } - [map_i makeGlobalPerform: @selector(newRegion)]; - + [map_i makeGlobalPerform:@selector (newRegion)]; + [self updateAll]; return self; } -- setBrushRegion: sender +-setBrushRegion:sender { - id b; + id b; // get the bounds of the current selection - - if ([map_i numSelected] != 1) - { + + if ([map_i numSelected] != 1) { qprintf ("must have a single brush selected"); return self; - } + } - b = [map_i selectedBrush]; - [b getMins: region_min maxs: region_max]; + b =[map_i selectedBrush]; + [b getMins: region_min maxs:region_max]; [b remove]; // turn region on - [regionbutton_i setIntValue: 1]; - [self applyRegion: self]; - + [regionbutton_i setIntValue:1]; + [self applyRegion:self]; + return self; } -- setXYRegion: sender +-setXYRegion:sender { - NSRect bounds; - + NSRect bounds; + // get xy size - bounds = [[xyview_i superview] bounds]; + bounds =[[xyview_i superview] bounds]; region_min[0] = bounds.origin.x; region_min[1] = bounds.origin.y; @@ -574,25 +557,25 @@ applyRegion: region_max[0] = bounds.origin.x + bounds.size.width; region_max[1] = bounds.origin.y + bounds.size.height; region_max[2] = 99999; - + // turn region on - [regionbutton_i setIntValue: 1]; - [self applyRegion: self]; - + [regionbutton_i setIntValue:1]; + [self applyRegion:self]; + return self; } // // UI querie for other objects // -- (BOOL)showCoordinates +-(BOOL) showCoordinates { - return [show_coordinates_i intValue]; + return[show_coordinates_i intValue]; } -- (BOOL)showNames +-(BOOL) showNames { - return [show_names_i intValue]; + return[show_names_i intValue]; } @@ -604,23 +587,19 @@ BSP PROCESSING ============================================================================== */ -void ExpandCommand (char *in, char *out, char *src, char *dest) +void +ExpandCommand (char *in, char *out, char *src, char *dest) { - while (*in) - { - if (in[0] == '$') - { - if (in[1] == '1') - { + while (*in) { + if (in[0] == '$') { + if (in[1] == '1') { strcpy (out, src); - out += strlen(src); - } - else if (in[1] == '2') - { + out += strlen (src); + } else if (in[1] == '2') { strcpy (out, dest); - out += strlen(dest); + out += strlen (dest); } - in += 2; + in += 2; continue; } *out++ = *in++; @@ -634,58 +613,55 @@ void ExpandCommand (char *in, char *out, char *src, char *dest) saveBSP ============= */ -- saveBSP:(char *)cmdline dialog:(BOOL)wt +-saveBSP:(char *) +cmdline dialog:(BOOL) wt { - char expandedcmd[1024]; - char mappath[1024]; - char bsppath[1024]; - int oldLightFilter; - int oldPathFilter; - char *destdir; - - if (bsppid) - { - NSBeep(); + char expandedcmd[1024]; + char mappath[1024]; + char bsppath[1024]; + int oldLightFilter; + int oldPathFilter; + char *destdir; + + if (bsppid) { + NSBeep (); return self; } - // // turn off the filters so all entities get saved // - oldLightFilter = [filter_light_i intValue]; - oldPathFilter = [filter_path_i intValue]; + oldLightFilter =[filter_light_i intValue]; + oldPathFilter =[filter_path_i intValue]; [filter_light_i setIntValue:0]; [filter_path_i setIntValue:0]; - [self applyRegion: self]; - - if ([regionbutton_i intValue]) - { + [self applyRegion:self]; + + if ([regionbutton_i intValue]) { strcpy (mappath, filename); - //XXX StripExtension (mappath); + // XXX StripExtension (mappath); strcat (mappath, ".reg"); - [map_i writeMapFile: mappath useRegion: YES]; - wt = YES; // allways pop the dialog on region ops - } - else + [map_i writeMapFile: mappath useRegion:YES]; + wt = YES; // allways pop the dialog on region ops + } else strcpy (mappath, filename); - + // save the entire thing, just in case there is a problem - [self save: self]; + [self save:self]; [filter_light_i setIntValue:oldLightFilter]; [filter_path_i setIntValue:oldPathFilter]; - [self applyRegion: self]; + [self applyRegion:self]; // // write the command to the bsp host -// - destdir = [project_i getFinalMapDirectory]; +// + destdir =[project_i getFinalMapDirectory]; strcpy (bsppath, destdir); strcat (bsppath, "/"); - //XXX ExtractFileBase (mappath, bsppath + strlen(bsppath)); + // XXX ExtractFileBase (mappath, bsppath + strlen(bsppath)); strcat (bsppath, ".bsp"); - + ExpandCommand (cmdline, expandedcmd, mappath, bsppath); strcat (expandedcmd, " > "); @@ -693,79 +669,74 @@ saveBSP strcat (expandedcmd, "\n"); printf ("system: %s", expandedcmd); - [project_i addToOutput: "\n\n========= BUSY =========\n\n"]; - [project_i addToOutput: expandedcmd]; + [project_i addToOutput:"\n\n========= BUSY =========\n\n"]; + [project_i addToOutput:expandedcmd]; if ([preferences_i getShowBSP]) [inspcontrol_i changeInspectorTo:i_output]; - - if (wt) - { - id panel; - - panel = NSGetAlertPanel(@"BSP In Progress",[NSString stringWithCString:expandedcmd],NULL,NULL,NULL); + + if (wt) { + id panel; + + panel = NSGetAlertPanel (@"BSP In Progress",[NSString stringWithCString:expandedcmd], NULL, NULL, NULL); [panel makeKeyAndOrderFront:NULL]; - system(expandedcmd); + system (expandedcmd); [panel release]; [self makeKeyAndOrderFront:NULL]; DisplayCmdOutput (); - } - else - { - //cmdte = DPSAddTimedEntry(1, CheckCmdDone, self, NS_BASETHRESHOLD); - if (! (bsppid = fork ()) ) - { + } else { + // cmdte = DPSAddTimedEntry(1, CheckCmdDone, self, NS_BASETHRESHOLD); + if (!(bsppid = fork ())) { system (expandedcmd); exit (0); } } - + return self; } -- BSP_Full: sender +-BSP_Full:sender { - [self saveBSP:[project_i getFullVisCmd] dialog: NO]; + [self saveBSP: [project_i getFullVisCmd] dialog:NO]; return self; } -- BSP_FastVis: sender +-BSP_FastVis:sender { - [self saveBSP:[project_i getFastVisCmd] dialog: NO]; + [self saveBSP: [project_i getFastVisCmd] dialog:NO]; return self; } -- BSP_NoVis: sender +-BSP_NoVis:sender { - [self saveBSP:[project_i getNoVisCmd] dialog: NO]; + [self saveBSP: [project_i getNoVisCmd] dialog:NO]; return self; } -- BSP_relight: sender +-BSP_relight:sender { - [self saveBSP:[project_i getRelightCmd] dialog: NO]; + [self saveBSP: [project_i getRelightCmd] dialog:NO]; return self; } -- BSP_entities: sender +-BSP_entities:sender { - [self saveBSP:[project_i getEntitiesCmd] dialog: NO]; + [self saveBSP: [project_i getEntitiesCmd] dialog:NO]; return self; } -- BSP_stop: sender +-BSP_stop:sender { - if (!bsppid) - { - NSBeep(); + if (!bsppid) { + NSBeep (); return self; } - + kill (bsppid, 9); - //CheckCmdDone (cmdte, 0, NULL); - [project_i addToOutput: "\n\n========= STOPPED =========\n\n"]; - + // CheckCmdDone (cmdte, 0, NULL); + [project_i addToOutput:"\n\n========= STOPPED =========\n\n"]; + return self; } @@ -778,18 +749,18 @@ doOpen: Called by open or the project panel ============== */ -- doOpen: (char *)fname; -{ +-doOpen:(char *) fname; +{ strcpy (filename, fname); - + [map_i readMapFile:filename]; - - [regionbutton_i setIntValue: 0]; - [self setTitleWithRepresentedFilename:[NSString stringWithCString:fname]]; + + [regionbutton_i setIntValue:0]; + [self setTitleWithRepresentedFilename: [NSString stringWithCString:fname]]; [self updateAll]; qprintf ("%s loaded\n", fname); - + return self; } @@ -799,21 +770,21 @@ Called by open or the project panel open ============== */ -- open: sender; +-open:sender; { - id openpanel; - NSString *suffixlist[] = {@"map"}; + id openpanel; + NSString *suffixlist[] = { @"map" }; - openpanel = [NSOpenPanel new]; + openpanel =[NSOpenPanel new]; - if ( [openpanel - runModalForDirectory: [NSString stringWithCString:[project_i getMapDirectory]] - file: @"" - types: [NSArray arrayWithObjects:suffixlist count:1]] != NSOKButton) + if ([openpanel runModalForDirectory: [NSString stringWithCString:[project_i + getMapDirectory]] + file: @"" types: [NSArray arrayWithObjects: suffixlist count:1]] != + NSOKButton) return self; - [self doOpen: (char *)[[openpanel filename] cString]]; - + [self doOpen:(char *)[[openpanel filename] cString]]; + return self; } @@ -823,22 +794,22 @@ open save: ============== */ -- save: sender; +-save:sender; { - char backup[1024]; + char backup[1024]; // force a name change if using tempname - if (!strcmp (filename, FN_TEMPSAVE) ) - return [self saveAs: self]; - + if (!strcmp (filename, FN_TEMPSAVE)) + return[self saveAs:self]; + dirty = autodirty = NO; strcpy (backup, filename); - //XXX StripExtension (backup); + // XXX StripExtension (backup); strcat (backup, ".bak"); - rename (filename, backup); // copy old to .bak + rename (filename, backup); // copy old to .bak - [map_i writeMapFile: filename useRegion: NO]; + [map_i writeMapFile: filename useRegion:NO]; return self; } @@ -849,23 +820,24 @@ save: saveAs ============== */ -- saveAs: sender; +-saveAs:sender; { - id panel_i; - char dir[1024]; - - panel_i = [NSSavePanel new]; - //XXX ExtractFileBase (filename, dir); - [panel_i setRequiredFileType: @"map"]; - if ( [panel_i runModalForDirectory:[NSString stringWithCString:[project_i getMapDirectory]] file: [NSString stringWithCString:dir]] != NSOKButton) + id panel_i; + char dir[1024]; + + panel_i =[NSSavePanel new]; + // XXX ExtractFileBase (filename, dir); + [panel_i setRequiredFileType:@"map"]; + if ([panel_i runModalForDirectory: [NSString stringWithCString: [project_i getMapDirectory]] file: [NSString stringWithCString:dir]] != + NSOKButton) return self; - - strcpy (filename, [[panel_i filename] cString]); - - [self setTitleWithRepresentedFilename:[NSString stringWithCString:filename]]; - - [self save: self]; - + + strcpy (filename,[[panel_i filename] cString]); + + [self setTitleWithRepresentedFilename: [NSString stringWithCString:filename]]; + + [self save:self]; + return self; } @@ -880,22 +852,23 @@ saveAs // -// AJR - added this for Project info +// AJR - added this for Project info // -- (char *)currentFilename +-(char *) currentFilename { return filename; } -- deselect: sender +-deselect:sender { - if ([clipper_i hide]) // first click hides only the clipper - return [self updateAll]; + if ([clipper_i hide]) // first click hides only the clipper + return[self updateAll]; - [map_i setCurrentEntity: [map_i objectAtIndex: 0]]; // make world selected - [map_i makeSelectedPerform: @selector(deselect)]; + [map_i setCurrentEntity: [map_i objectAtIndex:0]]; + // make world selected + [map_i makeSelectedPerform:@selector (deselect)]; [self updateAll]; - + return self; } @@ -911,150 +884,148 @@ keyDown #define KEY_UPARROW 0xad #define KEY_DOWNARROW 0xaf -- keyDown:(NSEvent *)theEvent +-keyDown:(NSEvent *) theEvent { - int ch; - + int ch; + // function keys - switch ([theEvent keyCode]) - { - case 60: // F2 - [cameraview_i setDrawMode: dr_wire]; - qprintf ("wire draw mode"); - return self; - case 61: // F3 - [cameraview_i setDrawMode: dr_flat]; - qprintf ("flat draw mode"); - return self; - case 62: // F4 - [cameraview_i setDrawMode: dr_texture]; - qprintf ("texture draw mode"); - return self; + switch ([theEvent keyCode]) { + case 60: // F2 + [cameraview_i setDrawMode:dr_wire]; + qprintf ("wire draw mode"); + return self; + case 61: // F3 + [cameraview_i setDrawMode:dr_flat]; + qprintf ("flat draw mode"); + return self; + case 62: // F4 + [cameraview_i setDrawMode:dr_texture]; + qprintf ("texture draw mode"); + return self; - case 63: // F5 - [xyview_i setDrawMode: dr_wire]; - qprintf ("wire draw mode"); - return self; - case 64: // F6 - qprintf ("texture draw mode"); - return self; - - case 66: // F8 - [cameraview_i homeView: self]; - return self; - - case 88: // F12 - [map_i subtractSelection: self]; - return self; + case 63: // F5 + [xyview_i setDrawMode:dr_wire]; + qprintf ("wire draw mode"); + return self; + case 64: // F6 + qprintf ("texture draw mode"); + return self; - case 106: // page up - [cameraview_i upFloor: self]; - return self; - - case 107: // page down - [cameraview_i downFloor: self]; - return self; - - case 109: // end - [self deselect: self]; - return self; + case 66: // F8 + [cameraview_i homeView:self]; + return self; + + case 88: // F12 + [map_i subtractSelection:self]; + return self; + + case 106: // page up + [cameraview_i upFloor:self]; + return self; + + case 107: // page down + [cameraview_i downFloor:self]; + return self; + + case 109: // end + [self deselect:self]; + return self; } // portable things - ch = tolower([[theEvent characters] cString][0]); - - switch (ch) - { - case KEY_RIGHTARROW: - case KEY_LEFTARROW: - case KEY_UPARROW: - case KEY_DOWNARROW: - case 'a': - case 'z': - case 'd': - case 'c': - case '.': - case ',': - [cameraview_i _keyDown: theEvent]; - break; + ch = tolower ([[theEvent characters] cString][0]); - case 27: // escape - autodirty = dirty = YES; - [self deselect: self]; - return self; - - case 127: // delete - autodirty = dirty = YES; - [map_i makeSelectedPerform: @selector(remove)]; - [clipper_i hide]; - [self updateAll]; - break; + switch (ch) { + case KEY_RIGHTARROW: + case KEY_LEFTARROW: + case KEY_UPARROW: + case KEY_DOWNARROW: + case 'a': + case 'z': + case 'd': + case 'c': + case '.': + case ',': + [cameraview_i _keyDown:theEvent]; + break; + + case 27: // escape + autodirty = dirty = YES; + [self deselect:self]; + return self; + + case 127: // delete + autodirty = dirty = YES; + [map_i makeSelectedPerform:@selector (remove)]; + [clipper_i hide]; + [self updateAll]; + break; + + case '/': + [clipper_i flipNormal]; + [self updateAll]; + break; + + case 13: // enter + [clipper_i carve]; + [self updateAll]; + qprintf ("carved brush"); + break; + + case ' ': + [map_i cloneSelection:self]; + break; - case '/': - [clipper_i flipNormal]; - [self updateAll]; - break; - - case 13: // enter - [clipper_i carve]; - [self updateAll]; - qprintf ("carved brush"); - break; - - case ' ': - [map_i cloneSelection: self]; - break; - // // move selection keys -// - case '2': - VectorCopy (vec3_origin, sb_translate); - sb_translate[1] = -[xyview_i gridsize]; - [map_i makeSelectedPerform: @selector(translate)]; - [self updateAll]; - break; - case '8': - VectorCopy (vec3_origin, sb_translate); - sb_translate[1] = [xyview_i gridsize]; - [map_i makeSelectedPerform: @selector(translate)]; - [self updateAll]; - break; +// + case '2': + VectorCopy (vec3_origin, sb_translate); + sb_translate[1] = -[xyview_i gridsize]; + [map_i makeSelectedPerform:@selector (translate)]; + [self updateAll]; + break; + case '8': + VectorCopy (vec3_origin, sb_translate); + sb_translate[1] =[xyview_i gridsize]; + [map_i makeSelectedPerform:@selector (translate)]; + [self updateAll]; + break; - case '4': - VectorCopy (vec3_origin, sb_translate); - sb_translate[0] = -[xyview_i gridsize]; - [map_i makeSelectedPerform: @selector(translate)]; - [self updateAll]; - break; - case '6': - VectorCopy (vec3_origin, sb_translate); - sb_translate[0] = [xyview_i gridsize]; - [map_i makeSelectedPerform: @selector(translate)]; - [self updateAll]; - break; + case '4': + VectorCopy (vec3_origin, sb_translate); + sb_translate[0] = -[xyview_i gridsize]; + [map_i makeSelectedPerform:@selector (translate)]; + [self updateAll]; + break; + case '6': + VectorCopy (vec3_origin, sb_translate); + sb_translate[0] =[xyview_i gridsize]; + [map_i makeSelectedPerform:@selector (translate)]; + [self updateAll]; + break; - case '-': - VectorCopy (vec3_origin, sb_translate); - sb_translate[2] = -[xyview_i gridsize]; - [map_i makeSelectedPerform: @selector(translate)]; - [self updateAll]; - break; - case '+': - VectorCopy (vec3_origin, sb_translate); - sb_translate[2] = [xyview_i gridsize]; - [map_i makeSelectedPerform: @selector(translate)]; - [self updateAll]; - break; + case '-': + VectorCopy (vec3_origin, sb_translate); + sb_translate[2] = -[xyview_i gridsize]; + [map_i makeSelectedPerform:@selector (translate)]; + [self updateAll]; + break; + case '+': + VectorCopy (vec3_origin, sb_translate); + sb_translate[2] =[xyview_i gridsize]; + [map_i makeSelectedPerform:@selector (translate)]; + [self updateAll]; + break; - default: - qprintf ("undefined keypress"); - NopSound (); - break; + default: + qprintf ("undefined keypress"); + NopSound (); + break; } - return self; + return self; } diff --git a/tools/Forge/Bundles/MapEdit/QuakeEd_main.m b/tools/Forge/Bundles/MapEdit/QuakeEd_main.m index 85734b4a6..54be2c713 100644 --- a/tools/Forge/Bundles/MapEdit/QuakeEd_main.m +++ b/tools/Forge/Bundles/MapEdit/QuakeEd_main.m @@ -1,7 +1,7 @@ #include int -main(int argc, const char *argv[]) +main (int argc, const char *argv[]) { - return NSApplicationMain (argc, argv); + return NSApplicationMain (argc, argv); } diff --git a/tools/Forge/Bundles/MapEdit/SetBrush.m b/tools/Forge/Bundles/MapEdit/SetBrush.m index 160da9323..be78ac854 100644 --- a/tools/Forge/Bundles/MapEdit/SetBrush.m +++ b/tools/Forge/Bundles/MapEdit/SetBrush.m @@ -13,58 +13,54 @@ #include "QuakeEd.h" @implementation SetBrush - /* ================== textureAxisFromPlane ================== */ #if 1 -vec3_t baseaxis[18] = -{ -{0,0,1}, {1,0,0}, {0,-1,0}, // floor -{0,0,-1}, {1,0,0}, {0,-1,0}, // ceiling -{1,0,0}, {0,1,0}, {0,0,-1}, // west wall -{-1,0,0}, {0,1,0}, {0,0,-1}, // east wall -{0,1,0}, {1,0,0}, {0,0,-1}, // south wall -{0,-1,0}, {1,0,0}, {0,0,-1} // north wall +vec3_t baseaxis[18] = { + {0, 0, 1}, {1, 0, 0}, {0, -1, 0}, // floor + {0, 0, -1}, {1, 0, 0}, {0, -1, 0}, // ceiling + {1, 0, 0}, {0, 1, 0}, {0, 0, -1}, // west wall + {-1, 0, 0}, {0, 1, 0}, {0, 0, -1}, // east wall + {0, 1, 0}, {1, 0, 0}, {0, 0, -1}, // south wall + {0, -1, 0}, {1, 0, 0}, {0, 0, -1} // north wall }; #else -vec3_t baseaxis[18] = -{ -{0,0,1}, {1,0,0}, {0,-1,0}, // floor -{0,0,-1}, {1,0,0}, {0,1,0}, // ceiling -{1,0,0}, {0,1,0}, {0,0,-1}, // west wall -{-1,0,0}, {0,-1,0}, {0,0,-1}, // east wall -{0,1,0}, {-1,0,0}, {0,0,-1}, // south wall -{0,-1,0}, {1,0,0}, {0,0,-1} // north wall +vec3_t baseaxis[18] = { + {0, 0, 1}, {1, 0, 0}, {0, -1, 0}, // floor + {0, 0, -1}, {1, 0, 0}, {0, 1, 0}, // ceiling + {1, 0, 0}, {0, 1, 0}, {0, 0, -1}, // west wall + {-1, 0, 0}, {0, -1, 0}, {0, 0, -1}, // east wall + {0, 1, 0}, {-1, 0, 0}, {0, 0, -1}, // south wall + {0, -1, 0}, {1, 0, 0}, {0, 0, -1} // north wall }; #endif -float TextureAxisFromPlane(plane_t *pln, float *xv, float *yv) +float +TextureAxisFromPlane (plane_t *pln, float *xv, float *yv) { - int bestaxis; - float dot,best; - int i; - + int bestaxis; + float dot, best; + int i; + best = 0; bestaxis = 0; - - for (i=0 ; i<6 ; i++) - { - dot = DotProduct (pln->normal, baseaxis[i*3]); - if (dot > best) - { + + for (i = 0; i < 6; i++) { + dot = DotProduct (pln->normal, baseaxis[i * 3]); + if (dot > best) { best = dot; bestaxis = i; } } - - VectorCopy (baseaxis[bestaxis*3+1], xv); - VectorCopy (baseaxis[bestaxis*3+2], yv); - - return lightaxis[bestaxis>>1]; + + VectorCopy (baseaxis[bestaxis * 3 + 1], xv); + VectorCopy (baseaxis[bestaxis * 3 + 2], yv); + + return lightaxis[bestaxis >> 1]; } #define BOGUS_RANGE 18000 @@ -76,51 +72,50 @@ CheckFace Note: this will not catch 0 area polygons ================= */ -void CheckFace (face_t *f) +void +CheckFace (face_t * f) { - int i, j; - float *p1, *p2; - float d, edgedist; - vec3_t dir, edgenormal; - winding_t *w; - + int i, j; + float *p1, *p2; + float d, edgedist; + vec3_t dir, edgenormal; + winding_t *w; + w = f->w; if (!w) Sys_Error ("CheckFace: no winding"); - + if (w->numpoints < 3) - Sys_Error ("CheckFace: %i points",w->numpoints); - - for (i=0 ; inumpoints ; i++) - { + Sys_Error ("CheckFace: %i points", w->numpoints); + + for (i = 0; i < w->numpoints; i++) { p1 = w->points[i]; - for (j=0 ; j<3 ; j++) + for (j = 0; j < 3; j++) if (p1[j] > BOGUS_RANGE || p1[j] < -BOGUS_RANGE) - Sys_Error ("CheckFace: BUGUS_RANGE: %f",p1[j]); + Sys_Error ("CheckFace: BUGUS_RANGE: %f", p1[j]); - j = i+1 == w->numpoints ? 0 : i+1; - - // check the point is on the face plane + j = i + 1 == w->numpoints ? 0 : i + 1; + + // check the point is on the face plane d = DotProduct (p1, f->plane.normal) - f->plane.dist; if (d < -ON_EPSILON || d > ON_EPSILON) Sys_Error ("CheckFace: point off plane"); - - // check the edge isn't degenerate + + // check the edge isn't degenerate p2 = w->points[j]; VectorSubtract (p2, p1, dir); - + if (VectorLength (dir) < ON_EPSILON) Sys_Error ("CheckFace: degenerate edge"); - + CrossProduct (f->plane.normal, dir, edgenormal); VectorNormalize (edgenormal); edgedist = DotProduct (p1, edgenormal); edgedist += ON_EPSILON; - - // all other points must be on front side - for (j=0 ; jnumpoints ; j++) - { + + // all other points must be on front side + for (j = 0; j < w->numpoints; j++) { if (j == i) continue; d = DotProduct (w->points[j], edgenormal); @@ -145,18 +140,19 @@ void CheckFace (face_t *f) NewWinding ================== */ -winding_t *NewWinding (int points) +winding_t * +NewWinding (int points) { - winding_t *w; - size_t size; - + winding_t *w; + size_t size; + if (points > MAX_POINTS_ON_WINDING) Sys_Error ("NewWinding: %i points", points); - - size = (size_t)((winding_t *)0)->points[points]; + + size = (size_t) ((winding_t *) 0)->points[points]; w = malloc (size); memset (w, 0, size); - + return w; } @@ -166,12 +162,13 @@ winding_t *NewWinding (int points) CopyWinding ================== */ -winding_t *CopyWinding (winding_t *w) +winding_t * +CopyWinding (winding_t * w) { - size_t size; - winding_t *c; - - size = (size_t)((winding_t *)0)->points[w->numpoints]; + size_t size; + winding_t *c; + + size = (size_t) ((winding_t *) 0)->points[w->numpoints]; c = malloc (size); memcpy (c, w, size); return c; @@ -186,22 +183,22 @@ Clips the winding to the plane, returning the new winding on the positive side Frees the input winding. ================== */ -winding_t *ClipWinding (winding_t *in, plane_t *split) +winding_t * +ClipWinding (winding_t * in, plane_t *split) { - float dists[MAX_POINTS_ON_WINDING]; - int sides[MAX_POINTS_ON_WINDING]; - int counts[3]; - float dot; - int i, j; - float *p1, *p2, *mid; - winding_t *neww; - int maxpts; - + float dists[MAX_POINTS_ON_WINDING]; + int sides[MAX_POINTS_ON_WINDING]; + int counts[3]; + float dot; + int i, j; + float *p1, *p2, *mid; + winding_t *neww; + int maxpts; + counts[0] = counts[1] = counts[2] = 0; // determine sides for each point - for (i=0 ; inumpoints ; i++) - { + for (i = 0; i < in->numpoints; i++) { dot = DotProduct (in->points[i], split->normal); dot -= split->dist; dists[i] = dot; @@ -209,38 +206,34 @@ winding_t *ClipWinding (winding_t *in, plane_t *split) sides[i] = SIDE_FRONT; else if (dot < -ON_EPSILON) sides[i] = SIDE_BACK; - else - { + else { sides[i] = SIDE_ON; } counts[sides[i]]++; } sides[i] = sides[0]; dists[i] = dists[0]; - + if (!counts[0] && !counts[1]) return in; - - if (!counts[0]) - { + + if (!counts[0]) { free (in); return NULL; } if (!counts[1]) return in; - - maxpts = in->numpoints+4; // can't use counts[0]+2 because - // of fp grouping errors + + maxpts = in->numpoints + 4; // can't use counts[0]+2 because + // of fp grouping errors neww = NewWinding (maxpts); - - for (i=0 ; inumpoints ; i++) - { + + for (i = 0; i < in->numpoints; i++) { p1 = in->points[i]; - + mid = neww->points[neww->numpoints]; - if (sides[i] == SIDE_FRONT || sides[i] == SIDE_ON) - { + if (sides[i] == SIDE_FRONT || sides[i] == SIDE_ON) { VectorCopy (p1, mid); mid[3] = p1[3]; mid[4] = p1[4]; @@ -249,29 +242,28 @@ winding_t *ClipWinding (winding_t *in, plane_t *split) continue; mid = neww->points[neww->numpoints]; } - - if (sides[i+1] == SIDE_ON || sides[i+1] == sides[i]) + + if (sides[i + 1] == SIDE_ON || sides[i + 1] == sides[i]) continue; - - // generate a split point + + // generate a split point if (i == in->numpoints - 1) p2 = in->points[0]; else p2 = p1 + 5; - + neww->numpoints++; - - dot = dists[i] / (dists[i]-dists[i+1]); - for (j=0 ; j<3 ; j++) - { // avoid round off error when possible + + dot = dists[i] / (dists[i] - dists[i + 1]); + for (j = 0; j < 3; j++) { // avoid round off error when possible if (split->normal[j] == 1) mid[j] = split->dist; else if (split->normal[j] == -1) mid[j] = -split->dist; - mid[j] = p1[j] + dot*(p2[j]-p1[j]); + mid[j] = p1[j] + dot * (p2[j] - p1[j]); } - mid[3] = p1[3] + dot*(p2[3]-p1[3]); - mid[4] = p1[4] + dot*(p2[4]-p1[4]); + mid[3] = p1[3] + dot * (p2[3] - p1[3]); + mid[4] = p1[4] + dot * (p2[4] - p1[4]); } if (neww->numpoints > maxpts) @@ -279,7 +271,7 @@ winding_t *ClipWinding (winding_t *in, plane_t *split) // free the original winding free (in); - + return neww; } @@ -290,102 +282,99 @@ BasePolyForPlane There has GOT to be a better way of doing this... ================= */ -winding_t *BasePolyForPlane (face_t *f) +winding_t * +BasePolyForPlane (face_t * f) { - int i, x; - float max, v; - vec3_t org, vright, vup; - vec3_t xaxis, yaxis; - winding_t *w; - texturedef_t *td; - plane_t *p; - float ang, sinv, cosv; - float s, t, ns, nt; + int i, x; + float max, v; + vec3_t org, vright, vup; + vec3_t xaxis, yaxis; + winding_t *w; + texturedef_t *td; + plane_t *p; + float ang, sinv, cosv; + float s, t, ns, nt; p = &f->plane; - + // find the major axis max = -BOGUS_RANGE; x = -1; - for (i=0 ; i<3; i++) - { - v = fabs(p->normal[i]); - if (v > max) - { + for (i = 0; i < 3; i++) { + v = fabs (p->normal[i]); + if (v > max) { x = i; max = v; } } - if (x==-1) + if (x == -1) Sys_Error ("BasePolyForPlane: no axis found"); - - VectorCopy (vec3_origin, vup); - switch (x) - { - case 0: - case 1: - vup[2] = 1; - break; - case 2: - vup[0] = 1; - break; + + VectorCopy (vec3_origin, vup); + switch (x) { + case 0: + case 1: + vup[2] = 1; + break; + case 2: + vup[0] = 1; + break; } v = DotProduct (vup, p->normal); VectorMultAdd (vup, -v, p->normal, vup); VectorNormalize (vup); - + VectorScale (p->normal, p->dist, org); - + CrossProduct (vup, p->normal, vright); - + VectorScale (vup, 8192, vup); VectorScale (vright, 8192, vright); -// project a really big axis aligned box onto the plane +// project a really big axis aligned box onto the plane w = NewWinding (4); w->numpoints = 4; - + VectorSubtract (org, vright, w->points[0]); VectorAdd (w->points[0], vup, w->points[0]); - + VectorAdd (org, vright, w->points[1]); VectorAdd (w->points[1], vup, w->points[1]); - + VectorAdd (org, vright, w->points[2]); VectorSubtract (w->points[2], vup, w->points[2]); - + VectorSubtract (org, vright, w->points[3]); VectorSubtract (w->points[3], vup, w->points[3]); - + // set texture values - f->light = TextureAxisFromPlane(&f->plane, xaxis, yaxis); + f->light = TextureAxisFromPlane (&f->plane, xaxis, yaxis); td = &f->texture; - + // rotate axis ang = td->rotate / 180 * M_PI; - sinv = sin(ang); - cosv = cos(ang); - + sinv = sin (ang); + cosv = cos (ang); + if (!td->scale[0]) td->scale[0] = 1; if (!td->scale[1]) td->scale[1] = 1; - for (i=0 ; i<4 ; i++) - { + for (i = 0; i < 4; i++) { s = DotProduct (w->points[i], xaxis); t = DotProduct (w->points[i], yaxis); ns = cosv * s - sinv * t; - nt = sinv * s + cosv * t; + nt = sinv * s + cosv * t; - w->points[i][3] = ns/td->scale[0] + td->shift[0]; - w->points[i][4] = nt/td->scale[1] + td->shift[1]; + w->points[i][3] = ns / td->scale[0] + td->shift[0]; + w->points[i][4] = nt / td->scale[1] + td->shift[1]; } - - return w; + + return w; } /* @@ -397,90 +386,80 @@ If a face has a NULL winding, it is an overconstraining plane and can be removed. =========== */ -- calcWindings +-calcWindings { - int i,j, k; - float v; - face_t *f; - winding_t *w; - plane_t plane; - vec3_t t1, t2, t3; - BOOL useplane[MAX_FACES]; - + int i, j, k; + float v; + face_t *f; + winding_t *w; + plane_t plane; + vec3_t t1, t2, t3; + BOOL useplane[MAX_FACES]; + bmins[0] = bmins[1] = bmins[2] = 99999; bmaxs[0] = bmaxs[1] = bmaxs[2] = -99999; invalid = NO; - + [self freeWindings]; - - for (i=0 ; iplanepts[0][j] - f->planepts[1][j]; t2[j] = f->planepts[2][j] - f->planepts[1][j]; t3[j] = f->planepts[1][j]; } - - CrossProduct(t1,t2, f->plane.normal); - if (VectorCompare (f->plane.normal, vec3_origin)) - { + + CrossProduct (t1, t2, f->plane.normal); + if (VectorCompare (f->plane.normal, vec3_origin)) { useplane[i] = NO; break; } VectorNormalize (f->plane.normal); f->plane.dist = DotProduct (t3, f->plane.normal); - - // if the plane duplicates another plane, ignore it - // (assume it is a brush being edited that will be fixed) + + // if the plane duplicates another plane, ignore it + // (assume it is a brush being edited that will be fixed) useplane[i] = YES; - for (j=0 ; j< i ; j++) - { - if ( f->plane.normal[0] == faces[j].plane.normal[0] - && f->plane.normal[1] == faces[j].plane.normal[1] - && f->plane.normal[2] == faces[j].plane.normal[2] - && f->plane.dist == faces[j].plane.dist ) - { + for (j = 0; j < i; j++) { + if (f->plane.normal[0] == faces[j].plane.normal[0] + && f->plane.normal[1] == faces[j].plane.normal[1] + && f->plane.normal[2] == faces[j].plane.normal[2] + && f->plane.dist == faces[j].plane.dist) { useplane[i] = NO; break; } } - + } - - for (i=0 ; iw = w; - if (w) - { + if (w) { CheckFace (f); - for (j=0 ; jnumpoints ; j++) - { - for (k=0 ; k<3 ; k++) - { + for (j = 0; j < w->numpoints; j++) { + for (k = 0; k < 3; k++) { v = w->points[j][k]; - if (fabs(v - rint(v)) < FP_EPSILON) - v = w->points[j][k] = rint(v); + if (fabs (v - rint (v)) < FP_EPSILON) + v = w->points[j][k] = rint (v); if (v < bmins[k]) bmins[k] = v; if (v > bmaxs[k]) @@ -488,16 +467,15 @@ can be removed. } } } - } + } - if (bmins[0] == 99999) - { + if (bmins[0] == 99999) { invalid = YES; VectorCopy (vec3_origin, bmins); VectorCopy (vec3_origin, bmaxs); return nil; } - + return self; } @@ -508,71 +486,70 @@ can be removed. initOwner::: =========== */ -- initOwner: own mins:(float *)mins maxs:(float *)maxs texture:(texturedef_t *)tex +-initOwner: own mins:(float *) +mins maxs:(float *) +maxs texture:(texturedef_t *) tex { - [super init]; + [super init]; parent = own; - - [self setTexturedef: tex]; - [self setMins: mins maxs: maxs]; + + [self setTexturedef:tex]; + [self setMins: mins maxs:maxs]; return self; } -- setMins:(float *)mins maxs:(float *)maxs +-setMins:(float *) +mins maxs:(float *) maxs { - int i, j; - vec3_t pts[4][2]; - - for (i=0 ; i<3 ; i++) - { - if (maxs[i] - mins[i] <= 0) - { + int i, j; + vec3_t pts[4][2]; + + for (i = 0; i < 3; i++) { + if (maxs[i] - mins[i] <= 0) { VectorCopy (mins, bmins); VectorCopy (maxs, bmaxs); invalid = YES; numfaces = 0; return self; - } + } } - + pts[0][0][0] = mins[0]; pts[0][0][1] = mins[1]; - + pts[1][0][0] = mins[0]; pts[1][0][1] = maxs[1]; - + pts[2][0][0] = maxs[0]; pts[2][0][1] = maxs[1]; - + pts[3][0][0] = maxs[0]; pts[3][0][1] = mins[1]; - - for (i=0 ; i<4 ; i++) - { + + for (i = 0; i < 4; i++) { pts[i][0][2] = mins[2]; pts[i][1][0] = pts[i][0][0]; pts[i][1][1] = pts[i][0][1]; pts[i][1][2] = maxs[2]; } - + numfaces = 6; - for (i=0 ; i<4 ; i++) - { - j = (i+1)%4; + for (i = 0; i < 4; i++) { + j = (i + 1) % 4; faces[i].planepts[0][0] = pts[j][1][0]; faces[i].planepts[0][1] = pts[j][1][1]; faces[i].planepts[0][2] = pts[j][1][2]; - + faces[i].planepts[1][0] = pts[i][1][0]; faces[i].planepts[1][1] = pts[i][1][1]; faces[i].planepts[1][2] = pts[i][1][2]; - + faces[i].planepts[2][0] = pts[i][0][0]; faces[i].planepts[2][1] = pts[i][0][1]; faces[i].planepts[2][2] = pts[i][0][2]; } - + faces[4].planepts[0][0] = pts[0][1][0]; faces[4].planepts[0][1] = pts[0][1][1]; faces[4].planepts[0][2] = pts[0][1][2]; @@ -584,7 +561,7 @@ initOwner::: faces[4].planepts[2][0] = pts[2][1][0]; faces[4].planepts[2][1] = pts[2][1][1]; faces[4].planepts[2][2] = pts[2][1][2]; - + faces[5].planepts[0][0] = pts[2][0][0]; faces[5].planepts[0][1] = pts[2][0][1]; @@ -597,46 +574,45 @@ initOwner::: faces[5].planepts[2][0] = pts[0][0][0]; faces[5].planepts[2][1] = pts[0][0][1]; faces[5].planepts[2][2] = pts[0][0][2]; - + [self calcWindings]; return self; } -- parent +-parent { return parent; } -- setParent: (id)p +-setParent:(id) p { parent = p; return self; } -- setEntityColor: (vec3_t)color +-setEntityColor:(vec3_t) color { VectorCopy (color, entitycolor); return self; } -- freeWindings +-freeWindings { - int i; - - for (i=0 ; iplanepts[i][j] = atoi(Script_Token (script)); - } - - Script_GetToken (script, false); - if (strcmp (Script_Token (script), ")") ) - Sys_Error ("parsing map file"); - } +{ +if (!Script_GetToken (script, true)) + break; +if (!strcmp (Script_Token (script), "}")) + break; +for (i = 0; i < 3; i++) { + if (i != 0) + Script_GetToken (script, true); + if (strcmp (Script_Token (script), "(")) + Sys_Error ("parsing map file"); + + for (j = 0; j < 3; j++) { Script_GetToken (script, false); - strcpy (f->texture.texture, Script_Token (script)); - Script_GetToken (script, false); - f->texture.shift[0] = atof(Script_Token (script)); - Script_GetToken (script, false); - f->texture.shift[1] = atof(Script_Token (script)); - Script_GetToken (script, false); - f->texture.rotate = atof(Script_Token (script)); - Script_GetToken (script, false); - f->texture.scale[0] = atof(Script_Token (script)); - Script_GetToken (script, false); - f->texture.scale[1] = atof(Script_Token (script)); - + f->planepts[i][j] = atoi (Script_Token (script)); + } Script_GetToken (script, false); + + if (strcmp (Script_Token (script), ")")) + Sys_Error ("parsing map file"); +} + +Script_GetToken (script, false); +strcpy (f->texture.texture, Script_Token (script)); +Script_GetToken (script, false); +f->texture.shift[0] = atof (Script_Token (script)); +Script_GetToken (script, false); +f->texture.shift[1] = atof (Script_Token (script)); +Script_GetToken (script, false); +f->texture.rotate = atof (Script_Token (script)); +Script_GetToken (script, false); +f->texture.scale[0] = atof (Script_Token (script)); +Script_GetToken (script, false); +f->texture.scale[1] = atof (Script_Token (script)); + #if 0 - flags = atoi(Script_Token (script)); - - flags &= 7; +flags = atoi (Script_Token (script)); - f->texture.rotate = 0; - f->texture.scale[0] = 1; - f->texture.scale[1] = 1; +flags &= 7; + +f->texture.rotate = 0; +f->texture.scale[0] = 1; +f->texture.scale[1] = 1; #define TEX_FLIPAXIS 1 #define TEX_FLIPS 2 #define TEX_FLIPT 4 - if (flags & TEX_FLIPAXIS) - { - f->texture.rotate = 90; - if ( !(flags & TEX_FLIPT) ) - f->texture.scale[0] = -1; - if (flags & TEX_FLIPS) - f->texture.scale[1] = -1; - } - else - { - if (flags & TEX_FLIPS) - f->texture.scale[0] = -1; - if (flags & TEX_FLIPT) - f->texture.scale[1] = -1; - } -#endif - f++; - numfaces++; +if (flags & TEX_FLIPAXIS) { + f->texture.rotate = 90; + if (!(flags & TEX_FLIPT)) + f->texture.scale[0] = -1; + if (flags & TEX_FLIPS) + f->texture.scale[1] = -1; +} else { + if (flags & TEX_FLIPS) + f->texture.scale[0] = -1; + if (flags & TEX_FLIPT) + f->texture.scale[1] = -1; +} +#endif +f++; +numfaces++; } while (1); - + numsb++; [self calcWindings]; @@ -739,27 +710,30 @@ int numsb; writeToFILE =========== */ -- writeToFILE: (FILE *)f region: (BOOL)reg +-writeToFILE:(FILE *) +f region:(BOOL) reg { - int i,j; - face_t *fa; - texturedef_t *td; - + int i, j; + face_t *fa; + texturedef_t *td; + if (reg && regioned) return self; fprintf (f, "{\n"); - for (i=0 ; iplanepts[j][0], (int)fa->planepts[j][1], (int)fa->planepts[j][2]); + for (j = 0; j < 3; j++) + fprintf (f, "( %d %d %d ) ", (int) fa->planepts[j][0], + (int) fa->planepts[j][1], (int) fa->planepts[j][2]); td = &fa->texture; - fprintf (f,"%s %d %d %d %f %f\n", td->texture, (int)td->shift[0], (int)td->shift[1], (int)td->rotate, td->scale[0], td->scale[1]); + fprintf (f, "%s %d %d %d %f %f\n", td->texture, (int) td->shift[0], + (int) td->shift[1], (int) td->rotate, td->scale[0], + td->scale[1]); } fprintf (f, "}\n"); - + return self; } @@ -773,7 +747,8 @@ INTERACTION ============================================================================== */ -- getMins: (vec3_t)mins maxs: (vec3_t)maxs +-getMins:(vec3_t) +mins maxs:(vec3_t) maxs { VectorCopy (bmins, mins); VectorCopy (bmaxs, maxs); @@ -781,23 +756,23 @@ INTERACTION } -- (BOOL)selected +-(BOOL) selected { return selected; } -- setSelected: (BOOL)s +-setSelected:(BOOL) s { selected = s; return self; } -- (BOOL)regioned +-(BOOL) regioned { return regioned; } -- setRegioned: (BOOL)s +-setRegioned:(BOOL) s { regioned = s; return self; @@ -809,29 +784,29 @@ INTERACTION setTexturedef =========== */ -- setTexturedef: (texturedef_t *)tex +-setTexturedef:(texturedef_t *) tex { - int i; - - for (i=0 ; i numfaces) - Sys_Error ("setTexturedef:forFace: bad face number %i",f); - - faces[f].texture = *tex; - faces[f].qtexture = NULL; // recache next render + if ((unsigned) f > numfaces) + Sys_Error ("setTexturedef:forFace: bad face number %i", f); - [self calcWindings]; // in case texture coords changed + faces[f].texture = *tex; + faces[f].qtexture = NULL; // recache next render + + [self calcWindings]; // in case texture coords changed return self; } @@ -840,12 +815,12 @@ setTexturedef texturedef =========== */ -- (texturedef_t *)texturedef +-(texturedef_t *) texturedef { return &faces[0].texture; } -- (texturedef_t *)texturedefForFace: (int)f +-(texturedef_t *) texturedefForFace:(int) f { return &faces[f].texture; } @@ -858,24 +833,22 @@ removeIfInvalid So created veneers don't stay around =========== */ -- removeIfInvalid +-removeIfInvalid { - int i, j; - - for (i=0 ; i= faces[i].plane.dist) return NO; - return YES; + return YES; } /* @@ -905,55 +878,50 @@ clipRay =========== */ -- clipRay: (vec3_t)p1 : (vec3_t) p2 - :(vec3_t)frontpoint : (int *)f_face - :(vec3_t)backpoint : (int *)b_face +-clipRay: (vec3_t) p1: (vec3_t) p2: (vec3_t) frontpoint: (int *) f_face: (vec3_t) backpoint:(int *) b_face { - int frontface, backface; - int i, j; - face_t *f; - float d1, d2, m; - float *start; - + int frontface, backface; + int i, j; + face_t *f; + float d1, d2, m; + float *start; + start = p1; frontface = -2; backface = -2; - + f = faces; - for (i=0 ; iw) - continue; // clipped off plane + continue; // clipped off plane d1 = DotProduct (p1, f->plane.normal) - f->plane.dist; d2 = DotProduct (p2, f->plane.normal) - f->plane.dist; - if (d1 >= 0 && d2 >= 0) - { // the entire ray is in front of the polytope + if (d1 >= 0 && d2 >= 0) { // the entire ray is in front of the + // polytope *f_face = -1; *b_face = -1; return self; } - if (d1 > 0 && d2 < 0) - { // new front plane + if (d1 > 0 && d2 < 0) { // new front plane frontface = i; - m = d1 / (d1-d2); - for (j=0 ; j<3 ; j++) - frontpoint[j] = p1[j] + m*(p2[j]-p1[j]); + m = d1 / (d1 - d2); + for (j = 0; j < 3; j++) + frontpoint[j] = p1[j] + m * (p2[j] - p1[j]); p1 = frontpoint; } - if (d1 < 0 && d2 > 0) - { // new back plane + if (d1 < 0 && d2 > 0) { // new back plane backface = i; - m = d1 / (d1-d2); - for (j=0 ; j<3 ; j++) - backpoint[j] = p1[j] + m*(p2[j]-p1[j]); + m = d1 / (d1 - d2); + for (j = 0; j < 3; j++) + backpoint[j] = p1[j] + m * (p2[j] - p1[j]); p2 = backpoint; } } - + *f_face = frontface; *b_face = backface; - + return self; } @@ -964,35 +932,34 @@ hitByRay =========== */ -- hitByRay: (vec3_t)p1 : (vec3_t) p2 : (float *)time : (int *)face +-hitByRay: (vec3_t) p1: (vec3_t) p2: (float *) time:(int *) face { - vec3_t frontpoint, backpoint, dir; - int frontface, backface; - - if (regioned) - { + vec3_t frontpoint, backpoint, dir; + int frontface, backface; + + if (regioned) { *time = -1; *face = -1; return self; } - - [self clipRay: p1 : p2 : frontpoint: &frontface : backpoint : &backface]; - - if (frontface == -2 && backface == -2) - { // entire ray is inside the brush, select first face + + [self clipRay: p1: p2: frontpoint: &frontface: backpoint:&backface]; + + if (frontface == -2 && backface == -2) { // entire ray is inside the + // brush, select first face *time = 0; *face = 0; return self; } - - - if (frontface < 0) - { // ray started inside the polytope, don't select it + + + if (frontface < 0) { // ray started inside the polytope, + // don't select it *time = -1; *face = -1; return self; } - + VectorSubtract (p2, p1, dir); VectorNormalize (dir); VectorSubtract (frontpoint, p1, frontpoint); @@ -1002,7 +969,7 @@ hitByRay Sys_Error ("hitByRay: negative t"); *face = frontface; - + return self; } @@ -1015,58 +982,57 @@ DRAWING ROUTINES ============================================================================== */ -BOOL fakebrush; +BOOL fakebrush; -- drawConnections +-drawConnections { - id obj; - int c, i; - vec3_t dest, origin; - vec3_t mid; - vec3_t forward, right; - char *targname; - vec3_t min, max, temp; + id obj; + int c, i; + vec3_t dest, origin; + vec3_t mid; + vec3_t forward, right; + char *targname; + vec3_t min, max, temp; char *targ; - - targ = [parent valueForQKey: "target"]; + + targ =[parent valueForQKey:"target"]; if (!targ || !targ[0]) return self; - - origin[0] = (bmins[0] + bmaxs[0]) /2; - origin[1] = (bmins[1] + bmaxs[1]) /2; - - c = [map_i count]; - for (i=0 ; i xy_draw_rect.origin.x + xy_draw_rect.size.width - || bmins[1] > xy_draw_rect.origin.y + xy_draw_rect.size.height) ) - return self; // off view, don't bother + (bmaxs[0] < xy_draw_rect.origin.x + || bmaxs[1] < xy_draw_rect.origin.y + || bmins[0] > xy_draw_rect.origin.x + xy_draw_rect.size.width + || bmins[1] > xy_draw_rect.origin.y + xy_draw_rect.size.height)) + return self; // off view, don't bother - for (i=0 ; i -VECTOR_EPSILON) + if (DotProduct (faces[i].plane.normal, xy_viewnormal) > -VECTOR_EPSILON) continue; - - XYmoveto (w->points[w->numpoints-1]); - for (j=0 ; jnumpoints ; j++) + + XYmoveto (w->points[w->numpoints - 1]); + for (j = 0; j < w->numpoints; j++) XYlineto (w->points[j]); } - - if (keybrush) - { + + if (keybrush) { // angle arrow - val = [parent valueForQKey: "angle"]; - if (val && val[0]) - { - ang = atof(val) * M_PI / 180; - if (ang > 0) // negative values are up/down flags + val =[parent valueForQKey:"angle"]; + if (val && val[0]) { + ang = atof (val) * M_PI / 180; + if (ang > 0) // negative values are up/down flags { - mid[0] = (bmins[0]+bmaxs[0])/2; - mid[1] = (bmins[1]+bmaxs[1])/2; - - end[0] = mid[0] + 16*cos(ang); - end[1] = mid[1] + 16*sin(ang); - - s1[0] = mid[0] + 12*cos(ang+0.4); - s1[1] = mid[1] + 12*sin(ang+0.4); - - s2[0] = mid[0] + 12*cos(ang-0.4); - s2[1] = mid[1] + 12*sin(ang-0.4); - - XYmoveto ( mid); - XYlineto ( end ); - XYmoveto ( s1); - XYlineto ( end ); - XYlineto ( s2 ); + mid[0] = (bmins[0] + bmaxs[0]) / 2; + mid[1] = (bmins[1] + bmaxs[1]) / 2; + + end[0] = mid[0] + 16 * cos (ang); + end[1] = mid[1] + 16 * sin (ang); + + s1[0] = mid[0] + 12 * cos (ang + 0.4); + s1[1] = mid[1] + 12 * sin (ang + 0.4); + + s2[0] = mid[0] + 12 * cos (ang - 0.4); + s2[1] = mid[1] + 12 * sin (ang - 0.4); + + XYmoveto (mid); + XYlineto (end); + XYmoveto (s1); + XYlineto (end); + XYlineto (s2); } } } - + return self; } @@ -1202,58 +1164,56 @@ XYDrawSelf ZDrawSelf =========== */ -- ZDrawSelf +-ZDrawSelf { - int i; - vec3_t p1, p2; - vec3_t frontpoint, backpoint; - int frontface, backface; - qtexture_t *q; - - if ([self fakeBrush: @selector(ZDrawSelf)]) + int i; + vec3_t p1, p2; + vec3_t frontpoint, backpoint; + int frontface, backface; + qtexture_t *q; + + if ([self fakeBrush:@selector (ZDrawSelf)]) return self; - [zview_i addToHeightRange: bmins[2]]; - [zview_i addToHeightRange: bmaxs[2]]; - - if (selected) - { + [zview_i addToHeightRange:bmins[2]]; + [zview_i addToHeightRange:bmaxs[2]]; + + if (selected) { PSmoveto (1, bmaxs[2]); PSlineto (23, bmaxs[2]); PSlineto (23, bmins[2]); PSlineto (1, bmins[2]); PSlineto (1, bmaxs[2]); - PSsetrgbcolor (1,0,0); + PSsetrgbcolor (1, 0, 0); PSstroke (); } - [zview_i getPoint: (NSPoint *)p1]; - - for (i=0 ; i<2 ; i++) + [zview_i getPoint:(NSPoint *) p1]; + + for (i = 0; i < 2; i++) if (bmins[i] >= p1[i] || bmaxs[i] <= p1[i]) return self; - + p1[2] = 4096; p2[0] = p1[0]; p2[1] = p1[1]; p2[2] = -4096; - [self clipRay: p1 : p2 : frontpoint: &frontface : backpoint : &backface]; + [self clipRay: p1: p2: frontpoint: &frontface: backpoint:&backface]; if (frontface == -1 || backface == -1) return self; - + q = TEX_ForName (faces[frontface].texture.texture); - + PSmoveto (-8, frontpoint[2]); PSlineto (8, frontpoint[2]); PSlineto (8, backpoint[2]); PSlineto (-8, backpoint[2]); PSlineto (-8, frontpoint[2]); - - PSsetrgbcolor (q->flatcolor.chan[0]/255.0 - , q->flatcolor.chan[1]/255.0 - , q->flatcolor.chan[2]/255.0); + + PSsetrgbcolor (q->flatcolor.chan[0] / 255.0, q->flatcolor.chan[1] / 255.0, + q->flatcolor.chan[2] / 255.0); PSfill (); PSmoveto (-12, frontpoint[2]); @@ -1261,10 +1221,10 @@ ZDrawSelf PSlineto (12, backpoint[2]); PSlineto (-12, backpoint[2]); PSlineto (-12, frontpoint[2]); - - PSsetrgbcolor (0,0,0); + + PSsetrgbcolor (0, 0, 0); PSstroke (); - + return self; } @@ -1273,34 +1233,33 @@ ZDrawSelf CameraDrawSelf =========== */ -- CameraDrawSelf +-CameraDrawSelf { - int i, j; - winding_t *w; - id worldent, currentent; - - if ([self fakeBrush: @selector(CameraDrawSelf)]) + int i, j; + winding_t *w; + id worldent, currentent; + + if ([self fakeBrush:@selector (CameraDrawSelf)]) return self; - - worldent = [map_i objectAtIndex: 0]; - currentent = [map_i currentEntity]; + + worldent =[map_i objectAtIndex:0]; + currentent =[map_i currentEntity]; if (parent != worldent && worldent == currentent) linecolor (entitycolor[0], entitycolor[1], entitycolor[2]); else if (selected) - linecolor (1,0,0); - else if (parent == [map_i currentEntity]) - linecolor (0,0,0); + linecolor (1, 0, 0); + else if (parent ==[map_i currentEntity]) + linecolor (0, 0, 0); else - linecolor (0,0.5,0); + linecolor (0, 0.5, 0); - for (i=0 ; ipoints[w->numpoints-1]); - for (j=0 ; jnumpoints ; j++) + CameraMoveto (w->points[w->numpoints - 1]); + for (j = 0; j < w->numpoints; j++) CameraLineto (w->points[j]); } return self; @@ -1312,16 +1271,16 @@ CameraDrawSelf XYRenderSelf =========== */ -- XYRenderSelf +-XYRenderSelf { - int i; - - if ([self fakeBrush: @selector(XYRenderSelf)]) + int i; + + if ([self fakeBrush:@selector (XYRenderSelf)]) return self; - - for (i=0 ; iw; if (!w) continue; - if (dragplane[i] && numdragplanes == 1) - { - for (j=0 ; j<3 ; j++) - { + if (dragplane[i] && numdragplanes == 1) { + for (j = 0; j < 3; j++) { controlpoints[numcontrolpoints] = faces[i].planepts[j]; numcontrolpoints++; } @@ -1513,39 +1461,36 @@ float *controlpoints[MAX_FACES*3]; } if (!dragplane[i] && numdragplanes > 1) continue; - + facectl = 0; - for (j=0 ; jnumpoints ; j++) - { + for (j = 0; j < w->numpoints; j++) { onplane[j] = NO; - for (k=0 ; kpoints[j], faces[k].plane.normal) - faces[k].plane.dist; - if (fabs(d) > ON_EPSILON) + if (fabs (d) > ON_EPSILON) continue; onplane[j] = YES; facectl++; - break; + break; } } if (facectl == 0) continue; - - // find one or two static points to go with the controlpoints - // and change the plane points + + // find one or two static points to go with the controlpoints + // and change the plane points k = 0; - for (j=0 ; jnumpoints ; j++) - { + for (j = 0; j < w->numpoints; j++) { if (!onplane[j]) continue; - if (facectl >= 2 && !onplane[(j+1)%w->numpoints]) + if (facectl >= 2 && !onplane[(j + 1) % w->numpoints]) continue; - if (facectl == 3 && !onplane[(j+2)%w->numpoints]) + if (facectl == 3 && !onplane[(j + 2) % w->numpoints]) continue; VectorCopy (w->points[j], f->planepts[k]); @@ -1553,49 +1498,44 @@ float *controlpoints[MAX_FACES*3]; numcontrolpoints++; k++; - if (facectl >= 2) - { - VectorCopy (w->points[(j+1)%w->numpoints], f->planepts[k]); + if (facectl >= 2) { + VectorCopy (w->points[(j + 1) % w->numpoints], f->planepts[k]); controlpoints[numcontrolpoints] = f->planepts[k]; numcontrolpoints++; k++; } - if (facectl == 3) - { - VectorCopy (w->points[(j+2)%w->numpoints], f->planepts[k]); + if (facectl == 3) { + VectorCopy (w->points[(j + 2) % w->numpoints], f->planepts[k]); controlpoints[numcontrolpoints] = f->planepts[k]; numcontrolpoints++; k++; } break; } - - for ( ; jnumpoints && k != 3 ; j++) - if (!onplane[j]) - { + + for (; j < w->numpoints && k != 3; j++) + if (!onplane[j]) { VectorCopy (w->points[j], f->planepts[k]); k++; } - - for (j=0 ; jnumpoints && k != 3 ; j++) - if (!onplane[j]) - { + + for (j = 0; j < w->numpoints && k != 3; j++) + if (!onplane[j]) { VectorCopy (w->points[j], f->planepts[k]); k++; } - - if (k != 3) - { -// Sys_Error ("getXYShearPoints: didn't get three points on plane"); + + if (k != 3) { +// Sys_Error ("getXYShearPoints: didn't get three points on plane"); numcontrolpoints = 0; return self; } - - for (j=0 ; j<3 ; j++) - for (k=0 ; k<3 ; k++) - f->planepts[j][k] = rint(f->planepts[j][k]); + + for (j = 0; j < 3; j++) + for (k = 0; k < 3; k++) + f->planepts[j][k] = rint (f->planepts[j][k]); } - + return self; } @@ -1607,7 +1547,7 @@ MULTIPLE BRUSH ACTIONS ============================================================================== */ -vec3_t region_min, region_max; +vec3_t region_min, region_max; /* =========== @@ -1616,77 +1556,71 @@ newRegion Set the regioned flag based on if the object is containted in region_min/max =========== */ -- newRegion +-newRegion { - int i; - char *name; - + int i; + char *name; + // filter away entities - if (parent != [map_i objectAtIndex: 0]) - { - if (filter_entities) - { + if (parent !=[map_i objectAtIndex:0]) { + if (filter_entities) { regioned = YES; return self; } - - name = [parent valueForQKey: "classname"]; - - if ( (filter_light && !strncmp(name,"light",5) ) - || (filter_path && !strncmp(name,"path",4) ) ) - { + + name =[parent valueForQKey:"classname"]; + + if ((filter_light && !strncmp (name, "light", 5)) + || (filter_path && !strncmp (name, "path", 4))) { regioned = YES; return self; } - } - else if (filter_world) - { + } else if (filter_world) { regioned = YES; return self; } - - if (filter_clip_brushes && !strcasecmp(faces[0].texture.texture, "clip")) - { + + if (filter_clip_brushes && !strcasecmp (faces[0].texture.texture, "clip")) { regioned = YES; return self; } - - if (filter_water_brushes && faces[0].texture.texture[0] == '*') - { + + if (filter_water_brushes && faces[0].texture.texture[0] == '*') { regioned = YES; return self; } - - for (i=0 ; i<3 ; i++) - { - if (region_min[i] >= bmaxs[i] || region_max[i] <= bmins[i]) - { + + for (i = 0; i < 3; i++) { + if (region_min[i] >= bmaxs[i] || region_max[i] <= bmins[i]) { if (selected) [self deselect]; regioned = YES; return self; } } - + regioned = NO; return self; } -vec3_t select_min, select_max; -- selectPartial +vec3_t select_min, select_max; + +-selectPartial { - int i; - for (i=0 ; i<3 ; i++) + int i; + + for (i = 0; i < 3; i++) if (select_min[i] >= bmaxs[i] || select_max[i] <= bmins[i]) return self; selected = YES; return self; } -- selectComplete +-selectComplete { - int i; - for (i=0 ; i<3 ; i++) + int i; + + for (i = 0; i < 3; i++) if (select_min[i] > bmins[i] || select_max[i] < bmaxs[i]) return self; selected = YES; @@ -1694,20 +1628,22 @@ vec3_t select_min, select_max; } -- regionPartial +-regionPartial { - int i; - for (i=0 ; i<3 ; i++) + int i; + + for (i = 0; i < 3; i++) if (select_min[i] >= bmaxs[i] || select_max[i] <= bmins[i]) return self; selected = YES; return self; } -- regionComplete +-regionComplete { - int i; - for (i=0 ; i<3 ; i++) + int i; + + for (i = 0; i < 3; i++) if (select_min[i] > bmins[i] || select_max[i] < bmaxs[i]) return self; selected = YES; @@ -1715,55 +1651,55 @@ vec3_t select_min, select_max; } -id sb_newowner; -- moveToEntity +id sb_newowner; + +-moveToEntity { - id eclass; - float *c; - - [parent removeObject: self]; + id eclass; + float *c; + + [parent removeObject:self]; parent = sb_newowner; - + // hack to allow them to be copied to another map - if ( [parent respondsToSelector:@selector(valueForQKey:)]) - { - eclass = [entity_classes_i classForName: [parent valueForQKey: "classname"]]; - c = [eclass drawColor]; - [self setEntityColor: c]; + if ([parent respondsToSelector: @selector (valueForQKey:)]) { + eclass =[entity_classes_i classForName: [parent valueForQKey:"classname"]]; + c =[eclass drawColor]; + [self setEntityColor:c]; } - - [parent addObject: self]; + + [parent addObject:self]; return self; } -vec3_t sb_translate; +vec3_t sb_translate; -- translate +-translate { - int i, j; - + int i, j; + // move the planes - for (i=0; i sb_maxs[k]) @@ -1773,65 +1709,64 @@ vec3_t sb_mins, sb_maxs; return self; } -- flushTextures -{ // call when texture palette changes - int i; - - for (i=0 ; i 0 && dist < sb_floor_dist) - sb_floor_dist = dist; - } - else - { + sb_floor_dist = dist; + } else { if (dist < 0 && dist > sb_floor_dist) - sb_floor_dist = dist; + sb_floor_dist = dist; } return self; } @@ -1929,79 +1862,78 @@ BRUSH SUBTRACTION =============================================================================== */ -vec3_t carvemin, carvemax; -int numcarvefaces; -face_t *carvefaces; -id carve_in, carve_out; +vec3_t carvemin, carvemax; +int numcarvefaces; +face_t *carvefaces; +id carve_in, carve_out; // returns the new brush formed after the addition of the given plane // nil is returned if it faced all of the original setbrush -- addFace: (face_t *)f +-addFace:(face_t *) f { if (numfaces == MAX_FACES) Sys_Error ("addFace: numfaces == MAX_FACES"); - + faces[numfaces] = *f; faces[numfaces].texture = faces[0].texture; faces[numfaces].qtexture = NULL; faces[numfaces].w = NULL; numfaces++; [self calcWindings]; - + // remove any degenerate faces - return [self removeIfInvalid]; + return[self removeIfInvalid]; } -- clipByFace: (face_t *)fa front:(id *)f back:(id *)b +-clipByFace:(face_t *) +fa front:(id *) +f back:(id *) b { - id front, back; - face_t fb; - vec3_t temp; - + id front, back; + face_t fb; + vec3_t temp; + fb = *fa; VectorCopy (fb.planepts[0], temp); VectorCopy (fb.planepts[2], fb.planepts[0]); VectorCopy (temp, fb.planepts[2]); - - front = [self copy]; - back = [self copy]; - *b = [back addFace: fa]; - *f = [front addFace: &fb]; - + front =[self copy]; + back =[self copy]; + + *b =[back addFace:fa]; + *f =[front addFace:&fb]; + return self; } -- carve +-carve { - int i; - id front, back; - + int i; + id front, back; + #if 0 - if ( (i = NSMallocCheck()) ) + if ((i = NSMallocCheck ())) Sys_Error ("MallocCheck failure"); #endif - + // check bboxes - for (i=0 ; i<3 ; i++) - if (bmins[i] >= carvemax[i] || bmaxs[i] <= carvemin[i]) - { - [carve_out addObject: self]; + for (i = 0; i < 3; i++) + if (bmins[i] >= carvemax[i] || bmaxs[i] <= carvemin[i]) { + [carve_out addObject:self]; return self; } - // carve by the planes back = self; - for (i=0 ; i - Dept. of Mathematics and Computer Science, Aalborg U., Denmark + Written by: Kresten Krab Thorup + Dept. of Mathematics and Computer Science, Aalborg U., Denmark - This file is part of the GNUstep Base Library. + This file is part of the GNUstep Base Library. - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ /* #include */ #include "Storage.h" @@ -28,257 +28,250 @@ #define GNU_STORAGE_NTH(x,N) \ - ({ GNUStorageId* __s=(GNUStorageId*)(x); \ - (void*)(((char*)__s->dataPtr)+(__s->elementSize*(N))); }) + ({ GNUStorageId* __s=(GNUStorageId*)(x); \ + (void*)(((char*)__s->dataPtr)+(__s->elementSize*(N))); }) #define STORAGE_NTH(N) GNU_STORAGE_NTH (self, N) typedef struct { - @defs(Storage) + @defs (Storage) } GNUStorageId; @implementation Storage -+ initialize ++initialize { - if (self == [Storage class]) - [self setVersion:0]; /* beta release */ - return self; + if (self ==[Storage class]) + [self setVersion:0]; /* beta release */ + return self; } // INITIALIZING, FREEING; -- initCount: (NSUInteger)numSlots - elementSize: (NSUInteger)sizeInBytes - description: (const char*)elemDesc; +-initCount: (NSUInteger) numSlots elementSize: (NSUInteger) sizeInBytes description:(const char *) + elemDesc; { - [super init]; - numElements = numSlots; - maxElements = (numSlots > 0) ? numSlots : 1; - elementSize = sizeInBytes; - description = elemDesc; - dataPtr = (void*) objc_malloc (maxElements * elementSize); - bzero(dataPtr, numElements * elementSize); - return self; + [super init]; + numElements = numSlots; + maxElements = (numSlots > 0) ? numSlots : 1; + elementSize = sizeInBytes; + description = elemDesc; + dataPtr = (void *) objc_malloc (maxElements * elementSize); + bzero (dataPtr, numElements * elementSize); + return self; } -- init +-init { - return [self initCount:1 - elementSize:sizeof(id) - description:@encode(id)]; + return[self initCount: 1 elementSize:sizeof (id) + description:@encode (id)]; } -- (void)dealloc +-(void) dealloc { - if (dataPtr) - free(dataPtr); - [super dealloc]; + if (dataPtr) + free (dataPtr); + [super dealloc]; } -- (const char*) description +-(const char *) description { - return description; + return description; } // COPYING; -- copy +-copy { - Storage *c = [super copy]; - c->dataPtr = (void*) objc_malloc (maxElements * elementSize); - memcpy(c->dataPtr, dataPtr, numElements * elementSize); - return c; + Storage *c =[super copy]; + + c->dataPtr = (void *) objc_malloc (maxElements * elementSize); + memcpy (c->dataPtr, dataPtr, numElements * elementSize); + return c; } // COMPARING TWO STORAGES; -- (BOOL)isEqual: anObject +-(BOOL) isEqual:anObject { - if ([anObject isKindOfClass: [Storage class]] - && [anObject count] == [self count] - && !memcmp(((GNUStorageId*)anObject)->dataPtr, - dataPtr, numElements*elementSize)) - return YES; - else - return NO; + if ([anObject isKindOfClass:[Storage class]] + &&[anObject count] ==[self count] + && !memcmp (((GNUStorageId *) anObject)->dataPtr, + dataPtr, numElements * elementSize)) + return YES; + else + return NO; } - + // MANAGING THE STORAGE CAPACITY; -static inline void _makeRoomForAnotherIfNecessary(Storage *self) +static inline void +_makeRoomForAnotherIfNecessary (Storage * self) { - if (self->numElements == self->maxElements) - { - self->maxElements *= 2; - self->dataPtr = (void*) - objc_realloc (self->dataPtr, self->maxElements*self->elementSize); - } + if (self->numElements == self->maxElements) { + self->maxElements *= 2; + self->dataPtr = (void *) + objc_realloc (self->dataPtr, self->maxElements * self->elementSize); + } } -static inline void _shrinkIfDesired(Storage *self) +static inline void +_shrinkIfDesired (Storage * self) { - if (self->numElements < (self->maxElements / 2)) - { - self->maxElements /= 2; - self->dataPtr = (void *) - objc_realloc (self->dataPtr, self->maxElements*self->elementSize); - } + if (self->numElements < (self->maxElements / 2)) { + self->maxElements /= 2; + self->dataPtr = (void *) + objc_realloc (self->dataPtr, self->maxElements * self->elementSize); + } } -- setAvailableCapacity:(NSUInteger)numSlots +-setAvailableCapacity:(NSUInteger) numSlots { - if (numSlots > numElements) - { - maxElements = numSlots; - dataPtr = (void*) objc_realloc (dataPtr, maxElements * elementSize); - } - return self; + if (numSlots > numElements) { + maxElements = numSlots; + dataPtr = (void *) objc_realloc (dataPtr, maxElements * elementSize); + } + return self; } -- setNumSlots:(NSUInteger)numSlots +-setNumSlots:(NSUInteger) numSlots { - if (numSlots > numElements) - { - maxElements = numSlots; - dataPtr = (void*) objc_realloc (dataPtr, maxElements * elementSize); - bzero(STORAGE_NTH(numElements), (maxElements-numElements)*elementSize); - } - else if (numSlots < numElements) - { - numElements = numSlots; - _shrinkIfDesired (self); - } - return self; + if (numSlots > numElements) { + maxElements = numSlots; + dataPtr = (void *) objc_realloc (dataPtr, maxElements * elementSize); + bzero (STORAGE_NTH (numElements), + (maxElements - numElements) * elementSize); + } else if (numSlots < numElements) { + numElements = numSlots; + _shrinkIfDesired (self); + } + return self; } /* Manipulating objects by index */ #define CHECK_INDEX(IND) if (IND >= numElements) return 0 -- (NSUInteger) count +-(NSUInteger) count { - return numElements; + return numElements; } -- (void*) elementAt: (NSUInteger)index +-(void *) elementAt:(NSUInteger) index { - CHECK_INDEX(index); - return STORAGE_NTH (index); + CHECK_INDEX (index); + return STORAGE_NTH (index); } -- addElement: (void*)anElement +-addElement:(void *) anElement { - _makeRoomForAnotherIfNecessary(self); - memcpy(STORAGE_NTH(numElements), anElement, elementSize); - numElements++; - return self; + _makeRoomForAnotherIfNecessary (self); + memcpy (STORAGE_NTH (numElements), anElement, elementSize); + numElements++; + return self; } -- insertElement: (void*)anElement at: (NSUInteger)index +-insertElement:(void *) +anElement at:(NSUInteger) index { - int i; + int i; - CHECK_INDEX(index); - _makeRoomForAnotherIfNecessary(self); -#ifndef STABLE_MEMCPY - for (i = numElements; i >= index; i--) - memcpy (STORAGE_NTH(i+1), STORAGE_NTH(i), elementSize); -#else - memcpy (STORAGE_NTH (index+1), - STORAGE_NTH (index), - elementSize*(numElements-index)); -#endif - memcpy(STORAGE_NTH(i), anElement, elementSize); - numElements++; - return self; -} - -- removeElementAt: (NSUInteger)index -{ - int i; - - CHECK_INDEX(index); - numElements--; + CHECK_INDEX (index); + _makeRoomForAnotherIfNecessary (self); #ifndef STABLE_MEMCPY - for (i = index; i < numElements; i++) - memcpy(STORAGE_NTH(i), - STORAGE_NTH(i+1), - elementSize); + for (i = numElements; i >= index; i--) + memcpy (STORAGE_NTH (i + 1), STORAGE_NTH (i), elementSize); #else - memcpy (STORAGE_NTH (index), - STORAGE_NTH (index+1), - elementSize*(numElements-index-1)); -#endif - _shrinkIfDesired(self); - return self; + memcpy (STORAGE_NTH (index + 1), + STORAGE_NTH (index), elementSize * (numElements - index)); +#endif + memcpy (STORAGE_NTH (i), anElement, elementSize); + numElements++; + return self; } -- removeLastElement +-removeElementAt:(NSUInteger) index { - if (numElements) - { - numElements--; - _shrinkIfDesired(self); - } - return self; + int i; + + CHECK_INDEX (index); + numElements--; +#ifndef STABLE_MEMCPY + for (i = index; i < numElements; i++) + memcpy (STORAGE_NTH (i), STORAGE_NTH (i + 1), elementSize); +#else + memcpy (STORAGE_NTH (index), + STORAGE_NTH (index + 1), elementSize * (numElements - index - 1)); +#endif + _shrinkIfDesired (self); + return self; } -- replaceElementAt:(NSUInteger)index with:(void*)newElement +-removeLastElement { - CHECK_INDEX(index); - memcpy(STORAGE_NTH(index), newElement, elementSize); - return self; + if (numElements) { + numElements--; + _shrinkIfDesired (self); + } + return self; +} + +-replaceElementAt:(NSUInteger) +index with:(void *) newElement +{ + CHECK_INDEX (index); + memcpy (STORAGE_NTH (index), newElement, elementSize); + return self; } /* Emptying the Storage */ -- empty +-empty { - numElements = 0; - maxElements = 1; - dataPtr = (void*) objc_realloc (dataPtr, maxElements * elementSize); - return self; + numElements = 0; + maxElements = 1; + dataPtr = (void *) objc_realloc (dataPtr, maxElements * elementSize); + return self; } /* Archiving */ -- write: (TypedStream*)aStream +-write:(TypedStream *) aStream { - int i; + int i; - [super write:aStream]; - objc_write_types(aStream, "III*", - &numElements, &maxElements, &elementSize, &description); - for (i = 0; i < numElements; i++) - objc_write_type(aStream, description, STORAGE_NTH(i)); - return self; + [super write:aStream]; + objc_write_types (aStream, "III*", + &numElements, &maxElements, &elementSize, &description); + for (i = 0; i < numElements; i++) + objc_write_type (aStream, description, STORAGE_NTH (i)); + return self; } -- read: (TypedStream*)aStream +-read:(TypedStream *) aStream { - int i; + int i; - [super read:aStream]; - objc_read_types(aStream, "III*", - &numElements, &maxElements, &elementSize, &description); - dataPtr = (void*) objc_malloc (maxElements * elementSize); - for (i = 0; i < numElements; i++) - objc_read_type(aStream, description, STORAGE_NTH(i)); - return self; + [super read:aStream]; + objc_read_types (aStream, "III*", + &numElements, &maxElements, &elementSize, &description); + dataPtr = (void *) objc_malloc (maxElements * elementSize); + for (i = 0; i < numElements; i++) + objc_read_type (aStream, description, STORAGE_NTH (i)); + return self; } -+ new ++new { - return [[self alloc] init]; + return[[self alloc] init]; } -+ newCount:(NSUInteger)count elementSize:(NSUInteger)sizeInBytes - description:(const char *)descriptor ++newCount:(NSUInteger) +count elementSize:(NSUInteger) sizeInBytes + description:(const char *) descriptor { - return [[self alloc] initCount:count elementSize:sizeInBytes - description:descriptor]; + return[[self alloc] initCount: count elementSize: sizeInBytes description:descriptor]; } @end diff --git a/tools/Forge/Bundles/MapEdit/TexturePalette.m b/tools/Forge/Bundles/MapEdit/TexturePalette.m index d345de3dd..ba91af565 100644 --- a/tools/Forge/Bundles/MapEdit/TexturePalette.m +++ b/tools/Forge/Bundles/MapEdit/TexturePalette.m @@ -13,82 +13,81 @@ #include "Storage.h" -id texturepalette_i; +id texturepalette_i; #define TYP_MIPTEX 67 -int tex_count; -qtexture_t qtextures[MAX_TEXTURES]; +int tex_count; +qtexture_t qtextures[MAX_TEXTURES]; -typedef struct -{ - char name[16]; - unsigned width, height; - unsigned offsets[4]; // four mip maps stored +typedef struct { + char name[16]; + unsigned width, height; + unsigned offsets[4]; // four mip maps stored } miptex_t; -unsigned tex_palette[256]; +unsigned tex_palette[256]; -unsigned badtex_d[] = -{ -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, +unsigned badtex_d[] = { + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, -0,0,0,0,0,0,0,0, -0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff }; -qtexture_t badtex = {"notexture",16,16,NULL, badtex_d, {{0,0,255,255}}}; +qtexture_t badtex = + { "notexture", 16, 16, NULL, badtex_d, {{0, 0, 255, 255}} }; /* ============== TEX_InitPalette ============== */ -void TEX_InitPalette (byte *pal) +void +TEX_InitPalette (byte * pal) { - int r,g,b,v; - int i; + int r, g, b, v; + int i; - for (i=0 ; i<256 ; i++) - { + for (i = 0; i < 256; i++) { r = pal[0]; g = pal[1]; b = pal[2]; pal += 3; - - v = (r<<24) + (g<<16) + (b<<8) + 255; + + v = (r << 24) + (g << 16) + (b << 8) + 255; v = BigLong (v); - + tex_palette[i] = v; } } @@ -99,77 +98,66 @@ void TEX_InitPalette (byte *pal) TEX_ImageFromMiptex ================= */ -void TEX_ImageFromMiptex (miptex_t *qtex) +void +TEX_ImageFromMiptex (miptex_t *qtex) { - NSBitmapImageRep *bm; - byte *source; - unsigned *dest; - int width, height, i, count; - qtexture_t *q; - int tr, tg, tb; - - width = LittleLong(qtex->width); - height = LittleLong(qtex->height); + NSBitmapImageRep *bm; + byte *source; + unsigned *dest; + int width, height, i, count; + qtexture_t *q; + int tr, tg, tb; + + width = LittleLong (qtex->width); + height = LittleLong (qtex->height); + + bm =[[NSBitmapImageRep alloc] + initWithBitmapDataPlanes: NULL pixelsWide: width pixelsHigh: height bitsPerSample: 8 samplesPerPixel: 3 hasAlpha: NO isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: width * 4 bitsPerPixel:32]; - bm = [[NSBitmapImageRep alloc] - initWithBitmapDataPlanes: NULL - pixelsWide: width - pixelsHigh: height - bitsPerSample: 8 - samplesPerPixel:3 - hasAlpha: NO - isPlanar: NO - colorSpaceName: NSCalibratedRGBColorSpace - bytesPerRow: width*4 - bitsPerPixel: 32]; - dest = (unsigned *)[bm bitmapData]; - count = width*height; - source = (byte *)qtex + LittleLong(qtex->offsets[0]); - + count = width * height; + source = (byte *) qtex + LittleLong (qtex->offsets[0]); + q = &qtextures[tex_count]; tex_count++; - + q->width = width; q->height = height; q->rep = bm; q->data = dest; tr = tg = tb = 0; - - for (i=0 ; ichan[0]; - tg += ((pixel32_t *)&dest[i])->chan[1]; - tb += ((pixel32_t *)&dest[i])->chan[2]; + tr += ((pixel32_t *) & dest[i])->chan[0]; + tg += ((pixel32_t *) & dest[i])->chan[1]; + tb += ((pixel32_t *) & dest[i])->chan[2]; } - + q->flatcolor.chan[0] = tr / count; q->flatcolor.chan[1] = tg / count; q->flatcolor.chan[2] = tb / count; - q->flatcolor.chan[3] = 0xff; + q->flatcolor.chan[3] = 0xff; } //============================================================================= -typedef struct -{ - char identification[4]; // should be WAD2 or 2DAW - int numlumps; - int infotableofs; +typedef struct { + char identification[4]; // should be WAD2 or 2DAW + int numlumps; + int infotableofs; } wadinfo_t; -typedef struct -{ - int filepos; - int disksize; - int size; // uncompressed - char type; - char compression; - char pad1, pad2; - char name[16]; // must be null terminated +typedef struct { + int filepos; + int disksize; + int size; // uncompressed + char type; + char compression; + char pad1, pad2; + char name[16]; // must be null terminated } lumpinfo_t; /* @@ -177,73 +165,71 @@ typedef struct TEX_InitFromWad ================= */ -void TEX_InitFromWad (char *path) +void +TEX_InitFromWad (char *path) { - int i; - char local[1024]; - char newpath[1024]; - byte *wadfile; - wadinfo_t *wadinfo; - lumpinfo_t *lumpinfo; - int numlumps; - float start, stop; + int i; + char local[1024]; + char newpath[1024]; + byte *wadfile; + wadinfo_t *wadinfo; + lumpinfo_t *lumpinfo; + int numlumps; + float start, stop; QFile *file; size_t size; - + start = I_FloatTime (); - - strcpy(newpath, [preferences_i getProjectPath]); - strcat(newpath,"/"); - strcat(newpath, path); - + + strcpy (newpath,[preferences_i getProjectPath]); + strcat (newpath, "/"); + strcat (newpath, path); + // free any textures - for (i=0 ; inumlumps); - lumpinfo = (lumpinfo_t *)(wadfile + LittleLong (wadinfo->infotableofs)); - - if (strcmp (lumpinfo->name, "PALETTE")) - { - unlink (local); - Sys_Error ("TEX_InitFromWad: %s doesn't have palette as 0",path); - } - - TEX_InitPalette (wadfile + LittleLong(lumpinfo->filepos)); - lumpinfo++; - for (i=1 ; inumlumps); + lumpinfo = (lumpinfo_t *) (wadfile + LittleLong (wadinfo->infotableofs)); + + if (strcmp (lumpinfo->name, "PALETTE")) { + unlink (local); + Sys_Error ("TEX_InitFromWad: %s doesn't have palette as 0", path); + } + + TEX_InitPalette (wadfile + LittleLong (lumpinfo->filepos)); + + lumpinfo++; + for (i = 1; i < numlumps; i++, lumpinfo++) { if (lumpinfo->type != TYP_MIPTEX) - Sys_Error ("TEX_InitFromWad: %s is not a miptex!",lumpinfo->name); - //XXX CleanupName (lumpinfo->name,qtextures[tex_count].name); - TEX_ImageFromMiptex ( (miptex_t *)(wadfile + - LittleLong(lumpinfo->filepos) )); + Sys_Error ("TEX_InitFromWad: %s is not a miptex!", lumpinfo->name); + // XXX CleanupName (lumpinfo->name,qtextures[tex_count].name); + TEX_ImageFromMiptex ((miptex_t *) (wadfile + + LittleLong (lumpinfo->filepos))); } free (wadfile); stop = I_FloatTime (); - + qprintf ("loaded %s (%5.1f)", local, stop - start); } @@ -252,20 +238,20 @@ void TEX_InitFromWad (char *path) TEX_NumForName ================= */ -qtexture_t *TEX_ForName (char *name) +qtexture_t * +TEX_ForName (char *name) { - //XXX char newname[16]; - int i; - qtexture_t *q; - - //XXX CleanupName (name, newname); - - for (i=0,q = qtextures ; i< tex_count ; i++, q++) - { - if (!strcmp(name, q->name)) + // XXX char newname[16]; + int i; + qtexture_t *q; + + // XXX CleanupName (name, newname); + + for (i = 0, q = qtextures; i < tex_count; i++, q++) { + if (!strcmp (name, q->name)) return q; } - + return &badtex; } @@ -274,8 +260,7 @@ qtexture_t *TEX_ForName (char *name) //=========================================================================== @implementation TexturePalette - -- init +-init { [super init]; texturepalette_i = self; @@ -283,52 +268,50 @@ qtexture_t *TEX_ForName (char *name) return self; } -- (void)display +-(void) display { [[textureView_i superview] display]; } -- (char *)currentWad +-(char *) currentWad { return currentwad; } -- initPaletteFromWadfile:(char *)wf +-initPaletteFromWadfile:(char *) wf { - int i; - texpal_t t; - qtexture_t *q; - + int i; + texpal_t t; + qtexture_t *q; + strcpy (currentwad, wf); - [map_i makeGlobalPerform: @selector(flushTextures)]; + [map_i makeGlobalPerform:@selector (flushTextures)]; selectedTexture = -1; - + // Init textures WAD - TEX_InitFromWad(wf); - + TEX_InitFromWad (wf); + // Create STORAGE if (textureList_i) [textureList_i empty]; else - textureList_i = [[Storage alloc] - initCount:0 - elementSize:sizeof(texpal_t) - description:NULL]; - + textureList_i =[[Storage alloc] + initCount: 0 elementSize:sizeof (texpal_t) + description: NULL]; + // Init STORAGE - - for (i = 0,q=qtextures;i < tex_count; i++,q++) - { + + for (i = 0, q = qtextures; i < tex_count; i++, q++) { t.image = q->rep; - t.r.size.width = [t.image pixelsWide]; + t.r.size.width =[t.image pixelsWide]; if (t.r.size.width < 64) t.r.size.width = 64; - t.r.size.height = [t.image pixelsHigh] + TEX_SPACING; + t.r.size.height =[t.image pixelsHigh] + TEX_SPACING; t.name = q->name; t.index = i; t.display = 1; - [textureList_i addElement:&t]; + [textureList_i addElement:&t]; } // Calculate size of TextureView @@ -342,38 +325,35 @@ qtexture_t *TEX_ForName (char *name) -// Return texture STORAGE list -- getList +// Return texture STORAGE list +-getList { return textureList_i; } -// Alphabetize texture list - reverse order! -- alphabetize +// Alphabetize texture list - reverse order! +-alphabetize { - int i; - int max; - texpal_t *t1p; - texpal_t *t2p; - texpal_t t1; - texpal_t t2; - int found; - - max = [textureList_i count]; + int i; + int max; + texpal_t *t1p; + texpal_t *t2p; + texpal_t t1; + texpal_t t2; + int found; + + max =[textureList_i count]; found = 1; - while(found) - { + while (found) { found = 0; - for (i = 0;i < max-1;i++) - { - t1p = [textureList_i elementAt:i]; - t2p = [textureList_i elementAt:i+1]; - if (strcmp(t1p->name,t2p->name) < 0) - { + for (i = 0; i < max - 1; i++) { + t1p =[textureList_i elementAt:i]; + t2p =[textureList_i elementAt:i + 1]; + if (strcmp (t1p->name, t2p->name) < 0) { t1 = *t1p; t2 = *t2p; - [textureList_i replaceElementAt:i with:&t2]; - [textureList_i replaceElementAt:i+1 with:&t1]; + [textureList_i replaceElementAt: i with:&t2]; + [textureList_i replaceElementAt: i + 1 with:&t1]; found = 1; } } @@ -381,33 +361,31 @@ qtexture_t *TEX_ForName (char *name) return self; } -- computeTextureViewSize +-computeTextureViewSize { - int i; - int max; - int x; - texpal_t *t; - int y; - id view; - NSRect b; - int maxwidth; - int maxheight; - NSPoint pt; - - max = [textureList_i count]; + int i; + int max; + int x; + texpal_t *t; + int y; + id view; + NSRect b; + int maxwidth; + int maxheight; + NSPoint pt; + + max =[textureList_i count]; y = 0; maxheight = 0; x = TEX_INDENT; - view = [textureView_i superview]; - b = [view bounds]; + view =[textureView_i superview]; + b =[view bounds]; maxwidth = b.size.width; - for (i = 0;i < max; i++) - { - t = [textureList_i elementAt:i]; - if (x + t->r.size.width + TEX_INDENT > maxwidth) - { + for (i = 0; i < max; i++) { + t =[textureList_i elementAt:i]; + if (x + t->r.size.width + TEX_INDENT > maxwidth) { x = TEX_INDENT; y += maxheight; maxheight = 0; @@ -430,68 +408,65 @@ qtexture_t *TEX_ForName (char *name) return self; } -- windowResized +-windowResized { [self computeTextureViewSize]; return self; } -- texturedefChanged: sender +-texturedefChanged:sender { - if ([map_i numSelected]) - { - if ( [[map_i currentEntity] modifiable] ) - { - [map_i makeSelectedPerform: @selector(takeCurrentTexture)]; + if ([map_i numSelected]) { + if ([[map_i currentEntity] modifiable]) { + [map_i makeSelectedPerform:@selector + (takeCurrentTexture)]; [quakeed_i updateAll]; - } - else + } else qprintf ("can't modify spawned entities"); } - [quakeed_i makeFirstResponder: quakeed_i]; + [quakeed_i makeFirstResponder:quakeed_i]; return self; } -- clearTexinfo: sender +-clearTexinfo:sender { - [field_Xshift_i setFloatValue:0]; - [field_Yshift_i setFloatValue:0]; - [field_Xscale_i setFloatValue:1]; - [field_Yscale_i setFloatValue:1]; - [field_Rotate_i setFloatValue:0]; - - [self texturedefChanged: self]; + [field_Xshift_i setFloatValue:0]; + [field_Yshift_i setFloatValue:0]; + [field_Xscale_i setFloatValue:1]; + [field_Yscale_i setFloatValue:1]; + [field_Rotate_i setFloatValue:0]; + + [self texturedefChanged:self]; return self; } // -// Set the selected texture +// Set the selected texture // -- setSelectedTexture:(int)which +-setSelectedTexture:(int) which { - texpal_t *t; - NSRect r; - char string[16]; + texpal_t *t; + NSRect r; + char string[16]; // wipe the fields - [self clearTexinfo: self]; - - if (which != selectedTexture) - { + [self clearTexinfo:self]; + + if (which != selectedTexture) { [textureView_i deselect]; selectedTexture = which; - t = [textureList_i elementAt:which]; + t =[textureList_i elementAt:which]; r = t->r; - r.size.width += TEX_INDENT*2; - r.size.height += TEX_INDENT*2; + r.size.width += TEX_INDENT * 2; + r.size.height += TEX_INDENT * 2; r.origin.x -= TEX_INDENT; r.origin.y -= TEX_INDENT; [textureView_i scrollRectToVisible:r]; [textureView_i display]; - sprintf(string,"%d x %d",(int)t->r.size.width, - (int)t->r.size.height - TEX_SPACING); - [sizeField_i setStringValue:[NSString stringWithCString:string]]; + sprintf (string, "%d x %d", (int) t->r.size.width, + (int) t->r.size.height - TEX_SPACING); + [sizeField_i setStringValue: [NSString stringWithCString:string]]; } [self texturedefChanged:self]; @@ -500,57 +475,55 @@ qtexture_t *TEX_ForName (char *name) } // -// Return the selected texture index +// Return the selected texture index // -- (int)getSelectedTexture +-(int) getSelectedTexture { return selectedTexture; } // -// Return the original tex_ index of the selected texture -// so the texture info can be indexed from tex_images, etc. +// Return the original tex_ index of the selected texture +// so the texture info can be indexed from tex_images, etc. // -- (int)getSelectedTexIndex +-(int) getSelectedTexIndex { - texpal_t *t; - + texpal_t *t; + if (selectedTexture == -1) return -1; - t = [textureList_i elementAt:selectedTexture]; + t =[textureList_i elementAt:selectedTexture]; return t->index; } // -// Return the name of the selected texture +// Return the name of the selected texture // -- (char *)getSelTextureName +-(char *) getSelTextureName { - texpal_t *t; - + texpal_t *t; + if (selectedTexture == -1) return NULL; - t = [textureList_i elementAt:selectedTexture]; + t =[textureList_i elementAt:selectedTexture]; return t->name; } // -// Set selected texture by texture name +// Set selected texture by texture name // -- setTextureByName:(char *)name +-setTextureByName:(char *) name { - texpal_t *t; - int i; - int max; - - max = [textureList_i count]; - //XXX CleanupName(name,name); - for (i = 0;i < max;i++) - { - t = [textureList_i elementAt:i]; - if (!strcmp(t->name,name)) - { - [self setSelectedTexture: i]; + texpal_t *t; + int i; + int max; + + max =[textureList_i count]; + // XXX CleanupName(name,name); + for (i = 0; i < max; i++) { + t =[textureList_i elementAt:i]; + if (!strcmp (t->name, name)) { + [self setSelectedTexture:i]; return self; } } @@ -559,111 +532,107 @@ qtexture_t *TEX_ForName (char *name) //=================================================== // -// Action methods +// Action methods // //=================================================== // -// Search for texture named in searchField +// Search for texture named in searchField // -- searchForTexture:sender +-searchForTexture:sender { - int i; - int max; - int len; - char name[32], *n; - texpal_t *t; - + int i; + int max; + int len; + char name[32], *n; + texpal_t *t; + if (selectedTexture == -1) return self; - max = [textureList_i count]; - strcpy(name,(const char *)[sender stringValue]); + max =[textureList_i count]; + strcpy (name, (const char *)[sender stringValue]); for (n = name; *n; n++) *n = toupper (*n); - [sender setStringValue:[NSString stringWithCString:name]]; - len = strlen(name); - - for (i = selectedTexture-1;i >= 0; i--) - { - t = [textureList_i elementAt:i]; - if (!strncmp(t->name,name,len)) - { + [sender setStringValue: [NSString stringWithCString:name]]; + len = strlen (name); + + for (i = selectedTexture - 1; i >= 0; i--) { + t =[textureList_i elementAt:i]; + if (!strncmp (t->name, name, len)) { [self setTextureByName:t->name]; [sender selectText:sender]; [self texturedefChanged:self]; return self; } } - - for (i = max-1;i >= selectedTexture; i--) - { - t = [textureList_i elementAt:i]; - if (!strncmp(t->name,name,len)) - { + + for (i = max - 1; i >= selectedTexture; i--) { + t =[textureList_i elementAt:i]; + if (!strncmp (t->name, name, len)) { [self setTextureByName:t->name]; [sender selectText:sender]; [self texturedefChanged:self]; return self; } } - + [self texturedefChanged:self]; return self; } // -// Set texture def from outside TexturePalette +// Set texture def from outside TexturePalette // -- setTextureDef:(texturedef_t *)td +-setTextureDef:(texturedef_t *) td { [self setTextureByName:td->texture]; - [field_Xshift_i setFloatValue:td->shift[0]]; - [field_Yshift_i setFloatValue:td->shift[1]]; - [field_Xscale_i setFloatValue:td->scale[0]]; - [field_Yscale_i setFloatValue:td->scale[1]]; - [field_Rotate_i setFloatValue:td->rotate]; + [field_Xshift_i setFloatValue:td->shift[0]]; + [field_Yshift_i setFloatValue:td->shift[1]]; + [field_Xscale_i setFloatValue:td->scale[0]]; + [field_Yscale_i setFloatValue:td->scale[1]]; + [field_Rotate_i setFloatValue:td->rotate]; [self texturedefChanged:self]; - + return self; } // -// Return the current texture def to passed * +// Return the current texture def to passed * // -- getTextureDef:(texturedef_t *)td +-getTextureDef:(texturedef_t *) td { - if (selectedTexture == -1) - { - memset (td, 0, sizeof(*td)); + if (selectedTexture == -1) { + memset (td, 0, sizeof (*td)); strcpy (td->texture, "notexture"); return self; } - - strncpy(td->texture,[self getSelTextureName],16); - td->shift[0] = [field_Xshift_i floatValue]; - td->shift[1] = [field_Yshift_i floatValue]; - td->scale[0] = [field_Xscale_i floatValue]; - td->scale[1] = [field_Yscale_i floatValue]; - td->rotate = [field_Rotate_i floatValue]; - + strncpy (td->texture,[self getSelTextureName], 16); + + td->shift[0] =[field_Xshift_i floatValue]; + td->shift[1] =[field_Yshift_i floatValue]; + td->scale[0] =[field_Xscale_i floatValue]; + td->scale[1] =[field_Yscale_i floatValue]; + td->rotate =[field_Rotate_i floatValue]; + return self; } //============================================================================ // -// Change value in a field +// Change value in a field // -- changeField:(id)field by:(int)amount +-changeField:(id) +field by:(int) amount { - int val; - - val = [field intValue]; + int val; + + val =[field intValue]; val += amount; [field setIntValue:val]; @@ -673,75 +642,80 @@ qtexture_t *TEX_ForName (char *name) } // -// Inc/Dec the XShift field +// Inc/Dec the XShift field // -- incXShift:sender +-incXShift:sender { - [self changeField:field_Xshift_i by:8]; + [self changeField: field_Xshift_i by:8]; return self; } -- decXShift:sender + +-decXShift:sender { - [self changeField:field_Xshift_i by:-8]; + [self changeField: field_Xshift_i by:-8]; return self; } // -// Inc/Dec the YShift field +// Inc/Dec the YShift field // -- incYShift:sender +-incYShift:sender { - [self changeField:field_Yshift_i by:8]; + [self changeField: field_Yshift_i by:8]; return self; } -- decYShift:sender + +-decYShift:sender { - [self changeField:field_Yshift_i by:-8]; + [self changeField: field_Yshift_i by:-8]; return self; } // -// Inc/Dec the Rotate field +// Inc/Dec the Rotate field // -- incRotate:sender +-incRotate:sender { - [self changeField:field_Rotate_i by:90]; + [self changeField: field_Rotate_i by:90]; return self; } -- decRotate:sender + +-decRotate:sender { - [self changeField:field_Rotate_i by:-90]; + [self changeField: field_Rotate_i by:-90]; return self; } // -// Inc/Dec the Xscale field +// Inc/Dec the Xscale field // -- incXScale:sender +-incXScale:sender { - [field_Xscale_i setIntValue: 1]; + [field_Xscale_i setIntValue:1]; [self texturedefChanged:self]; return self; } -- decXScale:sender + +-decXScale:sender { - [field_Xscale_i setIntValue: -1]; + [field_Xscale_i setIntValue:-1]; [self texturedefChanged:self]; return self; } // -// Inc/Dec the Yscale field +// Inc/Dec the Yscale field // -- incYScale:sender +-incYScale:sender { - [field_Yscale_i setIntValue: 1]; + [field_Yscale_i setIntValue:1]; [self texturedefChanged:self]; return self; } -- decYScale:sender + +-decYScale:sender { - [field_Yscale_i setIntValue: -1]; + [field_Yscale_i setIntValue:-1]; [self texturedefChanged:self]; return self; } @@ -751,26 +725,25 @@ qtexture_t *TEX_ForName (char *name) // -// Search for texture in entire palette -// Return index of texturedef, or -1 if unsuccessful +// Search for texture in entire palette +// Return index of texturedef, or -1 if unsuccessful // -- (int) searchForTextureInPalette:(char *)texture +-(int) searchForTextureInPalette:(char *) texture { - int i; - int max; - char name[32]; - texpal_t *t; - + int i; + int max; + char name[32]; + texpal_t *t; + if (selectedTexture == -1) return -1; - max = [textureList_i count]; - strcpy(name,texture); - - for (i = 0; i < max; i++) - { - t = [textureList_i elementAt:i]; - if (!strcmp(t->name,name)) + max =[textureList_i count]; + strcpy (name, texture); + + for (i = 0; i < max; i++) { + t =[textureList_i elementAt:i]; + if (!strcmp (t->name, name)) return i; } return -1; @@ -779,57 +752,55 @@ qtexture_t *TEX_ForName (char *name) // // Scan thru map & display only textures that are in map // -- onlyShowMapTextures:sender +-onlyShowMapTextures:sender { - int max; - int i; - int j; - id brushes; - SetBrush *b; - int numfaces; - face_t *f; - int index; - - // Turn 'em off - if ([sender intValue]) - { - max = [textureList_i count]; - for (i = 0;i < max; i++) - [self setDisplayFlag:i to:0]; + int max; + int i; + int j; + id brushes; + SetBrush *b; + int numfaces; + face_t *f; + int index; - brushes = [map_i objectAtIndex:0]; - max = [brushes count]; - for (i = 0;i < max; i++) - { + // Turn 'em off + if ([sender intValue]) { + max =[textureList_i count]; + for (i = 0; i < max; i++) + [self setDisplayFlag: i to:0]; + + brushes =[map_i objectAtIndex:0]; + max =[brushes count]; + for (i = 0; i < max; i++) { b = (SetBrush *)[brushes objectAtIndex:i]; - numfaces = [b getNumBrushFaces]; - for (j = 0; j < numfaces; j++) - { - f = [b getBrushFace:j]; - index = [self searchForTextureInPalette:f->texture.texture]; + numfaces =[b getNumBrushFaces]; + for (j = 0; j < numfaces; j++) { + f =[b getBrushFace:j]; + index =[self searchForTextureInPalette:f->texture. + texture]; if (index >= 0) - [self setDisplayFlag:index to:1]; + [self setDisplayFlag: index to:1]; } } } // Turn 'em on - else - { - max = [textureList_i count]; - for (i = 0;i < max; i++) - [self setDisplayFlag:i to:1]; + else { + max =[textureList_i count]; + for (i = 0; i < max; i++) + [self setDisplayFlag: i to:1]; } - + [textureView_i display]; - + return self; } -- setDisplayFlag:(int)index to:(int)value +-setDisplayFlag:(int) +index to:(int) value { - texpal_t *tp; - - tp = [textureList_i elementAt:index]; + texpal_t *tp; + + tp =[textureList_i elementAt:index]; tp->display = value; return self; }; diff --git a/tools/Forge/Bundles/MapEdit/TextureView.m b/tools/Forge/Bundles/MapEdit/TextureView.m index f982bf12b..4b5c0c285 100644 --- a/tools/Forge/Bundles/MapEdit/TextureView.m +++ b/tools/Forge/Bundles/MapEdit/TextureView.m @@ -13,143 +13,136 @@ NOTE: I am specifically not using cached image reps, because the data is also ne @implementation TextureView -- init +-init { deselectIndex = -1; return self; } -- setParent:(id)from +-setParent:(id) from { parent_i = from; return self; } -- (BOOL)acceptsFirstMouse +-(BOOL) acceptsFirstMouse { return YES; } -- drawSelf:(const NSRect *)rects :(int)rectCount +-drawSelf: (const NSRect *) rects:(int) rectCount { - int i; - int max; - id list_i; - texpal_t *t; - int x; - int y; - NSPoint p; - NSRect r; - int selected; - - selected = [parent_i getSelectedTexture]; - list_i = [parent_i getList]; - GSSetFont (DEFCTXT, [NSFont fontWithName:@"Helvetica-Medium" size:FONTSIZE]); - PSrotate(0); - - PSsetgray(NSLightGray); - PSrectfill(rects->origin.x, rects->origin.y, - rects->size.width, rects->size.height); + int i; + int max; + id list_i; + texpal_t *t; + int x; + int y; + NSPoint p; + NSRect r; + int selected; - if (!list_i) // WADfile didn't init + selected =[parent_i getSelectedTexture]; + list_i =[parent_i getList]; + GSSetFont (DEFCTXT,[NSFont fontWithName: @"Helvetica-Medium" size:FONTSIZE]); + PSrotate (0); + + PSsetgray (NSLightGray); + PSrectfill (rects->origin.x, rects->origin.y, + rects->size.width, rects->size.height); + + if (!list_i) // WADfile didn't init return self; - if (deselectIndex != -1) - { - t = [list_i elementAt:deselectIndex]; + if (deselectIndex != -1) { + t =[list_i elementAt:deselectIndex]; r = t->r; r.origin.x -= TEX_INDENT; r.origin.y -= TEX_INDENT; - r.size.width += TEX_INDENT*2; - r.size.height += TEX_INDENT*2; - - //XXX PSsetgray(NSGrayComponent(NS_COLORLTGRAY)); - PSrectfill(r.origin.x, r.origin.y, - r.size.width, r.size.height); + r.size.width += TEX_INDENT * 2; + r.size.height += TEX_INDENT * 2; + + // XXX PSsetgray(NSGrayComponent(NS_COLORLTGRAY)); + PSrectfill (r.origin.x, r.origin.y, r.size.width, r.size.height); p = t->r.origin; p.y += TEX_SPACING; - [t->image drawAtPoint:p fromRect:r operation:NSCompositeCopy fraction:1.0]; - PSsetgray(0); + [t->image drawAtPoint: p fromRect: r operation: NSCompositeCopy fraction:1.0]; + PSsetgray (0); x = t->r.origin.x; y = t->r.origin.y + 7; - PSmoveto(x,y); - PSshow(t->name); - PSstroke(); + PSmoveto (x, y); + PSshow (t->name); + PSstroke (); deselectIndex = -1; } - max = [list_i count]; - PSsetgray(0); + max =[list_i count]; + PSsetgray (0); - for (i = 0;i < max; i++) - { - t = [list_i elementAt:i]; + for (i = 0; i < max; i++) { + t =[list_i elementAt:i]; r = t->r; - r.origin.x -= TEX_INDENT/2; + r.origin.x -= TEX_INDENT / 2; r.size.width += TEX_INDENT; r.origin.y += 4; - if (NSIntersectsRect(rects[0],r) == YES && - t->display) - { - if (selected == i) - { - PSsetgray(1); - PSrectfill(r.origin.x,r.origin.y, - r.size.width,r.size.height); - PSsetrgbcolor(1,0,0); - PSrectstroke(r.origin.x, r.origin.y, - r.size.width, r.size.height); - PSsetgray(0); + if (NSIntersectsRect (rects[0], r) == YES && t->display) { + if (selected == i) { + PSsetgray (1); + PSrectfill (r.origin.x, r.origin.y, + r.size.width, r.size.height); + PSsetrgbcolor (1, 0, 0); + PSrectstroke (r.origin.x, r.origin.y, + r.size.width, r.size.height); + PSsetgray (0); } - + p = t->r.origin; p.y += TEX_SPACING; - [t->image drawAtPoint:p fromRect:r operation:NSCompositeCopy fraction:1.0]; + [t->image drawAtPoint: p fromRect: r operation: NSCompositeCopy fraction:1.0]; x = t->r.origin.x; y = t->r.origin.y + 7; - PSmoveto(x,y); - PSshow(t->name); + PSmoveto (x, y); + PSshow (t->name); } } - PSstroke(); + PSstroke (); return self; } -- deselect +-deselect { - deselectIndex = [parent_i getSelectedTexture]; + deselectIndex =[parent_i getSelectedTexture]; return self; } -- mouseDown:(NSEvent *)theEvent +-mouseDown:(NSEvent *) theEvent { - NSPoint loc; - int i; - int max; - //int oldwindowmask; - texpal_t *t; - id list; - NSRect r; + NSPoint loc; + int i; + int max; - //oldwindowmask = [window addToEventMask:NSLeftMouseDraggedMask]; - loc = [theEvent locationInWindow]; - [self convertPoint:loc fromView:NULL]; - - list = [parent_i getList]; - max = [list count]; - for (i = 0;i < max; i++) - { - t = [list elementAt:i]; + // int oldwindowmask; + texpal_t *t; + id list; + NSRect r; + + // oldwindowmask = [window addToEventMask:NSLeftMouseDraggedMask]; + loc =[theEvent locationInWindow]; + [self convertPoint: loc fromView:NULL]; + + list =[parent_i getList]; + max =[list count]; + for (i = 0; i < max; i++) { + t =[list elementAt:i]; r = t->r; - if (NSPointInRect(loc,r) == YES) - { - [self deselect]; - [parent_i setSelectedTexture:i]; + if (NSPointInRect (loc, r) == YES) { + [self deselect]; + [parent_i setSelectedTexture:i]; break; } } - - //[window setEventMask:oldwindowmask]; + + // [window setEventMask:oldwindowmask]; return self; } diff --git a/tools/Forge/Bundles/MapEdit/Things.m b/tools/Forge/Bundles/MapEdit/Things.m index efb9e8dd0..85703160f 100644 --- a/tools/Forge/Bundles/MapEdit/Things.m +++ b/tools/Forge/Bundles/MapEdit/Things.m @@ -6,222 +6,219 @@ #include "KeypairView.h" #include "Project.h" -id things_i; +id things_i; @implementation Things -- init +-init { [super init]; things_i = self; lastSelected = 0; - + return self; } // -// Load the TEXT object with the entity comment +// Load the TEXT object with the entity comment // -- loadEntityComment:(id)obj +-loadEntityComment:(id) obj { [entity_comment_i selectAll:self]; - [entity_comment_i replaceCharactersInRange:[entity_comment_i selectedRange] withString:[NSString stringWithCString:[obj comments]]]; + [entity_comment_i replaceCharactersInRange: [entity_comment_i selectedRange] withString: [NSString stringWithCString:[obj + comments]]]; return self; } -- initEntities -{ - char *path; +-initEntities +{ + char *path; - path = [project_i getProgDirectory]; + path =[project_i getProgDirectory]; [prog_path_i setStringValue: [NSString stringWithCString:path]]; - - [[EntityClassList alloc] initForSourceDirectory: path]; - [self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]]; + [[EntityClassList alloc] initForSourceDirectory:path]; + + [self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]]; [entity_browser_i loadColumnZero]; - [[entity_browser_i matrixInColumn:0] selectCellAtRow:lastSelected column:0]; + [[entity_browser_i matrixInColumn: 0] selectCellAtRow: lastSelected column:0]; + + [entity_browser_i setDoubleAction: @selector (doubleClickEntity:)]; - [entity_browser_i setDoubleAction: @selector(doubleClickEntity:)]; - return self; } -- selectEntity: sender +-selectEntity:sender { - id matr; - - matr = [sender matrixInColumn: 0]; - lastSelected = [matr selectedRow]; - [self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]]; - [quakeed_i makeFirstResponder: quakeed_i]; - + id matr; + + matr =[sender matrixInColumn:0]; + lastSelected =[matr selectedRow]; + [self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]]; + [quakeed_i makeFirstResponder:quakeed_i]; + return self; } -- doubleClickEntity: sender +-doubleClickEntity:sender { - [map_i makeEntity: sender]; - [quakeed_i makeFirstResponder: quakeed_i]; + [map_i makeEntity:sender]; + [quakeed_i makeFirstResponder:quakeed_i]; return self; } -- (char *)spawnName +-(char *) spawnName { - return [[entity_classes_i objectAtIndex:lastSelected] classname]; + return[[entity_classes_i objectAtIndex:lastSelected] classname]; } // -// Flush entity classes & reload them! +// Flush entity classes & reload them! // -- reloadEntityClasses: sender +-reloadEntityClasses:sender { EntityClass *ent; - char *path; - + char *path; + path = (char *)[prog_path_i stringValue]; - if (!path || !path[0]) - { - path = [project_i getProgDirectory]; + if (!path || !path[0]) { + path =[project_i getProgDirectory]; [prog_path_i setStringValue: [NSString stringWithCString:path]]; } - - // Free all entity info in memory... + // Free all entity info in memory... [entity_classes_i removeAllObjects]; [entity_classes_i release]; - - // Now, RELOAD! - [[EntityClassList alloc] initForSourceDirectory: path]; + + // Now, RELOAD! + [[EntityClassList alloc] initForSourceDirectory:path]; lastSelected = 0; - ent = [entity_classes_i objectAtIndex:lastSelected]; - [self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]]; + ent =[entity_classes_i objectAtIndex:lastSelected]; + [self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]]; [entity_browser_i loadColumnZero]; - [[entity_browser_i matrixInColumn:0] selectCellAtRow:lastSelected column:0]; + [[entity_browser_i matrixInColumn: 0] selectCellAtRow: lastSelected column:0]; + + [self newCurrentEntity]; // in case flags changed - [self newCurrentEntity]; // in case flags changed - return self; } -- selectClass: (char *)class +-selectClass:(char *) class { - id classent; - - classent = [entity_classes_i classForName:class]; + id classent; + + classent =[entity_classes_i classForName:class]; if (!classent) return self; - lastSelected = [entity_classes_i indexOfObject: classent]; - + lastSelected =[entity_classes_i indexOfObject:classent]; + if (lastSelected < 0) lastSelected = 0; - + [self loadEntityComment:classent]; - [[entity_browser_i matrixInColumn:0] selectCellAtRow:lastSelected column:0]; - [[entity_browser_i matrixInColumn:0] scrollCellToVisibleAtRow:lastSelected column:0]; + [[entity_browser_i matrixInColumn: 0] selectCellAtRow: lastSelected column:0]; + [[entity_browser_i matrixInColumn: 0] scrollCellToVisibleAtRow: lastSelected column:0]; return self; } -- newCurrentEntity +-newCurrentEntity { - id ent, classent, cell; - char *classname; - int r, c; - char *flagname; - int flags; - - ent = [map_i currentEntity]; - classname = [ent valueForQKey: "classname"]; - if (ent != [map_i objectAtIndex: 0]) - [self selectClass: classname]; // don't reset for world - classent = [entity_classes_i classForName:classname]; - flagname = [ent valueForQKey: "spawnflags"]; + id ent, classent, cell; + char *classname; + int r, c; + char *flagname; + int flags; + + ent =[map_i currentEntity]; + classname =[ent valueForQKey:"classname"]; + if (ent !=[map_i objectAtIndex:0]) + [self selectClass:classname]; // don't reset for world + classent =[entity_classes_i classForName:classname]; + flagname =[ent valueForQKey:"spawnflags"]; if (!flagname) flags = 0; else - flags = atoi(flagname); - - [flags_i setAutodisplay: NO]; - for (r=0 ; r<4 ; r++) - for (c=0 ; c<3 ; c++) - { - cell = [flags_i cellAtRow: r column: c]; - if (c < 2) - { - flagname = [classent flagName: c*4 + r]; + flags = atoi (flagname); + + [flags_i setAutodisplay:NO]; + for (r = 0; r < 4; r++) + for (c = 0; c < 3; c++) { + cell =[flags_i cellAtRow: r column:c]; + if (c < 2) { + flagname =[classent flagName:c * 4 + r]; [cell setTitle: [NSString stringWithCString:flagname]]; } - [cell setIntValue: (flags & (1<< ((c*4)+r)) ) > 0]; + [cell setIntValue:(flags & (1 << ((c * 4) + r))) > 0]; } - [flags_i setAutodisplay: YES]; + [flags_i setAutodisplay:YES]; [flags_i display]; - -// [keyInput_i setStringValue: ""]; -// [valueInput_i setStringValue: ""]; + +// [keyInput_i setStringValue: ""]; +// [valueInput_i setStringValue: ""]; [keypairview_i calcViewSize]; [keypairview_i display]; - - [quakeed_i makeFirstResponder: quakeed_i]; + + [quakeed_i makeFirstResponder:quakeed_i]; return self; } // -// Clicked in the Keypair view - set as selected +// Clicked in the Keypair view - set as selected // -- setSelectedKey:(epair_t *)ep; +-setSelectedKey:(epair_t *) ep; { - [keyInput_i setStringValue:[NSString stringWithCString:ep->key]]; - [valueInput_i setStringValue:[NSString stringWithCString:ep->value]]; - [valueInput_i selectText:self]; + [keyInput_i setStringValue: [NSString stringWithCString:ep->key]]; + [valueInput_i setStringValue: [NSString stringWithCString:ep->value]]; + [valueInput_i selectText:self]; return self; } -- clearInputs +-clearInputs { -// [keyInput_i setStringValue: ""]; -// [valueInput_i setStringValue: ""]; - - [quakeed_i makeFirstResponder: quakeed_i]; +// [keyInput_i setStringValue: ""]; +// [valueInput_i setStringValue: ""]; + + [quakeed_i makeFirstResponder:quakeed_i]; return self; } // -// Action methods +// Action methods // -addPair:sender { - char *key, *value; - + char *key, *value; + key = (char *)[keyInput_i stringValue]; value = (char *)[valueInput_i stringValue]; - - [ [map_i currentEntity] setKey: key toValue: value ]; + + [[map_i currentEntity] setKey: key toValue:value]; [keypairview_i calcViewSize]; [keypairview_i display]; [self clearInputs]; [quakeed_i updateXY]; - + return self; } -delPair:sender { - [quakeed_i makeFirstResponder: quakeed_i]; + [quakeed_i makeFirstResponder:quakeed_i]; - [ [map_i currentEntity] removeKeyPair: (char *)[keyInput_i stringValue] ]; + [[map_i currentEntity] removeKeyPair:(char *)[keyInput_i stringValue]]; [keypairview_i calcViewSize]; [keypairview_i display]; @@ -235,58 +232,56 @@ id things_i; // -// Set the key/value fields to "angle