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.
This commit is contained in:
Bill Currie 2010-09-11 19:03:41 +09:00
parent d3a12ee727
commit d23300d58b
25 changed files with 5481 additions and 5886 deletions

View file

@ -12,7 +12,6 @@ extern NSBezierPath *path;
BOOL timedrawing = 0; BOOL timedrawing = 0;
@implementation CameraView @implementation CameraView
/* /*
================== ==================
initWithFrame: initWithFrame:
@ -37,26 +36,26 @@ initWithFrame:
move = 16; move = 16;
size = _bounds.size.width * _bounds.size.height; size = _bounds.size.width * _bounds.size.height;
zbuffer = malloc (size*4); zbuffer = malloc (size * 4);
imagebuffer = malloc (size*4); imagebuffer = malloc (size * 4);
return self; return self;
} }
- setXYOrigin: (NSPoint *)pt -setXYOrigin:(NSPoint *)pt
{ {
origin[0] = pt->x; origin[0] = pt->x;
origin[1] = pt->y; origin[1] = pt->y;
return self; return self;
} }
- setZOrigin: (float)pt -setZOrigin:(float)pt
{ {
origin[2] = pt; origin[2] = pt;
return self; return self;
} }
- setOrigin: (vec3_t)org angle: (float)angle -setOrigin:(vec3_t)org angle:(float)angle
{ {
VectorCopy (org, origin); VectorCopy (org, origin);
ya = angle; ya = angle;
@ -64,24 +63,23 @@ initWithFrame:
return self; return self;
} }
- getOrigin: (vec3_t)org -getOrigin:(vec3_t)org
{ {
VectorCopy (origin, org); VectorCopy (origin, org);
return self; return self;
} }
- (float)yawAngle -(float)yawAngle
{ {
return ya; return ya;
} }
- upFloor:sender -upFloor:sender
{ {
sb_floor_dir = 1; sb_floor_dir = 1;
sb_floor_dist = 99999; sb_floor_dist = 99999;
[map_i makeAllPerform: @selector(feetToFloor)]; [map_i makeAllPerform: @selector (feetToFloor)];
if (sb_floor_dist == 99999) if (sb_floor_dist == 99999) {
{
Sys_Printf ("already on top floor"); Sys_Printf ("already on top floor");
return self; return self;
} }
@ -91,13 +89,12 @@ initWithFrame:
return self; return self;
} }
- downFloor: sender -downFloor:sender
{ {
sb_floor_dir = -1; sb_floor_dir = -1;
sb_floor_dist = -99999; sb_floor_dist = -99999;
[map_i makeAllPerform: @selector(feetToFloor)]; [map_i makeAllPerform: @selector (feetToFloor)];
if (sb_floor_dist == -99999) if (sb_floor_dist == -99999) {
{
Sys_Printf ("already on bottom floor"); Sys_Printf ("already on bottom floor");
return self; return self;
} }
@ -120,7 +117,7 @@ UI TARGETS
homeView homeView
============ ============
*/ */
- homeView: sender -homeView:sender
{ {
xa = za = 0; xa = za = 0;
@ -133,17 +130,17 @@ homeView
return self; return self;
} }
- drawMode: sender -drawMode:sender
{ {
drawmode = [sender selectedColumn]; drawmode =[sender selectedColumn];
[quakeed_i updateCamera]; [quakeed_i updateCamera];
return self; return self;
} }
- setDrawMode: (drawmode_t)mode -setDrawMode:(drawmode_t)mode
{ {
drawmode = mode; drawmode = mode;
//XXX[mode_radio_i selectCellAt:0: mode]; [mode_radio_i selectCellAtRow: 0 column: mode];
[quakeed_i updateCamera]; [quakeed_i updateCamera];
return self; return self;
} }
@ -156,22 +153,22 @@ TRANSFORMATION METHODS
=============================================================================== ===============================================================================
*/ */
- matrixFromAngles -matrixFromAngles
{ {
if (xa > M_PI*0.4) if (xa > M_PI * 0.4)
xa = M_PI*0.4; xa = M_PI * 0.4;
if (xa < -M_PI*0.4) if (xa < -M_PI * 0.4)
xa = -M_PI*0.4; xa = -M_PI * 0.4;
// vpn // vpn
matrix[2][0] = cos(xa)*cos(ya); matrix[2][0] = cos (xa) * cos (ya);
matrix[2][1] = cos(xa)*sin(ya); matrix[2][1] = cos (xa) * sin (ya);
matrix[2][2] = sin(xa); matrix[2][2] = sin (xa);
// vup // vup
matrix[1][0] = cos(xa+M_PI/2)*cos(ya); matrix[1][0] = cos (xa + M_PI / 2) * cos (ya);
matrix[1][1] = cos(xa+M_PI/2)*sin(ya); matrix[1][1] = cos (xa + M_PI / 2) * sin (ya);
matrix[1][2] = sin(xa+M_PI/2); matrix[1][2] = sin (xa + M_PI / 2);
// vright // vright
CrossProduct (matrix[2], matrix[1], matrix[0]); 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 inverse[3];
vec3_t temp; vec3_t temp;
int i,j; int i, j;
for (i=0 ; i<3 ; i++) for (i = 0; i < 3; i++)
for (j=0 ; j<3 ; j++) for (j = 0; j < 3; j++)
inverse[i][j] = matrix[j][i]; inverse[i][j] = matrix[j][i];
temp[0] = DotProduct(invec, inverse[0]); temp[0] = DotProduct (invec, inverse[0]);
temp[1] = DotProduct(invec, inverse[1]); temp[1] = DotProduct (invec, inverse[1]);
temp[2] = DotProduct(invec, inverse[2]); temp[2] = DotProduct (invec, inverse[2]);
VectorAdd (temp, origin, outvec); VectorAdd (temp, origin, outvec);
@ -209,12 +206,12 @@ TRANSFORMATION METHODS
=============================================================================== ===============================================================================
*/ */
typedef struct typedef struct {
{
vec3_t trans; vec3_t trans;
int clipflags; int clipflags;
vec3_t screen; // valid only if clipflags == 0 vec3_t screen; // valid only if clipflags == 0
} campt_t; } campt_t;
#define CLIP_RIGHT 1 #define CLIP_RIGHT 1
#define CLIP_LEFT 2 #define CLIP_LEFT 2
#define CLIP_TOP 4 #define CLIP_TOP 4
@ -227,12 +224,13 @@ campt_t campts[2];
vec3_t r_matrix[3]; vec3_t r_matrix[3];
vec3_t r_origin; vec3_t r_origin;
float mid_x, mid_y; float mid_x, mid_y;
float topscale = (240.0/3)/160; float topscale = (240.0 / 3) / 160;
float bottomscale = (240.0*2/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; vec3_t temp;
float scale; float scale;
@ -240,9 +238,9 @@ void MakeCampt (vec3_t in, campt_t *pt)
// transform the points // transform the points
VectorSubtract (in, r_origin, temp); VectorSubtract (in, r_origin, temp);
pt->trans[0] = DotProduct(temp, r_matrix[0]); pt->trans[0] = DotProduct (temp, r_matrix[0]);
pt->trans[1] = DotProduct(temp, r_matrix[1]); pt->trans[1] = DotProduct (temp, r_matrix[1]);
pt->trans[2] = DotProduct(temp, r_matrix[2]); pt->trans[2] = DotProduct (temp, r_matrix[2]);
// check clip flags // check clip flags
if (pt->trans[2] < 1) if (pt->trans[2] < 1)
@ -255,22 +253,23 @@ void MakeCampt (vec3_t in, campt_t *pt)
else if (-pt->trans[0] > pt->trans[2]) else if (-pt->trans[0] > pt->trans[2])
pt->clipflags |= CLIP_LEFT; pt->clipflags |= CLIP_LEFT;
if (pt->trans[1] > pt->trans[2]*topscale ) if (pt->trans[1] > pt->trans[2] * topscale)
pt->clipflags |= CLIP_TOP; 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; pt->clipflags |= CLIP_BOTTOM;
if (pt->clipflags) if (pt->clipflags)
return; return;
// project // project
scale = mid_x/pt->trans[2]; scale = mid_x / pt->trans[2];
pt->screen[0] = mid_x + pt->trans[0]*scale; pt->screen[0] = mid_x + pt->trans[0] * scale;
pt->screen[1] = mid_y + pt->trans[1]*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;
@ -279,15 +278,16 @@ void CameraMoveto(vec3_t p)
pt = &campts[cam_cur]; pt = &campts[cam_cur];
cam_cur ^= 1; cam_cur ^= 1;
MakeCampt (p,pt); MakeCampt (p, pt);
if (!pt->clipflags) { if (!pt->clipflags) {
// onscreen, so move there immediately // onscreen, so move there immediately
NSPoint point = {pt->screen[0], pt->screen[1]}; NSPoint point = { pt->screen[0], pt->screen[1] };
[path moveToPoint: point]; [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; float d, d2, frac;
vec3_t new; vec3_t new;
@ -297,14 +297,14 @@ void ClipLine (vec3_t p1, vec3_t p2, int planenum)
if (planenum == 5) { if (planenum == 5) {
// draw it! // draw it!
scale = mid_x/p1[2]; scale = mid_x / p1[2];
point.x = mid_x + p1[0]*scale; point.x = mid_x + p1[0] * scale;
point.y = mid_y + p1[1]*scale; point.y = mid_y + p1[1] * scale;
[path moveToPoint: point]; [path moveToPoint: point];
scale = mid_x/p2[2]; scale = mid_x / p2[2];
point.x = mid_x + p2[0]*scale; point.x = mid_x + p2[0] * scale;
point.y = mid_y + p2[1]*scale; point.y = mid_y + p2[1] * scale;
[path lineToPoint: point]; [path lineToPoint: point];
return; return;
} }
@ -313,31 +313,30 @@ void ClipLine (vec3_t p1, vec3_t p2, int planenum)
d = DotProduct (p1, pl->normal) - pl->dist; d = DotProduct (p1, pl->normal) - pl->dist;
d2 = DotProduct (p2, pl->normal) - pl->dist; d2 = DotProduct (p2, pl->normal) - pl->dist;
if (d <= ON_EPSILON && d2 <= ON_EPSILON) if (d <= ON_EPSILON && d2 <= ON_EPSILON) { // off screen
{ // off screen
return; return;
} }
if (d >= 0 && d2 >= 0) if (d >= 0 && d2 >= 0) { // on front
{ // on front ClipLine (p1, p2, planenum + 1);
ClipLine (p1, p2, planenum+1);
return; return;
} }
frac = d/(d-d2); frac = d / (d - d2);
new[0] = p1[0] + frac*(p2[0]-p1[0]); new[0] = p1[0] + frac * (p2[0] - p1[0]);
new[1] = p1[1] + frac*(p2[1]-p1[1]); new[1] = p1[1] + frac * (p2[1] - p1[1]);
new[2] = p1[2] + frac*(p2[2]-p1[2]); new[2] = p1[2] + frac * (p2[2] - p1[2]);
if (d > 0) if (d > 0)
ClipLine (p1, new, planenum+1); ClipLine (p1, new, planenum + 1);
else 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; campt_t *p1, *p2;
int bits; int bits;
@ -347,24 +346,21 @@ void CameraLineto(vec3_t p)
p1 = &campts[cam_cur]; p1 = &campts[cam_cur];
MakeCampt (p, p2); MakeCampt (p, p2);
if (p1->clipflags & p2->clipflags) if (p1->clipflags & p2->clipflags) {
{
c_off++; c_off++;
return; // entirely off screen return; // entirely off screen
} }
bits = p1->clipflags | p2->clipflags; bits = p1->clipflags | p2->clipflags;
if (! bits ) if (!bits) {
{ NSPoint point1 = { p1->screen[0], p1->screen[1] };
NSPoint point1 = {p1->screen[0], p1->screen[1]}; NSPoint point2 = { p2->screen[0], p2->screen[1] };
NSPoint point2 = {p2->screen[0], p2->screen[1]};
c_on++; c_on++;
[path moveToPoint: point1]; [path moveToPoint: point1];
[path lineToPoint: point2]; [path lineToPoint: point2];
return; // entirely on screen return; // entirely on screen
} }
// needs to be clipped // needs to be clipped
c_clip++; c_clip++;
@ -377,7 +373,7 @@ void CameraLineto(vec3_t p)
drawSolid drawSolid
============= =============
*/ */
- drawSolid -drawSolid
{ {
unsigned char *planes[5]; unsigned char *planes[5];
@ -402,30 +398,23 @@ drawSolid
// //
// render the setbrushes // render the setbrushes
// //
[map_i makeAllPerform: @selector(CameraRenderSelf)]; [map_i makeAllPerform: @selector (CameraRenderSelf)];
// //
// display the output // display the output
// //
[[self window] setBackingType:NSBackingStoreRetained]; [[self window] setBackingType: NSBackingStoreRetained];
planes[0] = (unsigned char *)imagebuffer; planes[0] = (unsigned char *) imagebuffer;
NSDrawBitmap( NSDrawBitmap (_bounds, r_width, r_height, 8, 3, 32, r_width * 4, NO, NO, @"RGB", // FIXME
_bounds, // what
r_width, // should
r_height, // this
8, // be?
3, (const unsigned char **const) planes);
32,
r_width*4,
NO,
NO,
@"RGB", //FIXME what should this be?
(const unsigned char **const)planes
);
//XXX NSPing (); // XXX NSPing ();
[[self window] setBackingType:NSBackingStoreBuffered]; [[self window] setBackingType: NSBackingStoreBuffered];
@ -438,7 +427,7 @@ drawSolid
drawWire 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_x = _bounds.size.width / 2;
@ -460,8 +449,8 @@ drawWire
NSEraseRect (rect); NSEraseRect (rect);
// draw all entities // draw all entities
linestart (0,0,0); linestart (0, 0, 0);
[map_i makeUnselectedPerform: @selector(CameraDrawSelf)]; [map_i makeUnselectedPerform: @selector (CameraDrawSelf)];
lineflush (); lineflush ();
return self; return self;
@ -472,7 +461,7 @@ drawWire
drawSelf drawSelf
=================== ===================
*/ */
- drawSelf:(NSRect)rects :(int)rectCount -drawSelf:(NSRect)rects :(int)rectCount
{ {
float drawtime = 0; float drawtime = 0;
@ -484,9 +473,8 @@ drawSelf
else else
[self drawWire: rects]; [self drawWire: rects];
if (timedrawing) if (timedrawing) {
{ // XXX NSPing ();
//XXX NSPing ();
drawtime = Sys_DoubleTime () - drawtime; drawtime = Sys_DoubleTime () - drawtime;
printf ("CameraView drawtime: %5.3f\n", drawtime); printf ("CameraView drawtime: %5.3f\n", drawtime);
} }
@ -500,22 +488,22 @@ drawSelf
XYDrawSelf XYDrawSelf
============= =============
*/ */
- XYDrawSelf -XYDrawSelf
{ {
PSsetrgbcolor (0,0,1.0); PSsetrgbcolor (0, 0, 1.0);
PSsetlinewidth (0.15); PSsetlinewidth (0.15);
PSmoveto (origin[0]-16,origin[1]); PSmoveto (origin[0] - 16, origin[1]);
PSrlineto (16,8); PSrlineto (16, 8);
PSrlineto (16,-8); PSrlineto (16, -8);
PSrlineto (-16,-8); PSrlineto (-16, -8);
PSrlineto (-16,8); PSrlineto (-16, 8);
PSrlineto (32,0); PSrlineto (32, 0);
PSmoveto (origin[0],origin[1]); PSmoveto (origin[0], origin[1]);
PSrlineto (64*cos(ya+M_PI/4), 64*sin(ya+M_PI/4)); PSrlineto (64 * cos (ya + M_PI / 4), 64 * sin (ya + M_PI / 4));
PSmoveto (origin[0],origin[1]); PSmoveto (origin[0], origin[1]);
PSrlineto (64*cos(ya-M_PI/4), 64*sin(ya-M_PI/4)); PSrlineto (64 * cos (ya - M_PI / 4), 64 * sin (ya - M_PI / 4));
PSstroke (); PSstroke ();
@ -527,23 +515,23 @@ XYDrawSelf
ZDrawSelf ZDrawSelf
============= =============
*/ */
- ZDrawSelf -ZDrawSelf
{ {
PSsetrgbcolor (0,0,1.0); PSsetrgbcolor (0, 0, 1.0);
PSsetlinewidth (0.15); PSsetlinewidth (0.15);
PSmoveto (-16,origin[2]); PSmoveto (-16, origin[2]);
PSrlineto (16,8); PSrlineto (16, 8);
PSrlineto (16,-8); PSrlineto (16, -8);
PSrlineto (-16,-8); PSrlineto (-16, -8);
PSrlineto (-16,8); PSrlineto (-16, 8);
PSrlineto (32,0); PSrlineto (32, 0);
PSmoveto (-15,origin[2]-47); PSmoveto (-15, origin[2] - 47);
PSrlineto (29,0); PSrlineto (29, 0);
PSrlineto (0,54); PSrlineto (0, 54);
PSrlineto (-29,0); PSrlineto (-29, 0);
PSrlineto (0,-54); PSrlineto (0, -54);
PSstroke (); PSstroke ();
@ -564,15 +552,18 @@ ZDrawSelf
modalMoveLoop modalMoveLoop
================ ================
*/ */
- modalMoveLoop: (NSPoint *)basept :(vec3_t)movemod : converter -modalMoveLoop:(NSPoint *)basept :(vec3_t)movemod :converter
{ {
vec3_t originbase; vec3_t originbase;
NSEvent *event = 0; //XXX NSEvent *event = 0; // XXX
NSPoint newpt; NSPoint newpt;
// NSPoint brushpt; // NSPoint brushpt;
vec3_t delta; vec3_t delta;
// id ent; // id ent;
int i; int i;
// vec3_t temp; // vec3_t temp;
Sys_Printf ("moving camera position"); Sys_Printf ("moving camera position");
@ -584,54 +575,49 @@ modalMoveLoop
// //
goto drawentry; goto drawentry;
while ([event type] != NSLeftMouseUp && [event type] != NSRightMouseUp) while ([event type] != NSLeftMouseUp &&[event type] != NSRightMouseUp) {
{
// //
// calculate new point // calculate new point
// //
newpt = [event locationInWindow]; newpt =[event locationInWindow];
newpt = [converter convertPoint:newpt fromView:NULL]; newpt =[converter convertPoint: newpt fromView: NULL];
delta[0] = newpt.x-basept->x; delta[0] = newpt.x - basept->x;
delta[1] = newpt.y-basept->y; delta[1] = newpt.y - basept->y;
delta[2] = delta[1]; // height change delta[2] = delta[1]; // height change
for (i=0 ; i<3 ; i++) for (i = 0; i < 3; i++)
origin[i] = originbase[i]+movemod[i]*delta[i]; origin[i] = originbase[i] + movemod[i] * delta[i];
#if 0 // FIXME #if 0 // FIXME
// //
// if command is down, look towards brush or entity // if command is down, look towards brush or entity
// //
if (event->flags & NS_SHIFTMASK) if (event->flags & NS_SHIFTMASK) {
{ ent =[quakemap_i selectedEntity];
ent = [quakemap_i selectedEntity]; if (ent) {
if (ent)
{
[ent origin: temp]; [ent origin: temp];
brushpt.x = temp[0]; brushpt.x = temp[0];
brushpt.y = temp[1]; brushpt.y = temp[1];
} } else
else brushpt =[brush_i centerPoint];
brushpt = [brush_i centerPoint];
ya = atan2 (brushpt.y - newpt.y, brushpt.x - newpt.x); ya = atan2 (brushpt.y - newpt.y, brushpt.x - newpt.x);
[self matrixFromAngles]; [self matrixFromAngles];
} }
#endif #endif
drawentry: drawentry:
// //
// instance draw new frame // instance draw new frame
// //
[quakeed_i newinstance]; [quakeed_i newinstance];
[self display]; [self display];
/*XXX
event = [NSApp nextEventMatchingMask: NSLeftMouseUpMask event = [NSApp nextEventMatchingMask: NSLeftMouseUpMask
| NSLeftMouseDraggedMask | NSRightMouseUpMask | NSLeftMouseDraggedMask | NSRightMouseUpMask
| NSRightMouseDraggedMask | NSApplicationDefinedMask]; | NSRightMouseDraggedMask | NSApplicationDefinedMask
*/ untilDate: [NSDate distantFuture]
if ([event type] == NSKeyDown) inMode: NSEventTrackingRunLoopMode dequeue: YES];
{ if ([event type] == NSKeyDown) {
[self _keyDown: event]; [self _keyDown: event];
[self display]; [self display];
goto drawentry; goto drawentry;
@ -649,22 +635,20 @@ drawentry:
XYmouseDown XYmouseDown
=============== ===============
*/ */
- (BOOL)XYmouseDown: (NSPoint *)pt flags:(int)flags // return YES if brush handled -(BOOL) XYmouseDown:(NSPoint *)pt flags:(int)flags
// return YES if brush handled
{ {
vec3_t movemod; vec3_t movemod;
if (fabs(pt->x - origin[0]) > 16 if (fabs (pt->x - origin[0]) > 16 || fabs (pt->y - origin[1]) > 16)
|| fabs(pt->y - origin[1]) > 16 )
return NO; return NO;
#if 0 #if 0
if (flags & NSAlternateKeyMask) if (flags & NSAlternateKeyMask) { // up / down drag
{ // up / down drag
movemod[0] = 0; movemod[0] = 0;
movemod[1] = 0; movemod[1] = 0;
movemod[2] = 1; movemod[2] = 1;
} } else
else
#endif #endif
{ {
movemod[0] = 1; movemod[0] = 1;
@ -683,12 +667,12 @@ XYmouseDown
ZmouseDown ZmouseDown
=============== ===============
*/ */
- (BOOL)ZmouseDown: (NSPoint *)pt flags:(int)flags // return YES if brush handled -(BOOL) ZmouseDown:(NSPoint *)pt flags:(int)flags
// return YES if brush handled
{ {
vec3_t movemod; vec3_t movemod;
if (fabs(pt->y - origin[2]) > 16 if (fabs (pt->y - origin[2]) > 16 || pt->x < -8 || pt->x > 8)
|| pt->x < -8 || pt->x > 8 )
return NO; return NO;
movemod[0] = 0; movemod[0] = 0;
@ -708,10 +692,10 @@ ZmouseDown
viewDrag: viewDrag:
=================== ===================
*/ */
- viewDrag:(NSPoint *)pt -viewDrag:(NSPoint *)pt
{ {
float dx,dy; float dx, dy;
NSEvent *event = 0; //XXX NSEvent *event = 0; // XXX
NSPoint newpt; NSPoint newpt;
// //
@ -719,33 +703,31 @@ viewDrag:
// //
goto drawentry; goto drawentry;
while ([event type] != NSRightMouseUp) while ([event type] != NSRightMouseUp) {
{
// //
// calculate new point // calculate new point
// //
newpt = [event locationInWindow]; newpt =[event locationInWindow];
newpt = [self convertPoint:newpt fromView:NULL]; newpt =[self convertPoint: newpt fromView: NULL];
dx = newpt.x - pt->x; dx = newpt.x - pt->x;
dy = newpt.y - pt->y; dy = newpt.y - pt->y;
*pt = newpt; *pt = newpt;
ya -= dx/_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; xa += dy / _bounds.size.width * M_PI / 2 * 4;
[self matrixFromAngles]; [self matrixFromAngles];
drawentry: drawentry:
[quakeed_i newinstance]; [quakeed_i newinstance];
[self display]; [self display];
/*XXX event = [NSApp nextEventMatchingMask: NSRightMouseUpMask
event = [NSApp getNextEvent: | NSRightMouseDraggedMask
NSKeyDownMask | NSRightMouseUpMask | NSRightMouseDraggedMask]; untilDate: [NSDate distantFuture]
*/ inMode: NSEventTrackingRunLoopMode dequeue: YES];
if ([event type] == NSKeyDown) if ([event type] == NSKeyDown) {
{ [self _keyDown:event];
[self _keyDown: event];
[self display]; [self display];
goto drawentry; goto drawentry;
} }
@ -763,7 +745,7 @@ drawentry:
mouseDown mouseDown
=================== ===================
*/ */
- (void) mouseDown:(NSEvent *)theEvent -(void) mouseDown:(NSEvent *)theEvent
{ {
NSPoint pt; NSPoint pt;
int i; int i;
@ -771,56 +753,51 @@ mouseDown
float forward, right, up; float forward, right, up;
int flags; int flags;
pt = [theEvent locationInWindow]; pt =[theEvent locationInWindow];
pt = [self convertPoint:pt fromView:NULL]; pt =[self convertPoint: pt fromView: NULL];
VectorCopy (origin, p1); VectorCopy (origin, p1);
forward = 160; forward = 160;
right = pt.x - 160; right = pt.x - 160;
up = pt.y - 240*2/3; up = pt.y - 240 * 2 / 3;
for (i=0 ; i<3 ; i++) for (i = 0; i < 3; i++)
p2[i] = forward*matrix[2][i] + up*matrix[1][i] + right*matrix[0][i]; p2[i] =
for (i=0 ; i<3 ; i++) forward * matrix[2][i] + up * matrix[1][i] + right * matrix[0][i];
p2[i] = p1[i] + 100*p2[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 // bare click to select a texture
// //
if (flags == 0) if (flags == 0) {
{
[map_i getTextureRay: p1 : p2]; [map_i getTextureRay: p1 : p2];
return; return;
} }
// //
// shift click to select / deselect a brush from the world // shift click to select / deselect a brush from the world
// //
if (flags == NSShiftKeyMask) if (flags == NSShiftKeyMask) {
{
[map_i selectRay: p1 : p2 : NO]; [map_i selectRay: p1 : p2 : NO];
return; return;
} }
// //
// cmd-shift click to set a target/targetname entity connection // cmd-shift click to set a target/targetname entity connection
// //
if (flags == (NSShiftKeyMask|NSCommandKeyMask) ) if (flags == (NSShiftKeyMask | NSCommandKeyMask)) {
{
[map_i entityConnect: p1 : p2]; [map_i entityConnect: p1 : p2];
return; return;
} }
// //
// alt click = set entire brush texture // alt click = set entire brush texture
// //
if (flags == NSAlternateKeyMask) if (flags == NSAlternateKeyMask) {
{ if (drawmode != dr_texture) {
if (drawmode != dr_texture)
{
Sys_Printf ("No texture setting except in texture mode!\n"); Sys_Printf ("No texture setting except in texture mode!\n");
NopSound (); NopSound ();
return; return;
@ -829,14 +806,11 @@ mouseDown
[quakeed_i updateAll]; [quakeed_i updateAll];
return; return;
} }
// //
// ctrl-alt click = set single face texture // ctrl-alt click = set single face texture
// //
if (flags == (NSControlKeyMask | NSAlternateKeyMask) ) if (flags == (NSControlKeyMask | NSAlternateKeyMask)) {
{ if (drawmode != dr_texture) {
if (drawmode != dr_texture)
{
Sys_Printf ("No texture setting except in texture mode!\n"); Sys_Printf ("No texture setting except in texture mode!\n");
NopSound (); NopSound ();
return; return;
@ -863,17 +837,18 @@ rightMouseDown
NSPoint pt; NSPoint pt;
int flags; int flags;
pt = [theEvent locationInWindow]; pt =[theEvent locationInWindow];
[self convertPoint:pt fromView:NULL]; [self convertPoint: pt fromView: NULL];
flags = [theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask); flags =
[theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask |
NSAlternateKeyMask | NSCommandKeyMask);
// //
// click = drag camera // click = drag camera
// //
if (flags == 0) if (flags == 0) {
{
Sys_Printf ("looking"); Sys_Printf ("looking");
[self viewDrag: &pt]; [self viewDrag: &pt];
Sys_Printf ("%s", ""); Sys_Printf ("%s", "");
@ -898,64 +873,63 @@ keyDown
#define KEY_DOWNARROW 0xaf #define KEY_DOWNARROW 0xaf
- _keyDown: (NSEvent *)theEvent -_keyDown:(NSEvent *)theEvent
{ {
int ch; int ch;
ch = tolower([[theEvent characters] characterAtIndex: 0]); ch = tolower ([[theEvent characters] characterAtIndex: 0]);
switch (ch) switch (ch) {
{
case 13: case 13:
return self; return self;
case 'a': case 'a':
case 'A': case 'A':
xa += M_PI/8; xa += M_PI / 8;
[self matrixFromAngles]; [self matrixFromAngles];
[quakeed_i updateCamera]; [quakeed_i updateCamera];
return self; return self;
case 'z': case 'z':
case 'Z': case 'Z':
xa -= M_PI/8; xa -= M_PI / 8;
[self matrixFromAngles]; [self matrixFromAngles];
[quakeed_i updateCamera]; [quakeed_i updateCamera];
return self; return self;
case KEY_RIGHTARROW: case KEY_RIGHTARROW:
ya -= M_PI*move/(64*2); ya -= M_PI * move / (64 * 2);
[self matrixFromAngles]; [self matrixFromAngles];
[quakeed_i updateCamera]; [quakeed_i updateCamera];
break; break;
case KEY_LEFTARROW: case KEY_LEFTARROW:
ya += M_PI*move/(64*2); ya += M_PI * move / (64 * 2);
[self matrixFromAngles]; [self matrixFromAngles];
[quakeed_i updateCamera]; [quakeed_i updateCamera];
break; break;
case KEY_UPARROW: case KEY_UPARROW:
origin[0] += move*cos(ya); origin[0] += move * cos (ya);
origin[1] += move*sin(ya); origin[1] += move * sin (ya);
[quakeed_i updateCamera]; [quakeed_i updateCamera];
break; break;
case KEY_DOWNARROW: case KEY_DOWNARROW:
origin[0] -= move*cos(ya); origin[0] -= move * cos (ya);
origin[1] -= move*sin(ya); origin[1] -= move * sin (ya);
[quakeed_i updateCamera]; [quakeed_i updateCamera];
break; break;
case '.': case '.':
origin[0] += move*cos(ya-M_PI_2); origin[0] += move * cos (ya - M_PI_2);
origin[1] += move*sin(ya-M_PI_2); origin[1] += move * sin (ya - M_PI_2);
[quakeed_i updateCamera]; [quakeed_i updateCamera];
break; break;
case ',': case ',':
origin[0] -= move*cos(ya-M_PI_2); origin[0] -= move * cos (ya - M_PI_2);
origin[1] -= move*sin(ya-M_PI_2); origin[1] -= move * sin (ya - M_PI_2);
[quakeed_i updateCamera]; [quakeed_i updateCamera];
break; break;
@ -979,4 +953,3 @@ keyDown
@end @end

View file

@ -14,14 +14,14 @@ id clipper_i;
@implementation Clipper @implementation Clipper
- init -init
{ {
[super init]; [super init];
clipper_i = self; clipper_i = self;
return self; return self;
} }
- (BOOL)hide -(BOOL) hide
{ {
int oldnum; int oldnum;
@ -30,24 +30,19 @@ id clipper_i;
return (oldnum > 0); return (oldnum > 0);
} }
- flipNormal -flipNormal
{ {
vec3_t temp; vec3_t temp;
if (num == 2) if (num == 2) {
{
VectorCopy (pos[0], temp); VectorCopy (pos[0], temp);
VectorCopy (pos[1], pos[0]); VectorCopy (pos[1], pos[0]);
VectorCopy (temp, pos[1]); VectorCopy (temp, pos[1]);
} } else if (num == 3) {
else if (num == 3)
{
VectorCopy (pos[0], temp); VectorCopy (pos[0], temp);
VectorCopy (pos[2], pos[0]); VectorCopy (pos[2], pos[0]);
VectorCopy (temp, pos[2]); VectorCopy (temp, pos[2]);
} } else {
else
{
Sys_Printf ("no clipplane"); Sys_Printf ("no clipplane");
NSBeep (); NSBeep ();
} }
@ -55,7 +50,7 @@ id clipper_i;
return self; return self;
} }
- (BOOL)getFace: (face_t *)f -(BOOL) getFace:(face_t *) f
{ {
vec3_t v1, v2, norm; vec3_t v1, v2, norm;
int i; int i;
@ -64,13 +59,12 @@ id clipper_i;
plane.dist = 0; plane.dist = 0;
if (num < 2) if (num < 2)
return NO; return NO;
if (num == 2) if (num == 2) {
{
VectorCopy (pos[0], pos[2]); VectorCopy (pos[0], pos[2]);
pos[2][2] += 16; pos[2][2] += 16;
} }
for (i=0 ; i<3 ; i++) for (i = 0; i < 3; i++)
VectorCopy (pos[i], f->planepts[i]); VectorCopy (pos[i], f->planepts[i]);
VectorSubtract (pos[2], pos[0], v1); VectorSubtract (pos[2], pos[0], v1);
@ -79,10 +73,10 @@ id clipper_i;
CrossProduct (v1, v2, norm); CrossProduct (v1, v2, norm);
VectorNormalize (norm); VectorNormalize (norm);
if ( !norm[0] && !norm[1] && !norm[2] ) if (!norm[0] && !norm[1] && !norm[2])
return NO; return NO;
[texturepalette_i getTextureDef: &f->texture]; [texturepalette_i getTextureDef:&f->texture];
return YES; return YES;
} }
@ -92,24 +86,22 @@ id clipper_i;
XYClick XYClick
================ ================
*/ */
- XYClick: (NSPoint)pt -XYClick:(NSPoint) pt
{ {
int i; int i;
vec3_t new; vec3_t new;
new[0] = [xyview_i snapToGrid: pt.x]; new[0] =[xyview_i snapToGrid:pt.x];
new[1] = [xyview_i snapToGrid: pt.y]; new[1] =[xyview_i snapToGrid:pt.y];
new[2] = [map_i currentMinZ]; new[2] =[map_i currentMinZ];
// see if a point is allready there // see if a point is allready there
for (i=0 ; i<num ; i++) for (i = 0; i < num; i++) {
{ if (new[0] == pos[i][0] && new[1] == pos[i][1]) {
if (new[0] == pos[i][0] && new[1] == pos[i][1]) if (pos[i][2] ==[map_i currentMinZ])
{ pos[i][2] =[map_i currentMaxZ];
if (pos[i][2] == [map_i currentMinZ])
pos[i][2] = [map_i currentMaxZ];
else else
pos[i][2] = [map_i currentMinZ]; pos[i][2] =[map_i currentMinZ];
[quakeed_i updateAll]; [quakeed_i updateAll];
return self; return self;
} }
@ -132,13 +124,12 @@ XYClick
XYDrag XYDrag
================ ================
*/ */
- (BOOL)XYDrag: (NSPoint *)pt -(BOOL) XYDrag:(NSPoint *) pt
{ {
int i; int i;
for (i=0 ; i<3 ; i++) for (i = 0; i < 3; i++) {
{ if (fabs (pt->x - pos[i][0] > 10) || fabs (pt->y - pos[i][1] > 10))
if (fabs(pt->x - pos[i][0] > 10) || fabs(pt->y - pos[i][1] > 10) )
continue; continue;
// drag this point // drag this point
@ -147,30 +138,29 @@ XYDrag
return NO; return NO;
} }
- ZClick: (NSPoint)pt -ZClick:(NSPoint) pt
{ {
return self; return self;
} }
//============================================================================= //=============================================================================
- carve -carve
{ {
[map_i makeSelectedPerform: @selector(carveByClipper)]; [map_i makeSelectedPerform:@selector (carveByClipper)];
num = 0; num = 0;
return self; return self;
} }
- cameraDrawSelf -cameraDrawSelf
{ {
vec3_t mid; vec3_t mid;
int i; int i;
linecolor (1,0.5,0); linecolor (1, 0.5, 0);
for (i=0 ; i<num ; i++) for (i = 0; i < num; i++) {
{
VectorCopy (pos[i], mid); VectorCopy (pos[i], mid);
mid[0] -= 8; mid[0] -= 8;
mid[1] -= 8; mid[1] -= 8;
@ -191,43 +181,41 @@ XYDrag
return self; return self;
} }
- XYDrawSelf -XYDrawSelf
{ {
int i; int i;
char text[8]; char text[8];
PSsetrgbcolor (1,0.5,0); PSsetrgbcolor (1, 0.5, 0);
//XXX PSselectfont("Helvetica-Medium",10/[xyview_i currentScale]); // XXX PSselectfont("Helvetica-Medium",10/[xyview_i currentScale]);
PSrotate(0); PSrotate (0);
for (i=0 ; i<num ; i++) for (i = 0; i < num; i++) {
{ PSmoveto (pos[i][0] - 4, pos[i][1] - 4);
PSmoveto (pos[i][0]-4, pos[i][1]-4);
sprintf (text, "%i", i); sprintf (text, "%i", i);
PSshow (text); PSshow (text);
PSstroke (); PSstroke ();
PSarc ( pos[i][0], pos[i][1], 10, 0, 360); PSarc (pos[i][0], pos[i][1], 10, 0, 360);
PSstroke (); PSstroke ();
} }
return self; return self;
} }
- ZDrawSelf -ZDrawSelf
{ {
int i; int i;
char text[8]; char text[8];
PSsetrgbcolor (1,0.5,0); PSsetrgbcolor (1, 0.5, 0);
//XXX PSselectfont("Helvetica-Medium",10/[zview_i currentScale]); // XXX PSselectfont("Helvetica-Medium",10/[zview_i currentScale]);
PSrotate(0); PSrotate (0);
for (i=0 ; i<num ; i++) for (i = 0; i < num; i++) {
{ PSmoveto (-28 + i * 8 - 4, pos[i][2] - 4);
PSmoveto (-28+i*8 - 4, pos[i][2]-4);
sprintf (text, "%i", i); sprintf (text, "%i", i);
PSshow (text); PSshow (text);
PSstroke (); PSstroke ();
PSarc ( -28+i*8, pos[i][2], 10, 0, 360); PSarc (-28 + i * 8, pos[i][2], 10, 0, 360);
PSstroke (); PSstroke ();
} }
return self; return self;

View file

@ -3,23 +3,21 @@
@implementation Dict @implementation Dict
- init -init
{ {
[super initCount:0 [super initCount: 0 elementSize:sizeof (dict_t)
elementSize:sizeof(dict_t)
description:NULL]; description:NULL];
return self; return self;
} }
- print -print
{ {
int i; int i;
dict_t *d; dict_t *d;
for (i=0 ; i<numElements ; i++) for (i = 0; i < numElements; i++) {
{ d =[self elementAt:i];
d = [self elementAt: i]; printf ("%s : %s\n", d->key, d->value);
printf ("%s : %s\n",d->key, d->value);
} }
return self; return self;
} }
@ -31,33 +29,32 @@ copyFromZone
JDC JDC
=========== ===========
*/ */
- copy -copy
{ {
id new; id new;
int i; int i;
dict_t *d; dict_t *d;
char *old; char *old;
new = [super copy]; new =[super copy];
for (i=0 ; i<numElements ; i++) for (i = 0; i < numElements; i++) {
{ d =[self elementAt:i];
d = [self elementAt: i];
old = d->key; old = d->key;
d->key = malloc(strlen(old)+1); d->key = malloc (strlen (old) + 1);
strcpy (d->key, old); strcpy (d->key, old);
old = d->value; old = d->value;
d->value = malloc(strlen(old)+1); d->value = malloc (strlen (old) + 1);
strcpy (d->value, old); strcpy (d->value, old);
} }
return new; return new;
} }
- initFromFile:(FILE *)fp -initFromFile:(FILE *) fp
{ {
[self init]; [self init];
return [self parseBraceBlock:fp]; return[self parseBraceBlock:fp];
} }
//=============================================== //===============================================
@ -69,20 +66,19 @@ JDC
// //
// Write a { } block out to a FILE* // Write a { } block out to a FILE*
// //
- writeBlockTo:(FILE *)fp -writeBlockTo:(FILE *) fp
{ {
int max; int max;
int i; int i;
dict_t *d; dict_t *d;
fprintf(fp,"{\n"); fprintf (fp, "{\n");
max = [super count]; max =[super count];
for (i = 0;i < max;i++) for (i = 0; i < max; i++) {
{ d =[super elementAt:i];
d = [super elementAt:i]; fprintf (fp, "\t{\"%s\"\t\"%s\"}\n", d->key, d->value);
fprintf(fp,"\t{\"%s\"\t\"%s\"}\n",d->key,d->value);
} }
fprintf(fp,"}\n"); fprintf (fp, "}\n");
return self; return self;
} }
@ -90,21 +86,18 @@ JDC
// //
// Write a single { } block out // Write a single { } block out
// //
- writeFile:(char *)path -writeFile:(char *) path
{ {
FILE *fp; FILE *fp;
fp = fopen(path,"w+t"); fp = fopen (path, "w+t");
if (fp != NULL) if (fp != NULL) {
{ printf ("Writing dictionary file %s.\n", path);
printf("Writing dictionary file %s.\n",path); fprintf (fp, "// QE_Project file %s\n", path);
fprintf(fp,"// QE_Project file %s\n",path);
[self writeBlockTo:fp]; [self writeBlockTo:fp];
fclose(fp); fclose (fp);
} } else {
else printf ("Error writing %s!\n", path);
{
printf("Error writing %s!\n",path);
return NULL; return NULL;
} }
@ -121,17 +114,16 @@ JDC
// Find a keyword in storage // Find a keyword in storage
// Returns * to dict_t, otherwise NULL // Returns * to dict_t, otherwise NULL
// //
- (dict_t *) findKeyword:(char *)key -(dict_t *) findKeyword:(char *) key
{ {
int max; int max;
int i; int i;
dict_t *d; dict_t *d;
max = [super count]; max =[super count];
for (i = 0;i < max;i++) for (i = 0; i < max; i++) {
{ d =[super elementAt:i];
d = [super elementAt:i]; if (!strcmp (d->key, key))
if (!strcmp(d->key,key))
return d; return d;
} }
@ -141,24 +133,22 @@ JDC
// //
// 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 *d;
dict_t newd; dict_t newd;
d = [self findKeyword:key]; d =[self findKeyword:key];
if (d != NULL) if (d != NULL) {
{ free (d->value);
free(d->value); d->value = malloc (strlen (value) + 1);
d->value = malloc(strlen(value)+1); strcpy (d->value, value);
strcpy(d->value,value); } else {
} newd.key = malloc (strlen (key) + 1);
else strcpy (newd.key, key);
{ newd.value = malloc (strlen (value) + 1);
newd.key = malloc(strlen(key)+1); strcpy (newd.value, value);
strcpy(newd.key,key);
newd.value = malloc(strlen(value)+1);
strcpy(newd.value,value);
[self addElement:&newd]; [self addElement:&newd];
} }
return self; return self;
@ -167,11 +157,11 @@ JDC
// //
// Search for keyword, return the string * // Search for keyword, return the string *
// //
- (char *)getStringFor:(char *)name -(char *) getStringFor:(char *) name
{ {
dict_t *d; dict_t *d;
d = [self findKeyword:name]; d =[self findKeyword:name];
if (d != NULL) if (d != NULL)
return d->value; return d->value;
@ -181,13 +171,13 @@ JDC
// //
// 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; dict_t *d;
d = [self findKeyword:name]; d =[self findKeyword:name];
if (d != NULL) if (d != NULL)
return atol(d->value); return atol (d->value);
return 0; return 0;
} }
@ -195,13 +185,13 @@ JDC
// //
// Return # of units in keyword's value // Return # of units in keyword's value
// //
- (int) getValueUnits:(char *)key -(int) getValueUnits:(char *) key
{ {
id temp; id temp;
int count; int count;
temp = [self parseMultipleFrom:key]; temp =[self parseMultipleFrom:key];
count = [temp count]; count =[temp count];
[temp release]; [temp release];
return count; return count;
@ -210,7 +200,7 @@ JDC
// //
// Convert List to string // Convert List to string
// //
- (char *)convertListToString:(id)list -(char *) convertListToString:(id) list
{ {
int i; int i;
int max; int max;
@ -218,16 +208,15 @@ JDC
char *s; char *s;
char *newstr; char *newstr;
max = [list count]; max =[list count];
tempstr[0] = 0; tempstr[0] = 0;
for (i = 0;i < max;i++) for (i = 0; i < max; i++) {
{ s =[list elementAt:i];
s = [list elementAt:i]; strcat (tempstr, s);
strcat(tempstr,s); strcat (tempstr, " ");
strcat(tempstr," ");
} }
newstr = malloc(strlen(tempstr)+1); newstr = malloc (strlen (tempstr) + 1);
strcpy(newstr,tempstr); strcpy (newstr, tempstr);
return newstr; return newstr;
} }
@ -235,21 +224,22 @@ JDC
// //
// JDC: I wrote this to simplify removing vectors // 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) if (d == NULL)
return self; return self;
[self removeElementAt:d - (dict_t*)dataPtr]; [self removeElementAt:d - (dict_t *) dataPtr];
return self; 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; id temp;
int count; int count;
@ -257,19 +247,17 @@ JDC
char *s; char *s;
dict_t *d; dict_t *d;
d = [self findKeyword:key]; d =[self findKeyword:key];
if (d == NULL) if (d == NULL)
return NULL; return NULL;
temp = [self parseMultipleFrom:key]; temp =[self parseMultipleFrom:key];
count = [temp count]; count =[temp count];
for (i = 0;i < count;i++) for (i = 0; i < count; i++) {
{ s =[temp elementAt:i];
s = [temp elementAt:i]; if (!strcmp (s, string)) {
if (!strcmp(s,string))
{
[temp removeElementAt:i]; [temp removeElementAt:i];
free(d->value); free (d->value);
d->value = [self convertListToString:temp]; d->value =[self convertListToString:temp];
[temp release]; [temp release];
break; break;
@ -281,20 +269,22 @@ 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 *newstr;
char spacing[] = "\t"; char spacing[] = "\t";
dict_t *d; dict_t *d;
d = [self findKeyword:key]; d =[self findKeyword:key];
if (d == NULL) if (d == NULL)
return NULL; return NULL;
newstr = malloc(strlen(string) + strlen(d->value) + strlen(spacing) + 1); newstr =
strcpy(newstr,d->value); malloc (strlen (string) + strlen (d->value) + strlen (spacing) + 1);
strcat(newstr,spacing); strcpy (newstr, d->value);
strcat(newstr,string); strcat (newstr, spacing);
free(d->value); strcat (newstr, string);
free (d->value);
d->value = newstr; d->value = newstr;
return self; return self;
@ -308,26 +298,25 @@ JDC
char *searchStr; char *searchStr;
char item[4096]; char item[4096];
- setupMultiple:(char *)value -setupMultiple:(char *) value
{ {
searchStr = value; searchStr = value;
return self; return self;
} }
- (char *)getNextParameter -(char *) getNextParameter
{ {
char *s; char *s;
if (!searchStr) if (!searchStr)
return NULL; return NULL;
strcpy(item,searchStr); strcpy (item, searchStr);
s = FindWhitespcInBuffer(item); s = FindWhitespcInBuffer (item);
if (!*s) if (!*s)
searchStr = NULL; searchStr = NULL;
else else {
{
*s = 0; *s = 0;
searchStr = FindNonwhitespcInBuffer(s+1); searchStr = FindNonwhitespcInBuffer (s + 1);
} }
return item; return item;
} }
@ -335,27 +324,24 @@ char item[4096];
// //
// 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 #define ITEMSIZE 128
id stuff; id stuff;
char string[ITEMSIZE]; char string[ITEMSIZE];
char *s; char *s;
s = [self getStringFor:key]; s =[self getStringFor:key];
if (s == NULL) if (s == NULL)
return NULL; return NULL;
stuff = [[Storage alloc] stuff =[[Storage alloc]
initCount:0 initCount: 0 elementSize: ITEMSIZE description:NULL];
elementSize:ITEMSIZE
description:NULL];
[self setupMultiple:s]; [self setupMultiple:s];
while((s = [self getNextParameter])) while ((s =[self getNextParameter])) {
{ bzero (string, ITEMSIZE);
bzero(string,ITEMSIZE); strcpy (string, s);
strcpy(string,s);
[stuff addElement:string]; [stuff addElement:string];
} }
@ -371,18 +357,17 @@ char item[4096];
// //
// parse all keyword/value pairs within { } 's // parse all keyword/value pairs within { } 's
// //
- (id) parseBraceBlock:(FILE *)fp -(id) parseBraceBlock:(FILE *) fp
{ {
int c; int c;
dict_t pair; dict_t pair;
char string[1024]; char string[1024];
c = FindBrace(fp); c = FindBrace (fp);
if (c == -1) if (c == -1)
return NULL; return NULL;
while((c = FindBrace(fp)) != '}') while ((c = FindBrace (fp)) != '}') {
{
if (c == -1) if (c == -1)
return NULL; return NULL;
// c = FindNonwhitespc(fp); // c = FindNonwhitespc(fp);
@ -391,74 +376,70 @@ char item[4096];
// CopyUntilWhitespc(fp,string); // CopyUntilWhitespc(fp,string);
// JDC: fixed to allow quoted keys // JDC: fixed to allow quoted keys
c = FindNonwhitespc(fp); c = FindNonwhitespc (fp);
if (c == -1) if (c == -1)
return NULL; return NULL;
c = fgetc(fp); c = fgetc (fp);
if ( c == '\"') if (c == '\"')
CopyUntilQuote(fp,string); CopyUntilQuote (fp, string);
else else {
{ ungetc (c, fp);
ungetc (c,fp); CopyUntilWhitespc (fp, string);
CopyUntilWhitespc(fp,string);
} }
pair.key = malloc(strlen(string)+1); pair.key = malloc (strlen (string) + 1);
strcpy(pair.key,string); strcpy (pair.key, string);
c = FindQuote(fp); c = FindQuote (fp);
CopyUntilQuote(fp,string); CopyUntilQuote (fp, string);
pair.value = malloc(strlen(string)+1); pair.value = malloc (strlen (string) + 1);
strcpy(pair.value,string); strcpy (pair.value, string);
[super addElement:&pair]; [super addElement:&pair];
c = FindBrace(fp); c = FindBrace (fp);
} }
return self; return self;
} }
@end @end
//=============================================== //===============================================
// //
// C routines for string parsing // C routines for string parsing
// //
//=============================================== //===============================================
int GetNextChar(FILE *fp) int
GetNextChar (FILE * fp)
{ {
int c; int c;
int c2; int c2;
c = getc(fp); c = getc (fp);
if (c == EOF) if (c == EOF)
return -1; return -1;
if (c == '/') // parse comments if (c == '/') // parse comments
{ {
c2 = getc(fp); c2 = getc (fp);
if (c2 == '/') if (c2 == '/') {
{ while ((c2 = getc (fp)) != '\n');
while((c2 = getc(fp)) != '\n'); c = getc (fp);
c = getc(fp); } else
} ungetc (c2, fp);
else
ungetc(c2,fp);
} }
return c; return c;
} }
void CopyUntilWhitespc(FILE *fp,char *buffer) void
CopyUntilWhitespc (FILE * fp, char *buffer)
{ {
int count = 800; int count = 800;
int c; int c;
while(count--) while (count--) {
{ c = GetNextChar (fp);
c = GetNextChar(fp);
if (c == EOF) if (c == EOF)
return; return;
if (c <= ' ') if (c <= ' ') {
{
*buffer = 0; *buffer = 0;
return; 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 count = 800;
int c; int c;
while(count--) while (count--) {
{ c = GetNextChar (fp);
c = GetNextChar(fp);
if (c == EOF) if (c == EOF)
return; return;
if (c == '\"') if (c == '\"') {
{
*buffer = 0; *buffer = 0;
return; return;
} }
@ -485,31 +465,30 @@ void CopyUntilQuote(FILE *fp,char *buffer)
} }
} }
int FindBrace(FILE *fp) int
FindBrace (FILE * fp)
{ {
int count = 800; int count = 800;
int c; int c;
while(count--) while (count--) {
{ c = GetNextChar (fp);
c = GetNextChar(fp);
if (c == EOF) if (c == EOF)
return -1; return -1;
if (c == '{' || if (c == '{' || c == '}')
c == '}')
return c; return c;
} }
return -1; return -1;
} }
int FindQuote(FILE *fp) int
FindQuote (FILE * fp)
{ {
int count = 800; int count = 800;
int c; int c;
while(count--) while (count--) {
{ c = GetNextChar (fp);
c = GetNextChar(fp);
if (c == EOF) if (c == EOF)
return -1; return -1;
if (c == '\"') if (c == '\"')
@ -518,50 +497,49 @@ int FindQuote(FILE *fp)
return -1; return -1;
} }
int FindWhitespc(FILE *fp) int
FindWhitespc (FILE * fp)
{ {
int count = 800; int count = 800;
int c; int c;
while(count--) while (count--) {
{ c = GetNextChar (fp);
c = GetNextChar(fp);
if (c == EOF) if (c == EOF)
return -1; return -1;
if (c <= ' ') if (c <= ' ') {
{ ungetc (c, fp);
ungetc(c,fp);
return c; return c;
} }
} }
return -1; return -1;
} }
int FindNonwhitespc(FILE *fp) int
FindNonwhitespc (FILE * fp)
{ {
int count = 800; int count = 800;
int c; int c;
while(count--) while (count--) {
{ c = GetNextChar (fp);
c = GetNextChar(fp);
if (c == EOF) if (c == EOF)
return -1; return -1;
if (c > ' ') if (c > ' ') {
{ ungetc (c, fp);
ungetc(c,fp);
return c; return c;
} }
} }
return -1; return -1;
} }
char *FindWhitespcInBuffer(char *buffer) char *
FindWhitespcInBuffer (char *buffer)
{ {
int count = 1000; int count = 1000;
char *b = buffer; char *b = buffer;
while(count--) while (count--)
if (*b <= ' ') if (*b <= ' ')
return b; return b;
else else
@ -569,12 +547,13 @@ char *FindWhitespcInBuffer(char *buffer)
return NULL; return NULL;
} }
char *FindNonwhitespcInBuffer(char *buffer) char *
FindNonwhitespcInBuffer (char *buffer)
{ {
int count = 1000; int count = 1000;
char *b = buffer; char *b = buffer;
while(count--) while (count--)
if (*b > ' ') if (*b > ' ')
return b; return b;
else else

View file

@ -3,21 +3,19 @@
#include "Dict.h" #include "Dict.h"
@implementation DictList @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]; [super init];
do do {
{ d =[(Dict *)[Dict alloc] initFromFile:fp];
d = [(Dict *)[Dict alloc] initFromFile:fp];
if (d != NULL) if (d != NULL)
[self addObject:d]; [self addObject:d];
} while(d != NULL); } while (d != NULL);
[d release]; [d release];
return self; return self;
@ -26,24 +24,23 @@
// //
// Write out list file // Write out list file
// //
- writeListFile:(char *)filename -writeListFile:(char *) filename
{ {
FILE *fp; FILE *fp;
int i; int i;
id obj; id obj;
fp = fopen(filename,"w+t"); fp = fopen (filename, "w+t");
if (fp == NULL) if (fp == NULL)
return NULL; return NULL;
fprintf(fp,"// Object List written by QuakeEd\n"); fprintf (fp, "// Object List written by QuakeEd\n");
for (i = 0;i < [self count];i++) for (i = 0; i <[self count]; i++) {
{ obj =[self objectAtIndex:i];
obj = [self objectAtIndex:i];
[obj writeBlockTo:fp]; [obj writeBlockTo:fp];
} }
fclose(fp); fclose (fp);
return self; return self;
} }
@ -51,16 +48,15 @@
// //
// 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; int i;
dict_t *d; dict_t *d;
id dict; id dict;
for (i = 0;i < [self count];i++) for (i = 0; i <[self count]; i++) {
{ dict =[self objectAtIndex:i];
dict = [self objectAtIndex:i]; d =[(Dict *) dict findKeyword:key];
d = [(Dict *)dict findKeyword:key];
if (d != NULL) if (d != NULL)
return dict; return dict;
} }

View file

@ -12,10 +12,10 @@
@implementation Entity @implementation Entity
vec3_t bad_mins = {-8, -8, -8}; vec3_t bad_mins = { -8, -8, -8 };
vec3_t bad_maxs = {8, 8, 8}; vec3_t bad_maxs = { 8, 8, 8 };
- createFixedBrush: (vec3_t)org -createFixedBrush:(vec3_t) org
{ {
vec3_t emins, emaxs; vec3_t emins, emaxs;
float *v, *v2, *color; float *v, *v2, *color;
@ -23,33 +23,32 @@ vec3_t bad_maxs = {8, 8, 8};
texturedef_t td; texturedef_t td;
// get class // get class
new = [entity_classes_i classForName: [self valueForQKey: "classname"]]; new =[entity_classes_i classForName: [self valueForQKey:"classname"]];
if (new) { if (new) {
v = [new mins]; v =[new mins];
v2 = [new maxs]; v2 =[new maxs];
} else { } else {
v = bad_mins; v = bad_mins;
v2 = bad_maxs; v2 = bad_maxs;
} }
color = [new drawColor]; color =[new drawColor];
modifiable = NO; modifiable = NO;
memset(&td,0,sizeof(td)); memset (&td, 0, sizeof (td));
strcpy (td.texture,"entity"); strcpy (td.texture, "entity");
VectorAdd (org, v, emins); VectorAdd (org, v, emins);
VectorAdd (org, v2, emaxs); VectorAdd (org, v2, emaxs);
new = [[SetBrush alloc] initOwner: self mins:emins maxs:emaxs new =[[SetBrush alloc] initOwner: self mins: emins maxs: emaxs texture:&td];
texture: &td]; [new setEntityColor:color];
[new setEntityColor: color];
[self addObject: new]; [self addObject:new];
return self; return self;
} }
- initClass: (char *)classname -initClass:(char *) classname
{ {
id new; id new;
esize_t esize; esize_t esize;
@ -64,37 +63,34 @@ vec3_t bad_maxs = {8, 8, 8};
[self setKey: "classname" toValue:classname]; [self setKey: "classname" toValue:classname];
// get class // get class
new = [entity_classes_i classForName: [self valueForQKey: "classname"]]; new =[entity_classes_i classForName: [self valueForQKey:"classname"]];
if (!new) if (!new)
esize = esize_model; esize = esize_model;
else else
esize = [new esize]; esize =[new esize];
// create a brush if needed // create a brush if needed
if (esize == esize_fixed) if (esize == esize_fixed) {
{ v =[new mins];
v = [new mins]; [[map_i selectedBrush] getMins: min maxs:max];
[[map_i selectedBrush] getMins: min maxs: max];
VectorSubtract (min, v, min); VectorSubtract (min, v, min);
sprintf (value, "%i %i %i",(int)min[0], (int)min[1], (int)min[2]); sprintf (value, "%i %i %i", (int) min[0], (int) min[1], (int) min[2]);
[self setKey:"origin" toValue: value]; [self setKey: "origin" toValue:value];
[self createFixedBrush: min]; [self createFixedBrush:min];
} } else
else
modifiable = YES; modifiable = YES;
return self; return self;
} }
- (void)dealloc -(void) dealloc
{ {
epair_t *e, *n; epair_t *e, *n;
for (e=epairs ; e ; e=n) for (e = epairs; e; e = n) {
{
n = e->next; n = e->next;
free (e->key); free (e->key);
free (e->value); free (e->value);
@ -103,50 +99,50 @@ vec3_t bad_maxs = {8, 8, 8};
[super dealloc]; [super dealloc];
} }
- (BOOL)modifiable -(BOOL) modifiable
{ {
return modifiable; return modifiable;
} }
- setModifiable: (BOOL)m -setModifiable:(BOOL) m
{ {
modifiable = m; modifiable = m;
return self; return self;
} }
- (void)removeObject: o -(void) removeObject:o
{ {
[super removeObject: o]; [super removeObject:o];
if ([self count]) if ([self count])
return; return;
// the entity is empty, so remove the entire thing // the entity is empty, so remove the entire thing
if ( self == [map_i objectAtIndex: 0]) if (self ==[map_i objectAtIndex:0])
return; // never remove the world return; // never remove the world
[map_i removeObject: self]; [map_i removeObject:self];
[self release]; [self release];
} }
- (char *)valueForQKey: (char *)k -(char *) valueForQKey:(char *) k
{ {
epair_t *e; epair_t *e;
static char ret[64]; static char ret[64];
for (e=epairs ; e ; e=e->next) for (e = epairs; e; e = e->next)
if (!strcmp(k,e->key)) if (!strcmp (k, e->key)) {
{
strcpy (ret, e->value); strcpy (ret, e->value);
return ret; return ret;
} }
return ""; return "";
} }
- getVector: (vec3_t)v forKey: (char *)k -getVector:(vec3_t)
v forKey:(char *) k
{ {
char *c; char *c;
c = [self valueForQKey: k]; c =[self valueForQKey:k];
v[0] = v[1] = v[2] = 0; v[0] = v[1] = v[2] = 0;
@ -155,17 +151,18 @@ vec3_t bad_maxs = {8, 8, 8};
return self; return self;
} }
- print -print
{ {
epair_t *e; epair_t *e;
for (e=epairs ; e ; e=e->next) for (e = epairs; e; e = e->next)
printf ("%20s : %20s\n",e->key, e->value); printf ("%20s : %20s\n", e->key, e->value);
return self; return self;
} }
- setKey:(const char *)k toValue:(const char *)v -setKey:(const char *)
k toValue:(const char *) v
{ {
epair_t *e; epair_t *e;
@ -174,7 +171,7 @@ vec3_t bad_maxs = {8, 8, 8};
if (!*k) if (!*k)
return self; // don't set NULL values return self; // don't set NULL values
for (e=epairs ; e ; e=e->next) { for (e = epairs; e; e = e->next) {
if (!strcmp (k, e->key)) { if (!strcmp (k, e->key)) {
free (e->value); free (e->value);
e->value = strdup (v); e->value = strdup (v);
@ -182,7 +179,7 @@ vec3_t bad_maxs = {8, 8, 8};
} }
} }
e = malloc (sizeof(epair_t)); e = malloc (sizeof (epair_t));
e->key = strdup (k); e->key = strdup (k);
e->value = strdup (v); e->value = strdup (v);
@ -192,40 +189,37 @@ vec3_t bad_maxs = {8, 8, 8};
return self; return self;
} }
- (int)numPairs -(int) numPairs
{ {
int i; int i;
epair_t *e; epair_t *e;
i=0; i = 0;
for (e=epairs ; e ; e=e->next) for (e = epairs; e; e = e->next)
i++; i++;
return i; return i;
} }
- (epair_t *)epairs -(epair_t *) epairs
{ {
return epairs; return epairs;
} }
- removeKeyPair: (char *)key -removeKeyPair:(char *) key
{ {
epair_t *e, *e2; epair_t *e, *e2;
if (!epairs) if (!epairs)
return self; return self;
e = epairs; e = epairs;
if (!strcmp(e->key, key)) if (!strcmp (e->key, key)) {
{
epairs = e->next; epairs = e->next;
free (e); free (e);
return self; return self;
} }
for (; e ; e=e->next) for (; e; e = e->next) {
{ if (e->next && !strcmp (e->next->key, key)) {
if (e->next && !strcmp(e->next->key, key))
{
e2 = e->next; e2 = e->next;
e->next = e2->next; e->next = e2->next;
free (e2); free (e2);
@ -245,7 +239,7 @@ targetname
If the entity does not have a "targetname" key, a unique one is generated If the entity does not have a "targetname" key, a unique one is generated
============= =============
*/ */
- (char *)targetname -(char *) targetname
{ {
char *t; char *t;
int i, count; int i, count;
@ -253,29 +247,29 @@ If the entity does not have a "targetname" key, a unique one is generated
int tval, maxt; int tval, maxt;
char name[20]; char name[20];
t = [self valueForQKey: "targetname"]; t =[self valueForQKey:"targetname"];
if (t && t[0]) if (t && t[0])
return t; return t;
// make a unique name of the form t<number> // make a unique name of the form t<number>
count = [map_i count]; count =[map_i count];
maxt = 0; maxt = 0;
for (i=1 ; i<count ; i++) for (i = 1; i < count; i++) {
{ ent =[map_i objectAtIndex:i];
ent = [map_i objectAtIndex: i]; t =[ent valueForQKey:"targetname"];
t = [ent valueForQKey: "targetname"];
if (!t || t[0] != 't') if (!t || t[0] != 't')
continue; continue;
tval = atoi (t+1); tval = atoi (t + 1);
if (tval > maxt) if (tval > maxt)
maxt = tval; maxt = tval;
} }
sprintf (name,"t%i",maxt+1); sprintf (name, "t%i", maxt + 1);
[self setKey: "targetname" toValue: name]; [self setKey: "targetname" toValue:name];
return [self valueForQKey: "targetname"]; // so it's not on the stack return[self valueForQKey:"targetname"];
// so it's not on the stack
} }
/* /*
@ -288,7 +282,7 @@ FILE METHODS
int nument; int nument;
- initFromScript: (script_t *) script -initFromScript:(script_t *) script
{ {
char *key; char *key;
id eclass, brush; id eclass, brush;
@ -302,24 +296,23 @@ int nument;
[self init]; [self init];
if (!Script_GetToken (script, true)) if (!Script_GetToken (script, true)) {
{
[self dealloc]; [self dealloc];
return nil; return nil;
} }
if (strcmp (Script_Token (script), "{") ) if (strcmp (Script_Token (script), "{"))
Sys_Error ("initFromFileP: { not found"); Sys_Error ("initFromFileP: { not found");
do { do {
if (!Script_GetToken (script, true)) if (!Script_GetToken (script, true))
break; break;
if (!strcmp (Script_Token (script), "}") ) if (!strcmp (Script_Token (script), "}"))
break; break;
if (!strcmp (Script_Token (script), "{") ) { if (!strcmp (Script_Token (script), "{")) {
// read a brush // read a brush
brush = [[SetBrush alloc] initFromScript: script owner:self]; brush =[[SetBrush alloc] initFromScript: script owner:self];
[self addObject: brush]; [self addObject:brush];
} else { } else {
// read a key / value pair // read a key / value pair
key = strdup (Script_Token (script)); key = strdup (Script_Token (script));
@ -332,54 +325,49 @@ int nument;
nument++; nument++;
// get class // get class
spawn = [self valueForQKey: "classname"]; spawn =[self valueForQKey:"classname"];
eclass = [entity_classes_i classForName: spawn]; eclass =[entity_classes_i classForName:spawn];
esize = [eclass esize]; esize =[eclass esize];
[self getVector: org forKey: "origin"]; [self getVector: org forKey:"origin"];
if ([self count] && esize != esize_model) if ([self count] && esize != esize_model) {
{
printf ("WARNING:Entity with brushes and wrong model type\n"); printf ("WARNING:Entity with brushes and wrong model type\n");
[self removeAllObjects]; [self removeAllObjects];
} }
if (![self count] && esize == esize_model) if (![self count] && esize == esize_model) {
{
printf ("WARNING:Entity with no brushes and esize_model\n"); printf ("WARNING:Entity with no brushes and esize_model\n");
[texturepalette_i getTextureDef: &td]; [texturepalette_i getTextureDef:&td];
for (i=0 ; i<3 ; i++) for (i = 0; i < 3; i++) {
{
emins[i] = org[i] - 8; emins[i] = org[i] - 8;
emaxs[i] = org[i] + 8; emaxs[i] = org[i] + 8;
} }
brush = [[SetBrush alloc] initOwner: self mins:emins maxs:emaxs brush =[[SetBrush alloc] initOwner: self mins: emins maxs: emaxs texture:&td];
texture: &td]; [self addObject:brush];
[self addObject: brush];
} }
// create a brush if needed // create a brush if needed
if (esize == esize_fixed) if (esize == esize_fixed)
[self createFixedBrush: org]; [self createFixedBrush:org];
else else
modifiable = YES; modifiable = YES;
// set all the brush colors // set all the brush colors
color = [eclass drawColor]; color =[eclass drawColor];
c = [self count]; c =[self count];
for (i=0 ; i<c ; i++) for (i = 0; i < c; i++) {
{ brush =[self objectAtIndex:i];
brush = [self objectAtIndex: i]; [brush setEntityColor:color];
[brush setEntityColor: color];
} }
return self; return self;
} }
- writeToFILE: (FILE *)f region:(BOOL)reg; -writeToFILE:(FILE *)
f region:(BOOL) reg;
{ {
epair_t *e; epair_t *e;
int i; int i;
@ -391,59 +379,56 @@ int nument;
char oldang[80]; char oldang[80];
temporg = NO; temporg = NO;
if (reg) if (reg) {
{ if (!strcmp ([self valueForQKey:"classname"], "info_player_start")) {
if ( !strcmp ([self valueForQKey: "classname"], "info_player_start") ) // move the playerstart
{ // move the playerstart temporarily to the camera position // temporarily to the camera
// position
temporg = YES; temporg = YES;
strcpy (oldang, [self valueForQKey: "angle"]); strcpy (oldang,[self valueForQKey:"angle"]);
sprintf (value, "%i", (int)([cameraview_i yawAngle]*180/M_PI)); sprintf (value, "%i", (int) ([cameraview_i yawAngle] * 180 / M_PI));
[self setKey: "angle" toValue: value]; [self setKey: "angle" toValue:value];
} } else if (self !=[map_i objectAtIndex:0]
else if ( self != [map_i objectAtIndex: 0] &&[[self objectAtIndex:0] regioned])
&& [[self objectAtIndex: 0] regioned] )
return self; // skip the entire entity definition return self; // skip the entire entity definition
} }
fprintf (f,"{\n"); fprintf (f, "{\n");
// set an origin epair // set an origin epair
if (!modifiable) if (!modifiable) {
{ [[self objectAtIndex: 0] getMins: mins maxs:maxs];
[[self objectAtIndex: 0] getMins: mins maxs: maxs]; if (temporg) {
if (temporg) [cameraview_i getOrigin:mins];
{
[cameraview_i getOrigin: mins];
mins[0] -= 16; mins[0] -= 16;
mins[1] -= 16; mins[1] -= 16;
mins[2] -= 48; mins[2] -= 48;
} }
new = [entity_classes_i classForName: new =[entity_classes_i classForName:
[self valueForQKey: "classname"]]; [self valueForQKey:"classname"]];
if (new) if (new)
v = [new mins]; v =[new mins];
else else
v = vec3_origin; v = vec3_origin;
VectorSubtract (mins, v, org); VectorSubtract (mins, v, org);
sprintf (value, "%i %i %i",(int)org[0], (int)org[1], (int)org[2]); sprintf (value, "%i %i %i", (int) org[0], (int) org[1], (int) org[2]);
[self setKey:"origin" toValue: value]; [self setKey: "origin" toValue:value];
} }
for (e=epairs ; e ; e=e->next) for (e = epairs; e; e = e->next)
fprintf (f,"\"%s\"\t\"%s\"\n", e->key, e->value); fprintf (f, "\"%s\"\t\"%s\"\n", e->key, e->value);
// fixed size entities don't save out brushes // fixed size entities don't save out brushes
if ( modifiable ) if (modifiable) {
{ for (i = 0; i <[self count]; i++)
for (i = 0 ; i < [self count]; i++) [[self objectAtIndex: i] writeToFILE: f region:reg];
[[self objectAtIndex: i] writeToFILE: f region: reg];
} }
fprintf (f,"}\n"); fprintf (f, "}\n");
if (temporg) if (temporg)
[self setKey: "angle" toValue: oldang]; [self setKey: "angle" toValue:oldang];
return self; return self;
} }

View file

@ -11,7 +11,7 @@
@implementation EntityClass @implementation EntityClass
static int static int
parse_vector (script_t *script, vec3_t vec) parse_vector (script_t * script, vec3_t vec)
{ {
int r; int r;
@ -41,7 +41,8 @@ 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 // /*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; const char *t;
size_t len; size_t len;
@ -50,7 +51,7 @@ parse_vector (script_t *script, vec3_t vec)
[super init]; [super init];
text += strlen("/*QUAKED "); text += strlen ("/*QUAKED ");
script = Script_New (); script = Script_New ();
Script_Start (script, filename, text); Script_Start (script, filename, text);
@ -93,8 +94,7 @@ parse_vector (script_t *script, vec3_t vec)
Script_GetToken (script, 0); Script_GetToken (script, 0);
// find the length until close comment // 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 // copy the comment block out
len = t - text; len = t - text;
@ -105,38 +105,38 @@ parse_vector (script_t *script, vec3_t vec)
return self; return self;
} }
- (esize_t)esize -(esize_t) esize
{ {
return esize; return esize;
} }
- (char *)classname -(char *) classname
{ {
return name; return name;
} }
- (float *)mins -(float *) mins
{ {
return mins; return mins;
} }
- (float *)maxs -(float *) maxs
{ {
return maxs; return maxs;
} }
- (float *)drawColor -(float *) drawColor
{ {
return color; return color;
} }
- (char *)comments -(char *) comments
{ {
return comments; return comments;
} }
- (char *)flagName: (unsigned)flagnum -(char *) flagName:(unsigned) flagnum
{ {
if (flagnum >= MAX_FLAGS) if (flagnum >= MAX_FLAGS)
Sys_Error ("EntityClass flagName: bad number"); Sys_Error ("EntityClass flagName: bad number");
@ -144,31 +144,27 @@ parse_vector (script_t *script, vec3_t vec)
} }
@end @end
//=========================================================================== //===========================================================================
@implementation EntityClassList @implementation EntityClassList
/* /*
================= =================
insertEC: insertEC:
================= =================
*/ */
- (void)insertEC: ec - (void) insertEC:ec
{ {
char *name; char *name;
int i; int i;
name = [ec classname]; name =[ec classname];
for (i=0 ; i<[self count] ; i++) for (i = 0; i <[self count]; i++) {
{ if (strcasecmp (name,[[self objectAtIndex:i] classname]) < 0) {
if (strcasecmp (name, [[self objectAtIndex: i] classname]) < 0)
{
[self insertObject: ec atIndex:i]; [self insertObject: ec atIndex:i];
return; return;
} }
} }
[self addObject: ec]; [self addObject:ec];
} }
@ -177,7 +173,7 @@ insertEC:
scanFile scanFile
================= =================
*/ */
- (void)scanFile: (char *)filename -(void) scanFile:(char *) filename
{ {
int size, line; int size, line;
char *data; char *data;
@ -186,7 +182,7 @@ scanFile
char path[1024]; char path[1024];
QFile *file; QFile *file;
sprintf (path,"%s/%s", source_path, filename); sprintf (path, "%s/%s", source_path, filename);
file = Qopen (path, "rt"); file = Qopen (path, "rt");
if (!file) if (!file)
@ -198,12 +194,12 @@ scanFile
Qclose (file); Qclose (file);
line = 1; line = 1;
for (i=0 ; i<size ; i++) { for (i = 0; i < size; i++) {
if (!strncmp(data+i, "/*QUAKED",8)) { if (!strncmp (data + i, "/*QUAKED", 8)) {
cl = [[EntityClass alloc] initFromText: (data + i) cl =[[EntityClass alloc] initFromText:(data + i)
source: va ("%s:%d", filename, line)]; source:va ("%s:%d", filename, line)];
if (cl) if (cl)
[self insertEC: cl]; [self insertEC:cl];
} else if (data[i] == '\n') { } else if (data[i] == '\n') {
line++; line++;
} }
@ -218,24 +214,24 @@ scanFile
scanDirectory scanDirectory
================= =================
*/ */
- (void)scanDirectory -(void) scanDirectory
{ {
int count, i; int count, i;
struct dirent **namelist, *ent; struct dirent **namelist, *ent;
[self removeAllObjects]; [self removeAllObjects];
count = scandir(source_path, &namelist, NULL, NULL); count = scandir (source_path, &namelist, NULL, NULL);
for (i=0 ; i<count ; i++) for (i = 0; i < count; i++) {
{
int len; int len;
ent = namelist[i]; ent = namelist[i];
len = strlen (ent->d_name); len = strlen (ent->d_name);
if (len <= 3) if (len <= 3)
continue; continue;
if (!strcmp (ent->d_name+len-3,".qc")) if (!strcmp (ent->d_name + len - 3, ".qc"))
[self scanFile: ent->d_name]; [self scanFile:ent->d_name];
} }
} }
@ -243,7 +239,7 @@ scanDirectory
id entity_classes_i; id entity_classes_i;
- initForSourceDirectory: (char *)path -initForSourceDirectory:(char *) path
{ {
[super init]; [super init];
@ -252,22 +248,22 @@ id entity_classes_i;
entity_classes_i = self; entity_classes_i = self;
nullclass = [[EntityClass alloc] nullclass =[[EntityClass alloc]
initFromText: "/*QUAKED UNKNOWN_CLASS (0 0.5 0) ?*/" initFromText: "/*QUAKED UNKNOWN_CLASS (0 0.5 0) ?*/" source:va ("%s:%d", __FILE__,
source: va ("%s:%d", __FILE__, __LINE__ - 1)]; __LINE__ -
1)];
return self; return self;
} }
- (id)classForName: (char *)name -(id) classForName:(char *) name
{ {
int i; int i;
id o; id o;
for (i=0 ; i<[self count] ; i++) for (i = 0; i <[self count]; i++) {
{ o =[self objectAtIndex:i];
o = [self objectAtIndex: i]; if (!strcmp (name,[o classname]))
if (!strcmp (name,[o classname]) )
return o; return o;
} }
@ -276,4 +272,3 @@ id entity_classes_i;
@end @end

View file

@ -10,15 +10,14 @@ id inspcontrol_i;
@implementation InspectorControl @implementation InspectorControl
- awakeFromNib -awakeFromNib {
{
inspcontrol_i = self; inspcontrol_i = self;
currentInspectorType = -1; currentInspectorType = -1;
contentList = [[NSArray alloc] init]; contentList =[[NSArray alloc] init];
windowList = [[NSArray alloc] init]; windowList =[[NSArray alloc] init];
itemList = [[NSArray alloc] init]; itemList =[[NSArray alloc] init];
// ADD NEW INSPECTORS HERE... // ADD NEW INSPECTORS HERE...
@ -61,7 +60,7 @@ id inspcontrol_i;
[inspectorView_i setAutoresizesSubviews:YES]; [inspectorView_i setAutoresizesSubviews:YES];
inspectorSubview_i = [contentList objectAtIndex:i_project]; inspectorSubview_i =[contentList objectAtIndex:i_project];
[inspectorView_i addSubview:inspectorSubview_i]; [inspectorView_i addSubview:inspectorSubview_i];
currentInspectorType = -1; currentInspectorType = -1;
@ -75,11 +74,11 @@ id inspcontrol_i;
// Sent by the PopUpList in the Inspector // Sent by the PopUpList in the Inspector
// Each cell in the PopUpList must have the correct tag // 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]]; [self changeInspectorTo:[cell tag]];
return self; return self;
} }
@ -87,7 +86,7 @@ id inspcontrol_i;
// //
// Change to specific Inspector // Change to specific Inspector
// //
- changeInspectorTo:(insp_e)which -changeInspectorTo:(insp_e) which
{ {
id newView; id newView;
NSRect r; NSRect r;
@ -98,30 +97,31 @@ id inspcontrol_i;
return self; return self;
currentInspectorType = which; currentInspectorType = which;
newView = [contentList objectAtIndex:which]; newView =[contentList objectAtIndex:which];
cell = [itemList objectAtIndex:which]; // set PopUpButton title cell =[itemList objectAtIndex:which];// set PopUpButton title
[popUpButton_i setTitle:[cell title]]; [popUpButton_i setTitle:[cell title]];
[inspectorView_i replaceSubview:inspectorSubview_i with:newView]; [inspectorView_i replaceSubview: inspectorSubview_i with:newView];
r = [inspectorView_i frame]; r =[inspectorView_i frame];
inspectorSubview_i = newView; inspectorSubview_i = newView;
[inspectorSubview_i setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [inspectorSubview_i setAutoresizingMask:NSViewWidthSizable |
NSViewHeightSizable];
r.size.width -= 4; r.size.width -= 4;
r.size.height -= 4; r.size.height -= 4;
[inspectorSubview_i setFrameSize:r.size]; [inspectorSubview_i setFrameSize:r.size];
[inspectorSubview_i lockFocus]; [inspectorSubview_i lockFocus];
f = [inspectorSubview_i bounds]; f =[inspectorSubview_i bounds];
PSsetgray(NSLightGray); PSsetgray (NSLightGray);
NSRectFill(f); NSRectFill (f);
[inspectorSubview_i unlockFocus]; [inspectorSubview_i unlockFocus];
[inspectorView_i display]; [inspectorView_i display];
return self; return self;
} }
- (insp_e)getCurrentInspector -(insp_e) getCurrentInspector
{ {
return currentInspectorType; return currentInspectorType;
} }

View file

@ -7,13 +7,12 @@
id keypairview_i; id keypairview_i;
@implementation KeypairView @implementation KeypairView
/* /*
================== ==================
initWithFrame: initWithFrame:
================== ==================
*/ */
- initWithFrame:(NSRect)frameRect - initWithFrame:(NSRect) frameRect
{ {
[super initWithFrame:frameRect]; [super initWithFrame:frameRect];
keypairview_i = self; keypairview_i = self;
@ -21,74 +20,72 @@ initWithFrame:
} }
- calcViewSize -calcViewSize
{ {
NSRect b; NSRect b;
NSPoint pt; NSPoint pt;
int count; int count;
id ent; id ent;
ent = [map_i currentEntity]; ent =[map_i currentEntity];
count = [ent numPairs]; count =[ent numPairs];
//XXX[_super_view setFlipped: YES]; // XXX[_super_view setFlipped: YES];
b = [_super_view bounds]; b =[_super_view bounds];
b.size.height = LINEHEIGHT*count + SPACING; b.size.height = LINEHEIGHT * count + SPACING;
[self setBounds: b]; [self setBounds:b];
pt.x = pt.y = 0; pt.x = pt.y = 0;
[self scrollPoint: pt]; [self scrollPoint:pt];
return self; return self;
} }
- drawSelf:(const NSRect *)rects :(int)rectCount -drawSelf: (const NSRect *) rects:(int) rectCount
{ {
epair_t *pair; epair_t *pair;
int y; int y;
//XXX PSsetgray(NSGrayComponent(NS_COLORLTGRAY)); // XXX PSsetgray(NSGrayComponent(NS_COLORLTGRAY));
PSrectfill(0,0,_bounds.size.width,_bounds.size.height); PSrectfill (0, 0, _bounds.size.width, _bounds.size.height);
//XXX PSselectfont("Helvetica-Bold",FONTSIZE); // XXX PSselectfont("Helvetica-Bold",FONTSIZE);
PSrotate(0); PSrotate (0);
PSsetgray(0); PSsetgray (0);
pair = [[map_i currentEntity] epairs]; pair =[[map_i currentEntity] epairs];
y = _bounds.size.height - LINEHEIGHT; y = _bounds.size.height - LINEHEIGHT;
for ( ; pair ; pair=pair->next) for (; pair; pair = pair->next) {
{ PSmoveto (SPACING, y);
PSmoveto(SPACING, y); PSshow (pair->key);
PSshow(pair->key); PSmoveto (100, y);
PSmoveto(100, y); PSshow (pair->value);
PSshow(pair->value);
y -= LINEHEIGHT; y -= LINEHEIGHT;
} }
PSstroke(); PSstroke ();
return self; return self;
} }
- (void)mouseDown:(NSEvent *)theEvent -(void) mouseDown:(NSEvent *) theEvent
{ {
NSPoint loc; NSPoint loc;
int i; int i;
epair_t *p; epair_t *p;
loc = [theEvent locationInWindow]; loc =[theEvent locationInWindow];
loc = [self convertPoint:loc fromView:NULL]; loc =[self convertPoint: loc fromView:NULL];
i = (_bounds.size.height - loc.y - 4) / LINEHEIGHT; i = (_bounds.size.height - loc.y - 4) / LINEHEIGHT;
p = [[map_i currentEntity] epairs]; p =[[map_i currentEntity] epairs];
while ( i ) while (i) {
{ p = p->next;
p=p->next;
if (!p) if (!p)
return; return;
i--; i--;
} }
if (p) if (p)
[things_i setSelectedKey: p]; [things_i setSelectedKey:p];
return; return;
} }

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,6 @@
#include "PopScrollView.h" #include "PopScrollView.h"
@implementation PopScrollView @implementation PopScrollView
/* /*
==================== ====================
initWithFrame: button: initWithFrame: button:
@ -10,57 +9,52 @@ initWithFrame: button:
Initizes a scroll view with a button at it's lower right corner Initizes a scroll view with a button at it's lower right corner
==================== ====================
*/ */
- initWithFrame:(NSRect)
frameRect button1:b1 button2:b2 {
[super initWithFrame:frameRect];
- initWithFrame:(NSRect)frameRect button1:b1 button2:b2 [self addSubview:b1];
{ [self addSubview:b2];
[super initWithFrame: frameRect];
[self addSubview: b1];
[self addSubview: b2];
button1 = b1; button1 = b1;
button2 = b2; button2 = b2;
[self setHasHorizontalScroller: YES]; [self setHasHorizontalScroller:YES];
[self setHasVerticalScroller: YES]; [self setHasVerticalScroller:YES];
[self setBorderType: NSBezelBorder]; [self setBorderType:NSBezelBorder];
return self; return self;
} }
/* /*
================ ================
tile tile
Adjust the size for the pop up scale menu Adjust the size for the pop up scale menu
================= =================
*/ */ -tile
- tile
{ {
NSRect scrollerframe; NSRect scrollerframe;
NSRect buttonframe, buttonframe2; NSRect buttonframe, buttonframe2;
NSRect newframe; NSRect newframe;
[super tile]; [super tile];
buttonframe = [button1 frame]; buttonframe =[button1 frame];
buttonframe2 = [button2 frame]; buttonframe2 =[button2 frame];
scrollerframe = [_horizScroller frame]; scrollerframe =[_horizScroller frame];
newframe.origin.y = scrollerframe.origin.y; newframe.origin.y = scrollerframe.origin.y;
newframe.origin.x = scrollerframe.size.width - buttonframe.size.width; newframe.origin.x = scrollerframe.size.width - buttonframe.size.width;
newframe.size.width = buttonframe.size.width; newframe.size.width = buttonframe.size.width;
newframe.size.height = scrollerframe.size.height; newframe.size.height = scrollerframe.size.height;
scrollerframe.size.width -= newframe.size.width; scrollerframe.size.width -= newframe.size.width;
[button1 setFrame: newframe]; [button1 setFrame:newframe];
newframe.size.width = buttonframe2.size.width; newframe.size.width = buttonframe2.size.width;
newframe.origin.x -= newframe.size.width; newframe.origin.x -= newframe.size.width;
[button2 setFrame: newframe]; [button2 setFrame:newframe];
scrollerframe.size.width -= newframe.size.width; scrollerframe.size.width -= newframe.size.width;
[_horizScroller setFrame: scrollerframe]; [_horizScroller setFrame:scrollerframe];
return self; return self;
} }
@ -84,4 +78,3 @@ Adjust the size for the pop up scale menu
@end @end

View file

@ -8,80 +8,86 @@ id preferences_i;
#define DEFOWNER "QuakeEd2" #define DEFOWNER "QuakeEd2"
float lightaxis[3] = {1, 0.6, 0.75}; float lightaxis[3] = { 1, 0.6, 0.75 };
@implementation Preferences @implementation Preferences
- init -init
{ {
[super init]; [super init];
preferences_i = self; preferences_i = self;
return self; return self;
} }
int _atoi (char *c) int
_atoi (char *c)
{ {
if (!c) if (!c)
return 0; return 0;
return atoi(c); return atoi (c);
} }
int _atof (char *c) int
_atof (char *c)
{ {
if (!c) if (!c)
return 0; return 0;
return atof(c); return atof (c);
} }
void WriteNumericDefault (char *name, float value) void
WriteNumericDefault (char *name, float value)
{ {
char str[128]; char str[128];
sprintf (str,"%f", value); sprintf (str, "%f", value);
//XXX NSWriteDefault (DEFOWNER, name, str); // XXX NSWriteDefault (DEFOWNER, name, str);
} }
void WriteStringDefault (char *name, char *value)
void
WriteStringDefault (char *name, char *value)
{ {
//XXX NSWriteDefault (DEFOWNER, name, value); // XXX NSWriteDefault (DEFOWNER, name, value);
} }
// //
// Read in at start of program // Read in at start of program
// //
- readDefaults -readDefaults
{ {
char *string = ""; char *string = "";
float value = 0; float value = 0;
//XXX string = (char *)NSGetDefaultValue(DEFOWNER,"ProjectPath"); // XXX string = (char *)NSGetDefaultValue(DEFOWNER,"ProjectPath");
[self setProjectPath: string]; [self setProjectPath:string];
//XXX string = (char *)NSGetDefaultValue(DEFOWNER,"BspSoundPath"); // XXX string = (char *)NSGetDefaultValue(DEFOWNER,"BspSoundPath");
[self setBspSoundPath:string]; [self setBspSoundPath:string];
//XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"ShowBSPOutput")); // XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"ShowBSPOutput"));
[self setShowBSP:value]; [self setShowBSP:value];
//XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"OffsetBrushCopy")); // XXX value = _atoi((char
// *)NSGetDefaultValue(DEFOWNER,"OffsetBrushCopy"));
[self setBrushOffset:value]; [self setBrushOffset:value];
//XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"StartWad")); // XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"StartWad"));
[self setStartWad:value]; [self setStartWad:value];
//XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Xlight")); // XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Xlight"));
[self setXlight:value]; [self setXlight:value];
//XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Ylight")); // XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Ylight"));
[self setYlight:value]; [self setYlight:value];
//XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Zlight")); // XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Zlight"));
[self setZlight:value]; [self setZlight:value];
return self; return self;
} }
- setProjectPath:(char *)path -setProjectPath:(char *) path
{ {
if (!path) if (!path)
path = ""; path = "";
@ -91,14 +97,15 @@ void WriteStringDefault (char *name, char *value)
return self; return self;
} }
- setCurrentProject:sender -setCurrentProject:sender
{ {
[startproject_i setStringValue: [NSString stringWithCString:[project_i currentProjectFile]]]; [startproject_i setStringValue: [NSString stringWithCString:[project_i
[self UIChanged: self]; currentProjectFile]]];
[self UIChanged:self];
return self; return self;
} }
- (char *)getProjectPath -(char *) getProjectPath
{ {
return projectpath; return projectpath;
} }
@ -111,30 +118,28 @@ void WriteStringDefault (char *name, char *value)
// //
// Set the BSP sound using an OpenPanel // Set the BSP sound using an OpenPanel
// //
- setBspSound:sender -setBspSound:sender
{ {
id panel; id panel;
NSString *types[] = {@"snd"}; NSString *types[] = { @"snd" };
int rtn; int rtn;
NSArray *filenames; NSArray *filenames;
char path[1024], file[64]; char path[1024], file[64];
panel = [NSOpenPanel new]; panel =[NSOpenPanel new];
//XXX ExtractFilePath (bspSound, path); // XXX ExtractFilePath (bspSound, path);
//XXX ExtractFileBase (bspSound, file); // XXX ExtractFileBase (bspSound, file);
rtn = [panel rtn =[panel runModalForDirectory: [NSString stringWithCString:path]
runModalForDirectory:[NSString stringWithCString:path]
file: [NSString stringWithCString:file] file: [NSString stringWithCString:file]
types: [NSArray arrayWithObjects:types count:1]]; types: [NSArray arrayWithObjects: types count:1]];
if (rtn) if (rtn) {
{ filenames =[panel filenames];
filenames = [panel filenames]; strcpy (bspSound,[[panel directory] cString]);
strcpy(bspSound,[[panel directory] cString]); strcat (bspSound, "/");
strcat(bspSound,"/"); strcat (bspSound,[[filenames objectAtIndex:0] cString]);
strcat(bspSound, [[filenames objectAtIndex:0] cString]);
[self setBspSoundPath:bspSound]; [self setBspSoundPath:bspSound];
[self playBspSound]; [self playBspSound];
} }
@ -146,7 +151,7 @@ void WriteStringDefault (char *name, char *value)
// //
// Play the BSP sound // Play the BSP sound
// //
- playBspSound -playBspSound
{ {
[bspSound_i play]; [bspSound_i play];
return self; return self;
@ -156,22 +161,21 @@ void WriteStringDefault (char *name, char *value)
// //
// Set the bspSound path // Set the bspSound path
// //
- setBspSoundPath:(char *)path -setBspSoundPath:(char *) path
{ {
if (!path) if (!path)
path = ""; path = "";
strcpy(bspSound,path); strcpy (bspSound, path);
if (bspSound_i) if (bspSound_i)
[bspSound_i release]; [bspSound_i release];
bspSound_i = [[NSSound alloc] initWithContentsOfFile:[NSString stringWithCString:bspSound]]; bspSound_i =[[NSSound alloc] initWithContentsOfFile: [NSString stringWithCString:bspSound]];
if (!bspSound_i) if (!bspSound_i) {
{
strcpy (bspSound, "/NextLibrary/Sounds/Funk.snd"); strcpy (bspSound, "/NextLibrary/Sounds/Funk.snd");
bspSound_i = [[NSSound alloc] initWithContentsOfFile:[NSString stringWithCString:bspSound]]; bspSound_i =[[NSSound alloc] initWithContentsOfFile: [NSString stringWithCString:bspSound]];
} }
[bspSoundField_i setStringValue:[NSString stringWithCString:bspSound]]; [bspSoundField_i setStringValue: [NSString stringWithCString:bspSound]];
WriteStringDefault ("BspSoundPath", bspSound); WriteStringDefault ("BspSoundPath", bspSound);
@ -185,7 +189,7 @@ void WriteStringDefault (char *name, char *value)
// //
// Set the state // Set the state
// //
- setShowBSP:(int)state -setShowBSP:(int) state
{ {
showBSP = state; showBSP = state;
[showBSP_i setIntValue:state]; [showBSP_i setIntValue:state];
@ -197,7 +201,7 @@ void WriteStringDefault (char *name, char *value)
// //
// Get the state // Get the state
// //
- (int)getShowBSP -(int) getShowBSP
{ {
return showBSP; return showBSP;
} }
@ -210,7 +214,7 @@ void WriteStringDefault (char *name, char *value)
// //
// Set the state // Set the state
// //
- setBrushOffset:(int)state -setBrushOffset:(int) state
{ {
brushOffset = state; brushOffset = state;
[brushOffset_i setIntValue:state]; [brushOffset_i setIntValue:state];
@ -221,7 +225,7 @@ void WriteStringDefault (char *name, char *value)
// //
// Get the state // Get the state
// //
- (int)getBrushOffset -(int) getBrushOffset
{ {
return brushOffset; return brushOffset;
} }
@ -230,19 +234,19 @@ void WriteStringDefault (char *name, char *value)
// StartWad // StartWad
//=============================================== //===============================================
- setStartWad:(int)value // set start wad (0-2) -setStartWad:(int) value // set start wad (0-2)
{ {
startwad = value; startwad = value;
if (startwad<0 || startwad>2) if (startwad < 0 || startwad > 2)
startwad = 0; startwad = 0;
[startwad_i selectCellAtRow:startwad column: 0]; [startwad_i selectCellAtRow: startwad column:0];
WriteNumericDefault ("StartWad", value); WriteNumericDefault ("StartWad", value);
return self; return self;
} }
- (int)getStartWad -(int) getStartWad
{ {
return startwad; return startwad;
} }
@ -254,7 +258,7 @@ void WriteStringDefault (char *name, char *value)
// //
// Set the state // Set the state
// //
- setXlight:(float)value -setXlight:(float) value
{ {
xlight = value; xlight = value;
if (xlight < 0.25 || xlight > 1) if (xlight < 0.25 || xlight > 1)
@ -264,7 +268,8 @@ void WriteStringDefault (char *name, char *value)
WriteNumericDefault ("Xlight", xlight); WriteNumericDefault ("Xlight", xlight);
return self; return self;
} }
- setYlight:(float)value
-setYlight:(float) value
{ {
ylight = value; ylight = value;
if (ylight < 0.25 || ylight > 1) if (ylight < 0.25 || ylight > 1)
@ -274,7 +279,8 @@ void WriteStringDefault (char *name, char *value)
WriteNumericDefault ("Ylight", ylight); WriteNumericDefault ("Ylight", ylight);
return self; return self;
} }
- setZlight:(float)value
-setZlight:(float) value
{ {
zlight = value; zlight = value;
if (zlight < 0.25 || zlight > 1) if (zlight < 0.25 || zlight > 1)
@ -288,17 +294,19 @@ 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,20 +318,20 @@ UIChanged
Grab all the current UI state Grab all the current UI state
============ ============
*/ */
-UIChanged: sender -UIChanged:sender
{ {
qprintf ("defaults updated"); qprintf ("defaults updated");
[self setProjectPath: (char *)[startproject_i stringValue]]; [self setProjectPath:(char *)[startproject_i stringValue]];
[self setBspSoundPath: (char *)[bspSoundField_i stringValue]]; [self setBspSoundPath:(char *)[bspSoundField_i stringValue]];
[self setShowBSP: [showBSP_i intValue]]; [self setShowBSP:[showBSP_i intValue]];
[self setBrushOffset: [brushOffset_i intValue]]; [self setBrushOffset:[brushOffset_i intValue]];
[self setStartWad: [startwad_i selectedRow]]; [self setStartWad:[startwad_i selectedRow]];
[self setXlight: [xlight_i floatValue]]; [self setXlight:[xlight_i floatValue]];
[self setYlight: [ylight_i floatValue]]; [self setYlight:[ylight_i floatValue]];
[self setZlight: [zlight_i floatValue]]; [self setZlight:[zlight_i floatValue]];
[map_i makeGlobalPerform: @selector(flushTextures)]; [map_i makeGlobalPerform:@selector (flushTextures)];
[quakeed_i updateAll]; [quakeed_i updateAll];
return self; return self;

View file

@ -21,7 +21,7 @@ id project_i;
@implementation Project @implementation Project
- init -init
{ {
project_i = self; project_i = self;
@ -33,86 +33,80 @@ id project_i;
// Project code // Project code
// //
//=========================================================== //===========================================================
- initVars -initVars
{ {
char *s; char *s;
s = [preferences_i getProjectPath]; s =[preferences_i getProjectPath];
//XXX StripFilename(s); // XXX StripFilename(s);
strcpy(path_basepath,s); strcpy (path_basepath, s);
strcpy(path_progdir,s); strcpy (path_progdir, s);
strcat(path_progdir,"/"SUBDIR_ENT); strcat (path_progdir, "/" SUBDIR_ENT);
strcpy(path_mapdirectory,s); strcpy (path_mapdirectory, s);
strcat(path_mapdirectory,"/"SUBDIR_MAPS); // source dir strcat (path_mapdirectory, "/" SUBDIR_MAPS); // source dir
strcpy(path_finalmapdir,s); strcpy (path_finalmapdir, s);
strcat(path_finalmapdir,"/"SUBDIR_MAPS); // dest dir strcat (path_finalmapdir, "/" SUBDIR_MAPS); // dest dir
[basepathinfo_i setStringValue:[NSString stringWithCString:s]]; // in Project Inspector [basepathinfo_i setStringValue: [NSString stringWithCString:s]];
// in Project Inspector
#if 0 #if 0
if ((s = [projectInfo getStringFor:BASEPATHKEY])) if ((s =[projectInfo getStringFor:BASEPATHKEY])) {
{ strcpy (path_basepath, s);
strcpy(path_basepath,s);
strcpy(path_progdir,s); strcpy (path_progdir, s);
strcat(path_progdir,"/"SUBDIR_ENT); strcat (path_progdir, "/" SUBDIR_ENT);
strcpy(path_mapdirectory,s); strcpy (path_mapdirectory, s);
strcat(path_mapdirectory,"/"SUBDIR_MAPS); // source dir strcat (path_mapdirectory, "/" SUBDIR_MAPS); // source dir
strcpy(path_finalmapdir,s); strcpy (path_finalmapdir, s);
strcat(path_finalmapdir,"/"SUBDIR_MAPS); // dest dir strcat (path_finalmapdir, "/" SUBDIR_MAPS); // dest dir
[basepathinfo_i setStringValue:s]; // in Project Inspector [basepathinfo_i setStringValue:s];
// in Project Inspector
} }
#endif #endif
if ((s = [projectInfo getStringFor:BSPFULLVIS])) if ((s =[projectInfo getStringFor:BSPFULLVIS])) {
{ strcpy (string_fullvis, s);
strcpy(string_fullvis,s); changeString ('@', '\"', string_fullvis);
changeString('@','\"',string_fullvis);
} }
if ((s = [projectInfo getStringFor:BSPFASTVIS])) if ((s =[projectInfo getStringFor:BSPFASTVIS])) {
{ strcpy (string_fastvis, s);
strcpy(string_fastvis,s); changeString ('@', '\"', string_fastvis);
changeString('@','\"',string_fastvis);
} }
if ((s = [projectInfo getStringFor:BSPNOVIS])) if ((s =[projectInfo getStringFor:BSPNOVIS])) {
{ strcpy (string_novis, s);
strcpy(string_novis,s); changeString ('@', '\"', string_novis);
changeString('@','\"',string_novis);
} }
if ((s = [projectInfo getStringFor:BSPRELIGHT])) if ((s =[projectInfo getStringFor:BSPRELIGHT])) {
{ strcpy (string_relight, s);
strcpy(string_relight,s); changeString ('@', '\"', string_relight);
changeString('@','\"',string_relight);
} }
if ((s = [projectInfo getStringFor:BSPLEAKTEST])) if ((s =[projectInfo getStringFor:BSPLEAKTEST])) {
{ strcpy (string_leaktest, s);
strcpy(string_leaktest,s); changeString ('@', '\"', string_leaktest);
changeString('@','\"',string_leaktest);
} }
if ((s = [projectInfo getStringFor:BSPENTITIES])) if ((s =[projectInfo getStringFor:BSPENTITIES])) {
{ strcpy (string_entities, s);
strcpy(string_entities,s); changeString ('@', '\"', string_entities);
changeString('@','\"', string_entities);
} }
// Build list of wads // Build list of wads
wadList = [projectInfo parseMultipleFrom:WADSKEY]; wadList =[projectInfo parseMultipleFrom:WADSKEY];
// Build list of maps & descriptions // Build list of maps & descriptions
mapList = [projectInfo parseMultipleFrom:MAPNAMESKEY]; mapList =[projectInfo parseMultipleFrom:MAPNAMESKEY];
descList = [projectInfo parseMultipleFrom:DESCKEY]; descList =[projectInfo parseMultipleFrom:DESCKEY];
[self changeChar:'_' to:' ' in:descList]; [self changeChar: '_' to: ' ' in:descList];
[self initProjSettings]; [self initProjSettings];
@ -122,14 +116,14 @@ id project_i;
// //
// Init Project Settings fields // Init Project Settings fields
// //
- initProjSettings -initProjSettings
{ {
[pis_basepath_i setStringValue:[NSString stringWithCString:path_basepath]]; [pis_basepath_i setStringValue: [NSString stringWithCString:path_basepath]];
[pis_fullvis_i setStringValue:[NSString stringWithCString:string_fullvis]]; [pis_fullvis_i setStringValue: [NSString stringWithCString:string_fullvis]];
[pis_fastvis_i setStringValue:[NSString stringWithCString:string_fastvis]]; [pis_fastvis_i setStringValue: [NSString stringWithCString:string_fastvis]];
[pis_novis_i setStringValue:[NSString stringWithCString:string_novis]]; [pis_novis_i setStringValue: [NSString stringWithCString:string_novis]];
[pis_relight_i setStringValue:[NSString stringWithCString:string_relight]]; [pis_relight_i setStringValue: [NSString stringWithCString:string_relight]];
[pis_leaktest_i setStringValue:[NSString stringWithCString:string_leaktest]]; [pis_leaktest_i setStringValue: [NSString stringWithCString:string_leaktest]];
return self; return self;
} }
@ -137,38 +131,38 @@ id project_i;
// //
// Add text to the BSP Output window // Add text to the BSP Output window
// //
- addToOutput:(char *)string -addToOutput:(char *) string
{ {
int end; int end;
end = [BSPoutput_i textLength]; end =[BSPoutput_i textLength];
[BSPoutput_i replaceCharactersInRange:NSMakeRange (end, 0) withString:[NSString stringWithCString:string]]; [BSPoutput_i replaceCharactersInRange: NSMakeRange (end, 0) withString: [NSString stringWithCString:string]];
end = [BSPoutput_i textLength]; end =[BSPoutput_i textLength];
[BSPoutput_i setSelectedRange:NSMakeRange (end, 0)]; [BSPoutput_i setSelectedRange:NSMakeRange (end, 0)];
//XXX [BSPoutput_i scrollSelToVisible]; // XXX [BSPoutput_i scrollSelToVisible];
return self; return self;
} }
- clearBspOutput:sender -clearBspOutput:sender
{ {
int end; int end;
end = [BSPoutput_i textLength]; end =[BSPoutput_i textLength];
[BSPoutput_i replaceCharactersInRange:NSMakeRange (0, end) withString:@""]; [BSPoutput_i replaceCharactersInRange: NSMakeRange (0, end) withString:@""];
return self; return self;
} }
- print -print
{ {
//XXX [BSPoutput_i printPSCode:self]; // XXX [BSPoutput_i printPSCode:self];
return self; return self;
} }
- initProject -initProject
{ {
[self parseProjectFile]; [self parseProjectFile];
if (projectInfo == NULL) if (projectInfo == NULL)
@ -187,17 +181,18 @@ id project_i;
// //
// 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 i;
int max; int max;
char *string; char *string;
max = [obj count]; max =[obj count];
for (i = 0;i < max;i++) for (i = 0; i < max; i++) {
{ string =[obj elementAt:i];
string = [obj elementAt:i]; changeString (f, t, string);
changeString(f,t,string);
} }
return self; return self;
} }
@ -206,7 +201,7 @@ id project_i;
// Fill the QuakeEd Maps or wads browser // Fill the QuakeEd Maps or wads browser
// (Delegate method - delegated in Interface Builder) // (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; id cell, list;
int max; int max;
@ -217,19 +212,17 @@ id project_i;
list = mapList; list = mapList;
else if (sender == pis_wads_i) else if (sender == pis_wads_i)
list = wadList; list = wadList;
else else {
{
list = nil; list = nil;
Sys_Error ("Project: unknown browser to fill"); Sys_Error ("Project: unknown browser to fill");
} }
max = [list count]; max =[list count];
for (i = 0 ; i<max ; i++) for (i = 0; i < max; i++) {
{ name =[list elementAt:i];
name = [list elementAt:i];
[matrix addRow]; [matrix addRow];
cell = [matrix cellAtRow:i column:0]; cell =[matrix cellAtRow: i column:0];
[cell setStringValue:[NSString stringWithCString:name]]; [cell setStringValue: [NSString stringWithCString:name]];
[cell setLeaf:YES]; [cell setLeaf:YES];
[cell setLoaded:YES]; [cell setLoaded:YES];
} }
@ -239,31 +232,30 @@ id project_i;
// //
// Clicked on a map name or description! // Clicked on a map name or description!
// //
- clickedOnMap:sender -clickedOnMap:sender
{ {
id matrix; id matrix;
int row; int row;
char fname[1024]; char fname[1024];
id panel; id panel;
matrix = [sender matrixInColumn:0]; matrix =[sender matrixInColumn:0];
row = [matrix selectedRow]; row =[matrix selectedRow];
sprintf(fname,"%s/%s.map",path_mapdirectory, sprintf (fname, "%s/%s.map", path_mapdirectory, (char *)[mapList elementAt:row]);
(char *)[mapList elementAt:row]);
panel = NSGetAlertPanel(@"Loading...", panel = NSGetAlertPanel (@"Loading...",
@"Loading map. Please wait.",NULL,NULL,NULL); @"Loading map. Please wait.", NULL, NULL, NULL);
[panel orderFront:NULL]; [panel orderFront:NULL];
[quakeed_i doOpen:fname]; [quakeed_i doOpen:fname];
[panel performClose:NULL]; [panel performClose:NULL];
//NSFreeAlertPanel(panel); // NSFreeAlertPanel(panel);
return self; return self;
} }
- setTextureWad: (char *)wf -setTextureWad:(char *) wf
{ {
int i, c; int i, c;
char *name; char *name;
@ -271,20 +263,18 @@ id project_i;
qprintf ("loading %s", wf); qprintf ("loading %s", wf);
// set the row in the settings inspector wad browser // set the row in the settings inspector wad browser
c = [wadList count]; c =[wadList count];
for (i=0 ; i<c ; i++) for (i = 0; i < c; i++) {
{
name = (char *)[wadList elementAt:i]; name = (char *)[wadList elementAt:i];
if (!strcmp(name, wf)) if (!strcmp (name, wf)) {
{ [[pis_wads_i matrixInColumn: 0] selectCellAtRow: i column:0];
[[pis_wads_i matrixInColumn:0] selectCellAtRow: i column: 0];
break; break;
} }
} }
// update the texture inspector // update the texture inspector
[texturepalette_i initPaletteFromWadfile:wf ]; [texturepalette_i initPaletteFromWadfile:wf];
[[map_i objectAtIndex: 0] setKey:"wad" toValue: wf]; [[map_i objectAtIndex: 0] setKey: "wad" toValue:wf];
// [inspcontrol_i changeInspectorTo:i_textures]; // [inspcontrol_i changeInspectorTo:i_textures];
[quakeed_i updateAll]; [quakeed_i updateAll];
@ -295,17 +285,17 @@ id project_i;
// //
// Clicked on a wad name // Clicked on a wad name
// //
- clickedOnWad:sender -clickedOnWad:sender
{ {
id matrix; id matrix;
int row; int row;
char *name; char *name;
matrix = [sender matrixInColumn:0]; matrix =[sender matrixInColumn:0];
row = [matrix selectedRow]; row =[matrix selectedRow];
name = (char *)[wadList elementAt:row]; name = (char *)[wadList elementAt:row];
[self setTextureWad: name]; [self setTextureWad:name];
return self; return self;
} }
@ -314,20 +304,19 @@ id project_i;
// //
// Read in the <name>.QE_Project file // Read in the <name>.QE_Project file
// //
- parseProjectFile -parseProjectFile
{ {
char *path; char *path;
int rtn; int rtn;
path = [preferences_i getProjectPath]; path =[preferences_i getProjectPath];
if (!path || !path[0] || access(path,0)) if (!path || !path[0] || access (path, 0)) {
{ rtn = NSRunAlertPanel (@"Project Error!",
rtn = NSRunAlertPanel(@"Project Error!", @"A default project has not been found.\n",
@"A default project has not been found.\n" @"Open Project", NULL, NULL);
, @"Open Project", NULL, NULL);
if ([self openProject] == nil) if ([self openProject] == nil)
while (1) // can't run without a project while (1) // can't run without a project
[NSApp terminate: self]; [NSApp terminate:self];
return self; return self;
} }
@ -338,28 +327,28 @@ id project_i;
// //
// Loads and parses a project file // Loads and parses a project file
// //
- openProjectFile:(char *)path -openProjectFile:(char *) path
{ {
FILE *fp; FILE *fp;
struct stat s; struct stat s;
strcpy(path_projectinfo,path); strcpy (path_projectinfo, path);
projectInfo = NULL; projectInfo = NULL;
fp = fopen(path,"r+t"); fp = fopen (path, "r+t");
if (fp == NULL) if (fp == NULL)
return self; return self;
stat(path,&s); stat (path, &s);
lastModified = s.st_mtime; lastModified = s.st_mtime;
projectInfo = [(Dict *)[Dict alloc] initFromFile:fp]; projectInfo =[(Dict *)[Dict alloc] initFromFile:fp];
fclose(fp); fclose (fp);
return self; return self;
} }
- (char *)currentProjectFile -(char *) currentProjectFile
{ {
return path_projectinfo; return path_projectinfo;
} }
@ -367,25 +356,24 @@ id project_i;
// //
// Open a project file // Open a project file
// //
- openProject -openProject
{ {
char path[128]; char path[128];
id openpanel; id openpanel;
int rtn; int rtn;
NSString *projtypes[] ={ @"qpr"}; NSString *projtypes[] = { @"qpr" };
NSArray *filenames; NSArray *filenames;
const char *dir; const char *dir;
openpanel = [NSOpenPanel new]; openpanel =[NSOpenPanel new];
//[openpanel allowMultipleFiles:NO]; // [openpanel allowMultipleFiles:NO];
//[openpanel chooseDirectories:NO]; // [openpanel chooseDirectories:NO];
rtn = [openpanel runModalForTypes:[NSArray arrayWithObjects: projtypes count:1]]; rtn =[openpanel runModalForTypes: [NSArray arrayWithObjects: projtypes count:1]];
if (rtn == NSOKButton) if (rtn == NSOKButton) {
{ filenames =[openpanel filenames];
filenames = [openpanel filenames]; dir =[[openpanel directory] cString];
dir = [[openpanel directory] cString]; sprintf (path, "%s/%s", dir,[[filenames objectAtIndex:0] cString]);
sprintf (path, "%s/%s", dir, [[filenames objectAtIndex:0] cString]); strcpy (path_projectinfo, path);
strcpy(path_projectinfo,path);
[self openProjectFile:path]; [self openProjectFile:path];
return self; return self;
} }
@ -397,33 +385,33 @@ id project_i;
// //
// 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 i;
int max; int max;
char *s; char *s;
max = [obj count]; max =[obj count];
for (i = 0;i < max; i++) for (i = 0; i < max; i++) {
{
s = (char *)[obj elementAt:i]; s = (char *)[obj elementAt:i];
if (!strcmp(s,str)) if (!strcmp (s, str))
return 1; return 1;
} }
return 0; return 0;
} }
- (char *)getMapDirectory -(char *) getMapDirectory
{ {
return path_mapdirectory; return path_mapdirectory;
} }
- (char *)getFinalMapDirectory -(char *) getFinalMapDirectory
{ {
return path_finalmapdir; return path_finalmapdir;
} }
- (char *)getProgDirectory -(char *) getProgDirectory
{ {
return path_progdir; return path_progdir;
} }
@ -432,7 +420,7 @@ id project_i;
// //
// Return the WAD name for cmd-8 // Return the WAD name for cmd-8
// //
- (char *)getWAD8 -(char *) getWAD8
{ {
if (!path_wad8[0]) if (!path_wad8[0])
return NULL; return NULL;
@ -442,7 +430,7 @@ 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]) if (!path_wad9[0])
return NULL; return NULL;
@ -452,7 +440,7 @@ 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]) if (!path_wad0[0])
return NULL; return NULL;
@ -462,7 +450,7 @@ id project_i;
// //
// Return the FULLVIS cmd string // Return the FULLVIS cmd string
// //
- (char *)getFullVisCmd -(char *) getFullVisCmd
{ {
if (!string_fullvis[0]) if (!string_fullvis[0])
return NULL; return NULL;
@ -472,7 +460,7 @@ id project_i;
// //
// Return the FASTVIS cmd string // Return the FASTVIS cmd string
// //
- (char *)getFastVisCmd -(char *) getFastVisCmd
{ {
if (!string_fastvis[0]) if (!string_fastvis[0])
return NULL; return NULL;
@ -482,7 +470,7 @@ id project_i;
// //
// Return the NOVIS cmd string // Return the NOVIS cmd string
// //
- (char *)getNoVisCmd -(char *) getNoVisCmd
{ {
if (!string_novis[0]) if (!string_novis[0])
return NULL; return NULL;
@ -492,7 +480,7 @@ id project_i;
// //
// Return the RELIGHT cmd string // Return the RELIGHT cmd string
// //
- (char *)getRelightCmd -(char *) getRelightCmd
{ {
if (!string_relight[0]) if (!string_relight[0])
return NULL; return NULL;
@ -502,14 +490,14 @@ id project_i;
// //
// Return the LEAKTEST cmd string // Return the LEAKTEST cmd string
// //
- (char *)getLeaktestCmd -(char *) getLeaktestCmd
{ {
if (!string_leaktest[0]) if (!string_leaktest[0])
return NULL; return NULL;
return string_leaktest; return string_leaktest;
} }
- (char *)getEntitiesCmd -(char *) getEntitiesCmd
{ {
if (!string_entities[0]) if (!string_entities[0])
return NULL; return NULL;
@ -517,21 +505,18 @@ id project_i;
} }
@end @end
//==================================================== //====================================================
// C Functions // C Functions
//==================================================== //====================================================
// //
// Change a character to a different char in a string // 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) if (string[j] == cf)
string[j] = ct; string[j] = ct;
} }

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
#include <AppKit/AppKit.h> #include <AppKit/AppKit.h>
int int
main(int argc, const char *argv[]) main (int argc, const char *argv[])
{ {
return NSApplicationMain (argc, argv); return NSApplicationMain (argc, argv);
} }

File diff suppressed because it is too large Load diff

View file

@ -33,50 +33,48 @@
#define STORAGE_NTH(N) GNU_STORAGE_NTH (self, N) #define STORAGE_NTH(N) GNU_STORAGE_NTH (self, N)
typedef struct { typedef struct {
@defs(Storage) @defs (Storage)
} GNUStorageId; } GNUStorageId;
@implementation Storage @implementation Storage
+ initialize +initialize
{ {
if (self == [Storage class]) if (self ==[Storage class])
[self setVersion:0]; /* beta release */ [self setVersion:0]; /* beta release */
return self; return self;
} }
// INITIALIZING, FREEING; // INITIALIZING, FREEING;
- initCount: (NSUInteger)numSlots -initCount: (NSUInteger) numSlots elementSize: (NSUInteger) sizeInBytes description:(const char *)
elementSize: (NSUInteger)sizeInBytes elemDesc;
description: (const char*)elemDesc;
{ {
[super init]; [super init];
numElements = numSlots; numElements = numSlots;
maxElements = (numSlots > 0) ? numSlots : 1; maxElements = (numSlots > 0) ? numSlots : 1;
elementSize = sizeInBytes; elementSize = sizeInBytes;
description = elemDesc; description = elemDesc;
dataPtr = (void*) objc_malloc (maxElements * elementSize); dataPtr = (void *) objc_malloc (maxElements * elementSize);
bzero(dataPtr, numElements * elementSize); bzero (dataPtr, numElements * elementSize);
return self; return self;
} }
- init -init
{ {
return [self initCount:1 return[self initCount: 1 elementSize:sizeof (id)
elementSize:sizeof(id) description:@encode (id)];
description:@encode(id)];
} }
- (void)dealloc -(void) dealloc
{ {
if (dataPtr) if (dataPtr)
free(dataPtr); free (dataPtr);
[super dealloc]; [super dealloc];
} }
- (const char*) description -(const char *) description
{ {
return description; return description;
} }
@ -84,22 +82,23 @@ typedef struct {
// COPYING; // COPYING;
- copy -copy
{ {
Storage *c = [super copy]; Storage *c =[super copy];
c->dataPtr = (void*) objc_malloc (maxElements * elementSize);
memcpy(c->dataPtr, dataPtr, numElements * elementSize); c->dataPtr = (void *) objc_malloc (maxElements * elementSize);
memcpy (c->dataPtr, dataPtr, numElements * elementSize);
return c; return c;
} }
// COMPARING TWO STORAGES; // COMPARING TWO STORAGES;
- (BOOL)isEqual: anObject -(BOOL) isEqual:anObject
{ {
if ([anObject isKindOfClass: [Storage class]] if ([anObject isKindOfClass:[Storage class]]
&& [anObject count] == [self count] &&[anObject count] ==[self count]
&& !memcmp(((GNUStorageId*)anObject)->dataPtr, && !memcmp (((GNUStorageId *) anObject)->dataPtr,
dataPtr, numElements*elementSize)) dataPtr, numElements * elementSize))
return YES; return YES;
else else
return NO; return NO;
@ -107,46 +106,43 @@ typedef struct {
// MANAGING THE STORAGE CAPACITY; // MANAGING THE STORAGE CAPACITY;
static inline void _makeRoomForAnotherIfNecessary(Storage *self) static inline void
_makeRoomForAnotherIfNecessary (Storage * self)
{ {
if (self->numElements == self->maxElements) if (self->numElements == self->maxElements) {
{
self->maxElements *= 2; self->maxElements *= 2;
self->dataPtr = (void*) self->dataPtr = (void *)
objc_realloc (self->dataPtr, self->maxElements*self->elementSize); 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)) if (self->numElements < (self->maxElements / 2)) {
{
self->maxElements /= 2; self->maxElements /= 2;
self->dataPtr = (void *) self->dataPtr = (void *)
objc_realloc (self->dataPtr, self->maxElements*self->elementSize); objc_realloc (self->dataPtr, self->maxElements * self->elementSize);
} }
} }
- setAvailableCapacity:(NSUInteger)numSlots -setAvailableCapacity:(NSUInteger) numSlots
{ {
if (numSlots > numElements) if (numSlots > numElements) {
{
maxElements = numSlots; maxElements = numSlots;
dataPtr = (void*) objc_realloc (dataPtr, maxElements * elementSize); dataPtr = (void *) objc_realloc (dataPtr, maxElements * elementSize);
} }
return self; return self;
} }
- setNumSlots:(NSUInteger)numSlots -setNumSlots:(NSUInteger) numSlots
{ {
if (numSlots > numElements) if (numSlots > numElements) {
{
maxElements = numSlots; maxElements = numSlots;
dataPtr = (void*) objc_realloc (dataPtr, maxElements * elementSize); dataPtr = (void *) objc_realloc (dataPtr, maxElements * elementSize);
bzero(STORAGE_NTH(numElements), (maxElements-numElements)*elementSize); bzero (STORAGE_NTH (numElements),
} (maxElements - numElements) * elementSize);
else if (numSlots < numElements) } else if (numSlots < numElements) {
{
numElements = numSlots; numElements = numSlots;
_shrinkIfDesired (self); _shrinkIfDesired (self);
} }
@ -157,128 +153,125 @@ static inline void _shrinkIfDesired(Storage *self)
#define CHECK_INDEX(IND) if (IND >= numElements) return 0 #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); CHECK_INDEX (index);
return STORAGE_NTH (index); return STORAGE_NTH (index);
} }
- addElement: (void*)anElement -addElement:(void *) anElement
{ {
_makeRoomForAnotherIfNecessary(self); _makeRoomForAnotherIfNecessary (self);
memcpy(STORAGE_NTH(numElements), anElement, elementSize); memcpy (STORAGE_NTH (numElements), anElement, elementSize);
numElements++; numElements++;
return self; return self;
} }
- insertElement: (void*)anElement at: (NSUInteger)index -insertElement:(void *)
anElement at:(NSUInteger) index
{ {
int i; int i;
CHECK_INDEX(index); CHECK_INDEX (index);
_makeRoomForAnotherIfNecessary(self); _makeRoomForAnotherIfNecessary (self);
#ifndef STABLE_MEMCPY #ifndef STABLE_MEMCPY
for (i = numElements; i >= index; i--) for (i = numElements; i >= index; i--)
memcpy (STORAGE_NTH(i+1), STORAGE_NTH(i), elementSize); memcpy (STORAGE_NTH (i + 1), STORAGE_NTH (i), elementSize);
#else #else
memcpy (STORAGE_NTH (index+1), memcpy (STORAGE_NTH (index + 1),
STORAGE_NTH (index), STORAGE_NTH (index), elementSize * (numElements - index));
elementSize*(numElements-index));
#endif #endif
memcpy(STORAGE_NTH(i), anElement, elementSize); memcpy (STORAGE_NTH (i), anElement, elementSize);
numElements++; numElements++;
return self; return self;
} }
- removeElementAt: (NSUInteger)index -removeElementAt:(NSUInteger) index
{ {
int i; int i;
CHECK_INDEX(index); CHECK_INDEX (index);
numElements--; numElements--;
#ifndef STABLE_MEMCPY #ifndef STABLE_MEMCPY
for (i = index; i < numElements; i++) for (i = index; i < numElements; i++)
memcpy(STORAGE_NTH(i), memcpy (STORAGE_NTH (i), STORAGE_NTH (i + 1), elementSize);
STORAGE_NTH(i+1),
elementSize);
#else #else
memcpy (STORAGE_NTH (index), memcpy (STORAGE_NTH (index),
STORAGE_NTH (index+1), STORAGE_NTH (index + 1), elementSize * (numElements - index - 1));
elementSize*(numElements-index-1));
#endif #endif
_shrinkIfDesired(self); _shrinkIfDesired (self);
return self; return self;
} }
- removeLastElement -removeLastElement
{ {
if (numElements) if (numElements) {
{
numElements--; numElements--;
_shrinkIfDesired(self); _shrinkIfDesired (self);
} }
return self; return self;
} }
- replaceElementAt:(NSUInteger)index with:(void*)newElement -replaceElementAt:(NSUInteger)
index with:(void *) newElement
{ {
CHECK_INDEX(index); CHECK_INDEX (index);
memcpy(STORAGE_NTH(index), newElement, elementSize); memcpy (STORAGE_NTH (index), newElement, elementSize);
return self; return self;
} }
/* Emptying the Storage */ /* Emptying the Storage */
- empty -empty
{ {
numElements = 0; numElements = 0;
maxElements = 1; maxElements = 1;
dataPtr = (void*) objc_realloc (dataPtr, maxElements * elementSize); dataPtr = (void *) objc_realloc (dataPtr, maxElements * elementSize);
return self; return self;
} }
/* Archiving */ /* Archiving */
- write: (TypedStream*)aStream -write:(TypedStream *) aStream
{ {
int i; int i;
[super write:aStream]; [super write:aStream];
objc_write_types(aStream, "III*", objc_write_types (aStream, "III*",
&numElements, &maxElements, &elementSize, &description); &numElements, &maxElements, &elementSize, &description);
for (i = 0; i < numElements; i++) for (i = 0; i < numElements; i++)
objc_write_type(aStream, description, STORAGE_NTH(i)); objc_write_type (aStream, description, STORAGE_NTH (i));
return self; return self;
} }
- read: (TypedStream*)aStream -read:(TypedStream *) aStream
{ {
int i; int i;
[super read:aStream]; [super read:aStream];
objc_read_types(aStream, "III*", objc_read_types (aStream, "III*",
&numElements, &maxElements, &elementSize, &description); &numElements, &maxElements, &elementSize, &description);
dataPtr = (void*) objc_malloc (maxElements * elementSize); dataPtr = (void *) objc_malloc (maxElements * elementSize);
for (i = 0; i < numElements; i++) for (i = 0; i < numElements; i++)
objc_read_type(aStream, description, STORAGE_NTH(i)); objc_read_type (aStream, description, STORAGE_NTH (i));
return self; return self;
} }
+ new +new
{ {
return [[self alloc] init]; return[[self alloc] init];
} }
+ newCount:(NSUInteger)count elementSize:(NSUInteger)sizeInBytes +newCount:(NSUInteger)
description:(const char *)descriptor count elementSize:(NSUInteger) sizeInBytes
description:(const char *) descriptor
{ {
return [[self alloc] initCount:count elementSize:sizeInBytes return[[self alloc] initCount: count elementSize: sizeInBytes description:descriptor];
description:descriptor];
} }
@end @end

View file

@ -21,8 +21,7 @@ id texturepalette_i;
int tex_count; int tex_count;
qtexture_t qtextures[MAX_TEXTURES]; qtexture_t qtextures[MAX_TEXTURES];
typedef struct typedef struct {
{
char name[16]; char name[16];
unsigned width, height; unsigned width, height;
unsigned offsets[4]; // four mip maps stored unsigned offsets[4]; // four mip maps stored
@ -30,63 +29,63 @@ typedef struct
unsigned tex_palette[256]; unsigned tex_palette[256];
unsigned badtex_d[] = unsigned badtex_d[] = {
{ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
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,
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,
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,
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,
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,
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,
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,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff, 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, 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, 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, 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, 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, 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, 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 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 TEX_InitPalette
============== ==============
*/ */
void TEX_InitPalette (byte *pal) void
TEX_InitPalette (byte * pal)
{ {
int r,g,b,v; int r, g, b, v;
int i; int i;
for (i=0 ; i<256 ; i++) for (i = 0; i < 256; i++) {
{
r = pal[0]; r = pal[0];
g = pal[1]; g = pal[1];
b = pal[2]; b = pal[2];
pal += 3; pal += 3;
v = (r<<24) + (g<<16) + (b<<8) + 255; v = (r << 24) + (g << 16) + (b << 8) + 255;
v = BigLong (v); v = BigLong (v);
tex_palette[i] = v; tex_palette[i] = v;
@ -99,7 +98,8 @@ void TEX_InitPalette (byte *pal)
TEX_ImageFromMiptex TEX_ImageFromMiptex
================= =================
*/ */
void TEX_ImageFromMiptex (miptex_t *qtex) void
TEX_ImageFromMiptex (miptex_t *qtex)
{ {
NSBitmapImageRep *bm; NSBitmapImageRep *bm;
byte *source; byte *source;
@ -108,24 +108,15 @@ void TEX_ImageFromMiptex (miptex_t *qtex)
qtexture_t *q; qtexture_t *q;
int tr, tg, tb; int tr, tg, tb;
width = LittleLong(qtex->width); width = LittleLong (qtex->width);
height = LittleLong(qtex->height); height = LittleLong (qtex->height);
bm = [[NSBitmapImageRep alloc] bm =[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: NULL initWithBitmapDataPlanes: NULL pixelsWide: width pixelsHigh: height bitsPerSample: 8 samplesPerPixel: 3 hasAlpha: NO isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: width * 4 bitsPerPixel:32];
pixelsWide: width
pixelsHigh: height
bitsPerSample: 8
samplesPerPixel:3
hasAlpha: NO
isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace
bytesPerRow: width*4
bitsPerPixel: 32];
dest = (unsigned *)[bm bitmapData]; dest = (unsigned *)[bm bitmapData];
count = width*height; count = width * height;
source = (byte *)qtex + LittleLong(qtex->offsets[0]); source = (byte *) qtex + LittleLong (qtex->offsets[0]);
q = &qtextures[tex_count]; q = &qtextures[tex_count];
tex_count++; tex_count++;
@ -137,12 +128,11 @@ void TEX_ImageFromMiptex (miptex_t *qtex)
tr = tg = tb = 0; tr = tg = tb = 0;
for (i=0 ; i<count ; i++) for (i = 0; i < count; i++) {
{
dest[i] = tex_palette[source[i]]; dest[i] = tex_palette[source[i]];
tr += ((pixel32_t *)&dest[i])->chan[0]; tr += ((pixel32_t *) & dest[i])->chan[0];
tg += ((pixel32_t *)&dest[i])->chan[1]; tg += ((pixel32_t *) & dest[i])->chan[1];
tb += ((pixel32_t *)&dest[i])->chan[2]; tb += ((pixel32_t *) & dest[i])->chan[2];
} }
q->flatcolor.chan[0] = tr / count; q->flatcolor.chan[0] = tr / count;
@ -153,16 +143,14 @@ void TEX_ImageFromMiptex (miptex_t *qtex)
//============================================================================= //=============================================================================
typedef struct typedef struct {
{
char identification[4]; // should be WAD2 or 2DAW char identification[4]; // should be WAD2 or 2DAW
int numlumps; int numlumps;
int infotableofs; int infotableofs;
} wadinfo_t; } wadinfo_t;
typedef struct typedef struct {
{
int filepos; int filepos;
int disksize; int disksize;
int size; // uncompressed int size; // uncompressed
@ -177,7 +165,8 @@ typedef struct
TEX_InitFromWad TEX_InitFromWad
================= =================
*/ */
void TEX_InitFromWad (char *path) void
TEX_InitFromWad (char *path)
{ {
int i; int i;
char local[1024]; char local[1024];
@ -192,52 +181,49 @@ void TEX_InitFromWad (char *path)
start = I_FloatTime (); start = I_FloatTime ();
strcpy(newpath, [preferences_i getProjectPath]); strcpy (newpath,[preferences_i getProjectPath]);
strcat(newpath,"/"); strcat (newpath, "/");
strcat(newpath, path); strcat (newpath, path);
// free any textures // free any textures
for (i=0 ; i<tex_count ; i++) for (i = 0; i < tex_count; i++)
[qtextures[i].rep release]; [qtextures[i].rep release];
tex_count = 0; tex_count = 0;
// try and use the cached wadfile // try and use the cached wadfile
sprintf (local, "/qcache%s", newpath); sprintf (local, "/qcache%s", newpath);
//Sys_UpdateFile (local, newpath); // Sys_UpdateFile (local, newpath);
//FIXME use wad functions // FIXME use wad functions
file = Qopen (local, "rb"); file = Qopen (local, "rb");
size = Qfilesize (file); size = Qfilesize (file);
wadfile = malloc (size); wadfile = malloc (size);
Qread (file, wadfile, size); Qread (file, wadfile, size);
Qclose (file); Qclose (file);
wadinfo = (wadinfo_t *)wadfile; wadinfo = (wadinfo_t *) wadfile;
if (strncmp ((char *)wadfile, "WAD2", 4)) if (strncmp ((char *) wadfile, "WAD2", 4)) {
{
unlink (local); unlink (local);
Sys_Error ("TEX_InitFromWad: %s isn't a wadfile", newpath); Sys_Error ("TEX_InitFromWad: %s isn't a wadfile", newpath);
} }
numlumps = LittleLong (wadinfo->numlumps); numlumps = LittleLong (wadinfo->numlumps);
lumpinfo = (lumpinfo_t *)(wadfile + LittleLong (wadinfo->infotableofs)); lumpinfo = (lumpinfo_t *) (wadfile + LittleLong (wadinfo->infotableofs));
if (strcmp (lumpinfo->name, "PALETTE")) if (strcmp (lumpinfo->name, "PALETTE")) {
{
unlink (local); unlink (local);
Sys_Error ("TEX_InitFromWad: %s doesn't have palette as 0",path); Sys_Error ("TEX_InitFromWad: %s doesn't have palette as 0", path);
} }
TEX_InitPalette (wadfile + LittleLong(lumpinfo->filepos)); TEX_InitPalette (wadfile + LittleLong (lumpinfo->filepos));
lumpinfo++; lumpinfo++;
for (i=1 ; i<numlumps ; i++, lumpinfo++) for (i = 1; i < numlumps; i++, lumpinfo++) {
{
if (lumpinfo->type != TYP_MIPTEX) if (lumpinfo->type != TYP_MIPTEX)
Sys_Error ("TEX_InitFromWad: %s is not a miptex!",lumpinfo->name); Sys_Error ("TEX_InitFromWad: %s is not a miptex!", lumpinfo->name);
//XXX CleanupName (lumpinfo->name,qtextures[tex_count].name); // XXX CleanupName (lumpinfo->name,qtextures[tex_count].name);
TEX_ImageFromMiptex ( (miptex_t *)(wadfile + TEX_ImageFromMiptex ((miptex_t *) (wadfile +
LittleLong(lumpinfo->filepos) )); LittleLong (lumpinfo->filepos)));
} }
free (wadfile); free (wadfile);
@ -252,17 +238,17 @@ void TEX_InitFromWad (char *path)
TEX_NumForName TEX_NumForName
================= =================
*/ */
qtexture_t *TEX_ForName (char *name) qtexture_t *
TEX_ForName (char *name)
{ {
//XXX char newname[16]; // XXX char newname[16];
int i; int i;
qtexture_t *q; qtexture_t *q;
//XXX CleanupName (name, newname); // XXX CleanupName (name, newname);
for (i=0,q = qtextures ; i< tex_count ; i++, q++) for (i = 0, q = qtextures; i < tex_count; i++, q++) {
{ if (!strcmp (name, q->name))
if (!strcmp(name, q->name))
return q; return q;
} }
@ -274,8 +260,7 @@ qtexture_t *TEX_ForName (char *name)
//=========================================================================== //===========================================================================
@implementation TexturePalette @implementation TexturePalette
-init
- init
{ {
[super init]; [super init];
texturepalette_i = self; texturepalette_i = self;
@ -283,48 +268,46 @@ qtexture_t *TEX_ForName (char *name)
return self; return self;
} }
- (void)display -(void) display
{ {
[[textureView_i superview] display]; [[textureView_i superview] display];
} }
- (char *)currentWad -(char *) currentWad
{ {
return currentwad; return currentwad;
} }
- initPaletteFromWadfile:(char *)wf -initPaletteFromWadfile:(char *) wf
{ {
int i; int i;
texpal_t t; texpal_t t;
qtexture_t *q; qtexture_t *q;
strcpy (currentwad, wf); strcpy (currentwad, wf);
[map_i makeGlobalPerform: @selector(flushTextures)]; [map_i makeGlobalPerform:@selector (flushTextures)];
selectedTexture = -1; selectedTexture = -1;
// Init textures WAD // Init textures WAD
TEX_InitFromWad(wf); TEX_InitFromWad (wf);
// Create STORAGE // Create STORAGE
if (textureList_i) if (textureList_i)
[textureList_i empty]; [textureList_i empty];
else else
textureList_i = [[Storage alloc] textureList_i =[[Storage alloc]
initCount:0 initCount: 0 elementSize:sizeof (texpal_t)
elementSize:sizeof(texpal_t) description: NULL];
description:NULL];
// Init STORAGE // 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.image = q->rep;
t.r.size.width = [t.image pixelsWide]; t.r.size.width =[t.image pixelsWide];
if (t.r.size.width < 64) if (t.r.size.width < 64)
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.name = q->name;
t.index = i; t.index = i;
t.display = 1; t.display = 1;
@ -343,13 +326,13 @@ qtexture_t *TEX_ForName (char *name)
// Return texture STORAGE list // Return texture STORAGE list
- getList -getList
{ {
return textureList_i; return textureList_i;
} }
// Alphabetize texture list - reverse order! // Alphabetize texture list - reverse order!
- alphabetize -alphabetize
{ {
int i; int i;
int max; int max;
@ -359,21 +342,18 @@ qtexture_t *TEX_ForName (char *name)
texpal_t t2; texpal_t t2;
int found; int found;
max = [textureList_i count]; max =[textureList_i count];
found = 1; found = 1;
while(found) while (found) {
{
found = 0; found = 0;
for (i = 0;i < max-1;i++) for (i = 0; i < max - 1; i++) {
{ t1p =[textureList_i elementAt:i];
t1p = [textureList_i elementAt:i]; t2p =[textureList_i elementAt:i + 1];
t2p = [textureList_i elementAt:i+1]; if (strcmp (t1p->name, t2p->name) < 0) {
if (strcmp(t1p->name,t2p->name) < 0)
{
t1 = *t1p; t1 = *t1p;
t2 = *t2p; t2 = *t2p;
[textureList_i replaceElementAt:i with:&t2]; [textureList_i replaceElementAt: i with:&t2];
[textureList_i replaceElementAt:i+1 with:&t1]; [textureList_i replaceElementAt: i + 1 with:&t1];
found = 1; found = 1;
} }
} }
@ -381,7 +361,7 @@ qtexture_t *TEX_ForName (char *name)
return self; return self;
} }
- computeTextureViewSize -computeTextureViewSize
{ {
int i; int i;
int max; int max;
@ -394,20 +374,18 @@ qtexture_t *TEX_ForName (char *name)
int maxheight; int maxheight;
NSPoint pt; NSPoint pt;
max = [textureList_i count]; max =[textureList_i count];
y = 0; y = 0;
maxheight = 0; maxheight = 0;
x = TEX_INDENT; x = TEX_INDENT;
view = [textureView_i superview]; view =[textureView_i superview];
b = [view bounds]; b =[view bounds];
maxwidth = b.size.width; maxwidth = b.size.width;
for (i = 0;i < max; i++) for (i = 0; i < max; i++) {
{ t =[textureList_i elementAt:i];
t = [textureList_i elementAt:i]; if (x + t->r.size.width + TEX_INDENT > maxwidth) {
if (x + t->r.size.width + TEX_INDENT > maxwidth)
{
x = TEX_INDENT; x = TEX_INDENT;
y += maxheight; y += maxheight;
maxheight = 0; maxheight = 0;
@ -430,29 +408,27 @@ qtexture_t *TEX_ForName (char *name)
return self; return self;
} }
- windowResized -windowResized
{ {
[self computeTextureViewSize]; [self computeTextureViewSize];
return self; return self;
} }
- texturedefChanged: sender -texturedefChanged:sender
{ {
if ([map_i numSelected]) if ([map_i numSelected]) {
{ if ([[map_i currentEntity] modifiable]) {
if ( [[map_i currentEntity] modifiable] ) [map_i makeSelectedPerform:@selector
{ (takeCurrentTexture)];
[map_i makeSelectedPerform: @selector(takeCurrentTexture)];
[quakeed_i updateAll]; [quakeed_i updateAll];
} } else
else
qprintf ("can't modify spawned entities"); qprintf ("can't modify spawned entities");
} }
[quakeed_i makeFirstResponder: quakeed_i]; [quakeed_i makeFirstResponder:quakeed_i];
return self; return self;
} }
- clearTexinfo: sender -clearTexinfo:sender
{ {
[field_Xshift_i setFloatValue:0]; [field_Xshift_i setFloatValue:0];
[field_Yshift_i setFloatValue:0]; [field_Yshift_i setFloatValue:0];
@ -460,7 +436,7 @@ qtexture_t *TEX_ForName (char *name)
[field_Yscale_i setFloatValue:1]; [field_Yscale_i setFloatValue:1];
[field_Rotate_i setFloatValue:0]; [field_Rotate_i setFloatValue:0];
[self texturedefChanged: self]; [self texturedefChanged:self];
return self; return self;
} }
@ -468,30 +444,29 @@ qtexture_t *TEX_ForName (char *name)
// //
// Set the selected texture // Set the selected texture
// //
- setSelectedTexture:(int)which -setSelectedTexture:(int) which
{ {
texpal_t *t; texpal_t *t;
NSRect r; NSRect r;
char string[16]; char string[16];
// wipe the fields // wipe the fields
[self clearTexinfo: self]; [self clearTexinfo:self];
if (which != selectedTexture) if (which != selectedTexture) {
{
[textureView_i deselect]; [textureView_i deselect];
selectedTexture = which; selectedTexture = which;
t = [textureList_i elementAt:which]; t =[textureList_i elementAt:which];
r = t->r; r = t->r;
r.size.width += TEX_INDENT*2; r.size.width += TEX_INDENT * 2;
r.size.height += TEX_INDENT*2; r.size.height += TEX_INDENT * 2;
r.origin.x -= TEX_INDENT; r.origin.x -= TEX_INDENT;
r.origin.y -= TEX_INDENT; r.origin.y -= TEX_INDENT;
[textureView_i scrollRectToVisible:r]; [textureView_i scrollRectToVisible:r];
[textureView_i display]; [textureView_i display];
sprintf(string,"%d x %d",(int)t->r.size.width, sprintf (string, "%d x %d", (int) t->r.size.width,
(int)t->r.size.height - TEX_SPACING); (int) t->r.size.height - TEX_SPACING);
[sizeField_i setStringValue:[NSString stringWithCString:string]]; [sizeField_i setStringValue: [NSString stringWithCString:string]];
} }
[self texturedefChanged:self]; [self texturedefChanged:self];
@ -502,7 +477,7 @@ qtexture_t *TEX_ForName (char *name)
// //
// Return the selected texture index // Return the selected texture index
// //
- (int)getSelectedTexture -(int) getSelectedTexture
{ {
return selectedTexture; return selectedTexture;
} }
@ -511,46 +486,44 @@ qtexture_t *TEX_ForName (char *name)
// Return the original tex_ index of the selected texture // Return the original tex_ index of the selected texture
// so the texture info can be indexed from tex_images, etc. // so the texture info can be indexed from tex_images, etc.
// //
- (int)getSelectedTexIndex -(int) getSelectedTexIndex
{ {
texpal_t *t; texpal_t *t;
if (selectedTexture == -1) if (selectedTexture == -1)
return -1; return -1;
t = [textureList_i elementAt:selectedTexture]; t =[textureList_i elementAt:selectedTexture];
return t->index; 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) if (selectedTexture == -1)
return NULL; return NULL;
t = [textureList_i elementAt:selectedTexture]; t =[textureList_i elementAt:selectedTexture];
return t->name; return t->name;
} }
// //
// Set selected texture by texture name // Set selected texture by texture name
// //
- setTextureByName:(char *)name -setTextureByName:(char *) name
{ {
texpal_t *t; texpal_t *t;
int i; int i;
int max; int max;
max = [textureList_i count]; max =[textureList_i count];
//XXX CleanupName(name,name); // XXX CleanupName(name,name);
for (i = 0;i < max;i++) for (i = 0; i < max; i++) {
{ t =[textureList_i elementAt:i];
t = [textureList_i elementAt:i]; if (!strcmp (t->name, name)) {
if (!strcmp(t->name,name)) [self setSelectedTexture:i];
{
[self setSelectedTexture: i];
return self; return self;
} }
} }
@ -567,7 +540,7 @@ qtexture_t *TEX_ForName (char *name)
// //
// Search for texture named in searchField // Search for texture named in searchField
// //
- searchForTexture:sender -searchForTexture:sender
{ {
int i; int i;
int max; int max;
@ -578,18 +551,16 @@ qtexture_t *TEX_ForName (char *name)
if (selectedTexture == -1) if (selectedTexture == -1)
return self; return self;
max = [textureList_i count]; max =[textureList_i count];
strcpy(name,(const char *)[sender stringValue]); strcpy (name, (const char *)[sender stringValue]);
for (n = name; *n; n++) for (n = name; *n; n++)
*n = toupper (*n); *n = toupper (*n);
[sender setStringValue:[NSString stringWithCString:name]]; [sender setStringValue: [NSString stringWithCString:name]];
len = strlen(name); len = strlen (name);
for (i = selectedTexture-1;i >= 0; i--) for (i = selectedTexture - 1; i >= 0; i--) {
{ t =[textureList_i elementAt:i];
t = [textureList_i elementAt:i]; if (!strncmp (t->name, name, len)) {
if (!strncmp(t->name,name,len))
{
[self setTextureByName:t->name]; [self setTextureByName:t->name];
[sender selectText:sender]; [sender selectText:sender];
[self texturedefChanged:self]; [self texturedefChanged:self];
@ -597,11 +568,9 @@ qtexture_t *TEX_ForName (char *name)
} }
} }
for (i = max-1;i >= selectedTexture; i--) for (i = max - 1; i >= selectedTexture; i--) {
{ t =[textureList_i elementAt:i];
t = [textureList_i elementAt:i]; if (!strncmp (t->name, name, len)) {
if (!strncmp(t->name,name,len))
{
[self setTextureByName:t->name]; [self setTextureByName:t->name];
[sender selectText:sender]; [sender selectText:sender];
[self texturedefChanged:self]; [self texturedefChanged:self];
@ -616,7 +585,7 @@ qtexture_t *TEX_ForName (char *name)
// //
// Set texture def from outside TexturePalette // Set texture def from outside TexturePalette
// //
- setTextureDef:(texturedef_t *)td -setTextureDef:(texturedef_t *) td
{ {
[self setTextureByName:td->texture]; [self setTextureByName:td->texture];
@ -634,22 +603,21 @@ qtexture_t *TEX_ForName (char *name)
// //
// 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) if (selectedTexture == -1) {
{ memset (td, 0, sizeof (*td));
memset (td, 0, sizeof(*td));
strcpy (td->texture, "notexture"); strcpy (td->texture, "notexture");
return self; return self;
} }
strncpy(td->texture,[self getSelTextureName],16); strncpy (td->texture,[self getSelTextureName], 16);
td->shift[0] = [field_Xshift_i floatValue]; td->shift[0] =[field_Xshift_i floatValue];
td->shift[1] = [field_Yshift_i floatValue]; td->shift[1] =[field_Yshift_i floatValue];
td->scale[0] = [field_Xscale_i floatValue]; td->scale[0] =[field_Xscale_i floatValue];
td->scale[1] = [field_Yscale_i floatValue]; td->scale[1] =[field_Yscale_i floatValue];
td->rotate = [field_Rotate_i floatValue]; td->rotate =[field_Rotate_i floatValue];
return self; return self;
} }
@ -659,11 +627,12 @@ qtexture_t *TEX_ForName (char *name)
// //
// Change value in a field // Change value in a field
// //
- changeField:(id)field by:(int)amount -changeField:(id)
field by:(int) amount
{ {
int val; int val;
val = [field intValue]; val =[field intValue];
val += amount; val += amount;
[field setIntValue:val]; [field setIntValue:val];
@ -675,57 +644,61 @@ 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; return self;
} }
- decXShift:sender
-decXShift:sender
{ {
[self changeField:field_Xshift_i by:-8]; [self changeField: field_Xshift_i by:-8];
return self; 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; return self;
} }
- decYShift:sender
-decYShift:sender
{ {
[self changeField:field_Yshift_i by:-8]; [self changeField: field_Yshift_i by:-8];
return self; 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; return self;
} }
- decRotate:sender
-decRotate:sender
{ {
[self changeField:field_Rotate_i by:-90]; [self changeField: field_Rotate_i by:-90];
return self; 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]; [self texturedefChanged:self];
return self; return self;
} }
- decXScale:sender
-decXScale:sender
{ {
[field_Xscale_i setIntValue: -1]; [field_Xscale_i setIntValue:-1];
[self texturedefChanged:self]; [self texturedefChanged:self];
return self; return self;
} }
@ -733,15 +706,16 @@ qtexture_t *TEX_ForName (char *name)
// //
// 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]; [self texturedefChanged:self];
return self; return self;
} }
- decYScale:sender
-decYScale:sender
{ {
[field_Yscale_i setIntValue: -1]; [field_Yscale_i setIntValue:-1];
[self texturedefChanged:self]; [self texturedefChanged:self];
return self; return self;
} }
@ -754,7 +728,7 @@ qtexture_t *TEX_ForName (char *name)
// Search for texture in entire palette // Search for texture in entire palette
// Return index of texturedef, or -1 if unsuccessful // Return index of texturedef, or -1 if unsuccessful
// //
- (int) searchForTextureInPalette:(char *)texture -(int) searchForTextureInPalette:(char *) texture
{ {
int i; int i;
int max; int max;
@ -764,13 +738,12 @@ qtexture_t *TEX_ForName (char *name)
if (selectedTexture == -1) if (selectedTexture == -1)
return -1; return -1;
max = [textureList_i count]; max =[textureList_i count];
strcpy(name,texture); strcpy (name, texture);
for (i = 0; i < max; i++) for (i = 0; i < max; i++) {
{ t =[textureList_i elementAt:i];
t = [textureList_i elementAt:i]; if (!strcmp (t->name, name))
if (!strcmp(t->name,name))
return i; return i;
} }
return -1; return -1;
@ -779,7 +752,7 @@ qtexture_t *TEX_ForName (char *name)
// //
// Scan thru map & display only textures that are in map // Scan thru map & display only textures that are in map
// //
- onlyShowMapTextures:sender -onlyShowMapTextures:sender
{ {
int max; int max;
int i; int i;
@ -791,33 +764,30 @@ qtexture_t *TEX_ForName (char *name)
int index; int index;
// Turn 'em off // Turn 'em off
if ([sender intValue]) if ([sender intValue]) {
{ max =[textureList_i count];
max = [textureList_i count]; for (i = 0; i < max; i++)
for (i = 0;i < max; i++) [self setDisplayFlag: i to:0];
[self setDisplayFlag:i to:0];
brushes = [map_i objectAtIndex:0]; brushes =[map_i objectAtIndex:0];
max = [brushes count]; max =[brushes count];
for (i = 0;i < max; i++) for (i = 0; i < max; i++) {
{
b = (SetBrush *)[brushes objectAtIndex:i]; b = (SetBrush *)[brushes objectAtIndex:i];
numfaces = [b getNumBrushFaces]; numfaces =[b getNumBrushFaces];
for (j = 0; j < numfaces; j++) for (j = 0; j < numfaces; j++) {
{ f =[b getBrushFace:j];
f = [b getBrushFace:j]; index =[self searchForTextureInPalette:f->texture.
index = [self searchForTextureInPalette:f->texture.texture]; texture];
if (index >= 0) if (index >= 0)
[self setDisplayFlag:index to:1]; [self setDisplayFlag: index to:1];
} }
} }
} }
// Turn 'em on // Turn 'em on
else else {
{ max =[textureList_i count];
max = [textureList_i count]; for (i = 0; i < max; i++)
for (i = 0;i < max; i++) [self setDisplayFlag: i to:1];
[self setDisplayFlag:i to:1];
} }
[textureView_i display]; [textureView_i display];
@ -825,11 +795,12 @@ qtexture_t *TEX_ForName (char *name)
return self; return self;
} }
- setDisplayFlag:(int)index to:(int)value -setDisplayFlag:(int)
index to:(int) value
{ {
texpal_t *tp; texpal_t *tp;
tp = [textureList_i elementAt:index]; tp =[textureList_i elementAt:index];
tp->display = value; tp->display = value;
return self; return self;
}; };

View file

@ -13,24 +13,24 @@ NOTE: I am specifically not using cached image reps, because the data is also ne
@implementation TextureView @implementation TextureView
- init -init
{ {
deselectIndex = -1; deselectIndex = -1;
return self; return self;
} }
- setParent:(id)from -setParent:(id) from
{ {
parent_i = from; parent_i = from;
return self; return self;
} }
- (BOOL)acceptsFirstMouse -(BOOL) acceptsFirstMouse
{ {
return YES; return YES;
} }
- drawSelf:(const NSRect *)rects :(int)rectCount -drawSelf: (const NSRect *) rects:(int) rectCount
{ {
int i; int i;
int max; int max;
@ -42,114 +42,107 @@ NOTE: I am specifically not using cached image reps, because the data is also ne
NSRect r; NSRect r;
int selected; int selected;
selected = [parent_i getSelectedTexture]; selected =[parent_i getSelectedTexture];
list_i = [parent_i getList]; list_i =[parent_i getList];
GSSetFont (DEFCTXT, [NSFont fontWithName:@"Helvetica-Medium" size:FONTSIZE]); GSSetFont (DEFCTXT,[NSFont fontWithName: @"Helvetica-Medium" size:FONTSIZE]);
PSrotate(0); PSrotate (0);
PSsetgray(NSLightGray); PSsetgray (NSLightGray);
PSrectfill(rects->origin.x, rects->origin.y, PSrectfill (rects->origin.x, rects->origin.y,
rects->size.width, rects->size.height); rects->size.width, rects->size.height);
if (!list_i) // WADfile didn't init if (!list_i) // WADfile didn't init
return self; return self;
if (deselectIndex != -1) if (deselectIndex != -1) {
{ t =[list_i elementAt:deselectIndex];
t = [list_i elementAt:deselectIndex];
r = t->r; r = t->r;
r.origin.x -= TEX_INDENT; r.origin.x -= TEX_INDENT;
r.origin.y -= TEX_INDENT; r.origin.y -= TEX_INDENT;
r.size.width += TEX_INDENT*2; r.size.width += TEX_INDENT * 2;
r.size.height += TEX_INDENT*2; r.size.height += TEX_INDENT * 2;
//XXX PSsetgray(NSGrayComponent(NS_COLORLTGRAY)); // XXX PSsetgray(NSGrayComponent(NS_COLORLTGRAY));
PSrectfill(r.origin.x, r.origin.y, PSrectfill (r.origin.x, r.origin.y, r.size.width, r.size.height);
r.size.width, r.size.height);
p = t->r.origin; p = t->r.origin;
p.y += TEX_SPACING; 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];
PSsetgray(0); PSsetgray (0);
x = t->r.origin.x; x = t->r.origin.x;
y = t->r.origin.y + 7; y = t->r.origin.y + 7;
PSmoveto(x,y); PSmoveto (x, y);
PSshow(t->name); PSshow (t->name);
PSstroke(); PSstroke ();
deselectIndex = -1; deselectIndex = -1;
} }
max = [list_i count]; max =[list_i count];
PSsetgray(0); PSsetgray (0);
for (i = 0;i < max; i++) for (i = 0; i < max; i++) {
{ t =[list_i elementAt:i];
t = [list_i elementAt:i];
r = t->r; r = t->r;
r.origin.x -= TEX_INDENT/2; r.origin.x -= TEX_INDENT / 2;
r.size.width += TEX_INDENT; r.size.width += TEX_INDENT;
r.origin.y += 4; r.origin.y += 4;
if (NSIntersectsRect(rects[0],r) == YES && if (NSIntersectsRect (rects[0], r) == YES && t->display) {
t->display) if (selected == i) {
{ PSsetgray (1);
if (selected == i) PSrectfill (r.origin.x, r.origin.y,
{
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); r.size.width, r.size.height);
PSsetgray(0); PSsetrgbcolor (1, 0, 0);
PSrectstroke (r.origin.x, r.origin.y,
r.size.width, r.size.height);
PSsetgray (0);
} }
p = t->r.origin; p = t->r.origin;
p.y += TEX_SPACING; 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; x = t->r.origin.x;
y = t->r.origin.y + 7; y = t->r.origin.y + 7;
PSmoveto(x,y); PSmoveto (x, y);
PSshow(t->name); PSshow (t->name);
} }
} }
PSstroke(); PSstroke ();
return self; return self;
} }
- deselect -deselect
{ {
deselectIndex = [parent_i getSelectedTexture]; deselectIndex =[parent_i getSelectedTexture];
return self; return self;
} }
- mouseDown:(NSEvent *)theEvent -mouseDown:(NSEvent *) theEvent
{ {
NSPoint loc; NSPoint loc;
int i; int i;
int max; int max;
//int oldwindowmask;
// int oldwindowmask;
texpal_t *t; texpal_t *t;
id list; id list;
NSRect r; NSRect r;
//oldwindowmask = [window addToEventMask:NSLeftMouseDraggedMask]; // oldwindowmask = [window addToEventMask:NSLeftMouseDraggedMask];
loc = [theEvent locationInWindow]; loc =[theEvent locationInWindow];
[self convertPoint:loc fromView:NULL]; [self convertPoint: loc fromView:NULL];
list = [parent_i getList]; list =[parent_i getList];
max = [list count]; max =[list count];
for (i = 0;i < max; i++) for (i = 0; i < max; i++) {
{ t =[list elementAt:i];
t = [list elementAt:i];
r = t->r; r = t->r;
if (NSPointInRect(loc,r) == YES) if (NSPointInRect (loc, r) == YES) {
{
[self deselect]; [self deselect];
[parent_i setSelectedTexture:i]; [parent_i setSelectedTexture:i];
break; break;
} }
} }
//[window setEventMask:oldwindowmask]; // [window setEventMask:oldwindowmask];
return self; return self;
} }

View file

@ -10,7 +10,7 @@ id things_i;
@implementation Things @implementation Things
- init -init
{ {
[super init]; [super init];
@ -23,87 +23,86 @@ id things_i;
// //
// 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 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; return self;
} }
- initEntities -initEntities
{ {
char *path; char *path;
path = [project_i getProgDirectory]; path =[project_i getProgDirectory];
[prog_path_i setStringValue: [NSString stringWithCString:path]]; [prog_path_i setStringValue: [NSString stringWithCString:path]];
[[EntityClassList alloc] initForSourceDirectory: path]; [[EntityClassList alloc] initForSourceDirectory:path];
[self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]]; [self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]];
[entity_browser_i loadColumnZero]; [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; return self;
} }
- selectEntity: sender -selectEntity:sender
{ {
id matr; id matr;
matr = [sender matrixInColumn: 0]; matr =[sender matrixInColumn:0];
lastSelected = [matr selectedRow]; lastSelected =[matr selectedRow];
[self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]]; [self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]];
[quakeed_i makeFirstResponder: quakeed_i]; [quakeed_i makeFirstResponder:quakeed_i];
return self; return self;
} }
- doubleClickEntity: sender -doubleClickEntity:sender
{ {
[map_i makeEntity: sender]; [map_i makeEntity:sender];
[quakeed_i makeFirstResponder: quakeed_i]; [quakeed_i makeFirstResponder:quakeed_i];
return self; 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; EntityClass *ent;
char *path; char *path;
path = (char *)[prog_path_i stringValue]; path = (char *)[prog_path_i stringValue];
if (!path || !path[0]) if (!path || !path[0]) {
{ path =[project_i getProgDirectory];
path = [project_i getProgDirectory];
[prog_path_i setStringValue: [NSString stringWithCString:path]]; [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 removeAllObjects];
[entity_classes_i release]; [entity_classes_i release];
// Now, RELOAD! // Now, RELOAD!
[[EntityClassList alloc] initForSourceDirectory: path]; [[EntityClassList alloc] initForSourceDirectory:path];
lastSelected = 0; lastSelected = 0;
ent = [entity_classes_i objectAtIndex:lastSelected]; ent =[entity_classes_i objectAtIndex:lastSelected];
[self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]]; [self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]];
[entity_browser_i loadColumnZero]; [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
@ -111,27 +110,27 @@ id things_i;
} }
- selectClass: (char *)class -selectClass:(char *) class
{ {
id classent; id classent;
classent = [entity_classes_i classForName:class]; classent =[entity_classes_i classForName:class];
if (!classent) if (!classent)
return self; return self;
lastSelected = [entity_classes_i indexOfObject: classent]; lastSelected =[entity_classes_i indexOfObject:classent];
if (lastSelected < 0) if (lastSelected < 0)
lastSelected = 0; lastSelected = 0;
[self loadEntityComment:classent]; [self loadEntityComment:classent];
[[entity_browser_i matrixInColumn:0] selectCellAtRow:lastSelected column:0]; [[entity_browser_i matrixInColumn: 0] selectCellAtRow: lastSelected column:0];
[[entity_browser_i matrixInColumn:0] scrollCellToVisibleAtRow:lastSelected column:0]; [[entity_browser_i matrixInColumn: 0] scrollCellToVisibleAtRow: lastSelected column:0];
return self; return self;
} }
- newCurrentEntity -newCurrentEntity
{ {
id ent, classent, cell; id ent, classent, cell;
char *classname; char *classname;
@ -139,30 +138,28 @@ id things_i;
char *flagname; char *flagname;
int flags; int flags;
ent = [map_i currentEntity]; ent =[map_i currentEntity];
classname = [ent valueForQKey: "classname"]; classname =[ent valueForQKey:"classname"];
if (ent != [map_i objectAtIndex: 0]) if (ent !=[map_i objectAtIndex:0])
[self selectClass: classname]; // don't reset for world [self selectClass:classname]; // don't reset for world
classent = [entity_classes_i classForName:classname]; classent =[entity_classes_i classForName:classname];
flagname = [ent valueForQKey: "spawnflags"]; flagname =[ent valueForQKey:"spawnflags"];
if (!flagname) if (!flagname)
flags = 0; flags = 0;
else else
flags = atoi(flagname); flags = atoi (flagname);
[flags_i setAutodisplay: NO]; [flags_i setAutodisplay:NO];
for (r=0 ; r<4 ; r++) for (r = 0; r < 4; r++)
for (c=0 ; c<3 ; c++) for (c = 0; c < 3; c++) {
{ cell =[flags_i cellAtRow: r column:c];
cell = [flags_i cellAtRow: r column: c]; if (c < 2) {
if (c < 2) flagname =[classent flagName:c * 4 + r];
{
flagname = [classent flagName: c*4 + r];
[cell setTitle: [NSString stringWithCString:flagname]]; [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]; [flags_i display];
// [keyInput_i setStringValue: ""]; // [keyInput_i setStringValue: ""];
@ -171,27 +168,27 @@ id things_i;
[keypairview_i calcViewSize]; [keypairview_i calcViewSize];
[keypairview_i display]; [keypairview_i display];
[quakeed_i makeFirstResponder: quakeed_i]; [quakeed_i makeFirstResponder:quakeed_i];
return self; 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]]; [keyInput_i setStringValue: [NSString stringWithCString:ep->key]];
[valueInput_i setStringValue:[NSString stringWithCString:ep->value]]; [valueInput_i setStringValue: [NSString stringWithCString:ep->value]];
[valueInput_i selectText:self]; [valueInput_i selectText:self];
return self; return self;
} }
- clearInputs -clearInputs
{ {
// [keyInput_i setStringValue: ""]; // [keyInput_i setStringValue: ""];
// [valueInput_i setStringValue: ""]; // [valueInput_i setStringValue: ""];
[quakeed_i makeFirstResponder: quakeed_i]; [quakeed_i makeFirstResponder:quakeed_i];
return self; return self;
} }
@ -206,7 +203,7 @@ id things_i;
key = (char *)[keyInput_i stringValue]; key = (char *)[keyInput_i stringValue];
value = (char *)[valueInput_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 calcViewSize];
[keypairview_i display]; [keypairview_i display];
@ -219,9 +216,9 @@ id things_i;
-delPair:sender -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 calcViewSize];
[keypairview_i display]; [keypairview_i display];
@ -237,21 +234,21 @@ id things_i;
// //
// Set the key/value fields to "angle <button value>" // Set the key/value fields to "angle <button value>"
// //
- setAngle:sender -setAngle:sender
{ {
const char *title; const char *title;
char value[10]; char value[10];
title = [[[sender selectedCell] title] cString]; title =[[[sender selectedCell] title] cString];
if (!strcmp(title,"Up")) if (!strcmp (title, "Up"))
strcpy (value, "-1"); strcpy (value, "-1");
else if (!strcmp(title,"Dn")) else if (!strcmp (title, "Dn"))
strcpy (value, "-2"); strcpy (value, "-2");
else else
strcpy (value, title); strcpy (value, title);
[keyInput_i setStringValue:@"angle"]; [keyInput_i setStringValue:@"angle"];
[valueInput_i setStringValue:[NSString stringWithCString:value]]; [valueInput_i setStringValue: [NSString stringWithCString:value]];
[self addPair:NULL]; [self addPair:NULL];
[self clearInputs]; [self clearInputs];
@ -261,7 +258,7 @@ id things_i;
return self; return self;
} }
- setFlags:sender -setFlags:sender
{ {
int flags; int flags;
int r, c, i; int r, c, i;
@ -271,20 +268,18 @@ id things_i;
[self clearInputs]; [self clearInputs];
flags = 0; flags = 0;
for (r=0 ; r<4 ; r++) for (r = 0; r < 4; r++)
for (c=0 ; c<3 ; c++) for (c = 0; c < 3; c++) {
{ cell =[flags_i cellAtRow: r column:c];
cell = [flags_i cellAtRow: r column: c];
i = ([cell intValue] > 0); i = ([cell intValue] > 0);
flags |= (i<< ((c*4)+r)); flags |= (i << ((c * 4) + r));
} }
if (!flags) if (!flags)
[[map_i currentEntity] removeKeyPair: "spawnflags"]; [[map_i currentEntity] removeKeyPair:"spawnflags"];
else else {
{
sprintf (str, "%i", flags); sprintf (str, "%i", flags);
[[map_i currentEntity] setKey: "spawnflags" toValue: str]; [[map_i currentEntity] setKey: "spawnflags" toValue:str];
} }
[keypairview_i calcViewSize]; [keypairview_i calcViewSize];
@ -298,21 +293,21 @@ id things_i;
// Fill the Entity browser // Fill the Entity browser
// (Delegate method - delegated in Interface Builder) // (Delegate method - delegated in Interface Builder)
// //
- (int)browser:sender fillMatrix:matrix inColumn:(int)column -(int) browser: sender fillMatrix: matrix inColumn:(int) column
{ {
id cell; id cell;
int max; int max;
int i; int i;
id object; id object;
max = [entity_classes_i count]; max =[entity_classes_i count];
i = 0; i = 0;
while(max--) while (max--) {
{ object =[entity_classes_i objectAtIndex:i];
object = [entity_classes_i objectAtIndex:i];
[matrix addRow]; [matrix addRow];
cell = [matrix cellAtRow:i++ column:0]; cell =[matrix cellAtRow: i++ column:0];
[cell setStringValue:[NSString stringWithCString:[object classname]]]; [cell setStringValue: [NSString stringWithCString:[object
classname]]];
[cell setLeaf:YES]; [cell setLeaf:YES];
[cell setLoaded:YES]; [cell setLoaded:YES];
} }

View file

@ -16,43 +16,47 @@
static NSZone *upZone = NULL; static NSZone *upZone = NULL;
NSZone *userPathZone() NSZone *
userPathZone ()
/* Creates a unique zone for use by all user paths */ /* Creates a unique zone for use by all user paths */
{ {
if (!upZone) { if (!upZone) {
upZone = NSCreateZone(vm_page_size, vm_page_size, 1); upZone = NSCreateZone (vm_page_size, vm_page_size, 1);
} }
return upZone; return upZone;
} }
UserPath *newUserPath() UserPath *
newUserPath ()
/* Creates a new User Path in the zone returned by userPathZone */ /* Creates a new User Path in the zone returned by userPathZone */
{ {
UserPath *up; UserPath *up;
up = (UserPath *)NSZoneMalloc(userPathZone(), sizeof(UserPath)); up = (UserPath *) NSZoneMalloc (userPathZone (), sizeof (UserPath));
up->max = 8192; // JDC up->max = 8192; // JDC
up->points = (float *)NSZoneMalloc(userPathZone(), up->points = (float *) NSZoneMalloc (userPathZone (),
sizeof(float) * up->max); sizeof (float) * up->max);
up->ops = (char *)NSZoneMalloc(userPathZone(), up->ops = (char *) NSZoneMalloc (userPathZone (),
(2 + (up->max / 2)) * sizeof(char)); (2 + (up->max / 2)) * sizeof (char));
up->ping = NO; up->ping = NO;
return up; return up;
} }
void freeUserPath(UserPath *up) void
freeUserPath (UserPath * up)
/* Frees User Path and its associated buffers */ /* Frees User Path and its associated buffers */
{ {
free(up->points); free (up->points);
free(up->ops); free (up->ops);
free(up); free (up);
return; return;
} }
void growUserPath(UserPath *up) void
growUserPath (UserPath * up)
/* /*
* grows the associated buffers as necessary. buffer size doubles on each * grows the associated buffers as necessary. buffer size doubles on each
* call. You never need to call grow directly as it is called as needed by the * call. You never need to call grow directly as it is called as needed by the
@ -60,17 +64,18 @@ void growUserPath(UserPath *up)
*/ */
{ {
/* double the size of the internal buffers */ /* double the size of the internal buffers */
printf ("growUserPath\n"); printf ("growUserPath\n");
up->max *= 2; up->max *= 2;
up->points = (float *)NSZoneRealloc(userPathZone(), up->points, up->points = (float *) NSZoneRealloc (userPathZone (), up->points,
sizeof(float) * up->max); sizeof (float) * up->max);
up->ops = (char *)NSZoneRealloc(userPathZone(), up->ops, up->ops = (char *) NSZoneRealloc (userPathZone (), up->ops,
(2 + (up->max / 2)) * sizeof(char)); (2 + (up->max / 2)) * sizeof (char));
return; return;
} }
void beginUserPath(UserPath *up, BOOL cache) void
beginUserPath (UserPath * up, BOOL cache)
/* /*
* Call this to start generating a user path. The cache argument specifies if * Call this to start generating a user path. The cache argument specifies if
* you want the user path cached at the server (i.e. dps_ucache). In either * you want the user path cached at the server (i.e. dps_ucache). In either
@ -91,7 +96,8 @@ void beginUserPath(UserPath *up, BOOL cache)
return; return;
} }
void endUserPath(UserPath *up, int op) void
endUserPath (UserPath * up, int op)
/* /*
* Call this to stop filling the path. Note this does not send the userpath to * Call this to stop filling the path. Note this does not send the userpath to
* the server -- use sendUserPath. The op argument should be one of the * the server -- use sendUserPath. The op argument should be one of the
@ -107,7 +113,8 @@ void endUserPath(UserPath *up, int op)
} }
void UPdebug(UserPath *up, BOOL shouldPing) void
UPdebug (UserPath * up, BOOL shouldPing)
/* /*
* Sets ping to YES so that after each time a user path is sent down to the * Sets ping to YES so that after each time a user path is sent down to the
* window server, an NSPing() is sent after. The purpose is to catch PostScript * window server, an NSPing() is sent after. The purpose is to catch PostScript
@ -121,7 +128,8 @@ void UPdebug(UserPath *up, BOOL shouldPing)
return; return;
} }
int sendUserPath(UserPath *up) int
sendUserPath (UserPath * up)
/* /*
* Call this to send the path down to the server. If ping==YES (set via * Call this to send the path down to the server. If ping==YES (set via
* debug:), the function will send an NSPing() after the Path. In any event, * debug:), the function will send an NSPing() after the Path. In any event,
@ -137,18 +145,17 @@ int sendUserPath(UserPath *up)
exception.code = 0; exception.code = 0;
if (up->opForUserPath != 0) { if (up->opForUserPath != 0) {
//NS_DURING // NS_DURING
DPSDoUserPath(up->points, up->numberOfPoints, dps_float, up->ops, DPSDoUserPath (up->points, up->numberOfPoints, dps_float, up->ops,
up->numberOfOps, up->bbox, up->opForUserPath); up->numberOfOps, up->bbox, up->opForUserPath);
if (up->ping) { if (up->ping) {
NSPing(); NSPing ();
} }
// NS_HANDLER
//NS_HANDLER
// exception = NSLocalHandler; // exception = NSLocalHandler;
//NS_ENDHANDLER // NS_ENDHANDLER
if (exception.code) { if (exception.code) {
NSReportError(&exception); NSReportError (&exception);
if (exception.code == dps_err_ps) { if (exception.code == dps_err_ps) {
return -1; return -1;
} }
@ -161,7 +168,8 @@ int sendUserPath(UserPath *up)
} }
void UPmoveto(UserPath *up, float x, float y) void
UPmoveto (UserPath * up, float x, float y)
/* adds <x y moveto> to user path and updates bounding box */ /* adds <x y moveto> to user path and updates bounding box */
{ {
up->ops[up->numberOfOps++] = dps_moveto; up->ops[up->numberOfOps++] = dps_moveto;
@ -185,7 +193,8 @@ void UPmoveto(UserPath *up, float x, float y)
} }
void UPlineto(UserPath *up, float x, float y) void
UPlineto (UserPath * up, float x, float y)
/* adds <x y lineto> to user path and updates bounding box */ /* adds <x y lineto> to user path and updates bounding box */
{ {
up->ops[up->numberOfOps++] = dps_lineto; up->ops[up->numberOfOps++] = dps_lineto;
@ -206,4 +215,3 @@ void UPlineto(UserPath *up, float x, float y)
} }
return; return;
} }

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,6 @@
#include "ZScrollView.h" #include "ZScrollView.h"
@implementation ZScrollView @implementation ZScrollView
/* /*
==================== ====================
initWithFrame: button: initWithFrame: button:
@ -9,42 +8,37 @@ initWithFrame: button:
Initizes a scroll view with a button at it's lower right corner Initizes a scroll view with a button at it's lower right corner
==================== ====================
*/ */
- initWithFrame:(NSRect)
frameRect button1:b1 {
[super initWithFrame:frameRect];
- initWithFrame:(NSRect)frameRect button1:b1 [self addSubview:b1];
{
[super initWithFrame: frameRect];
[self addSubview: b1];
button1 = b1; button1 = b1;
[self setHasHorizontalScroller: YES]; [self setHasHorizontalScroller:YES];
[self setHasVerticalScroller: YES]; [self setHasVerticalScroller:YES];
[self setBorderType: NSBezelBorder]; [self setBorderType:NSBezelBorder];
return self; return self;
} }
/* /*
================ ================
tile tile
Adjust the size for the pop up scale menu Adjust the size for the pop up scale menu
================= =================
*/ */ -tile
- tile
{ {
NSRect scrollerframe; NSRect scrollerframe;
[super tile]; [super tile];
scrollerframe = [_horizScroller frame]; scrollerframe =[_horizScroller frame];
[button1 setFrame: scrollerframe]; [button1 setFrame:scrollerframe];
scrollerframe.size.width = 0; scrollerframe.size.width = 0;
[_horizScroller setFrame: scrollerframe]; [_horizScroller setFrame:scrollerframe];
return self; return self;
} }
@ -55,6 +49,7 @@ Adjust the size for the pop up scale menu
{ {
return YES; return YES;
} }
/* /*
- superviewSizeChanged:(const NSSize *)oldSize - superviewSizeChanged:(const NSSize *)oldSize
{ {
@ -68,4 +63,3 @@ Adjust the size for the pop up scale menu
@end @end

View file

@ -16,13 +16,12 @@ float zplanedir;
extern NSBezierPath *path; extern NSBezierPath *path;
@implementation ZView @implementation ZView
/* /*
================== ==================
initWithFrame: initWithFrame:
================== ==================
*/ */
- (id)initWithFrame:(NSRect)frameRect - (id) initWithFrame:(NSRect) frameRect
{ {
NSPoint pt; NSPoint pt;
@ -39,28 +38,27 @@ initWithFrame:
// //
// initialize the pop up menus // initialize the pop up menus
// //
zscalebutton_i = [[NSPopUpButton alloc] init]; zscalebutton_i =[[NSPopUpButton alloc] init];
[zscalebutton_i setTarget: self]; [zscalebutton_i setTarget:self];
[zscalebutton_i setAction: @selector(scaleMenuTarget:)]; [zscalebutton_i setAction: @selector (scaleMenuTarget:)];
[zscalebutton_i addItemWithTitle: @"12.5%"]; [zscalebutton_i addItemWithTitle:@"12.5%"];
[zscalebutton_i addItemWithTitle: @"25%"]; [zscalebutton_i addItemWithTitle:@"25%"];
[zscalebutton_i addItemWithTitle: @"50%"]; [zscalebutton_i addItemWithTitle:@"50%"];
[zscalebutton_i addItemWithTitle: @"75%"]; [zscalebutton_i addItemWithTitle:@"75%"];
[zscalebutton_i addItemWithTitle: @"100%"]; [zscalebutton_i addItemWithTitle:@"100%"];
[zscalebutton_i addItemWithTitle: @"200%"]; [zscalebutton_i addItemWithTitle:@"200%"];
[zscalebutton_i addItemWithTitle: @"300%"]; [zscalebutton_i addItemWithTitle:@"300%"];
[zscalebutton_i selectItemAtIndex: 4]; [zscalebutton_i selectItemAtIndex:4];
// initialize the scroll view // initialize the scroll view
zscrollview_i = [[ZScrollView alloc] zscrollview_i =[[ZScrollView alloc]
initWithFrame: frameRect initWithFrame: frameRect button1:zscalebutton_i];
button1: zscalebutton_i [zscrollview_i setAutoresizingMask:NSViewWidthSizable |
]; NSViewHeightSizable];
[zscrollview_i setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[zscrollview_i setDocumentView: self]; [zscrollview_i setDocumentView:self];
RELEASE (zscrollview_i); RELEASE (zscrollview_i);
// [_super_view setDrawOrigin: 0 : 0]; // [_super_view setDrawOrigin: 0 : 0];
@ -73,19 +71,19 @@ initWithFrame:
[self newRealBounds]; [self newRealBounds];
[self setOrigin: &pt scale: 1]; [self setOrigin: &pt scale:1];
return zscrollview_i; return zscrollview_i;
} }
- setXYOrigin: (NSPoint *)pt -setXYOrigin:(NSPoint *) pt
{ {
origin[0] = pt->x + 0.333; origin[0] = pt->x + 0.333;
origin[1] = pt->y + 0.333; origin[1] = pt->y + 0.333;
return self; return self;
} }
- (float)currentScale -(float) currentScale
{ {
return scale; return scale;
} }
@ -95,7 +93,8 @@ initWithFrame:
setOrigin:scale: setOrigin:scale:
=================== ===================
*/ */
- setOrigin: (NSPoint *)pt scale: (float)sc -setOrigin:(NSPoint *)
pt scale:(float) sc
{ {
NSRect sframe; NSRect sframe;
NSRect newbounds; NSRect newbounds;
@ -105,8 +104,8 @@ setOrigin:scale:
// //
scale = sc; scale = sc;
sframe = [_super_view frame]; sframe =[_super_view frame];
newbounds = [_super_view frame]; newbounds =[_super_view frame];
newbounds.origin = *pt; newbounds.origin = *pt;
newbounds.size.width /= scale; newbounds.size.width /= scale;
newbounds.size.height /= scale; newbounds.size.height /= scale;
@ -114,38 +113,35 @@ setOrigin:scale:
// //
// union with the realbounds // union with the realbounds
// //
if (newbounds.origin.y > oldminheight) if (newbounds.origin.y > oldminheight) {
{
newbounds.size.height += newbounds.origin.y - oldminheight; newbounds.size.height += newbounds.origin.y - oldminheight;
newbounds.origin.y = oldminheight; newbounds.origin.y = oldminheight;
} }
if (newbounds.origin.y+newbounds.size.height < oldmaxheight) if (newbounds.origin.y + newbounds.size.height < oldmaxheight) {
{
newbounds.size.height += oldmaxheight newbounds.size.height += oldmaxheight
- (newbounds.origin.y + newbounds.size.height); - (newbounds.origin.y + newbounds.size.height);
} }
// //
// redisplay everything // redisplay everything
// //
//XXX[quakeed_i disableDisplay]; // XXX[quakeed_i disableDisplay];
// //
// size this view // size this view
// //
[self setBoundsSize: newbounds.size]; [self setBoundsSize:newbounds.size];
//XXX[self setDrawOrigin: -newbounds.size.width/2 : newbounds.origin.y]; // XXX[self setDrawOrigin: -newbounds.size.width/2 : newbounds.origin.y];
//XXX[self moveTo: -newbounds.size.width/2 : newbounds.origin.y]; // XXX[self moveTo: -newbounds.size.width/2 : newbounds.origin.y];
// //
// scroll and scale the clip view // scroll and scale the clip view
// //
//XXX[_super_view setDrawSize // XXX[_super_view setDrawSize
//XXX : sframe.size.width/scale // XXX : sframe.size.width/scale
//XXX : sframe.size.height/scale]; // XXX : sframe.size.height/scale];
//XXX[_super_view setDrawOrigin: pt->x : pt->y]; // XXX[_super_view setDrawOrigin: pt->x : pt->y];
//XXX[quakeed_i reenableDisplay]; // XXX[quakeed_i reenableDisplay];
[zscrollview_i display]; [zscrollview_i display];
return self; return self;
@ -159,35 +155,35 @@ scaleMenuTarget:
Called when the scaler popup on the window is used Called when the scaler popup on the window is used
==================== ====================
*/ */
- scaleMenuTarget: sender -scaleMenuTarget:sender
{ {
char const *item; char const *item;
NSRect visrect, sframe; NSRect visrect, sframe;
float nscale; float nscale;
item = [[sender titleOfSelectedItem] cString]; item =[[sender titleOfSelectedItem] cString];
sscanf (item,"%f",&nscale); sscanf (item, "%f", &nscale);
nscale /= 100; nscale /= 100;
if (nscale == scale) if (nscale == scale)
return NULL; return NULL;
// keep the center of the view constant // keep the center of the view constant
visrect = [_super_view bounds]; visrect =[_super_view bounds];
sframe = [_super_view frame]; sframe =[_super_view frame];
visrect.origin.x += visrect.size.width/2; visrect.origin.x += visrect.size.width / 2;
visrect.origin.y += visrect.size.height/2; visrect.origin.y += visrect.size.height / 2;
visrect.origin.x -= sframe.size.width/2/nscale; visrect.origin.x -= sframe.size.width / 2 / nscale;
visrect.origin.y -= sframe.size.height/2/nscale; visrect.origin.y -= sframe.size.height / 2 / nscale;
[self setOrigin: &visrect.origin scale: nscale]; [self setOrigin: &visrect.origin scale:nscale];
return self; return self;
} }
- clearBounds -clearBounds
{ {
topbound = 999999; topbound = 999999;
bottombound = -999999; bottombound = -999999;
@ -195,7 +191,7 @@ Called when the scaler popup on the window is used
return self; return self;
} }
- getBounds: (float *)top :(float *)bottom; -getBounds: (float *) top:(float *) bottom;
{ {
*top = topbound; *top = topbound;
*bottom = bottombound; *bottom = bottombound;
@ -208,7 +204,7 @@ Called when the scaler popup on the window is used
addToHeightRange: addToHeightRange:
================== ==================
*/ */
- addToHeightRange: (float)height -addToHeightRange:(float) height
{ {
if (height < minheight) if (height < minheight)
minheight = height; minheight = height;
@ -225,7 +221,7 @@ newSuperBounds
When _super_view is resized When _super_view is resized
================== ==================
*/ */
- newSuperBounds -newSuperBounds
{ {
oldminheight++; oldminheight++;
[self newRealBounds]; [self newRealBounds];
@ -242,7 +238,7 @@ Should only change the scroll bars, not cause any redraws.
If realbounds has shrunk, nothing will change. If realbounds has shrunk, nothing will change.
=================== ===================
*/ */
- newRealBounds -newRealBounds
{ {
NSRect sbounds; NSRect sbounds;
float vistop, visbottom; float vistop, visbottom;
@ -259,7 +255,7 @@ If realbounds has shrunk, nothing will change.
// //
// calculate the area visible in the cliprect // calculate the area visible in the cliprect
// //
sbounds = [_super_view bounds]; sbounds =[_super_view bounds];
visbottom = sbounds.origin.y; visbottom = sbounds.origin.y;
vistop = visbottom + sbounds.size.height; vistop = visbottom + sbounds.size.height;
@ -267,7 +263,8 @@ If realbounds has shrunk, nothing will change.
maxheight = vistop; maxheight = vistop;
if (visbottom < minheight) if (visbottom < minheight)
minheight = visbottom; minheight = visbottom;
if (minheight == _bounds.origin.y && maxheight-minheight == _bounds.size.height) if (minheight == _bounds.origin.y
&& maxheight - minheight == _bounds.size.height)
return self; return self;
sbounds.origin.y = minheight; sbounds.origin.y = minheight;
@ -276,18 +273,18 @@ If realbounds has shrunk, nothing will change.
// //
// size this view // size this view
// //
//XXX[quakeed_i disableDisplay]; // XXX[quakeed_i disableDisplay];
//XXX[self suspendNotifyAncestorWhenFrameChanged:YES]; // XXX[self suspendNotifyAncestorWhenFrameChanged:YES];
[self setBoundsSize: sbounds.size]; [self setBoundsSize:sbounds.size];
//XXX[self setDrawOrigin: -sbounds.size.width/2 : sbounds.origin.y]; // XXX[self setDrawOrigin: -sbounds.size.width/2 : sbounds.origin.y];
//XXX[self moveTo: -sbounds.size.width/2 : sbounds.origin.y]; // XXX[self moveTo: -sbounds.size.width/2 : sbounds.origin.y];
//XXX[self suspendNotifyAncestorWhenFrameChanged:NO]; // XXX[self suspendNotifyAncestorWhenFrameChanged:NO];
//XXX[[_super_view _super_view] reflectScroll: _super_view]; // XXX[[_super_view _super_view] reflectScroll: _super_view];
//XXX[quakeed_i reenableDisplay]; // XXX[quakeed_i reenableDisplay];
//XXX[[[[self _super_view] _super_view] vertScroller] display]; // XXX[[[[self _super_view] _super_view] vertScroller] display];
return self; return self;
} }
@ -305,26 +302,26 @@ Rect is in global world (unscaled) coordinates
============ ============
*/ */
- drawGrid: (const NSRect *)rect -drawGrid:(const NSRect *) rect
{ {
int y, stopy; int y, stopy;
float top,bottom; float top, bottom;
int left, right; int left, right;
int gridsize; int gridsize;
char text[10]; char text[10];
BOOL showcoords; BOOL showcoords;
showcoords = [quakeed_i showCoordinates]; showcoords =[quakeed_i showCoordinates];
PSsetlinewidth (0); PSsetlinewidth (0);
gridsize = [xyview_i gridsize]; gridsize =[xyview_i gridsize];
left = _bounds.origin.x; left = _bounds.origin.x;
right = 24; right = 24;
bottom = rect->origin.y-1; bottom = rect->origin.y - 1;
top = rect->origin.y+rect->size.height+2; top = rect->origin.y + rect->size.height + 2;
// //
// grid // grid
@ -332,37 +329,33 @@ Rect is in global world (unscaled) coordinates
// can't just divide by grid size because of negetive coordinate // can't just divide by grid size because of negetive coordinate
// truncating direction // truncating direction
// //
if (gridsize>= 4/scale) if (gridsize >= 4 / scale) {
{ y = floor (bottom / gridsize);
y = floor(bottom/gridsize); stopy = floor (top / gridsize);
stopy = floor(top/gridsize);
y *= gridsize; y *= gridsize;
stopy *= gridsize; stopy *= gridsize;
if (y<bottom) if (y < bottom)
y+= gridsize; y += gridsize;
[path removeAllPoints]; [path removeAllPoints];
for ( ; y<=stopy ; y+= gridsize) for (; y <= stopy; y += gridsize)
if (y&31) if (y & 31) {
{ [path moveToPoint:NSMakePoint (left, y)];
[path moveToPoint: NSMakePoint (left, y)]; [path lineToPoint:NSMakePoint (right, y)];
[path lineToPoint: NSMakePoint (right, y)];
} }
// endUserPath (upath, dps_ustroke);
//endUserPath (upath, dps_ustroke); PSsetrgbcolor (0.8, 0.8, 1.0); // thin grid color
PSsetrgbcolor (0.8,0.8,1.0); // thin grid color
[path stroke]; [path stroke];
} }
// //
// half tiles // half tiles
// //
y = floor(bottom/32); y = floor (bottom / 32);
stopy = floor(top/32); stopy = floor (top / 32);
if ( ! (((int)y + 4096) & 1) ) if (!(((int) y + 4096) & 1))
y++; y++;
y *= 32; y *= 32;
stopy *= 32; stopy *= 32;
@ -371,61 +364,59 @@ Rect is in global world (unscaled) coordinates
[path removeAllPoints]; [path removeAllPoints];
for ( ; y<=stopy ; y+= 64) for (; y <= stopy; y += 64) {
{ [path moveToPoint:NSMakePoint (left, y)];
[path moveToPoint: NSMakePoint (left, y)]; [path lineToPoint:NSMakePoint (right, y)];
[path lineToPoint: NSMakePoint (right, y)];
} }
//endUserPath (upath, dps_ustroke); // endUserPath (upath, dps_ustroke);
PSsetgray (12.0/16.0); PSsetgray (12.0 / 16.0);
[path stroke]; [path stroke];
// //
// tiles // tiles
// //
y = floor(bottom/64); y = floor (bottom / 64);
stopy = floor(top/64); stopy = floor (top / 64);
y *= 64; y *= 64;
stopy *= 64; stopy *= 64;
if (y<bottom) if (y < bottom)
y+= 64; y += 64;
if (stopy >= top) if (stopy >= top)
stopy -= 64; stopy -= 64;
[path removeAllPoints]; [path removeAllPoints];
PSsetgray (0); // for text PSsetgray (0); // for text
GSSetFont (DEFCTXT, [NSFont fontWithName:@"Helvetica-Medium" size: 10/scale]); GSSetFont (DEFCTXT,[NSFont fontWithName: @"Helvetica-Medium" size:10 / scale]);
PSrotate(0); PSrotate (0);
for ( ; y<=stopy ; y+= 64) for (; y <= stopy; y += 64) {
{ if (showcoords) {
if (showcoords) sprintf (text, "%i", y);
{ PSmoveto (left, y);
sprintf (text, "%i",y); PSshow (text);
PSmoveto(left,y);
PSshow(text);
} }
[path moveToPoint: NSMakePoint (left + 24, y)]; [path moveToPoint:NSMakePoint (left + 24, y)];
[path lineToPoint: NSMakePoint (right, y)]; [path lineToPoint:NSMakePoint (right, y)];
} }
// divider // divider
[path moveToPoint: NSMakePoint (0, _bounds.origin.y)]; [path moveToPoint:NSMakePoint (0, _bounds.origin.y)];
[path lineToPoint: NSMakePoint (0, _bounds.origin.y + _bounds.size.height)]; [path lineToPoint:NSMakePoint (0,
_bounds.origin.y + _bounds.size.height)];
//endUserPath (upath, dps_ustroke); // endUserPath (upath, dps_ustroke);
PSsetgray (10.0/16.0); PSsetgray (10.0 / 16.0);
[path stroke]; [path stroke];
// //
// origin // origin
// //
PSsetlinewidth (5); PSsetlinewidth (5);
PSsetgray (4.0/16.0); PSsetgray (4.0 / 16.0);
PSmoveto (right,0); PSmoveto (right, 0);
PSlineto (left,0); PSlineto (left, 0);
PSstroke (); PSstroke ();
PSsetlinewidth (0.15); PSsetlinewidth (0.15);
@ -433,10 +424,10 @@ Rect is in global world (unscaled) coordinates
} }
- drawZplane -drawZplane
{ {
PSsetrgbcolor (0.2, 0.2, 0); PSsetrgbcolor (0.2, 0.2, 0);
PSarc (0, zplane, 4, 0, M_PI*2); PSarc (0, zplane, 4, 0, M_PI * 2);
PSfill (); PSfill ();
return self; return self;
} }
@ -447,7 +438,7 @@ drawSelf
=============================================================================== ===============================================================================
*/ */
- drawSelf:(const NSRect *)rects :(int)rectCount -drawSelf: (const NSRect *) rects:(int) rectCount
{ {
NSRect visRect; NSRect visRect;
@ -455,20 +446,20 @@ drawSelf
maxheight = -999999; maxheight = -999999;
// allways draw the entire bar // allways draw the entire bar
visRect = [self visibleRect]; visRect =[self visibleRect];
rects = &visRect; rects = &visRect;
// erase window // erase window
NSEraseRect (rects[0]); NSEraseRect (rects[0]);
// draw grid // draw grid
[self drawGrid: &rects[0]]; [self drawGrid:&rects[0]];
// draw zplane // draw zplane
// [self drawZplane]; // [self drawZplane];
// draw all entities // draw all entities
[map_i makeUnselectedPerform: @selector(ZDrawSelf)]; [map_i makeUnselectedPerform:@selector (ZDrawSelf)];
// possibly resize the view // possibly resize the view
[self newRealBounds]; [self newRealBounds];
@ -481,14 +472,14 @@ drawSelf
XYDrawSelf XYDrawSelf
============== ==============
*/ */
- XYDrawSelf -XYDrawSelf
{ {
PSsetrgbcolor (0,0.5,1.0); PSsetrgbcolor (0, 0.5, 1.0);
PSsetlinewidth (0.15); PSsetlinewidth (0.15);
PSmoveto (origin[0]-16, origin[1]-16); PSmoveto (origin[0] - 16, origin[1] - 16);
PSrlineto (32,32); PSrlineto (32, 32);
PSmoveto (origin[0]-16, origin[1]+16); PSmoveto (origin[0] - 16, origin[1] + 16);
PSrlineto (32,-32); PSrlineto (32, -32);
PSstroke (); PSstroke ();
return self; return self;
@ -500,14 +491,14 @@ XYDrawSelf
getPoint: (NSPoint *)pt getPoint: (NSPoint *)pt
============== ==============
*/ */
- getPoint: (NSPoint *)pt -getPoint:(NSPoint *) pt
{ {
pt->x = origin[0] + 0.333; // offset a bit to avoid edge cases pt->x = origin[0] + 0.333; // offset a bit to avoid edge cases
pt->y = origin[1] + 0.333; pt->y = origin[1] + 0.333;
return self; return self;
} }
- setPoint: (NSPoint *)pt -setPoint:(NSPoint *) pt
{ {
origin[0] = pt->x; origin[0] = pt->x;
origin[1] = pt->y; origin[1] = pt->y;
@ -530,44 +521,41 @@ dragLoop:
================ ================
*/ */
static NSPoint oldreletive; static NSPoint oldreletive;
- dragFrom: (NSEvent *)startevent
useGrid: (BOOL)ug -dragFrom: (NSEvent *) startevent useGrid: (BOOL) ug callback:(void (*)(float dy)) callback
callback: (void (*) (float dy)) callback
{ {
NSEvent *event; NSEvent *event;
NSPoint startpt, newpt; NSPoint startpt, newpt;
NSPoint reletive, delta; NSPoint reletive, delta;
int gridsize; int gridsize;
gridsize = [xyview_i gridsize]; gridsize =[xyview_i gridsize];
startpt = [startevent locationInWindow]; startpt =[startevent locationInWindow];
startpt = [self convertPoint:startpt fromView:NULL]; startpt =[self convertPoint: startpt fromView:NULL];
oldreletive.x = oldreletive.y = 0; oldreletive.x = oldreletive.y = 0;
reletive.x = 0; reletive.x = 0;
while (1) while (1) {
{
unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask
| NSRightMouseUpMask | NSRightMouseDraggedMask | NSRightMouseUpMask | NSRightMouseDraggedMask
| NSApplicationDefinedMask; | NSApplicationDefinedMask;
event = [NSApp nextEventMatchingMask: eventMask event =[NSApp nextEventMatchingMask: eventMask untilDate:[NSDate
untilDate: [NSDate distantFuture] distantFuture]
inMode: NSEventTrackingRunLoopMode inMode: NSEventTrackingRunLoopMode dequeue:YES];
dequeue: YES];
if ([event type] == NSLeftMouseUp || [event type] == NSRightMouseUp) if ([event type] == NSLeftMouseUp ||[event type] == NSRightMouseUp)
break; break;
newpt = [event locationInWindow]; newpt =[event locationInWindow];
newpt = [self convertPoint:newpt fromView:NULL]; newpt =[self convertPoint: newpt fromView:NULL];
reletive.y = newpt.y - startpt.y; reletive.y = newpt.y - startpt.y;
if (ug) if (ug) { // we want truncate towards 0 behavior
{ // we want truncate towards 0 behavior here // here
reletive.y = gridsize * (int)(reletive.y / gridsize); reletive.y = gridsize * (int) (reletive.y / gridsize);
} }
if (reletive.y == oldreletive.y) if (reletive.y == oldreletive.y)
@ -584,23 +572,22 @@ static NSPoint oldreletive;
//============================================================================ //============================================================================
void ZDragCallback (float dy) void
ZDragCallback (float dy)
{ {
sb_translate[0] = 0; sb_translate[0] = 0;
sb_translate[1] = 0; sb_translate[1] = 0;
sb_translate[2] = dy; sb_translate[2] = dy;
[map_i makeSelectedPerform: @selector(translate)]; [map_i makeSelectedPerform:@selector (translate)];
[quakeed_i redrawInstance]; [quakeed_i redrawInstance];
} }
- selectionDragFrom: (NSEvent*)theEvent -selectionDragFrom:(NSEvent *) theEvent
{ {
qprintf ("dragging selection"); qprintf ("dragging selection");
[self dragFrom: theEvent [self dragFrom: theEvent useGrid: YES callback:ZDragCallback];
useGrid: YES
callback: ZDragCallback ];
[quakeed_i updateCamera]; [quakeed_i updateCamera];
qprintf (""); qprintf ("");
return self; return self;
@ -609,47 +596,48 @@ void ZDragCallback (float dy)
//============================================================================ //============================================================================
void ZScrollCallback (float dy) void
ZScrollCallback (float dy)
{ {
NSRect basebounds; NSRect basebounds;
NSPoint neworg; NSPoint neworg;
float scale; float scale;
basebounds = [[zview_i superview] bounds]; basebounds =[[zview_i superview] bounds];
basebounds = [zview_i convertRect: basebounds fromView: [zview_i superview]]; basebounds =[zview_i convertRect: basebounds fromView:[zview_i
superview]];
neworg.y = basebounds.origin.y - dy; neworg.y = basebounds.origin.y - dy;
scale = [zview_i currentScale]; scale =[zview_i currentScale];
oldreletive.y -= dy; oldreletive.y -= dy;
[zview_i setOrigin: &neworg scale: scale]; [zview_i setOrigin: &neworg scale:scale];
} }
- scrollDragFrom: (NSEvent*)theEvent -scrollDragFrom:(NSEvent *) theEvent
{ {
qprintf ("scrolling view"); qprintf ("scrolling view");
[self dragFrom: theEvent [self dragFrom: theEvent useGrid: YES callback:ZScrollCallback];
useGrid: YES
callback: ZScrollCallback ];
qprintf (""); qprintf ("");
return self; return self;
} }
//============================================================================ //============================================================================
void ZControlCallback (float dy) void
ZControlCallback (float dy)
{ {
int i; int i;
for (i=0 ; i<numcontrolpoints ; i++) for (i = 0; i < numcontrolpoints; i++)
controlpoints[i][2] += dy; controlpoints[i][2] += dy;
[[map_i selectedBrush] calcWindings]; [[map_i selectedBrush] calcWindings];
[quakeed_i redrawInstance]; [quakeed_i redrawInstance];
} }
- (BOOL)planeDragFrom: (NSEvent*)theEvent -(BOOL) planeDragFrom:(NSEvent *) theEvent
{ {
NSPoint pt; NSPoint pt;
vec3_t dragpoint; vec3_t dragpoint;
@ -657,25 +645,23 @@ void ZControlCallback (float dy)
if ([map_i numSelected] != 1) if ([map_i numSelected] != 1)
return NO; return NO;
pt= [theEvent locationInWindow]; pt =[theEvent locationInWindow];
pt = [self convertPoint:pt fromView:NULL]; pt =[self convertPoint: pt fromView:NULL];
dragpoint[0] = origin[0]; dragpoint[0] = origin[0];
dragpoint[1] = origin[1]; dragpoint[1] = origin[1];
dragpoint[2] = pt.y; dragpoint[2] = pt.y;
[[map_i selectedBrush] getZdragface: dragpoint]; [[map_i selectedBrush] getZdragface:dragpoint];
if (!numcontrolpoints) if (!numcontrolpoints)
return NO; return NO;
qprintf ("dragging brush plane"); qprintf ("dragging brush plane");
pt= [theEvent locationInWindow]; pt =[theEvent locationInWindow];
pt = [self convertPoint:pt fromView:NULL]; pt =[self convertPoint: pt fromView:NULL];
[self dragFrom: theEvent [self dragFrom: theEvent useGrid: YES callback:ZControlCallback];
useGrid: YES
callback: ZControlCallback ];
[[map_i selectedBrush] removeIfInvalid]; [[map_i selectedBrush] removeIfInvalid];
@ -692,67 +678,61 @@ void ZControlCallback (float dy)
mouseDown mouseDown
=================== ===================
*/ */
- (void)mouseDown:(NSEvent *)theEvent -(void) mouseDown:(NSEvent *) theEvent
{ {
NSPoint pt; NSPoint pt;
int flags; int flags;
vec3_t p1; vec3_t p1;
pt= [theEvent locationInWindow]; pt =[theEvent locationInWindow];
pt = [self convertPoint:pt fromView:NULL]; pt =[self convertPoint: pt fromView:NULL];
p1[0] = origin[0]; p1[0] = origin[0];
p1[1] = origin[1]; p1[1] = origin[1];
p1[2] = pt.y; p1[2] = pt.y;
flags = [theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask); flags =
[theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask |
NSAlternateKeyMask | NSCommandKeyMask);
// //
// shift click to select / deselect a brush from the world // shift click to select / deselect a brush from the world
// //
if (flags == NSShiftKeyMask) if (flags == NSShiftKeyMask) {
{ [map_i selectRay: p1: p1:NO];
[map_i selectRay: p1 : p1 : NO];
return; return;
} }
// //
// alt click = set entire brush texture // alt click = set entire brush texture
// //
if (flags == NSAlternateKeyMask) if (flags == NSAlternateKeyMask) {
{ [map_i setTextureRay: p1: p1:YES];
[map_i setTextureRay: p1 : p1 : YES];
return; return;
} }
// //
// control click = position view // control click = position view
// //
if (flags == NSControlKeyMask) if (flags == NSControlKeyMask) {
{ [cameraview_i setZOrigin:pt.y];
[cameraview_i setZOrigin: pt.y];
[quakeed_i updateAll]; [quakeed_i updateAll];
[cameraview_i ZmouseDown: &pt flags:[theEvent modifierFlags]]; [cameraview_i ZmouseDown: &pt flags:[theEvent modifierFlags]];
return; return;
} }
// //
// bare click to drag icons or new brush drag // bare click to drag icons or new brush drag
// //
if ( flags == 0 ) if (flags == 0) {
{
// check eye // check eye
if ( [cameraview_i ZmouseDown: &pt flags:[theEvent modifierFlags]] ) if ([cameraview_i ZmouseDown: &pt flags:[theEvent
modifierFlags]])
return; return;
if ([map_i numSelected]) if ([map_i numSelected]) {
{ if (pt.x > 0) {
if ( pt.x > 0) if ([self planeDragFrom:theEvent])
{
if ([self planeDragFrom: theEvent])
return; return;
} }
[self selectionDragFrom: theEvent]; [self selectionDragFrom:theEvent];
return; return;
} }
@ -768,23 +748,24 @@ mouseDown
rightMouseDown rightMouseDown
=================== ===================
*/ */
- (void)rightMouseDown:(NSEvent *)theEvent -(void) rightMouseDown:(NSEvent *) theEvent
{ {
NSPoint pt; NSPoint pt;
int flags; int flags;
pt= [theEvent locationInWindow]; pt =[theEvent locationInWindow];
pt = [self convertPoint:pt fromView:NULL]; pt =[self convertPoint: pt fromView:NULL];
flags = [theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask); flags =
[theEvent modifierFlags] & (NSShiftKeyMask | NSControlKeyMask |
NSAlternateKeyMask | NSCommandKeyMask);
// //
// click = scroll view // click = scroll view
// //
if (flags == 0) if (flags == 0) {
{ [self scrollDragFrom:theEvent];
[self scrollDragFrom: theEvent];
} }
qprintf ("bad flags for click"); qprintf ("bad flags for click");
@ -805,7 +786,7 @@ rightMouseDown
modalMoveLoop modalMoveLoop
================ ================
*/ */
- modalMoveLoop: (NSPoint *)basept :(vec3_t)movemod : converter -modalMoveLoop: (NSPoint *) basept: (vec3_t) movemod:converter
{ {
vec3_t originbase; vec3_t originbase;
NSEvent *event; NSEvent *event;
@ -821,23 +802,22 @@ modalMoveLoop
// //
goto drawentry; goto drawentry;
while ([event type] != NSLeftMouseUp) while ([event type] != NSLeftMouseUp) {
{
// //
// calculate new point // calculate new point
// //
newpt = [event locationInWindow]; newpt =[event locationInWindow];
newpt = [converter convertPoint:newpt fromView:NULL]; newpt =[converter convertPoint: newpt fromView:NULL];
delta[0] = newpt.x-basept->x; delta[0] = newpt.x - basept->x;
delta[1] = newpt.y-basept->y; delta[1] = newpt.y - basept->y;
delta[2] = delta[1]; // height change delta[2] = delta[1]; // height change
for (i=0 ; i<3 ; i++) for (i = 0; i < 3; i++)
origin[i] = originbase[i]+movemod[i]*delta[i]; origin[i] = originbase[i] + movemod[i] * delta[i];
drawentry: drawentry:
// //
// instance draw new frame // instance draw new frame
// //
@ -845,10 +825,10 @@ drawentry:
[self display]; [self display];
unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask; unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask;
event = [NSApp nextEventMatchingMask: eventMask
untilDate: [NSDate distantFuture] event =[NSApp nextEventMatchingMask: eventMask untilDate:[NSDate
inMode: NSEventTrackingRunLoopMode distantFuture]
dequeue: YES]; inMode: NSEventTrackingRunLoopMode dequeue:YES];
} }
// //
@ -864,19 +844,18 @@ drawentry:
XYmouseDown XYmouseDown
=============== ===============
*/ */
- (BOOL)XYmouseDown: (NSPoint *)pt -(BOOL) XYmouseDown:(NSPoint *) pt
{ {
vec3_t movemod; vec3_t movemod;
if (fabs(pt->x - origin[0]) > 16 if (fabs (pt->x - origin[0]) > 16 || fabs (pt->y - origin[1]) > 16)
|| fabs(pt->y - origin[1]) > 16)
return NO; return NO;
movemod[0] = 1; movemod[0] = 1;
movemod[1] = 1; movemod[1] = 1;
movemod[2] = 0; movemod[2] = 0;
[self modalMoveLoop: pt : movemod : xyview_i]; [self modalMoveLoop: pt: movemod:xyview_i];
return YES; return YES;
} }

View file

@ -6,14 +6,16 @@ boolean unget;
char *script_p; char *script_p;
int scriptline; int scriptline;
void StartTokenParsing (char *data) void
StartTokenParsing (char *data)
{ {
scriptline = 1; scriptline = 1;
script_p = data; script_p = data;
unget = false; unget = false;
} }
boolean GetToken (boolean crossline) boolean
GetToken (boolean crossline)
{ {
char *token_p; char *token_p;
@ -23,19 +25,16 @@ boolean GetToken (boolean crossline)
// //
// skip space // skip space
// //
skipspace: skipspace:
while (*script_p <= 32) while (*script_p <= 32) {
{ if (!*script_p) {
if (!*script_p)
{
if (!crossline) if (!crossline)
Error ("Line %i is incomplete",scriptline); Error ("Line %i is incomplete", scriptline);
return false; return false;
} }
if (*script_p++ == '\n') if (*script_p++ == '\n') {
{
if (!crossline) if (!crossline)
Error ("Line %i is incomplete",scriptline); Error ("Line %i is incomplete", scriptline);
scriptline++; scriptline++;
} }
} }
@ -43,40 +42,35 @@ skipspace:
if (script_p[0] == '/' && script_p[1] == '/') // comment field if (script_p[0] == '/' && script_p[1] == '/') // comment field
{ {
if (!crossline) if (!crossline)
Error ("Line %i is incomplete\n",scriptline); Error ("Line %i is incomplete\n", scriptline);
while (*script_p++ != '\n') while (*script_p++ != '\n')
if (!*script_p) if (!*script_p) {
{
if (!crossline) if (!crossline)
Error ("Line %i is incomplete",scriptline); Error ("Line %i is incomplete", scriptline);
return false; return false;
} }
goto skipspace; goto skipspace;
} }
// //
// copy token // copy token
// //
token_p = token; token_p = token;
if (*script_p == '"') if (*script_p == '"') {
{
script_p++; script_p++;
while ( *script_p != '"' ) while (*script_p != '"') {
{
if (!*script_p) if (!*script_p)
Error ("EOF inside quoted token"); Error ("EOF inside quoted token");
*token_p++ = *script_p++; *token_p++ = *script_p++;
if (token_p == &token[MAXTOKEN]) if (token_p == &token[MAXTOKEN])
Error ("Token too large on line %i",scriptline); Error ("Token too large on line %i", scriptline);
} }
script_p++; script_p++;
} } else
else while ( *script_p > 32 ) while (*script_p > 32) {
{
*token_p++ = *script_p++; *token_p++ = *script_p++;
if (token_p == &token[MAXTOKEN]) if (token_p == &token[MAXTOKEN])
Error ("Token too large on line %i",scriptline); Error ("Token too large on line %i", scriptline);
} }
*token_p = 0; *token_p = 0;
@ -84,7 +78,8 @@ skipspace:
return true; return true;
} }
void UngetToken () void
UngetToken ()
{ {
unget = true; unget = true;
} }
@ -93,17 +88,18 @@ void UngetToken ()
void qprintf (char *fmt, ...) // prints text to cmd_out_i void
qprintf (char *fmt, ...) // prints text to cmd_out_i
{ {
va_list argptr; va_list argptr;
static char string[1024]; static char string[1024];
va_start (argptr, fmt); va_start (argptr, fmt);
vsprintf (string, fmt,argptr); vsprintf (string, fmt, argptr);
va_end (argptr); va_end (argptr);
[g_cmd_out_i setStringValue: [NSString stringWithCString: string]]; [g_cmd_out_i setStringValue: [NSString stringWithCString:string]];
//NSPing (); // NSPing ();
return; return;
} }
@ -117,52 +113,54 @@ For abnormal program terminations
================= =================
*/ */
BOOL in_error; BOOL in_error;
void Error (char *error, ...) void
Error (char *error, ...)
{ {
va_list argptr; va_list argptr;
static char string[1024]; static char string[1024];
if (in_error) if (in_error)
[NSApp terminate: NULL]; [NSApp terminate:NULL];
in_error = YES; in_error = YES;
va_start (argptr,error); va_start (argptr, error);
vsprintf (string,error,argptr); vsprintf (string, error, argptr);
va_end (argptr); va_end (argptr);
strcat (string, "\nmap saved to "FN_CRASHSAVE); strcat (string, "\nmap saved to " FN_CRASHSAVE);
[map_i writeMapFile: FN_CRASHSAVE useRegion: NO]; [map_i writeMapFile: FN_CRASHSAVE useRegion:NO];
NSRunAlertPanel (@"Error", [NSString stringWithCString: string],NULL,NULL,NULL); NSRunAlertPanel (@"Error",[NSString stringWithCString:string], NULL, NULL,
NULL);
[NSApp terminate: NULL]; [NSApp terminate:NULL];
} }
void CleanupName (char *in, char *out) void
CleanupName (char *in, char *out)
{ {
int i; int i;
for (i=0 ; i< 16 ; i++ ) for (i = 0; i < 16; i++) {
{
if (!in[i]) if (!in[i])
break; break;
out[i] = toupper(in[i]); out[i] = toupper (in[i]);
} }
for ( ; i< 16 ; i++ ) for (; i < 16; i++)
out[i] = 0; out[i] = 0;
} }
void PrintRect (NSRect *r) void
PrintRect (NSRect * r)
{ {
printf ("(%4.0f, %4.0f) + (%4.0f, %4.0f) = (%4.0f,%4.0f)\n" printf ("(%4.0f, %4.0f) + (%4.0f, %4.0f) = (%4.0f,%4.0f)\n", r->origin.x,
,r->origin.x,r->origin.y, r->origin.y, r->size.width, r->size.height,
r->size.width, r->size.height, r->origin.x+r->size.width, r->origin.x + r->size.width, r->origin.y + r->size.height);
r->origin.y+r->size.height);
} }
@ -173,11 +171,12 @@ FileTime
returns -1 if not present returns -1 if not present
============ ============
*/ */
int FileTime (char *path) int
FileTime (char *path)
{ {
struct stat buf; struct stat buf;
if (stat (path,&buf) == -1) if (stat (path, &buf) == -1)
return -1; return -1;
return buf.st_mtime; return buf.st_mtime;
@ -188,22 +187,22 @@ int FileTime (char *path)
CreatePath CreatePath
============ ============
*/ */
void CreatePath (char *path) void
CreatePath (char *path)
{ {
char *ofs; char *ofs;
for (ofs = path+1 ; *ofs ; ofs++) for (ofs = path + 1; *ofs; ofs++) {
{ if (*ofs == '/') { // create the directory
if (*ofs == '/')
{ // create the directory
*ofs = 0; *ofs = 0;
mkdir (path,0777); mkdir (path, 0777);
*ofs = '/'; *ofs = '/';
} }
} }
} }
int I_FileOpenRead (char *path, int *handle) int
I_FileOpenRead (char *path, int *handle)
{ {
int h; int h;
struct stat fileinfo; struct stat fileinfo;
@ -214,23 +213,23 @@ int I_FileOpenRead (char *path, int *handle)
if (h == -1) if (h == -1)
return -1; return -1;
if (fstat (h,&fileinfo) == -1) if (fstat (h, &fileinfo) == -1)
Error ("Error fstating %s", path); Error ("Error fstating %s", path);
return fileinfo.st_size; return fileinfo.st_size;
} }
int I_FileOpenWrite (char *path) int
I_FileOpenWrite (char *path)
{ {
int handle; int handle;
umask (0); umask (0);
handle = open(path,O_RDWR | O_CREAT | O_TRUNC handle = open (path, O_RDWR | O_CREAT | O_TRUNC, 0666);
, 0666);
if (handle == -1) if (handle == -1)
Error ("Error opening %s: %s", path,strerror(errno)); Error ("Error opening %s: %s", path, strerror (errno));
return handle; return handle;
} }
@ -242,7 +241,8 @@ Sys_UpdateFile
Copies a more recent net file to the local drive Copies a more recent net file to the local drive
============ ============
*/ */
void Sys_UpdateFile (char *path, char *netpath) void
Sys_UpdateFile (char *path, char *netpath)
{ {
int ltime, ntime; int ltime, ntime;
int in, out, size; int in, out, size;
@ -269,5 +269,3 @@ void Sys_UpdateFile (char *path, char *netpath)
close (out); close (out);
} }

View file

@ -16,7 +16,7 @@ int r_width, r_height;
float *r_zbuffer; float *r_zbuffer;
unsigned *r_picbuffer; unsigned *r_picbuffer;
vec5_t rightside, leftside, rightstep,leftstep; vec5_t rightside, leftside, rightstep, leftstep;
face_t *r_face; face_t *r_face;
@ -31,11 +31,12 @@ int sy[20];
REN_ClearBuffers REN_ClearBuffers
==================== ====================
*/ */
void REN_ClearBuffers (void) void
REN_ClearBuffers (void)
{ {
int size; int size;
size = r_width * r_height*4; size = r_width * r_height * 4;
memset (r_zbuffer, 0, size); memset (r_zbuffer, 0, size);
memset (r_picbuffer, 0, size); memset (r_picbuffer, 0, size);
@ -48,7 +49,8 @@ REN_SetTexture
==================== ====================
*/ */
void REN_SetTexture (face_t *face) void
REN_SetTexture (face_t * face)
{ {
int i; int i;
int t_heightshift; int t_heightshift;
@ -67,29 +69,27 @@ void REN_SetTexture (face_t *face)
r_flatcolor.chan[1] *= r_face->light; r_flatcolor.chan[1] *= r_face->light;
r_flatcolor.chan[2] *= r_face->light; r_flatcolor.chan[2] *= r_face->light;
t_widthadd = t_width*1024; t_widthadd = t_width * 1024;
t_heightadd = t_height*1024; t_heightadd = t_height * 1024;
t_widthmask = t_width-1; t_widthmask = t_width - 1;
t_heightmask = t_height-1; t_heightmask = t_height - 1;
t_widthshift = 0; t_widthshift = 0;
i = t_width; i = t_width;
while (i >= 2) while (i >= 2) {
{
t_widthshift++; t_widthshift++;
i>>=1; i >>= 1;
} }
t_heightshift = 0; t_heightshift = 0;
i = t_width; i = t_width;
while (i >= 2) while (i >= 2) {
{
t_heightshift++; t_heightshift++;
i>>=1; i >>= 1;
} }
if ( (1<<t_widthshift) != t_width || (1<<t_heightshift) != t_height) if ((1 << t_widthshift) != t_width || (1 << t_heightshift) != t_height)
t_widthshift = t_heightshift = 0; // non power of two t_widthshift = t_heightshift = 0; // non power of two
} }
@ -98,7 +98,8 @@ void REN_SetTexture (face_t *face)
REN_DrawSpan REN_DrawSpan
================== ==================
*/ */
void REN_DrawSpan (int y) void
REN_DrawSpan (int y)
{ {
int x, count; int x, count;
int ofs; int ofs;
@ -108,7 +109,7 @@ void REN_DrawSpan (int y)
pixel32_t *in, *out; pixel32_t *in, *out;
float scale; float scale;
if (y<0 || y >= r_height) if (y < 0 || y >= r_height)
return; return;
x1 = (leftside[0]); x1 = (leftside[0]);
@ -126,54 +127,48 @@ void REN_DrawSpan (int y)
if (!count) if (!count)
scale = 1; scale = 1;
else else
scale = 1.0/count; scale = 1.0 / count;
zstep = (rightside[2] - zfrac)*scale; zstep = (rightside[2] - zfrac) * scale;
ustep = (rightside[3] - ufrac)*scale; ustep = (rightside[3] - ufrac) * scale;
vstep = (rightside[4] - vfrac)*scale; vstep = (rightside[4] - vfrac) * scale;
if (x1 < 0) if (x1 < 0) {
{ ufrac -= x1 * ustep;
ufrac -= x1*ustep; vfrac -= x1 * vstep;
vfrac -= x1*vstep; zfrac -= x1 * zstep;
zfrac -= x1*zstep;
x1 = 0; x1 = 0;
} }
if (x2 > r_width) if (x2 > r_width)
x2 = r_width; x2 = r_width;
ofs = y*r_width+x1; ofs = y * r_width + x1;
// this should be specialized for 1.0 / 0.5 / 0.75 light levels // this should be specialized for 1.0 / 0.5 / 0.75 light levels
for (x=x1 ; x < x2 ; x++) for (x = x1; x < x2; x++) {
{ if (r_zbuffer[ofs] <= zfrac) {
if (r_zbuffer[ofs] <= zfrac) scale = 1 / zfrac;
{
scale = 1/zfrac;
r_zbuffer[ofs] = zfrac; r_zbuffer[ofs] = zfrac;
if (t_widthshift) if (t_widthshift) {
{ tx = (int) ((ufrac * scale)) & t_widthmask;
tx = (int)((ufrac*scale)) & t_widthmask; ty = (int) ((vfrac * scale)) & t_heightmask;
ty = (int)((vfrac*scale)) & t_heightmask; in = (pixel32_t *) & t_data[(ty << t_widthshift) + tx];
in = (pixel32_t *)&t_data [(ty<<t_widthshift)+tx]; } else {
} tx = (int) ((ufrac * scale) + t_widthadd) % t_width;
else ty = (int) ((vfrac * scale) + t_heightadd) % t_height;
{ in = (pixel32_t *) & t_data[ty * t_width + tx];
tx = (int)((ufrac*scale)+t_widthadd) % t_width;
ty = (int)((vfrac*scale)+t_heightadd) % t_height;
in = (pixel32_t *)&t_data [ty*t_width+tx];
} }
out = (pixel32_t *)&r_picbuffer[ofs]; out = (pixel32_t *) & r_picbuffer[ofs];
#ifdef NOLIGHT #ifdef NOLIGHT
*out = *in; *out = *in;
#else #else
out->chan[0] = in->chan[0]*lightfrac; out->chan[0] = in->chan[0] * lightfrac;
out->chan[1] = in->chan[1]*lightfrac; out->chan[1] = in->chan[1] * lightfrac;
out->chan[2] = in->chan[2]*lightfrac; out->chan[2] = in->chan[2] * lightfrac;
out->chan[3] = 0xff; out->chan[3] = 0xff;
#endif #endif
} }
@ -190,7 +185,8 @@ void REN_DrawSpan (int y)
REN_DrawFlatSpan REN_DrawFlatSpan
================== ==================
*/ */
void REN_DrawFlatSpan (int y) void
REN_DrawFlatSpan (int y)
{ {
int x, count; int x, count;
int ofs; int ofs;
@ -198,7 +194,7 @@ void REN_DrawFlatSpan (int y)
float zfrac, zstep; float zfrac, zstep;
int *out; int *out;
if (y<0 || y >= r_height) if (y < 0 || y >= r_height)
return; return;
x1 = (leftside[0]); x1 = (leftside[0]);
@ -210,26 +206,23 @@ void REN_DrawFlatSpan (int y)
zfrac = leftside[2]; zfrac = leftside[2];
zstep = (rightside[2] - zfrac)/count; zstep = (rightside[2] - zfrac) / count;
if (x1 < 0) if (x1 < 0) {
{ zfrac -= x1 * zstep;
zfrac -= x1*zstep;
x1 = 0; x1 = 0;
} }
if (x2 > r_width) if (x2 > r_width)
x2 = r_width; x2 = r_width;
ofs = y*r_width+x1; ofs = y * r_width + x1;
// this should be specialized for 1.0 / 0.5 / 0.75 light levels // this should be specialized for 1.0 / 0.5 / 0.75 light levels
for (x=x1 ; x < x2 ; x++) for (x = x1; x < x2; x++) {
{ if (r_zbuffer[ofs] <= zfrac) {
if (r_zbuffer[ofs] <= zfrac)
{
r_zbuffer[ofs] = zfrac; r_zbuffer[ofs] = zfrac;
out = (int *)&r_picbuffer[ofs]; out = (int *) &r_picbuffer[ofs];
*out = r_flatcolor.p; *out = r_flatcolor.p;
} }
zfrac += zstep; zfrac += zstep;
@ -244,7 +237,8 @@ REN_RasterizeFace
===================== =====================
*/ */
void REN_RasterizeFace (winding_t *w) void
REN_RasterizeFace (winding_t * w)
{ {
int y; int y;
int i; int i;
@ -261,15 +255,13 @@ void REN_RasterizeFace (winding_t *w)
bot = 0x80000000; bot = 0x80000000;
leftv = 0; leftv = 0;
for (i=0 ; i<numvertex ; i++) for (i = 0; i < numvertex; i++) {
{
w->points[i][3] *= w->points[i][2]; w->points[i][3] *= w->points[i][2];
w->points[i][4] *= w->points[i][2]; w->points[i][4] *= w->points[i][2];
sy[i] = (int)w->points[i][1]; sy[i] = (int) w->points[i][1];
if (sy[i] < top) if (sy[i] < top) {
{
top = sy[i]; top = sy[i];
leftv = i; leftv = i;
} }
@ -286,35 +278,30 @@ void REN_RasterizeFace (winding_t *w)
// //
y = top; y = top;
while (y < bot) while (y < bot) {
{ if (y >= sy[leftv]) {
if (y >= sy[leftv]) do {
{ for (i = 0; i < 5; i++)
do
{
for (i=0 ; i<5 ; i++)
leftside[i] = w->points[leftv][i]; leftside[i] = w->points[leftv][i];
leftv--; leftv--;
if (leftv == -1) if (leftv == -1)
leftv = numvertex-1; leftv = numvertex - 1;
} while (sy[leftv] <= y); } while (sy[leftv] <= y);
count = sy[leftv]-y; count = sy[leftv] - y;
for (i=0 ; i<5 ; i++) for (i = 0; i < 5; i++)
leftstep[i] = (w->points[leftv][i] - leftside[i])/count; leftstep[i] = (w->points[leftv][i] - leftside[i]) / count;
} }
if (y >= sy[rightv]) if (y >= sy[rightv]) {
{ do {
do for (i = 0; i < 5; i++)
{
for (i=0 ; i<5 ; i++)
rightside[i] = w->points[rightv][i]; rightside[i] = w->points[rightv][i];
rightv++; rightv++;
if (rightv == numvertex) if (rightv == numvertex)
rightv = 0; rightv = 0;
} while (sy[rightv] <= y); } while (sy[rightv] <= y);
count = sy[rightv]-y; count = sy[rightv] - y;
for (i=0 ; i<5 ; i++) for (i = 0; i < 5; i++)
rightstep[i] = (w->points[rightv][i] - rightside[i])/count; rightstep[i] = (w->points[rightv][i] - rightside[i]) / count;
} }
if (r_drawflat) if (r_drawflat)
@ -322,8 +309,7 @@ void REN_RasterizeFace (winding_t *w)
else else
REN_DrawSpan (y); REN_DrawSpan (y);
for (i=0 ; i<5 ; i++) for (i = 0; i < 5; i++) {
{
leftside[i] += leftstep[i]; leftside[i] += leftstep[i];
rightside[i] += rightstep[i]; rightside[i] += rightstep[i];
} }
@ -339,7 +325,8 @@ void REN_RasterizeFace (winding_t *w)
REN_DrawSpanLinear REN_DrawSpanLinear
================== ==================
*/ */
void REN_DrawSpanLinear (int y) void
REN_DrawSpanLinear (int y)
{ {
int x, count; int x, count;
int ofs; int ofs;
@ -349,7 +336,7 @@ void REN_DrawSpanLinear (int y)
pixel32_t *in, *out; pixel32_t *in, *out;
float scale; float scale;
if (y<0 || y >= r_height) if (y < 0 || y >= r_height)
return; return;
x1 = (leftside[0]); x1 = (leftside[0]);
@ -366,46 +353,40 @@ void REN_DrawSpanLinear (int y)
if (!count) if (!count)
scale = 1; scale = 1;
else else
scale = 1.0/count; scale = 1.0 / count;
zstep = (rightside[2] - zfrac)*scale; zstep = (rightside[2] - zfrac) * scale;
ustep = (rightside[3] - ufrac)*scale; ustep = (rightside[3] - ufrac) * scale;
vstep = (rightside[4] - vfrac)*scale; vstep = (rightside[4] - vfrac) * scale;
if (x1 < 0) if (x1 < 0) {
{ ufrac -= x1 * ustep;
ufrac -= x1*ustep; vfrac -= x1 * vstep;
vfrac -= x1*vstep; zfrac -= x1 * zstep;
zfrac -= x1*zstep;
x1 = 0; x1 = 0;
} }
if (x2 > r_width) if (x2 > r_width)
x2 = r_width; x2 = r_width;
ofs = y*r_width+x1; ofs = y * r_width + x1;
for (x=x1 ; x < x2 ; x++) for (x = x1; x < x2; x++) {
{ if (r_zbuffer[ofs] <= zfrac) {
if (r_zbuffer[ofs] <= zfrac)
{
r_zbuffer[ofs] = zfrac; r_zbuffer[ofs] = zfrac;
if (t_widthshift) if (t_widthshift) {
{ tx = (int) ufrac & t_widthmask;
tx = (int)ufrac & t_widthmask; ty = (int) vfrac & t_heightmask;
ty = (int)vfrac & t_heightmask; in = (pixel32_t *) & t_data[(ty << t_widthshift) + tx];
in = (pixel32_t *)&t_data [(ty<<t_widthshift)+tx]; } else {
} tx = (int) (ufrac + t_widthadd) % t_width;
else ty = (int) (vfrac + t_heightadd) % t_height;
{ in = (pixel32_t *) & t_data[ty * t_width + tx];
tx = (int)(ufrac+t_widthadd) % t_width;
ty = (int)(vfrac+t_heightadd) % t_height;
in = (pixel32_t *)&t_data [ty*t_width+tx];
} }
out = (pixel32_t *)&r_picbuffer[ofs]; out = (pixel32_t *) & r_picbuffer[ofs];
*out = *in; *out = *in;
} }
ufrac += ustep; ufrac += ustep;
@ -422,7 +403,8 @@ REN_RasterizeFaceLinear
===================== =====================
*/ */
void REN_RasterizeFaceLinear (winding_t *w) void
REN_RasterizeFaceLinear (winding_t * w)
{ {
int y; int y;
int i; int i;
@ -439,12 +421,10 @@ void REN_RasterizeFaceLinear (winding_t *w)
bot = 0x80000000; bot = 0x80000000;
leftv = 0; leftv = 0;
for (i=0 ; i<numvertex ; i++) for (i = 0; i < numvertex; i++) {
{ sy[i] = (int) w->points[i][1];
sy[i] = (int)w->points[i][1];
if (sy[i] < top) if (sy[i] < top) {
{
top = sy[i]; top = sy[i];
leftv = i; leftv = i;
} }
@ -461,41 +441,35 @@ void REN_RasterizeFaceLinear (winding_t *w)
// //
y = top; y = top;
while (y < bot) while (y < bot) {
{ if (y >= sy[leftv]) {
if (y >= sy[leftv]) do {
{ for (i = 0; i < 5; i++)
do
{
for (i=0 ; i<5 ; i++)
leftside[i] = w->points[leftv][i]; leftside[i] = w->points[leftv][i];
leftv--; leftv--;
if (leftv == -1) if (leftv == -1)
leftv = numvertex-1; leftv = numvertex - 1;
} while (sy[leftv] <= y); } while (sy[leftv] <= y);
count = sy[leftv]-y; count = sy[leftv] - y;
for (i=0 ; i<5 ; i++) for (i = 0; i < 5; i++)
leftstep[i] = (w->points[leftv][i] - leftside[i])/count; leftstep[i] = (w->points[leftv][i] - leftside[i]) / count;
} }
if (y >= sy[rightv]) if (y >= sy[rightv]) {
{ do {
do for (i = 0; i < 5; i++)
{
for (i=0 ; i<5 ; i++)
rightside[i] = w->points[rightv][i]; rightside[i] = w->points[rightv][i];
rightv++; rightv++;
if (rightv == numvertex) if (rightv == numvertex)
rightv = 0; rightv = 0;
} while (sy[rightv] <= y); } while (sy[rightv] <= y);
count = sy[rightv]-y; count = sy[rightv] - y;
for (i=0 ; i<5 ; i++) for (i = 0; i < 5; i++)
rightstep[i] = (w->points[rightv][i] - rightside[i])/count; rightstep[i] = (w->points[rightv][i] - rightside[i]) / count;
} }
REN_DrawSpanLinear (y); REN_DrawSpanLinear (y);
for (i=0 ; i<5 ; i++) for (i = 0; i < 5; i++) {
{
leftside[i] += leftstep[i]; leftside[i] += leftstep[i];
rightside[i] += rightstep[i]; rightside[i] += rightstep[i];
} }
@ -514,10 +488,11 @@ REN_BeginCamera
float r_width_2, r_height_3; float r_width_2, r_height_3;
plane_t rfrustum[5]; plane_t rfrustum[5];
void REN_BeginCamera (void) void
REN_BeginCamera (void)
{ {
r_width_2 = (float)r_width / 2; r_width_2 = (float) r_width / 2;
r_height_3 = (float)r_height / 3; r_height_3 = (float) r_height / 3;
// clip to right side // clip to right side
@ -541,7 +516,7 @@ void REN_BeginCamera (void)
// clip to bottom side // clip to bottom side
rfrustum[3].normal[0] = 0; rfrustum[3].normal[0] = 0;
rfrustum[3].normal[1] = 1; rfrustum[3].normal[1] = 1;
rfrustum[3].normal[2] = 2*r_height_3 / r_width_2; rfrustum[3].normal[2] = 2 * r_height_3 / r_width_2;
rfrustum[3].dist = 0; rfrustum[3].dist = 0;
// near Z // near Z
@ -552,7 +527,8 @@ void REN_BeginCamera (void)
} }
void REN_BeginXY (void) void
REN_BeginXY (void)
{ {
rfrustum[0].normal[0] = 1; rfrustum[0].normal[0] = 1;
rfrustum[0].normal[1] = 0; rfrustum[0].normal[1] = 0;
@ -580,7 +556,8 @@ void REN_BeginXY (void)
REN_DrawCameraFace REN_DrawCameraFace
===================== =====================
*/ */
void REN_DrawCameraFace (face_t *idpol) void
REN_DrawCameraFace (face_t * idpol)
{ {
int i; int i;
float scale; float scale;
@ -607,13 +584,12 @@ void REN_DrawCameraFace (face_t *idpol)
w = NewWinding (numvertex); w = NewWinding (numvertex);
w->numpoints = numvertex; w->numpoints = numvertex;
for (i=0 ; i<numvertex ; i++) for (i = 0; i < numvertex; i++) {
{
VectorSubtract (in->points[i], r_origin, temp); VectorSubtract (in->points[i], r_origin, temp);
w->points[i][0] = DotProduct(temp,r_matrix[0]); w->points[i][0] = DotProduct (temp, r_matrix[0]);
w->points[i][1] = DotProduct(temp,r_matrix[1]); w->points[i][1] = DotProduct (temp, r_matrix[1]);
w->points[i][2] = DotProduct(temp,r_matrix[2]); w->points[i][2] = DotProduct (temp, r_matrix[2]);
w->points[i][3] = in->points[i][3]; w->points[i][3] = in->points[i][3];
w->points[i][4] = in->points[i][4]; w->points[i][4] = in->points[i][4];
@ -622,8 +598,7 @@ void REN_DrawCameraFace (face_t *idpol)
// //
// 3D clip // 3D clip
// //
for (i=0 ; i<4 ; i++) for (i = 0; i < 4; i++) {
{
w = ClipWinding (w, &rfrustum[i]); w = ClipWinding (w, &rfrustum[i]);
if (!w) if (!w)
return; return;
@ -632,11 +607,10 @@ void REN_DrawCameraFace (face_t *idpol)
// //
// project to 2D // project to 2D
// //
for (i=0 ; i<w->numpoints ; i++) for (i = 0; i < w->numpoints; i++) {
{
scale = r_width_2 / w->points[i][2]; scale = r_width_2 / w->points[i][2];
w->points[i][0] = r_width_2 + scale*w->points[i][0]; w->points[i][0] = r_width_2 + scale * w->points[i][0];
w->points[i][1] = r_height_3 - scale*w->points[i][1]; w->points[i][1] = r_height_3 - scale * w->points[i][1];
w->points[i][2] = scale; w->points[i][2] = scale;
} }
@ -656,7 +630,8 @@ void REN_DrawCameraFace (face_t *idpol)
REN_DrawXYFace REN_DrawXYFace
===================== =====================
*/ */
void REN_DrawXYFace (face_t *idpol) void
REN_DrawXYFace (face_t * idpol)
{ {
int i, j, numvertex; int i, j, numvertex;
winding_t *w, *in; winding_t *w, *in;
@ -684,11 +659,11 @@ void REN_DrawXYFace (face_t *idpol)
w = NewWinding (numvertex); w = NewWinding (numvertex);
w->numpoints = numvertex; w->numpoints = numvertex;
for (i=0 ; i<numvertex ; i++) for (i = 0; i < numvertex; i++) {
{
// using Z as a scale for the 2D projection // using Z as a scale for the 2D projection
w->points[i][0] = (in->points[i][0] - r_origin[0])*r_origin[2]; w->points[i][0] = (in->points[i][0] - r_origin[0]) * r_origin[2];
w->points[i][1] = r_height - (in->points[i][1] - r_origin[1])*r_origin[2]; w->points[i][1] =
r_height - (in->points[i][1] - r_origin[1]) * r_origin[2];
w->points[i][2] = in->points[i][2] + 3000; w->points[i][2] = in->points[i][2] + 3000;
w->points[i][3] = in->points[i][3]; w->points[i][3] = in->points[i][3];
w->points[i][4] = in->points[i][4]; w->points[i][4] = in->points[i][4];
@ -697,8 +672,7 @@ void REN_DrawXYFace (face_t *idpol)
// //
// clip // clip
// //
for (i=0 ; i<4 ; i++) for (i = 0; i < 4; i++) {
{
w = ClipWinding (w, &rfrustum[i]); w = ClipWinding (w, &rfrustum[i]);
if (!w) if (!w)
return; return;
@ -707,8 +681,7 @@ void REN_DrawXYFace (face_t *idpol)
// //
// project to 2D // project to 2D
// //
for (i=0 ; i<w->numpoints ; i++) for (i = 0; i < w->numpoints; i++) {
{
dest = w->points[i]; dest = w->points[i];
if (dest[0] < 0) if (dest[0] < 0)
dest[0] = 0; dest[0] = 0;
@ -719,17 +692,14 @@ void REN_DrawXYFace (face_t *idpol)
if (dest[1] > r_height) if (dest[1] > r_height)
dest[1] = r_height; dest[1] = r_height;
if (xy_viewnormal[2] > 0) if (xy_viewnormal[2] > 0)
dest[2] = 4096-dest[2]; dest[2] = 4096 - dest[2];
} }
if (xy_viewnormal[2] > 0) if (xy_viewnormal[2] > 0) { // flip order when upside down
{ // flip order when upside down for (i = 0; i < w->numpoints / 2; i++) {
for (i=0 ; i<w->numpoints/2 ; i++)
{
dest = w->points[i]; dest = w->points[i];
source = w->points[w->numpoints-1-i]; source = w->points[w->numpoints - 1 - i];
for (j=0 ; j<5 ; j++) for (j = 0; j < 5; j++) {
{
temp = dest[j]; temp = dest[j];
dest[j] = source[j]; dest[j] = source[j];
source[j] = temp; source[j] = temp;
@ -746,4 +716,3 @@ void REN_DrawXYFace (face_t *idpol)
REN_RasterizeFaceLinear (w); REN_RasterizeFaceLinear (w);
free (w); free (w);
} }