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

File diff suppressed because it is too large Load diff

View file

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

View file

@ -3,23 +3,21 @@
@implementation Dict
- init
-init
{
[super initCount:0
elementSize:sizeof(dict_t)
description:NULL];
return self;
[super initCount: 0 elementSize:sizeof (dict_t)
description:NULL];
return self;
}
- print
-print
{
int i;
dict_t *d;
for (i=0 ; i<numElements ; i++)
{
d = [self elementAt: i];
printf ("%s : %s\n",d->key, d->value);
int i;
dict_t *d;
for (i = 0; i < numElements; i++) {
d =[self elementAt:i];
printf ("%s : %s\n", d->key, d->value);
}
return self;
}
@ -31,80 +29,75 @@ copyFromZone
JDC
===========
*/
- copy
-copy
{
id new;
int i;
dict_t *d;
char *old;
new = [super copy];
for (i=0 ; i<numElements ; i++)
{
d = [self elementAt: i];
id new;
int i;
dict_t *d;
char *old;
new =[super copy];
for (i = 0; i < numElements; i++) {
d =[self elementAt:i];
old = d->key;
d->key = malloc(strlen(old)+1);
d->key = malloc (strlen (old) + 1);
strcpy (d->key, old);
old = d->value;
d->value = malloc(strlen(old)+1);
d->value = malloc (strlen (old) + 1);
strcpy (d->value, old);
}
return new;
}
- initFromFile:(FILE *)fp
-initFromFile:(FILE *) fp
{
[self init];
return [self parseBraceBlock:fp];
return[self parseBraceBlock:fp];
}
//===============================================
//
// Dictionary pair functions
// Dictionary pair functions
//
//===============================================
//
// Write a { } block out to a FILE*
// Write a { } block out to a FILE*
//
- writeBlockTo:(FILE *)fp
-writeBlockTo:(FILE *) fp
{
int max;
int i;
dict_t *d;
fprintf(fp,"{\n");
max = [super count];
for (i = 0;i < max;i++)
{
d = [super elementAt:i];
fprintf(fp,"\t{\"%s\"\t\"%s\"}\n",d->key,d->value);
int max;
int i;
dict_t *d;
fprintf (fp, "{\n");
max =[super count];
for (i = 0; i < max; i++) {
d =[super elementAt:i];
fprintf (fp, "\t{\"%s\"\t\"%s\"}\n", d->key, d->value);
}
fprintf(fp,"}\n");
fprintf (fp, "}\n");
return self;
}
//
// Write a single { } block out
// Write a single { } block out
//
- writeFile:(char *)path
-writeFile:(char *) path
{
FILE *fp;
fp = fopen(path,"w+t");
if (fp != NULL)
{
printf("Writing dictionary file %s.\n",path);
fprintf(fp,"// QE_Project file %s\n",path);
FILE *fp;
fp = fopen (path, "w+t");
if (fp != NULL) {
printf ("Writing dictionary file %s.\n", path);
fprintf (fp, "// QE_Project file %s\n", path);
[self writeBlockTo:fp];
fclose(fp);
}
else
{
printf("Error writing %s!\n",path);
fclose (fp);
} else {
printf ("Error writing %s!\n", path);
return NULL;
}
@ -113,165 +106,160 @@ JDC
//===============================================
//
// Utility methods
// Utility methods
//
//===============================================
//
// Find a keyword in storage
// Returns * to dict_t, otherwise NULL
// Find a keyword in storage
// Returns * to dict_t, otherwise NULL
//
- (dict_t *) findKeyword:(char *)key
{
int max;
int i;
dict_t *d;
max = [super count];
for (i = 0;i < max;i++)
{
d = [super elementAt:i];
if (!strcmp(d->key,key))
-(dict_t *) findKeyword:(char *) key
{
int max;
int i;
dict_t *d;
max =[super count];
for (i = 0; i < max; i++) {
d =[super elementAt:i];
if (!strcmp (d->key, key))
return d;
}
return NULL;
}
//
// Change a keyword's string
// Change a keyword's string
//
- changeStringFor:(char *)key to:(char *)value
-changeStringFor:(char *)
key to:(char *) value
{
dict_t *d;
dict_t newd;
d = [self findKeyword:key];
if (d != NULL)
{
free(d->value);
d->value = malloc(strlen(value)+1);
strcpy(d->value,value);
}
else
{
newd.key = malloc(strlen(key)+1);
strcpy(newd.key,key);
newd.value = malloc(strlen(value)+1);
strcpy(newd.value,value);
dict_t *d;
dict_t newd;
d =[self findKeyword:key];
if (d != NULL) {
free (d->value);
d->value = malloc (strlen (value) + 1);
strcpy (d->value, value);
} else {
newd.key = malloc (strlen (key) + 1);
strcpy (newd.key, key);
newd.value = malloc (strlen (value) + 1);
strcpy (newd.value, value);
[self addElement:&newd];
}
return self;
}
//
// Search for keyword, return the string *
// Search for keyword, return the string *
//
- (char *)getStringFor:(char *)name
-(char *) getStringFor:(char *) name
{
dict_t *d;
d = [self findKeyword:name];
dict_t *d;
d =[self findKeyword:name];
if (d != NULL)
return d->value;
return "";
}
//
// Search for keyword, return the value
// Search for keyword, return the value
//
- (unsigned int)getValueFor:(char *)name
-(unsigned int) getValueFor:(char *) name
{
dict_t *d;
d = [self findKeyword:name];
dict_t *d;
d =[self findKeyword:name];
if (d != NULL)
return atol(d->value);
return atol (d->value);
return 0;
}
//
// Return # of units in keyword's value
// Return # of units in keyword's value
//
- (int) getValueUnits:(char *)key
-(int) getValueUnits:(char *) key
{
id temp;
int count;
temp = [self parseMultipleFrom:key];
count = [temp count];
id temp;
int count;
temp =[self parseMultipleFrom:key];
count =[temp count];
[temp release];
return count;
}
//
// Convert List to string
// Convert List to string
//
- (char *)convertListToString:(id)list
-(char *) convertListToString:(id) list
{
int i;
int max;
char tempstr[4096];
char *s;
char *newstr;
max = [list count];
int i;
int max;
char tempstr[4096];
char *s;
char *newstr;
max =[list count];
tempstr[0] = 0;
for (i = 0;i < max;i++)
{
s = [list elementAt:i];
strcat(tempstr,s);
strcat(tempstr," ");
for (i = 0; i < max; i++) {
s =[list elementAt:i];
strcat (tempstr, s);
strcat (tempstr, " ");
}
newstr = malloc(strlen(tempstr)+1);
strcpy(newstr,tempstr);
newstr = malloc (strlen (tempstr) + 1);
strcpy (newstr, tempstr);
return newstr;
}
//
// JDC: I wrote this to simplify removing vectors
//
- removeKeyword:(char *)key
-removeKeyword:(char *) key
{
dict_t *d;
dict_t *d;
d = [self findKeyword:key];
d =[self findKeyword:key];
if (d == NULL)
return self;
[self removeElementAt:d - (dict_t*)dataPtr];
[self removeElementAt:d - (dict_t *) dataPtr];
return self;
}
//
// Delete string from keyword's value
// Delete string from keyword's value
//
- delString:(char *)string fromValue:(char *)key
-delString:(char *)
string fromValue:(char *) key
{
id temp;
int count;
int i;
char *s;
dict_t *d;
d = [self findKeyword:key];
id temp;
int count;
int i;
char *s;
dict_t *d;
d =[self findKeyword:key];
if (d == NULL)
return NULL;
temp = [self parseMultipleFrom:key];
count = [temp count];
for (i = 0;i < count;i++)
{
s = [temp elementAt:i];
if (!strcmp(s,string))
{
temp =[self parseMultipleFrom:key];
count =[temp count];
for (i = 0; i < count; i++) {
s =[temp elementAt:i];
if (!strcmp (s, string)) {
[temp removeElementAt:i];
free(d->value);
d->value = [self convertListToString:temp];
free (d->value);
d->value =[self convertListToString:temp];
[temp release];
break;
}
}
@ -279,186 +267,179 @@ JDC
}
//
// Add string to keyword's value
// Add string to keyword's value
//
- addString:(char *)string toValue:(char *)key
-addString:(char *)
string toValue:(char *) key
{
char *newstr;
char spacing[] = "\t";
dict_t *d;
d = [self findKeyword:key];
char *newstr;
char spacing[] = "\t";
dict_t *d;
d =[self findKeyword:key];
if (d == NULL)
return NULL;
newstr = malloc(strlen(string) + strlen(d->value) + strlen(spacing) + 1);
strcpy(newstr,d->value);
strcat(newstr,spacing);
strcat(newstr,string);
free(d->value);
newstr =
malloc (strlen (string) + strlen (d->value) + strlen (spacing) + 1);
strcpy (newstr, d->value);
strcat (newstr, spacing);
strcat (newstr, string);
free (d->value);
d->value = newstr;
return self;
}
//===============================================
//
// Use these for multiple parameters in a keyword value
// Use these for multiple parameters in a keyword value
//
//===============================================
char *searchStr;
char item[4096];
char *searchStr;
char item[4096];
- setupMultiple:(char *)value
-setupMultiple:(char *) value
{
searchStr = value;
return self;
}
- (char *)getNextParameter
-(char *) getNextParameter
{
char *s;
char *s;
if (!searchStr)
return NULL;
strcpy(item,searchStr);
s = FindWhitespcInBuffer(item);
strcpy (item, searchStr);
s = FindWhitespcInBuffer (item);
if (!*s)
searchStr = NULL;
else
{
else {
*s = 0;
searchStr = FindNonwhitespcInBuffer(s+1);
searchStr = FindNonwhitespcInBuffer (s + 1);
}
return item;
}
//
// Parses a keyvalue string & returns a Storage full of those items
// Parses a keyvalue string & returns a Storage full of those items
//
- (id) parseMultipleFrom:(char *)key
-(id) parseMultipleFrom:(char *) key
{
#define ITEMSIZE 128
id stuff;
char string[ITEMSIZE];
char *s;
s = [self getStringFor:key];
#define ITEMSIZE 128
id stuff;
char string[ITEMSIZE];
char *s;
s =[self getStringFor:key];
if (s == NULL)
return NULL;
stuff = [[Storage alloc]
initCount:0
elementSize:ITEMSIZE
description:NULL];
stuff =[[Storage alloc]
initCount: 0 elementSize: ITEMSIZE description:NULL];
[self setupMultiple:s];
while((s = [self getNextParameter]))
{
bzero(string,ITEMSIZE);
strcpy(string,s);
while ((s =[self getNextParameter])) {
bzero (string, ITEMSIZE);
strcpy (string, s);
[stuff addElement:string];
}
return stuff;
}
//===============================================
//
// Dictionary pair parsing
// Dictionary pair parsing
//
//===============================================
//
// parse all keyword/value pairs within { } 's
// parse all keyword/value pairs within { } 's
//
- (id) parseBraceBlock:(FILE *)fp
-(id) parseBraceBlock:(FILE *) fp
{
int c;
dict_t pair;
char string[1024];
c = FindBrace(fp);
int c;
dict_t pair;
char string[1024];
c = FindBrace (fp);
if (c == -1)
return NULL;
while((c = FindBrace(fp)) != '}')
{
while ((c = FindBrace (fp)) != '}') {
if (c == -1)
return NULL;
// c = FindNonwhitespc(fp);
// if (c == -1)
// return NULL;
// CopyUntilWhitespc(fp,string);
// c = FindNonwhitespc(fp);
// if (c == -1)
// return NULL;
// CopyUntilWhitespc(fp,string);
// JDC: fixed to allow quoted keys
c = FindNonwhitespc(fp);
c = FindNonwhitespc (fp);
if (c == -1)
return NULL;
c = fgetc(fp);
if ( c == '\"')
CopyUntilQuote(fp,string);
else
{
ungetc (c,fp);
CopyUntilWhitespc(fp,string);
c = fgetc (fp);
if (c == '\"')
CopyUntilQuote (fp, string);
else {
ungetc (c, fp);
CopyUntilWhitespc (fp, string);
}
pair.key = malloc(strlen(string)+1);
strcpy(pair.key,string);
c = FindQuote(fp);
CopyUntilQuote(fp,string);
pair.value = malloc(strlen(string)+1);
strcpy(pair.value,string);
pair.key = malloc (strlen (string) + 1);
strcpy (pair.key, string);
c = FindQuote (fp);
CopyUntilQuote (fp, string);
pair.value = malloc (strlen (string) + 1);
strcpy (pair.value, string);
[super addElement:&pair];
c = FindBrace(fp);
c = FindBrace (fp);
}
return self;
}
@end
//===============================================
//
// C routines for string parsing
// C routines for string parsing
//
//===============================================
int GetNextChar(FILE *fp)
int
GetNextChar (FILE * fp)
{
int c;
int c2;
c = getc(fp);
int c;
int c2;
c = getc (fp);
if (c == EOF)
return -1;
if (c == '/') // parse comments
if (c == '/') // parse comments
{
c2 = getc(fp);
if (c2 == '/')
{
while((c2 = getc(fp)) != '\n');
c = getc(fp);
}
else
ungetc(c2,fp);
c2 = getc (fp);
if (c2 == '/') {
while ((c2 = getc (fp)) != '\n');
c = getc (fp);
} else
ungetc (c2, fp);
}
return c;
}
void CopyUntilWhitespc(FILE *fp,char *buffer)
void
CopyUntilWhitespc (FILE * fp, char *buffer)
{
int count = 800;
int c;
while(count--)
{
c = GetNextChar(fp);
int count = 800;
int c;
while (count--) {
c = GetNextChar (fp);
if (c == EOF)
return;
if (c <= ' ')
{
if (c <= ' ') {
*buffer = 0;
return;
}
@ -466,18 +447,17 @@ void CopyUntilWhitespc(FILE *fp,char *buffer)
}
}
void CopyUntilQuote(FILE *fp,char *buffer)
void
CopyUntilQuote (FILE * fp, char *buffer)
{
int count = 800;
int c;
while(count--)
{
c = GetNextChar(fp);
int count = 800;
int c;
while (count--) {
c = GetNextChar (fp);
if (c == EOF)
return;
if (c == '\"')
{
if (c == '\"') {
*buffer = 0;
return;
}
@ -485,31 +465,30 @@ void CopyUntilQuote(FILE *fp,char *buffer)
}
}
int FindBrace(FILE *fp)
int
FindBrace (FILE * fp)
{
int count = 800;
int c;
while(count--)
{
c = GetNextChar(fp);
int count = 800;
int c;
while (count--) {
c = GetNextChar (fp);
if (c == EOF)
return -1;
if (c == '{' ||
c == '}')
if (c == '{' || c == '}')
return c;
}
return -1;
}
int FindQuote(FILE *fp)
int
FindQuote (FILE * fp)
{
int count = 800;
int c;
while(count--)
{
c = GetNextChar(fp);
int count = 800;
int c;
while (count--) {
c = GetNextChar (fp);
if (c == EOF)
return -1;
if (c == '\"')
@ -518,63 +497,63 @@ int FindQuote(FILE *fp)
return -1;
}
int FindWhitespc(FILE *fp)
int
FindWhitespc (FILE * fp)
{
int count = 800;
int c;
while(count--)
{
c = GetNextChar(fp);
if (c == EOF)
return -1;
if (c <= ' ')
{
ungetc(c,fp);
return c;
}
}
return -1;
}
int count = 800;
int c;
int FindNonwhitespc(FILE *fp)
{
int count = 800;
int c;
while(count--)
{
c = GetNextChar(fp);
while (count--) {
c = GetNextChar (fp);
if (c == EOF)
return -1;
if (c > ' ')
{
ungetc(c,fp);
if (c <= ' ') {
ungetc (c, fp);
return c;
}
}
return -1;
}
char *FindWhitespcInBuffer(char *buffer)
int
FindNonwhitespc (FILE * fp)
{
int count = 1000;
char *b = buffer;
while(count--)
int count = 800;
int c;
while (count--) {
c = GetNextChar (fp);
if (c == EOF)
return -1;
if (c > ' ') {
ungetc (c, fp);
return c;
}
}
return -1;
}
char *
FindWhitespcInBuffer (char *buffer)
{
int count = 1000;
char *b = buffer;
while (count--)
if (*b <= ' ')
return b;
else
b++;
return NULL;
return NULL;
}
char *FindNonwhitespcInBuffer(char *buffer)
char *
FindNonwhitespcInBuffer (char *buffer)
{
int count = 1000;
char *b = buffer;
while(count--)
int count = 1000;
char *b = buffer;
while (count--)
if (*b > ' ')
return b;
else

View file

@ -3,64 +3,60 @@
#include "Dict.h"
@implementation DictList
//
// Read in variable # of objects from FILE *
// Read in variable # of objects from FILE *
//
- initListFromFile:(FILE *)fp
- initListFromFile:(FILE *) fp
{
id d;
id d;
[super init];
do
{
d = [(Dict *)[Dict alloc] initFromFile:fp];
do {
d =[(Dict *)[Dict alloc] initFromFile:fp];
if (d != NULL)
[self addObject:d];
} while(d != NULL);
} while (d != NULL);
[d release];
return self;
}
//
// Write out list file
// Write out list file
//
- writeListFile:(char *)filename
-writeListFile:(char *) filename
{
FILE *fp;
int i;
id obj;
fp = fopen(filename,"w+t");
FILE *fp;
int i;
id obj;
fp = fopen (filename, "w+t");
if (fp == NULL)
return NULL;
fprintf(fp,"// Object List written by QuakeEd\n");
for (i = 0;i < [self count];i++)
{
obj = [self objectAtIndex:i];
fprintf (fp, "// Object List written by QuakeEd\n");
for (i = 0; i <[self count]; i++) {
obj =[self objectAtIndex:i];
[obj writeBlockTo:fp];
}
fclose(fp);
fclose (fp);
return self;
}
//
// Find the keyword in all the Dict objects
// Find the keyword in all the Dict objects
//
- (id) findDictKeyword:(char *)key
-(id) findDictKeyword:(char *) key
{
int i;
dict_t *d;
id dict;
int i;
dict_t *d;
id dict;
for (i = 0;i < [self count];i++)
{
dict = [self objectAtIndex:i];
d = [(Dict *)dict findKeyword:key];
for (i = 0; i <[self count]; i++) {
dict =[self objectAtIndex:i];
d =[(Dict *) dict findKeyword:key];
if (d != NULL)
return dict;
}

View file

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

View file

@ -11,7 +11,7 @@
@implementation EntityClass
static int
parse_vector (script_t *script, vec3_t vec)
parse_vector (script_t * script, vec3_t vec)
{
int r;
@ -23,7 +23,7 @@ parse_vector (script_t *script, vec3_t vec)
r = sscanf (script->p, "%f %f %f)", &vec[0], &vec[1], &vec[2]);
if (r != 3)
return 0;
while (strcmp (script->token->str, ")")) {
if (!Script_GetToken (script, 0))
return 0;
@ -41,16 +41,17 @@ parse_vector (script_t *script, vec3_t vec)
//
// /*QUAKED func_door (0 .5 .8) ? START_OPEN STONE_SOUND DOOR_DONT_LINK GOLD_KEY SILVER_KEY
- initFromText: (const char *)text source: (const char *)filename
-initFromText:(const char *)
text source:(const char *) filename
{
const char *t;
size_t len;
int i;
script_t *script;
[super init];
text += strlen("/*QUAKED ");
text += strlen ("/*QUAKED ");
script = Script_New ();
Script_Start (script, filename, text);
@ -65,8 +66,8 @@ parse_vector (script_t *script, vec3_t vec)
// grab the color
if (!parse_vector (script, color))
return 0;
// get the size
// get the size
if (!strcmp (script->token->str, "(")) {
Script_UngetToken (script);
if (!parse_vector (script, mins))
@ -80,7 +81,7 @@ parse_vector (script_t *script, vec3_t vec)
} else {
return 0;
}
// get the flags
// any remaining words on the line are parm flags
for (i = 0; i < MAX_FLAGS; i++) {
@ -93,50 +94,49 @@ parse_vector (script_t *script, vec3_t vec)
Script_GetToken (script, 0);
// find the length until close comment
for (t = script->p; t[0] && !(t[0] == '*' && t[1] == '/'); t++)
;
for (t = script->p; t[0] && !(t[0] == '*' && t[1] == '/'); t++);
// copy the comment block out
len = t - text;
comments = malloc (len + 1);
memcpy (comments, text, len);
comments[len] = 0;
return self;
}
- (esize_t)esize
-(esize_t) esize
{
return esize;
}
- (char *)classname
-(char *) classname
{
return name;
}
- (float *)mins
-(float *) mins
{
return mins;
}
- (float *)maxs
-(float *) maxs
{
return maxs;
}
- (float *)drawColor
-(float *) drawColor
{
return color;
}
- (char *)comments
-(char *) comments
{
return comments;
}
- (char *)flagName: (unsigned)flagnum
-(char *) flagName:(unsigned) flagnum
{
if (flagnum >= MAX_FLAGS)
Sys_Error ("EntityClass flagName: bad number");
@ -144,31 +144,27 @@ parse_vector (script_t *script, vec3_t vec)
}
@end
//===========================================================================
@implementation EntityClassList
/*
=================
insertEC:
=================
*/
- (void)insertEC: ec
- (void) insertEC:ec
{
char *name;
int i;
name = [ec classname];
for (i=0 ; i<[self count] ; i++)
{
if (strcasecmp (name, [[self objectAtIndex: i] classname]) < 0)
{
char *name;
int i;
name =[ec classname];
for (i = 0; i <[self count]; i++) {
if (strcasecmp (name,[[self objectAtIndex:i] classname]) < 0) {
[self insertObject: ec atIndex:i];
return;
}
}
[self addObject: ec];
[self addObject:ec];
}
@ -177,16 +173,16 @@ insertEC:
scanFile
=================
*/
- (void)scanFile: (char *)filename
-(void) scanFile:(char *) filename
{
int size, line;
char *data;
id cl;
int i;
char path[1024];
QFile *file;
int size, line;
char *data;
id cl;
int i;
char path[1024];
QFile *file;
sprintf (path,"%s/%s", source_path, filename);
sprintf (path, "%s/%s", source_path, filename);
file = Qopen (path, "rt");
if (!file)
@ -198,12 +194,12 @@ scanFile
Qclose (file);
line = 1;
for (i=0 ; i<size ; i++) {
if (!strncmp(data+i, "/*QUAKED",8)) {
cl = [[EntityClass alloc] initFromText: (data + i)
source: va ("%s:%d", filename, line)];
for (i = 0; i < size; i++) {
if (!strncmp (data + i, "/*QUAKED", 8)) {
cl =[[EntityClass alloc] initFromText:(data + i)
source:va ("%s:%d", filename, line)];
if (cl)
[self insertEC: cl];
[self insertEC:cl];
} else if (data[i] == '\n') {
line++;
}
@ -218,62 +214,61 @@ scanFile
scanDirectory
=================
*/
- (void)scanDirectory
-(void) scanDirectory
{
int count, i;
int count, i;
struct dirent **namelist, *ent;
[self removeAllObjects];
count = scandir(source_path, &namelist, NULL, NULL);
for (i=0 ; i<count ; i++)
{
int len;
count = scandir (source_path, &namelist, NULL, NULL);
for (i = 0; i < count; i++) {
int len;
ent = namelist[i];
len = strlen (ent->d_name);
if (len <= 3)
continue;
if (!strcmp (ent->d_name+len-3,".qc"))
[self scanFile: ent->d_name];
if (!strcmp (ent->d_name + len - 3, ".qc"))
[self scanFile:ent->d_name];
}
}
id entity_classes_i;
id entity_classes_i;
- initForSourceDirectory: (char *)path
-initForSourceDirectory:(char *) path
{
[super init];
source_path = path;
source_path = path;
[self scanDirectory];
entity_classes_i = self;
nullclass = [[EntityClass alloc]
initFromText: "/*QUAKED UNKNOWN_CLASS (0 0.5 0) ?*/"
source: va ("%s:%d", __FILE__, __LINE__ - 1)];
nullclass =[[EntityClass alloc]
initFromText: "/*QUAKED UNKNOWN_CLASS (0 0.5 0) ?*/" source:va ("%s:%d", __FILE__,
__LINE__ -
1)];
return self;
}
- (id)classForName: (char *)name
-(id) classForName:(char *) name
{
int i;
id o;
for (i=0 ; i<[self count] ; i++)
{
o = [self objectAtIndex: i];
if (!strcmp (name,[o classname]) )
int i;
id o;
for (i = 0; i <[self count]; i++) {
o =[self objectAtIndex:i];
if (!strcmp (name,[o classname]))
return o;
}
return nullclass;
}
@end

View file

@ -6,19 +6,18 @@
#include "TexturePalette.h"
#include "Preferences.h"
id inspcontrol_i;
id inspcontrol_i;
@implementation InspectorControl
- awakeFromNib
{
-awakeFromNib {
inspcontrol_i = self;
currentInspectorType = -1;
contentList = [[NSArray alloc] init];
windowList = [[NSArray alloc] init];
itemList = [[NSArray alloc] init];
contentList =[[NSArray alloc] init];
windowList =[[NSArray alloc] init];
itemList =[[NSArray alloc] init];
// ADD NEW INSPECTORS HERE...
@ -36,7 +35,7 @@ id inspcontrol_i;
[contentList addObject:[win_things_i contentView]];
[itemThings_i setKeyEquivalent:@"3"];
[itemList addObject:itemThings_i];
[windowList addObject:win_prefs_i];
[contentList addObject:[win_prefs_i contentView]];
[itemPrefs_i setKeyEquivalent:@"4"];
@ -61,7 +60,7 @@ id inspcontrol_i;
[inspectorView_i setAutoresizesSubviews:YES];
inspectorSubview_i = [contentList objectAtIndex:i_project];
inspectorSubview_i =[contentList objectAtIndex:i_project];
[inspectorView_i addSubview:inspectorSubview_i];
currentInspectorType = -1;
@ -72,56 +71,57 @@ id inspcontrol_i;
//
// Sent by the PopUpList in the Inspector
// Each cell in the PopUpList must have the correct tag
// Sent by the PopUpList in the Inspector
// Each cell in the PopUpList must have the correct tag
//
- changeInspector:sender
-changeInspector:sender
{
id cell;
id cell;
cell = [sender selectedCell];
cell =[sender selectedCell];
[self changeInspectorTo:[cell tag]];
return self;
}
//
// Change to specific Inspector
// Change to specific Inspector
//
- changeInspectorTo:(insp_e)which
-changeInspectorTo:(insp_e) which
{
id newView;
NSRect r;
id cell;
NSRect f;
id newView;
NSRect r;
id cell;
NSRect f;
if (which == currentInspectorType)
return self;
currentInspectorType = which;
newView = [contentList objectAtIndex:which];
cell = [itemList objectAtIndex:which]; // set PopUpButton title
newView =[contentList objectAtIndex:which];
cell =[itemList objectAtIndex:which];// set PopUpButton title
[popUpButton_i setTitle:[cell title]];
[inspectorView_i replaceSubview:inspectorSubview_i with:newView];
r = [inspectorView_i frame];
[inspectorView_i replaceSubview: inspectorSubview_i with:newView];
r =[inspectorView_i frame];
inspectorSubview_i = newView;
[inspectorSubview_i setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[inspectorSubview_i setAutoresizingMask:NSViewWidthSizable |
NSViewHeightSizable];
r.size.width -= 4;
r.size.height -= 4;
[inspectorSubview_i setFrameSize:r.size];
[inspectorSubview_i lockFocus];
f = [inspectorSubview_i bounds];
PSsetgray(NSLightGray);
NSRectFill(f);
f =[inspectorSubview_i bounds];
PSsetgray (NSLightGray);
NSRectFill (f);
[inspectorSubview_i unlockFocus];
[inspectorView_i display];
return self;
}
- (insp_e)getCurrentInspector
-(insp_e) getCurrentInspector
{
return currentInspectorType;
}

View file

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

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,6 @@
#include "PopScrollView.h"
@implementation PopScrollView
/*
====================
initWithFrame: button:
@ -10,57 +9,52 @@ initWithFrame: button:
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
{
[super initWithFrame: frameRect];
[self addSubview: b1];
[self addSubview: b2];
[self addSubview:b1];
[self addSubview:b2];
button1 = b1;
button2 = b2;
[self setHasHorizontalScroller: YES];
[self setHasVerticalScroller: YES];
[self setHasHorizontalScroller:YES];
[self setHasVerticalScroller:YES];
[self setBorderType:NSBezelBorder];
[self setBorderType: NSBezelBorder];
return self;
}
/*
================
tile
Adjust the size for the pop up scale menu
=================
*/
- tile
*/ -tile
{
NSRect scrollerframe;
NSRect buttonframe, buttonframe2;
NSRect newframe;
NSRect scrollerframe;
NSRect buttonframe, buttonframe2;
NSRect newframe;
[super tile];
buttonframe = [button1 frame];
buttonframe2 = [button2 frame];
scrollerframe = [_horizScroller frame];
buttonframe =[button1 frame];
buttonframe2 =[button2 frame];
scrollerframe =[_horizScroller frame];
newframe.origin.y = scrollerframe.origin.y;
newframe.origin.x = scrollerframe.size.width - buttonframe.size.width;
newframe.size.width = buttonframe.size.width;
newframe.size.height = scrollerframe.size.height;
scrollerframe.size.width -= newframe.size.width;
[button1 setFrame: newframe];
[button1 setFrame:newframe];
newframe.size.width = buttonframe2.size.width;
newframe.origin.x -= newframe.size.width;
[button2 setFrame: newframe];
[button2 setFrame:newframe];
scrollerframe.size.width -= newframe.size.width;
[_horizScroller setFrame: scrollerframe];
[_horizScroller setFrame:scrollerframe];
return self;
}
@ -78,10 +72,9 @@ Adjust the size for the pop up scale menu
-(BOOL) acceptsFirstResponder
{
return YES;
return YES;
}
@end

View file

@ -4,84 +4,90 @@
#include "QuakeEd.h"
#include "Project.h"
id preferences_i;
id preferences_i;
#define DEFOWNER "QuakeEd2"
float lightaxis[3] = {1, 0.6, 0.75};
float lightaxis[3] = { 1, 0.6, 0.75 };
@implementation Preferences
- init
-init
{
[super init];
preferences_i = self;
return self;
}
int _atoi (char *c)
int
_atoi (char *c)
{
if (!c)
return 0;
return atoi(c);
return atoi (c);
}
int _atof (char *c)
int
_atof (char *c)
{
if (!c)
return 0;
return atof(c);
return atof (c);
}
void WriteNumericDefault (char *name, float value)
void
WriteNumericDefault (char *name, float value)
{
char str[128];
sprintf (str,"%f", value);
//XXX NSWriteDefault (DEFOWNER, name, str);
char str[128];
sprintf (str, "%f", value);
// 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 = "";
float value = 0;
//XXX string = (char *)NSGetDefaultValue(DEFOWNER,"ProjectPath");
[self setProjectPath: string];
//XXX string = (char *)NSGetDefaultValue(DEFOWNER,"BspSoundPath");
char *string = "";
float value = 0;
// XXX string = (char *)NSGetDefaultValue(DEFOWNER,"ProjectPath");
[self setProjectPath:string];
// XXX string = (char *)NSGetDefaultValue(DEFOWNER,"BspSoundPath");
[self setBspSoundPath:string];
//XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"ShowBSPOutput"));
// XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"ShowBSPOutput"));
[self setShowBSP:value];
//XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"OffsetBrushCopy"));
// XXX value = _atoi((char
// *)NSGetDefaultValue(DEFOWNER,"OffsetBrushCopy"));
[self setBrushOffset:value];
//XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"StartWad"));
// XXX value = _atoi((char *)NSGetDefaultValue(DEFOWNER,"StartWad"));
[self setStartWad:value];
//XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Xlight"));
// XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Xlight"));
[self setXlight:value];
//XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Ylight"));
// XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Ylight"));
[self setYlight:value];
//XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Zlight"));
// XXX value = _atof((char *)NSGetDefaultValue(DEFOWNER,"Zlight"));
[self setZlight:value];
return self;
}
- setProjectPath:(char *)path
-setProjectPath:(char *) path
{
if (!path)
path = "";
@ -91,14 +97,15 @@ void WriteStringDefault (char *name, char *value)
return self;
}
- setCurrentProject:sender
-setCurrentProject:sender
{
[startproject_i setStringValue: [NSString stringWithCString:[project_i currentProjectFile]]];
[self UIChanged: self];
[startproject_i setStringValue: [NSString stringWithCString:[project_i
currentProjectFile]]];
[self UIChanged:self];
return self;
}
- (char *)getProjectPath
-(char *) getProjectPath
{
return projectpath;
}
@ -106,35 +113,33 @@ void WriteStringDefault (char *name, char *value)
//
//===============================================
// BSP sound stuff
// BSP sound stuff
//===============================================
//
// Set the BSP sound using an OpenPanel
// Set the BSP sound using an OpenPanel
//
- setBspSound:sender
-setBspSound:sender
{
id panel;
NSString *types[] = {@"snd"};
int rtn;
id panel;
NSString *types[] = { @"snd" };
int rtn;
NSArray *filenames;
char path[1024], file[64];
panel = [NSOpenPanel new];
char path[1024], file[64];
//XXX ExtractFilePath (bspSound, path);
//XXX ExtractFileBase (bspSound, file);
rtn = [panel
runModalForDirectory:[NSString stringWithCString:path]
file: [NSString stringWithCString:file]
types: [NSArray arrayWithObjects:types count:1]];
panel =[NSOpenPanel new];
if (rtn)
{
filenames = [panel filenames];
strcpy(bspSound,[[panel directory] cString]);
strcat(bspSound,"/");
strcat(bspSound, [[filenames objectAtIndex:0] cString]);
// XXX ExtractFilePath (bspSound, path);
// XXX ExtractFileBase (bspSound, file);
rtn =[panel runModalForDirectory: [NSString stringWithCString:path]
file: [NSString stringWithCString:file]
types: [NSArray arrayWithObjects: types count:1]];
if (rtn) {
filenames =[panel filenames];
strcpy (bspSound,[[panel directory] cString]);
strcat (bspSound, "/");
strcat (bspSound,[[filenames objectAtIndex:0] cString]);
[self setBspSoundPath:bspSound];
[self playBspSound];
}
@ -144,48 +149,47 @@ void WriteStringDefault (char *name, char *value)
//
// Play the BSP sound
// Play the BSP sound
//
- playBspSound
-playBspSound
{
[bspSound_i play];
[bspSound_i play];
return self;
}
//
// Set the bspSound path
// Set the bspSound path
//
- setBspSoundPath:(char *)path
-setBspSoundPath:(char *) path
{
if (!path)
path = "";
strcpy(bspSound,path);
strcpy (bspSound, path);
if (bspSound_i)
[bspSound_i release];
bspSound_i = [[NSSound alloc] initWithContentsOfFile:[NSString stringWithCString:bspSound]];
if (!bspSound_i)
{
bspSound_i =[[NSSound alloc] initWithContentsOfFile: [NSString stringWithCString:bspSound]];
if (!bspSound_i) {
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);
return self;
}
//===============================================
// Show BSP Output management
// Show BSP Output management
//===============================================
//
// Set the state
// Set the state
//
- setShowBSP:(int)state
-setShowBSP:(int) state
{
showBSP = state;
[showBSP_i setIntValue:state];
@ -195,22 +199,22 @@ void WriteStringDefault (char *name, char *value)
}
//
// Get the state
// Get the state
//
- (int)getShowBSP
-(int) getShowBSP
{
return showBSP;
}
//===============================================
// "Offset Brush ..." management
// "Offset Brush ..." management
//===============================================
//
// Set the state
// Set the state
//
- setBrushOffset:(int)state
-setBrushOffset:(int) state
{
brushOffset = state;
[brushOffset_i setIntValue:state];
@ -219,42 +223,42 @@ void WriteStringDefault (char *name, char *value)
}
//
// Get the state
// Get the state
//
- (int)getBrushOffset
-(int) getBrushOffset
{
return brushOffset;
}
//===============================================
// StartWad
// StartWad
//===============================================
- setStartWad:(int)value // set start wad (0-2)
-setStartWad:(int) value // set start wad (0-2)
{
startwad = value;
if (startwad<0 || startwad>2)
if (startwad < 0 || startwad > 2)
startwad = 0;
[startwad_i selectCellAtRow:startwad column: 0];
[startwad_i selectCellAtRow: startwad column:0];
WriteNumericDefault ("StartWad", value);
return self;
}
- (int)getStartWad
-(int) getStartWad
{
return startwad;
}
//===============================================
// X,Y,Z light values
// X,Y,Z light values
//===============================================
//
// Set the state
// Set the state
//
- setXlight:(float)value
-setXlight:(float) value
{
xlight = value;
if (xlight < 0.25 || xlight > 1)
@ -264,7 +268,8 @@ void WriteStringDefault (char *name, char *value)
WriteNumericDefault ("Xlight", xlight);
return self;
}
- setYlight:(float)value
-setYlight:(float) value
{
ylight = value;
if (ylight < 0.25 || ylight > 1)
@ -274,7 +279,8 @@ void WriteStringDefault (char *name, char *value)
WriteNumericDefault ("Ylight", ylight);
return self;
}
- setZlight:(float)value
-setZlight:(float) value
{
zlight = value;
if (zlight < 0.25 || zlight > 1)
@ -286,19 +292,21 @@ void WriteStringDefault (char *name, char *value)
}
//
// Get the state
// Get the state
//
- (float)getXlight
-(float) getXlight
{
return [xlight_i floatValue];
return[xlight_i floatValue];
}
- (float)getYlight
-(float) getYlight
{
return [ylight_i floatValue];
return[ylight_i floatValue];
}
- (float)getZlight
-(float) getZlight
{
return [zlight_i floatValue];
return[zlight_i floatValue];
}
@ -310,22 +318,22 @@ UIChanged
Grab all the current UI state
============
*/
-UIChanged: sender
-UIChanged:sender
{
qprintf ("defaults updated");
[self setProjectPath: (char *)[startproject_i stringValue]];
[self setBspSoundPath: (char *)[bspSoundField_i stringValue]];
[self setShowBSP: [showBSP_i intValue]];
[self setBrushOffset: [brushOffset_i intValue]];
[self setStartWad: [startwad_i selectedRow]];
[self setXlight: [xlight_i floatValue]];
[self setYlight: [ylight_i floatValue]];
[self setZlight: [zlight_i floatValue]];
[map_i makeGlobalPerform: @selector(flushTextures)];
[self setProjectPath:(char *)[startproject_i stringValue]];
[self setBspSoundPath:(char *)[bspSoundField_i stringValue]];
[self setShowBSP:[showBSP_i intValue]];
[self setBrushOffset:[brushOffset_i intValue]];
[self setStartWad:[startwad_i selectedRow]];
[self setXlight:[xlight_i floatValue]];
[self setYlight:[ylight_i floatValue]];
[self setZlight:[zlight_i floatValue]];
[map_i makeGlobalPerform:@selector (flushTextures)];
[quakeed_i updateAll];
return self;
}

View file

@ -17,11 +17,11 @@
#include "TexturePalette.h"
id project_i;
id project_i;
@implementation Project
- init
-init
{
project_i = self;
@ -30,145 +30,139 @@ id project_i;
//===========================================================
//
// Project code
// Project code
//
//===========================================================
- initVars
-initVars
{
char *s;
s = [preferences_i getProjectPath];
//XXX StripFilename(s);
strcpy(path_basepath,s);
strcpy(path_progdir,s);
strcat(path_progdir,"/"SUBDIR_ENT);
strcpy(path_mapdirectory,s);
strcat(path_mapdirectory,"/"SUBDIR_MAPS); // source dir
char *s;
strcpy(path_finalmapdir,s);
strcat(path_finalmapdir,"/"SUBDIR_MAPS); // dest dir
[basepathinfo_i setStringValue:[NSString stringWithCString:s]]; // in Project Inspector
#if 0
if ((s = [projectInfo getStringFor:BASEPATHKEY]))
{
strcpy(path_basepath,s);
strcpy(path_progdir,s);
strcat(path_progdir,"/"SUBDIR_ENT);
strcpy(path_mapdirectory,s);
strcat(path_mapdirectory,"/"SUBDIR_MAPS); // source dir
s =[preferences_i getProjectPath];
// XXX StripFilename(s);
strcpy (path_basepath, s);
strcpy(path_finalmapdir,s);
strcat(path_finalmapdir,"/"SUBDIR_MAPS); // dest dir
[basepathinfo_i setStringValue:s]; // in Project Inspector
strcpy (path_progdir, s);
strcat (path_progdir, "/" SUBDIR_ENT);
strcpy (path_mapdirectory, s);
strcat (path_mapdirectory, "/" SUBDIR_MAPS); // source dir
strcpy (path_finalmapdir, s);
strcat (path_finalmapdir, "/" SUBDIR_MAPS); // dest dir
[basepathinfo_i setStringValue: [NSString stringWithCString:s]];
// in Project Inspector
#if 0
if ((s =[projectInfo getStringFor:BASEPATHKEY])) {
strcpy (path_basepath, s);
strcpy (path_progdir, s);
strcat (path_progdir, "/" SUBDIR_ENT);
strcpy (path_mapdirectory, s);
strcat (path_mapdirectory, "/" SUBDIR_MAPS); // source dir
strcpy (path_finalmapdir, s);
strcat (path_finalmapdir, "/" SUBDIR_MAPS); // dest dir
[basepathinfo_i setStringValue:s];
// in Project Inspector
}
#endif
if ((s = [projectInfo getStringFor:BSPFULLVIS]))
{
strcpy(string_fullvis,s);
changeString('@','\"',string_fullvis);
}
if ((s = [projectInfo getStringFor:BSPFASTVIS]))
{
strcpy(string_fastvis,s);
changeString('@','\"',string_fastvis);
}
if ((s = [projectInfo getStringFor:BSPNOVIS]))
{
strcpy(string_novis,s);
changeString('@','\"',string_novis);
}
if ((s = [projectInfo getStringFor:BSPRELIGHT]))
{
strcpy(string_relight,s);
changeString('@','\"',string_relight);
}
if ((s = [projectInfo getStringFor:BSPLEAKTEST]))
{
strcpy(string_leaktest,s);
changeString('@','\"',string_leaktest);
#endif
if ((s =[projectInfo getStringFor:BSPFULLVIS])) {
strcpy (string_fullvis, s);
changeString ('@', '\"', string_fullvis);
}
if ((s = [projectInfo getStringFor:BSPENTITIES]))
{
strcpy(string_entities,s);
changeString('@','\"', string_entities);
if ((s =[projectInfo getStringFor:BSPFASTVIS])) {
strcpy (string_fastvis, s);
changeString ('@', '\"', string_fastvis);
}
// Build list of wads
wadList = [projectInfo parseMultipleFrom:WADSKEY];
if ((s =[projectInfo getStringFor:BSPNOVIS])) {
strcpy (string_novis, s);
changeString ('@', '\"', string_novis);
}
if ((s =[projectInfo getStringFor:BSPRELIGHT])) {
strcpy (string_relight, s);
changeString ('@', '\"', string_relight);
}
if ((s =[projectInfo getStringFor:BSPLEAKTEST])) {
strcpy (string_leaktest, s);
changeString ('@', '\"', string_leaktest);
}
if ((s =[projectInfo getStringFor:BSPENTITIES])) {
strcpy (string_entities, s);
changeString ('@', '\"', string_entities);
}
// Build list of wads
wadList =[projectInfo parseMultipleFrom:WADSKEY];
// Build list of maps & descriptions
mapList =[projectInfo parseMultipleFrom:MAPNAMESKEY];
descList =[projectInfo parseMultipleFrom:DESCKEY];
[self changeChar: '_' to: ' ' in:descList];
// Build list of maps & descriptions
mapList = [projectInfo parseMultipleFrom:MAPNAMESKEY];
descList = [projectInfo parseMultipleFrom:DESCKEY];
[self changeChar:'_' to:' ' in:descList];
[self initProjSettings];
return self;
}
//
// Init Project Settings fields
// Init Project Settings fields
//
- initProjSettings
-initProjSettings
{
[pis_basepath_i setStringValue:[NSString stringWithCString:path_basepath]];
[pis_fullvis_i setStringValue:[NSString stringWithCString:string_fullvis]];
[pis_fastvis_i setStringValue:[NSString stringWithCString:string_fastvis]];
[pis_novis_i setStringValue:[NSString stringWithCString:string_novis]];
[pis_relight_i setStringValue:[NSString stringWithCString:string_relight]];
[pis_leaktest_i setStringValue:[NSString stringWithCString:string_leaktest]];
[pis_basepath_i setStringValue: [NSString stringWithCString:path_basepath]];
[pis_fullvis_i setStringValue: [NSString stringWithCString:string_fullvis]];
[pis_fastvis_i setStringValue: [NSString stringWithCString:string_fastvis]];
[pis_novis_i setStringValue: [NSString stringWithCString:string_novis]];
[pis_relight_i setStringValue: [NSString stringWithCString:string_relight]];
[pis_leaktest_i setStringValue: [NSString stringWithCString:string_leaktest]];
return self;
}
//
// Add text to the BSP Output window
// Add text to the BSP Output window
//
- addToOutput:(char *)string
-addToOutput:(char *) string
{
int end;
end = [BSPoutput_i textLength];
[BSPoutput_i replaceCharactersInRange:NSMakeRange (end, 0) withString:[NSString stringWithCString:string]];
end = [BSPoutput_i textLength];
int end;
end =[BSPoutput_i textLength];
[BSPoutput_i replaceCharactersInRange: NSMakeRange (end, 0) withString: [NSString stringWithCString:string]];
end =[BSPoutput_i textLength];
[BSPoutput_i setSelectedRange:NSMakeRange (end, 0)];
//XXX [BSPoutput_i scrollSelToVisible];
// XXX [BSPoutput_i scrollSelToVisible];
return self;
}
- clearBspOutput:sender
-clearBspOutput:sender
{
int end;
end = [BSPoutput_i textLength];
[BSPoutput_i replaceCharactersInRange:NSMakeRange (0, end) withString:@""];
int end;
end =[BSPoutput_i textLength];
[BSPoutput_i replaceCharactersInRange: NSMakeRange (0, end) withString:@""];
return self;
}
- print
-print
{
//XXX [BSPoutput_i printPSCode:self];
// XXX [BSPoutput_i printPSCode:self];
return self;
}
- initProject
-initProject
{
[self parseProjectFile];
if (projectInfo == NULL)
@ -179,57 +173,56 @@ id project_i;
[pis_wads_i setReusesColumns:YES];
[pis_wads_i loadColumnZero];
[things_i initEntities];
[things_i initEntities];
return self;
}
//
// Change a character to another in a Storage list of strings
// Change a character to another in a Storage list of strings
//
- changeChar:(char)f to:(char)t in:(id)obj
-changeChar:(char)
f to:(char)
t in:(id) obj
{
int i;
int max;
char *string;
int i;
int max;
char *string;
max = [obj count];
for (i = 0;i < max;i++)
{
string = [obj elementAt:i];
changeString(f,t,string);
max =[obj count];
for (i = 0; i < max; i++) {
string =[obj elementAt:i];
changeString (f, t, string);
}
return self;
}
//
// Fill the QuakeEd Maps or wads browser
// (Delegate method - delegated in Interface Builder)
// Fill the QuakeEd Maps or wads browser
// (Delegate method - delegated in Interface Builder)
//
- (int)browser:sender fillMatrix:matrix inColumn:(int)column
-(int) browser: sender fillMatrix: matrix inColumn:(int) column
{
id cell, list;
int max;
char *name;
int i;
id cell, list;
int max;
char *name;
int i;
if (sender == mapbrowse_i)
list = mapList;
else if (sender == pis_wads_i)
list = wadList;
else
{
else {
list = nil;
Sys_Error ("Project: unknown browser to fill");
}
max = [list count];
for (i = 0 ; i<max ; i++)
{
name = [list elementAt:i];
max =[list count];
for (i = 0; i < max; i++) {
name =[list elementAt:i];
[matrix addRow];
cell = [matrix cellAtRow:i column:0];
[cell setStringValue:[NSString stringWithCString:name]];
cell =[matrix cellAtRow: i column:0];
[cell setStringValue: [NSString stringWithCString:name]];
[cell setLeaf:YES];
[cell setLoaded:YES];
}
@ -237,55 +230,52 @@ id project_i;
}
//
// Clicked on a map name or description!
// Clicked on a map name or description!
//
- clickedOnMap:sender
-clickedOnMap:sender
{
id matrix;
int row;
char fname[1024];
id panel;
matrix = [sender matrixInColumn:0];
row = [matrix selectedRow];
sprintf(fname,"%s/%s.map",path_mapdirectory,
(char *)[mapList elementAt:row]);
panel = NSGetAlertPanel(@"Loading...",
@"Loading map. Please wait.",NULL,NULL,NULL);
id matrix;
int row;
char fname[1024];
id panel;
matrix =[sender matrixInColumn:0];
row =[matrix selectedRow];
sprintf (fname, "%s/%s.map", path_mapdirectory, (char *)[mapList elementAt:row]);
panel = NSGetAlertPanel (@"Loading...",
@"Loading map. Please wait.", NULL, NULL, NULL);
[panel orderFront:NULL];
[quakeed_i doOpen:fname];
[panel performClose:NULL];
//NSFreeAlertPanel(panel);
// NSFreeAlertPanel(panel);
return self;
}
- setTextureWad: (char *)wf
-setTextureWad:(char *) wf
{
int i, c;
char *name;
int i, c;
char *name;
qprintf ("loading %s", wf);
// set the row in the settings inspector wad browser
c = [wadList count];
for (i=0 ; i<c ; i++)
{
c =[wadList count];
for (i = 0; i < c; i++) {
name = (char *)[wadList elementAt:i];
if (!strcmp(name, wf))
{
[[pis_wads_i matrixInColumn:0] selectCellAtRow: i column: 0];
if (!strcmp (name, wf)) {
[[pis_wads_i matrixInColumn: 0] selectCellAtRow: i column:0];
break;
}
}
// update the texture inspector
[texturepalette_i initPaletteFromWadfile:wf ];
[[map_i objectAtIndex: 0] setKey:"wad" toValue: wf];
// [inspcontrol_i changeInspectorTo:i_textures];
[texturepalette_i initPaletteFromWadfile:wf];
[[map_i objectAtIndex: 0] setKey: "wad" toValue:wf];
// [inspcontrol_i changeInspectorTo:i_textures];
[quakeed_i updateAll];
@ -293,42 +283,41 @@ id project_i;
}
//
// Clicked on a wad name
// Clicked on a wad name
//
- clickedOnWad:sender
-clickedOnWad:sender
{
id matrix;
int row;
char *name;
matrix = [sender matrixInColumn:0];
row = [matrix selectedRow];
id matrix;
int row;
char *name;
matrix =[sender matrixInColumn:0];
row =[matrix selectedRow];
name = (char *)[wadList elementAt:row];
[self setTextureWad: name];
[self setTextureWad:name];
return self;
}
//
// Read in the <name>.QE_Project file
// Read in the <name>.QE_Project file
//
- parseProjectFile
-parseProjectFile
{
char *path;
int rtn;
path = [preferences_i getProjectPath];
if (!path || !path[0] || access(path,0))
{
rtn = NSRunAlertPanel(@"Project Error!",
@"A default project has not been found.\n"
, @"Open Project", NULL, NULL);
char *path;
int rtn;
path =[preferences_i getProjectPath];
if (!path || !path[0] || access (path, 0)) {
rtn = NSRunAlertPanel (@"Project Error!",
@"A default project has not been found.\n",
@"Open Project", NULL, NULL);
if ([self openProject] == nil)
while (1) // can't run without a project
[NSApp terminate: self];
return self;
while (1) // can't run without a project
[NSApp terminate:self];
return self;
}
[self openProjectFile:path];
@ -336,103 +325,102 @@ id project_i;
}
//
// Loads and parses a project file
// Loads and parses a project file
//
- openProjectFile:(char *)path
{
FILE *fp;
struct stat s;
-openProjectFile:(char *) path
{
FILE *fp;
struct stat s;
strcpy(path_projectinfo,path);
strcpy (path_projectinfo, path);
projectInfo = NULL;
fp = fopen(path,"r+t");
fp = fopen (path, "r+t");
if (fp == NULL)
return self;
stat(path,&s);
stat (path, &s);
lastModified = s.st_mtime;
projectInfo = [(Dict *)[Dict alloc] initFromFile:fp];
fclose(fp);
projectInfo =[(Dict *)[Dict alloc] initFromFile:fp];
fclose (fp);
return self;
}
- (char *)currentProjectFile
-(char *) currentProjectFile
{
return path_projectinfo;
}
//
// Open a project file
// Open a project file
//
- openProject
-openProject
{
char path[128];
id openpanel;
int rtn;
NSString *projtypes[] ={ @"qpr"};
char path[128];
id openpanel;
int rtn;
NSString *projtypes[] = { @"qpr" };
NSArray *filenames;
const char *dir;
openpanel = [NSOpenPanel new];
//[openpanel allowMultipleFiles:NO];
//[openpanel chooseDirectories:NO];
rtn = [openpanel runModalForTypes:[NSArray arrayWithObjects: projtypes count:1]];
if (rtn == NSOKButton)
{
filenames = [openpanel filenames];
dir = [[openpanel directory] cString];
sprintf (path, "%s/%s", dir, [[filenames objectAtIndex:0] cString]);
strcpy(path_projectinfo,path);
[self openProjectFile:path];
return self;
openpanel =[NSOpenPanel new];
// [openpanel allowMultipleFiles:NO];
// [openpanel chooseDirectories:NO];
rtn =[openpanel runModalForTypes: [NSArray arrayWithObjects: projtypes count:1]];
if (rtn == NSOKButton) {
filenames =[openpanel filenames];
dir =[[openpanel directory] cString];
sprintf (path, "%s/%s", dir,[[filenames objectAtIndex:0] cString]);
strcpy (path_projectinfo, path);
[self openProjectFile:path];
return self;
}
return nil;
}
//
// Search for a string in a List of strings
// Search for a string in a List of strings
//
- (int)searchForString:(char *)str in:(id)obj
-(int) searchForString:(char *)
str in:(id) obj
{
int i;
int max;
char *s;
int i;
int max;
char *s;
max = [obj count];
for (i = 0;i < max; i++)
{
max =[obj count];
for (i = 0; i < max; i++) {
s = (char *)[obj elementAt:i];
if (!strcmp(s,str))
if (!strcmp (s, str))
return 1;
}
return 0;
}
- (char *)getMapDirectory
-(char *) getMapDirectory
{
return path_mapdirectory;
}
- (char *)getFinalMapDirectory
-(char *) getFinalMapDirectory
{
return path_finalmapdir;
}
- (char *)getProgDirectory
-(char *) getProgDirectory
{
return path_progdir;
}
//
// Return the WAD name for cmd-8
// Return the WAD name for cmd-8
//
- (char *)getWAD8
-(char *) getWAD8
{
if (!path_wad8[0])
return NULL;
@ -440,9 +428,9 @@ id project_i;
}
//
// Return the WAD name for cmd-9
// Return the WAD name for cmd-9
//
- (char *)getWAD9
-(char *) getWAD9
{
if (!path_wad9[0])
return NULL;
@ -450,9 +438,9 @@ id project_i;
}
//
// Return the WAD name for cmd-0
// Return the WAD name for cmd-0
//
- (char *)getWAD0
-(char *) getWAD0
{
if (!path_wad0[0])
return NULL;
@ -460,9 +448,9 @@ id project_i;
}
//
// Return the FULLVIS cmd string
// Return the FULLVIS cmd string
//
- (char *)getFullVisCmd
-(char *) getFullVisCmd
{
if (!string_fullvis[0])
return NULL;
@ -470,9 +458,9 @@ id project_i;
}
//
// Return the FASTVIS cmd string
// Return the FASTVIS cmd string
//
- (char *)getFastVisCmd
-(char *) getFastVisCmd
{
if (!string_fastvis[0])
return NULL;
@ -480,9 +468,9 @@ id project_i;
}
//
// Return the NOVIS cmd string
// Return the NOVIS cmd string
//
- (char *)getNoVisCmd
-(char *) getNoVisCmd
{
if (!string_novis[0])
return NULL;
@ -490,9 +478,9 @@ id project_i;
}
//
// Return the RELIGHT cmd string
// Return the RELIGHT cmd string
//
- (char *)getRelightCmd
-(char *) getRelightCmd
{
if (!string_relight[0])
return NULL;
@ -500,16 +488,16 @@ id project_i;
}
//
// Return the LEAKTEST cmd string
// Return the LEAKTEST cmd string
//
- (char *)getLeaktestCmd
-(char *) getLeaktestCmd
{
if (!string_leaktest[0])
return NULL;
return string_leaktest;
}
- (char *)getEntitiesCmd
-(char *) getEntitiesCmd
{
if (!string_entities[0])
return NULL;
@ -517,21 +505,18 @@ id project_i;
}
@end
//====================================================
// C Functions
//====================================================
//
// Change a character to a different char in a string
//
void changeString(char cf,char ct,char *string)
void
changeString (char cf, char ct, char *string)
{
int j;
int j;
for (j = 0;j < strlen(string);j++)
for (j = 0; j < strlen (string); j++)
if (string[j] == cf)
string[j] = ct;
}

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
#include <AppKit/AppKit.h>
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

@ -1,25 +1,25 @@
/* Implementation of Objective C NeXT-compatible Storage object
Copyright (C) 1993,1994, 1996 Free Software Foundation, Inc.
Copyright (C) 1993,1994, 1996 Free Software Foundation, Inc.
Written by: Kresten Krab Thorup <krab@iesd.auc.dk>
Dept. of Mathematics and Computer Science, Aalborg U., Denmark
Written by: Kresten Krab Thorup <krab@iesd.auc.dk>
Dept. of Mathematics and Computer Science, Aalborg U., Denmark
This file is part of the GNUstep Base Library.
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* #include <config.h> */
#include "Storage.h"
@ -28,257 +28,250 @@
#define GNU_STORAGE_NTH(x,N) \
({ GNUStorageId* __s=(GNUStorageId*)(x); \
(void*)(((char*)__s->dataPtr)+(__s->elementSize*(N))); })
({ GNUStorageId* __s=(GNUStorageId*)(x); \
(void*)(((char*)__s->dataPtr)+(__s->elementSize*(N))); })
#define STORAGE_NTH(N) GNU_STORAGE_NTH (self, N)
typedef struct {
@defs(Storage)
@defs (Storage)
} GNUStorageId;
@implementation Storage
+ initialize
+initialize
{
if (self == [Storage class])
[self setVersion:0]; /* beta release */
return self;
if (self ==[Storage class])
[self setVersion:0]; /* beta release */
return self;
}
// INITIALIZING, FREEING;
- initCount: (NSUInteger)numSlots
elementSize: (NSUInteger)sizeInBytes
description: (const char*)elemDesc;
-initCount: (NSUInteger) numSlots elementSize: (NSUInteger) sizeInBytes description:(const char *)
elemDesc;
{
[super init];
numElements = numSlots;
maxElements = (numSlots > 0) ? numSlots : 1;
elementSize = sizeInBytes;
description = elemDesc;
dataPtr = (void*) objc_malloc (maxElements * elementSize);
bzero(dataPtr, numElements * elementSize);
return self;
[super init];
numElements = numSlots;
maxElements = (numSlots > 0) ? numSlots : 1;
elementSize = sizeInBytes;
description = elemDesc;
dataPtr = (void *) objc_malloc (maxElements * elementSize);
bzero (dataPtr, numElements * elementSize);
return self;
}
- init
-init
{
return [self initCount:1
elementSize:sizeof(id)
description:@encode(id)];
return[self initCount: 1 elementSize:sizeof (id)
description:@encode (id)];
}
- (void)dealloc
-(void) dealloc
{
if (dataPtr)
free(dataPtr);
[super dealloc];
if (dataPtr)
free (dataPtr);
[super dealloc];
}
- (const char*) description
-(const char *) description
{
return description;
return description;
}
// COPYING;
- copy
-copy
{
Storage *c = [super copy];
c->dataPtr = (void*) objc_malloc (maxElements * elementSize);
memcpy(c->dataPtr, dataPtr, numElements * elementSize);
return c;
Storage *c =[super copy];
c->dataPtr = (void *) objc_malloc (maxElements * elementSize);
memcpy (c->dataPtr, dataPtr, numElements * elementSize);
return c;
}
// COMPARING TWO STORAGES;
- (BOOL)isEqual: anObject
-(BOOL) isEqual:anObject
{
if ([anObject isKindOfClass: [Storage class]]
&& [anObject count] == [self count]
&& !memcmp(((GNUStorageId*)anObject)->dataPtr,
dataPtr, numElements*elementSize))
return YES;
else
return NO;
if ([anObject isKindOfClass:[Storage class]]
&&[anObject count] ==[self count]
&& !memcmp (((GNUStorageId *) anObject)->dataPtr,
dataPtr, numElements * elementSize))
return YES;
else
return NO;
}
// MANAGING THE STORAGE CAPACITY;
static inline void _makeRoomForAnotherIfNecessary(Storage *self)
static inline void
_makeRoomForAnotherIfNecessary (Storage * self)
{
if (self->numElements == self->maxElements)
{
self->maxElements *= 2;
self->dataPtr = (void*)
objc_realloc (self->dataPtr, self->maxElements*self->elementSize);
}
if (self->numElements == self->maxElements) {
self->maxElements *= 2;
self->dataPtr = (void *)
objc_realloc (self->dataPtr, self->maxElements * self->elementSize);
}
}
static inline void _shrinkIfDesired(Storage *self)
static inline void
_shrinkIfDesired (Storage * self)
{
if (self->numElements < (self->maxElements / 2))
{
self->maxElements /= 2;
self->dataPtr = (void *)
objc_realloc (self->dataPtr, self->maxElements*self->elementSize);
}
if (self->numElements < (self->maxElements / 2)) {
self->maxElements /= 2;
self->dataPtr = (void *)
objc_realloc (self->dataPtr, self->maxElements * self->elementSize);
}
}
- setAvailableCapacity:(NSUInteger)numSlots
-setAvailableCapacity:(NSUInteger) numSlots
{
if (numSlots > numElements)
{
maxElements = numSlots;
dataPtr = (void*) objc_realloc (dataPtr, maxElements * elementSize);
}
return self;
if (numSlots > numElements) {
maxElements = numSlots;
dataPtr = (void *) objc_realloc (dataPtr, maxElements * elementSize);
}
return self;
}
- setNumSlots:(NSUInteger)numSlots
-setNumSlots:(NSUInteger) numSlots
{
if (numSlots > numElements)
{
maxElements = numSlots;
dataPtr = (void*) objc_realloc (dataPtr, maxElements * elementSize);
bzero(STORAGE_NTH(numElements), (maxElements-numElements)*elementSize);
}
else if (numSlots < numElements)
{
numElements = numSlots;
_shrinkIfDesired (self);
}
return self;
if (numSlots > numElements) {
maxElements = numSlots;
dataPtr = (void *) objc_realloc (dataPtr, maxElements * elementSize);
bzero (STORAGE_NTH (numElements),
(maxElements - numElements) * elementSize);
} else if (numSlots < numElements) {
numElements = numSlots;
_shrinkIfDesired (self);
}
return self;
}
/* Manipulating objects by index */
#define CHECK_INDEX(IND) if (IND >= numElements) return 0
- (NSUInteger) count
-(NSUInteger) count
{
return numElements;
return numElements;
}
- (void*) elementAt: (NSUInteger)index
-(void *) elementAt:(NSUInteger) index
{
CHECK_INDEX(index);
return STORAGE_NTH (index);
CHECK_INDEX (index);
return STORAGE_NTH (index);
}
- addElement: (void*)anElement
-addElement:(void *) anElement
{
_makeRoomForAnotherIfNecessary(self);
memcpy(STORAGE_NTH(numElements), anElement, elementSize);
numElements++;
return self;
_makeRoomForAnotherIfNecessary (self);
memcpy (STORAGE_NTH (numElements), anElement, elementSize);
numElements++;
return self;
}
- insertElement: (void*)anElement at: (NSUInteger)index
-insertElement:(void *)
anElement at:(NSUInteger) index
{
int i;
int i;
CHECK_INDEX(index);
_makeRoomForAnotherIfNecessary(self);
#ifndef STABLE_MEMCPY
for (i = numElements; i >= index; i--)
memcpy (STORAGE_NTH(i+1), STORAGE_NTH(i), elementSize);
#else
memcpy (STORAGE_NTH (index+1),
STORAGE_NTH (index),
elementSize*(numElements-index));
#endif
memcpy(STORAGE_NTH(i), anElement, elementSize);
numElements++;
return self;
}
- removeElementAt: (NSUInteger)index
{
int i;
CHECK_INDEX(index);
numElements--;
CHECK_INDEX (index);
_makeRoomForAnotherIfNecessary (self);
#ifndef STABLE_MEMCPY
for (i = index; i < numElements; i++)
memcpy(STORAGE_NTH(i),
STORAGE_NTH(i+1),
elementSize);
for (i = numElements; i >= index; i--)
memcpy (STORAGE_NTH (i + 1), STORAGE_NTH (i), elementSize);
#else
memcpy (STORAGE_NTH (index),
STORAGE_NTH (index+1),
elementSize*(numElements-index-1));
#endif
_shrinkIfDesired(self);
return self;
memcpy (STORAGE_NTH (index + 1),
STORAGE_NTH (index), elementSize * (numElements - index));
#endif
memcpy (STORAGE_NTH (i), anElement, elementSize);
numElements++;
return self;
}
- removeLastElement
-removeElementAt:(NSUInteger) index
{
if (numElements)
{
numElements--;
_shrinkIfDesired(self);
}
return self;
int i;
CHECK_INDEX (index);
numElements--;
#ifndef STABLE_MEMCPY
for (i = index; i < numElements; i++)
memcpy (STORAGE_NTH (i), STORAGE_NTH (i + 1), elementSize);
#else
memcpy (STORAGE_NTH (index),
STORAGE_NTH (index + 1), elementSize * (numElements - index - 1));
#endif
_shrinkIfDesired (self);
return self;
}
- replaceElementAt:(NSUInteger)index with:(void*)newElement
-removeLastElement
{
CHECK_INDEX(index);
memcpy(STORAGE_NTH(index), newElement, elementSize);
return self;
if (numElements) {
numElements--;
_shrinkIfDesired (self);
}
return self;
}
-replaceElementAt:(NSUInteger)
index with:(void *) newElement
{
CHECK_INDEX (index);
memcpy (STORAGE_NTH (index), newElement, elementSize);
return self;
}
/* Emptying the Storage */
- empty
-empty
{
numElements = 0;
maxElements = 1;
dataPtr = (void*) objc_realloc (dataPtr, maxElements * elementSize);
return self;
numElements = 0;
maxElements = 1;
dataPtr = (void *) objc_realloc (dataPtr, maxElements * elementSize);
return self;
}
/* Archiving */
- write: (TypedStream*)aStream
-write:(TypedStream *) aStream
{
int i;
int i;
[super write:aStream];
objc_write_types(aStream, "III*",
&numElements, &maxElements, &elementSize, &description);
for (i = 0; i < numElements; i++)
objc_write_type(aStream, description, STORAGE_NTH(i));
return self;
[super write:aStream];
objc_write_types (aStream, "III*",
&numElements, &maxElements, &elementSize, &description);
for (i = 0; i < numElements; i++)
objc_write_type (aStream, description, STORAGE_NTH (i));
return self;
}
- read: (TypedStream*)aStream
-read:(TypedStream *) aStream
{
int i;
int i;
[super read:aStream];
objc_read_types(aStream, "III*",
&numElements, &maxElements, &elementSize, &description);
dataPtr = (void*) objc_malloc (maxElements * elementSize);
for (i = 0; i < numElements; i++)
objc_read_type(aStream, description, STORAGE_NTH(i));
return self;
[super read:aStream];
objc_read_types (aStream, "III*",
&numElements, &maxElements, &elementSize, &description);
dataPtr = (void *) objc_malloc (maxElements * elementSize);
for (i = 0; i < numElements; i++)
objc_read_type (aStream, description, STORAGE_NTH (i));
return self;
}
+ new
+new
{
return [[self alloc] init];
return[[self alloc] init];
}
+ newCount:(NSUInteger)count elementSize:(NSUInteger)sizeInBytes
description:(const char *)descriptor
+newCount:(NSUInteger)
count elementSize:(NSUInteger) sizeInBytes
description:(const char *) descriptor
{
return [[self alloc] initCount:count elementSize:sizeInBytes
description:descriptor];
return[[self alloc] initCount: count elementSize: sizeInBytes description:descriptor];
}
@end

File diff suppressed because it is too large Load diff

View file

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

View file

@ -6,222 +6,219 @@
#include "KeypairView.h"
#include "Project.h"
id things_i;
id things_i;
@implementation Things
- init
-init
{
[super init];
things_i = self;
lastSelected = 0;
return self;
}
//
// Load the TEXT object with the entity comment
// Load the TEXT object with the entity comment
//
- loadEntityComment:(id)obj
-loadEntityComment:(id) obj
{
[entity_comment_i selectAll:self];
[entity_comment_i replaceCharactersInRange:[entity_comment_i selectedRange] withString:[NSString stringWithCString:[obj comments]]];
[entity_comment_i replaceCharactersInRange: [entity_comment_i selectedRange] withString: [NSString stringWithCString:[obj
comments]]];
return self;
}
- initEntities
{
char *path;
-initEntities
{
char *path;
path = [project_i getProgDirectory];
path =[project_i getProgDirectory];
[prog_path_i setStringValue: [NSString stringWithCString:path]];
[[EntityClassList alloc] initForSourceDirectory: path];
[self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]];
[[EntityClassList alloc] initForSourceDirectory:path];
[self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]];
[entity_browser_i loadColumnZero];
[[entity_browser_i matrixInColumn:0] selectCellAtRow:lastSelected column:0];
[[entity_browser_i matrixInColumn: 0] selectCellAtRow: lastSelected column:0];
[entity_browser_i setDoubleAction: @selector (doubleClickEntity:)];
[entity_browser_i setDoubleAction: @selector(doubleClickEntity:)];
return self;
}
- selectEntity: sender
-selectEntity:sender
{
id matr;
matr = [sender matrixInColumn: 0];
lastSelected = [matr selectedRow];
[self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]];
[quakeed_i makeFirstResponder: quakeed_i];
id matr;
matr =[sender matrixInColumn:0];
lastSelected =[matr selectedRow];
[self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]];
[quakeed_i makeFirstResponder:quakeed_i];
return self;
}
- doubleClickEntity: sender
-doubleClickEntity:sender
{
[map_i makeEntity: sender];
[quakeed_i makeFirstResponder: quakeed_i];
[map_i makeEntity:sender];
[quakeed_i makeFirstResponder:quakeed_i];
return self;
}
- (char *)spawnName
-(char *) spawnName
{
return [[entity_classes_i objectAtIndex:lastSelected] classname];
return[[entity_classes_i objectAtIndex:lastSelected] classname];
}
//
// Flush entity classes & reload them!
// Flush entity classes & reload them!
//
- reloadEntityClasses: sender
-reloadEntityClasses:sender
{
EntityClass *ent;
char *path;
char *path;
path = (char *)[prog_path_i stringValue];
if (!path || !path[0])
{
path = [project_i getProgDirectory];
if (!path || !path[0]) {
path =[project_i getProgDirectory];
[prog_path_i setStringValue: [NSString stringWithCString:path]];
}
// Free all entity info in memory...
// Free all entity info in memory...
[entity_classes_i removeAllObjects];
[entity_classes_i release];
// Now, RELOAD!
[[EntityClassList alloc] initForSourceDirectory: path];
// Now, RELOAD!
[[EntityClassList alloc] initForSourceDirectory:path];
lastSelected = 0;
ent = [entity_classes_i objectAtIndex:lastSelected];
[self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]];
ent =[entity_classes_i objectAtIndex:lastSelected];
[self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]];
[entity_browser_i loadColumnZero];
[[entity_browser_i matrixInColumn:0] selectCellAtRow:lastSelected column:0];
[[entity_browser_i matrixInColumn: 0] selectCellAtRow: lastSelected column:0];
[self newCurrentEntity]; // in case flags changed
[self newCurrentEntity]; // in case flags changed
return self;
}
- selectClass: (char *)class
-selectClass:(char *) class
{
id classent;
classent = [entity_classes_i classForName:class];
id classent;
classent =[entity_classes_i classForName:class];
if (!classent)
return self;
lastSelected = [entity_classes_i indexOfObject: classent];
lastSelected =[entity_classes_i indexOfObject:classent];
if (lastSelected < 0)
lastSelected = 0;
[self loadEntityComment:classent];
[[entity_browser_i matrixInColumn:0] selectCellAtRow:lastSelected column:0];
[[entity_browser_i matrixInColumn:0] scrollCellToVisibleAtRow:lastSelected column:0];
[[entity_browser_i matrixInColumn: 0] selectCellAtRow: lastSelected column:0];
[[entity_browser_i matrixInColumn: 0] scrollCellToVisibleAtRow: lastSelected column:0];
return self;
}
- newCurrentEntity
-newCurrentEntity
{
id ent, classent, cell;
char *classname;
int r, c;
char *flagname;
int flags;
ent = [map_i currentEntity];
classname = [ent valueForQKey: "classname"];
if (ent != [map_i objectAtIndex: 0])
[self selectClass: classname]; // don't reset for world
classent = [entity_classes_i classForName:classname];
flagname = [ent valueForQKey: "spawnflags"];
id ent, classent, cell;
char *classname;
int r, c;
char *flagname;
int flags;
ent =[map_i currentEntity];
classname =[ent valueForQKey:"classname"];
if (ent !=[map_i objectAtIndex:0])
[self selectClass:classname]; // don't reset for world
classent =[entity_classes_i classForName:classname];
flagname =[ent valueForQKey:"spawnflags"];
if (!flagname)
flags = 0;
else
flags = atoi(flagname);
[flags_i setAutodisplay: NO];
for (r=0 ; r<4 ; r++)
for (c=0 ; c<3 ; c++)
{
cell = [flags_i cellAtRow: r column: c];
if (c < 2)
{
flagname = [classent flagName: c*4 + r];
flags = atoi (flagname);
[flags_i setAutodisplay:NO];
for (r = 0; r < 4; r++)
for (c = 0; c < 3; c++) {
cell =[flags_i cellAtRow: r column:c];
if (c < 2) {
flagname =[classent flagName:c * 4 + r];
[cell setTitle: [NSString stringWithCString:flagname]];
}
[cell setIntValue: (flags & (1<< ((c*4)+r)) ) > 0];
[cell setIntValue:(flags & (1 << ((c * 4) + r))) > 0];
}
[flags_i setAutodisplay: YES];
[flags_i setAutodisplay:YES];
[flags_i display];
// [keyInput_i setStringValue: ""];
// [valueInput_i setStringValue: ""];
// [keyInput_i setStringValue: ""];
// [valueInput_i setStringValue: ""];
[keypairview_i calcViewSize];
[keypairview_i display];
[quakeed_i makeFirstResponder: quakeed_i];
[quakeed_i makeFirstResponder:quakeed_i];
return self;
}
//
// Clicked in the Keypair view - set as selected
// Clicked in the Keypair view - set as selected
//
- setSelectedKey:(epair_t *)ep;
-setSelectedKey:(epair_t *) ep;
{
[keyInput_i setStringValue:[NSString stringWithCString:ep->key]];
[valueInput_i setStringValue:[NSString stringWithCString:ep->value]];
[valueInput_i selectText:self];
[keyInput_i setStringValue: [NSString stringWithCString:ep->key]];
[valueInput_i setStringValue: [NSString stringWithCString:ep->value]];
[valueInput_i selectText:self];
return self;
}
- clearInputs
-clearInputs
{
// [keyInput_i setStringValue: ""];
// [valueInput_i setStringValue: ""];
[quakeed_i makeFirstResponder: quakeed_i];
// [keyInput_i setStringValue: ""];
// [valueInput_i setStringValue: ""];
[quakeed_i makeFirstResponder:quakeed_i];
return self;
}
//
// Action methods
// Action methods
//
-addPair:sender
{
char *key, *value;
char *key, *value;
key = (char *)[keyInput_i stringValue];
value = (char *)[valueInput_i stringValue];
[ [map_i currentEntity] setKey: key toValue: value ];
[[map_i currentEntity] setKey: key toValue:value];
[keypairview_i calcViewSize];
[keypairview_i display];
[self clearInputs];
[quakeed_i updateXY];
return self;
}
-delPair:sender
{
[quakeed_i makeFirstResponder: quakeed_i];
[quakeed_i makeFirstResponder:quakeed_i];
[ [map_i currentEntity] removeKeyPair: (char *)[keyInput_i stringValue] ];
[[map_i currentEntity] removeKeyPair:(char *)[keyInput_i stringValue]];
[keypairview_i calcViewSize];
[keypairview_i display];
@ -235,58 +232,56 @@ id things_i;
//
// Set the key/value fields to "angle <button value>"
// Set the key/value fields to "angle <button value>"
//
- setAngle:sender
-setAngle:sender
{
const char *title;
char value[10];
title = [[[sender selectedCell] title] cString];
if (!strcmp(title,"Up"))
char value[10];
title =[[[sender selectedCell] title] cString];
if (!strcmp (title, "Up"))
strcpy (value, "-1");
else if (!strcmp(title,"Dn"))
else if (!strcmp (title, "Dn"))
strcpy (value, "-2");
else
strcpy (value, title);
[keyInput_i setStringValue:@"angle"];
[valueInput_i setStringValue:[NSString stringWithCString:value]];
[valueInput_i setStringValue: [NSString stringWithCString:value]];
[self addPair:NULL];
[self clearInputs];
[quakeed_i updateXY];
return self;
}
- setFlags:sender
-setFlags:sender
{
int flags;
int r, c, i;
id cell;
char str[20];
int flags;
int r, c, i;
id cell;
char str[20];
[self clearInputs];
flags = 0;
for (r=0 ; r<4 ; r++)
for (c=0 ; c<3 ; c++)
{
cell = [flags_i cellAtRow: r column: c];
for (r = 0; r < 4; r++)
for (c = 0; c < 3; c++) {
cell =[flags_i cellAtRow: r column:c];
i = ([cell intValue] > 0);
flags |= (i<< ((c*4)+r));
flags |= (i << ((c * 4) + r));
}
if (!flags)
[[map_i currentEntity] removeKeyPair: "spawnflags"];
else
{
[[map_i currentEntity] removeKeyPair:"spawnflags"];
else {
sprintf (str, "%i", flags);
[[map_i currentEntity] setKey: "spawnflags" toValue: str];
[[map_i currentEntity] setKey: "spawnflags" toValue:str];
}
[keypairview_i calcViewSize];
[keypairview_i display];
@ -295,24 +290,24 @@ id things_i;
//
// Fill the Entity browser
// (Delegate method - delegated in Interface Builder)
// Fill the Entity browser
// (Delegate method - delegated in Interface Builder)
//
- (int)browser:sender fillMatrix:matrix inColumn:(int)column
-(int) browser: sender fillMatrix: matrix inColumn:(int) column
{
id cell;
int max;
int i;
id object;
max = [entity_classes_i count];
id cell;
int max;
int i;
id object;
max =[entity_classes_i count];
i = 0;
while(max--)
{
object = [entity_classes_i objectAtIndex:i];
while (max--) {
object =[entity_classes_i objectAtIndex:i];
[matrix addRow];
cell = [matrix cellAtRow:i++ column:0];
[cell setStringValue:[NSString stringWithCString:[object classname]]];
cell =[matrix cellAtRow: i++ column:0];
[cell setStringValue: [NSString stringWithCString:[object
classname]]];
[cell setLeaf:YES];
[cell setLoaded:YES];
}

View file

@ -14,63 +14,68 @@
#include <math.h>
#include <libc.h>
static NSZone *upZone = NULL;
static NSZone *upZone = NULL;
NSZone *userPathZone()
NSZone *
userPathZone ()
/* Creates a unique zone for use by all user paths */
{
if (!upZone) {
upZone = NSCreateZone(vm_page_size, vm_page_size, 1);
}
return upZone;
if (!upZone) {
upZone = NSCreateZone (vm_page_size, vm_page_size, 1);
}
return upZone;
}
UserPath *newUserPath()
UserPath *
newUserPath ()
/* Creates a new User Path in the zone returned by userPathZone */
{
UserPath *up;
UserPath *up;
up = (UserPath *)NSZoneMalloc(userPathZone(), sizeof(UserPath));
up->max = 8192; // JDC
up->points = (float *)NSZoneMalloc(userPathZone(),
sizeof(float) * up->max);
up->ops = (char *)NSZoneMalloc(userPathZone(),
(2 + (up->max / 2)) * sizeof(char));
up->ping = NO;
return up;
up = (UserPath *) NSZoneMalloc (userPathZone (), sizeof (UserPath));
up->max = 8192; // JDC
up->points = (float *) NSZoneMalloc (userPathZone (),
sizeof (float) * up->max);
up->ops = (char *) NSZoneMalloc (userPathZone (),
(2 + (up->max / 2)) * sizeof (char));
up->ping = NO;
return up;
}
void freeUserPath(UserPath *up)
void
freeUserPath (UserPath * up)
/* Frees User Path and its associated buffers */
{
free(up->points);
free(up->ops);
free(up);
return;
free (up->points);
free (up->ops);
free (up);
return;
}
void growUserPath(UserPath *up)
void
growUserPath (UserPath * up)
/*
* 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
* methods and functions which add elements into the buffer
*/
{
/* double the size of the internal buffers */
printf ("growUserPath\n");
up->max *= 2;
up->points = (float *)NSZoneRealloc(userPathZone(), up->points,
sizeof(float) * up->max);
up->ops = (char *)NSZoneRealloc(userPathZone(), up->ops,
(2 + (up->max / 2)) * sizeof(char));
/* double the size of the internal buffers */
printf ("growUserPath\n");
up->max *= 2;
up->points = (float *) NSZoneRealloc (userPathZone (), up->points,
sizeof (float) * up->max);
up->ops = (char *) NSZoneRealloc (userPathZone (), up->ops,
(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
* you want the user path cached at the server (i.e. dps_ucache). In either
@ -78,20 +83,21 @@ void beginUserPath(UserPath *up, BOOL cache)
* the path and add the dps_setbbox operator.
*/
{
up->numberOfPoints = up->numberOfOps = 0;
up->cp.x = up->cp.y = 0;
up->bbox[0] = up->bbox[1] = 1.0e6;
up->bbox[2] = up->bbox[3] = -1.0e6;
if (cache) {
up->ops[up->numberOfOps++] = dps_ucache;
}
up->ops[up->numberOfOps++] = dps_setbbox;
up->opForUserPath = 0;
return;
up->numberOfPoints = up->numberOfOps = 0;
up->cp.x = up->cp.y = 0;
up->bbox[0] = up->bbox[1] = 1.0e6;
up->bbox[2] = up->bbox[3] = -1.0e6;
if (cache) {
up->ops[up->numberOfOps++] = dps_ucache;
}
up->ops[up->numberOfOps++] = dps_setbbox;
up->opForUserPath = 0;
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
* the server -- use sendUserPath. The op argument should be one of the
@ -101,13 +107,14 @@ void endUserPath(UserPath *up, int op)
* These are defined in <dpsclient/dpsNext.h.
*/
{
up->opForUserPath = op;
return;
up->opForUserPath = op;
return;
}
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
* window server, an NSPing() is sent after. The purpose is to catch PostScript
@ -116,12 +123,13 @@ void UPdebug(UserPath *up, BOOL shouldPing)
* ping is NO.
*/
{
up->ping = shouldPing;
return;
up->ping = shouldPing;
return;
}
int sendUserPath(UserPath *up)
int
sendUserPath (UserPath * up)
/*
* 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,
@ -133,77 +141,77 @@ int sendUserPath(UserPath *up)
* server.
*/
{
NSHandler exception;
NSHandler exception;
exception.code = 0;
if (up->opForUserPath != 0) {
//NS_DURING
DPSDoUserPath(up->points, up->numberOfPoints, dps_float, up->ops,
up->numberOfOps, up->bbox, up->opForUserPath);
if (up->ping) {
NSPing();
exception.code = 0;
if (up->opForUserPath != 0) {
// NS_DURING
DPSDoUserPath (up->points, up->numberOfPoints, dps_float, up->ops,
up->numberOfOps, up->bbox, up->opForUserPath);
if (up->ping) {
NSPing ();
}
// NS_HANDLER
// exception = NSLocalHandler;
// NS_ENDHANDLER
if (exception.code) {
NSReportError (&exception);
if (exception.code == dps_err_ps) {
return -1;
}
} else {
return 0;
}
}
//NS_HANDLER
// exception = NSLocalHandler;
//NS_ENDHANDLER
if (exception.code) {
NSReportError(&exception);
if (exception.code == dps_err_ps) {
return -1;
}
} else {
return 0;
}
}
return -1;
return -1;
}
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 */
{
up->ops[up->numberOfOps++] = dps_moveto;
up->points[up->numberOfPoints++] = x;
up->points[up->numberOfPoints++] = y;
if (x < up->bbox[0]) {
up->bbox[0] = x;
}
if (y < up->bbox[1]) {
up->bbox[1] = y;
}
if (x > up->bbox[2]) {
up->bbox[2] = x;
}
if (y > up->bbox[3]) {
up->bbox[3] = y;
}
return;
up->ops[up->numberOfOps++] = dps_moveto;
up->points[up->numberOfPoints++] = x;
up->points[up->numberOfPoints++] = y;
if (x < up->bbox[0]) {
up->bbox[0] = x;
}
if (y < up->bbox[1]) {
up->bbox[1] = y;
}
if (x > up->bbox[2]) {
up->bbox[2] = x;
}
if (y > up->bbox[3]) {
up->bbox[3] = y;
}
return;
}
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 */
{
up->ops[up->numberOfOps++] = dps_lineto;
up->points[up->numberOfPoints++] = x;
up->points[up->numberOfPoints++] = y;
if (x < up->bbox[0]) {
up->bbox[0] = x;
}
if (y < up->bbox[1]) {
up->bbox[1] = y;
}
if (x > up->bbox[2]) {
up->bbox[2] = x;
}
if (y > up->bbox[3]) {
up->bbox[3] = y;
}
return;
}
up->ops[up->numberOfOps++] = dps_lineto;
up->points[up->numberOfPoints++] = x;
up->points[up->numberOfPoints++] = y;
if (x < up->bbox[0]) {
up->bbox[0] = x;
}
if (y < up->bbox[1]) {
up->bbox[1] = y;
}
if (x > up->bbox[2]) {
up->bbox[2] = x;
}
if (y > up->bbox[3]) {
up->bbox[3] = y;
}
return;
}

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,6 @@
#include "ZScrollView.h"
@implementation ZScrollView
/*
====================
initWithFrame: button:
@ -9,42 +8,37 @@ initWithFrame: button:
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
{
[super initWithFrame: frameRect];
[self addSubview: b1];
[self addSubview:b1];
button1 = b1;
[self setHasHorizontalScroller: YES];
[self setHasVerticalScroller: YES];
[self setHasHorizontalScroller:YES];
[self setHasVerticalScroller:YES];
[self setBorderType:NSBezelBorder];
[self setBorderType: NSBezelBorder];
return self;
}
/*
================
tile
Adjust the size for the pop up scale menu
=================
*/
- tile
*/ -tile
{
NSRect scrollerframe;
NSRect scrollerframe;
[super tile];
scrollerframe = [_horizScroller frame];
[button1 setFrame: scrollerframe];
scrollerframe =[_horizScroller frame];
[button1 setFrame:scrollerframe];
scrollerframe.size.width = 0;
[_horizScroller setFrame: scrollerframe];
[_horizScroller setFrame:scrollerframe];
return self;
}
@ -53,8 +47,9 @@ Adjust the size for the pop up scale menu
-(BOOL) acceptsFirstResponder
{
return YES;
return YES;
}
/*
- superviewSizeChanged:(const NSSize *)oldSize
{
@ -68,4 +63,3 @@ Adjust the size for the pop up scale menu
@end

File diff suppressed because it is too large Load diff

View file

@ -1,41 +1,40 @@
char token[MAXTOKEN];
boolean unget;
char *script_p;
int scriptline;
char token[MAXTOKEN];
boolean unget;
char *script_p;
int scriptline;
void StartTokenParsing (char *data)
void
StartTokenParsing (char *data)
{
scriptline = 1;
script_p = data;
unget = false;
}
boolean GetToken (boolean crossline)
boolean
GetToken (boolean crossline)
{
char *token_p;
char *token_p;
if (unget) // is a token allready waiting?
if (unget) // is a token allready waiting?
return true;
//
// skip space
//
skipspace:
while (*script_p <= 32)
{
if (!*script_p)
{
skipspace:
while (*script_p <= 32) {
if (!*script_p) {
if (!crossline)
Error ("Line %i is incomplete",scriptline);
Error ("Line %i is incomplete", scriptline);
return false;
}
if (*script_p++ == '\n')
{
if (*script_p++ == '\n') {
if (!crossline)
Error ("Line %i is incomplete",scriptline);
Error ("Line %i is incomplete", scriptline);
scriptline++;
}
}
@ -43,48 +42,44 @@ skipspace:
if (script_p[0] == '/' && script_p[1] == '/') // comment field
{
if (!crossline)
Error ("Line %i is incomplete\n",scriptline);
Error ("Line %i is incomplete\n", scriptline);
while (*script_p++ != '\n')
if (!*script_p)
{
if (!*script_p) {
if (!crossline)
Error ("Line %i is incomplete",scriptline);
Error ("Line %i is incomplete", scriptline);
return false;
}
goto skipspace;
}
//
// copy token
//
token_p = token;
if (*script_p == '"')
{
if (*script_p == '"') {
script_p++;
while ( *script_p != '"' )
{
while (*script_p != '"') {
if (!*script_p)
Error ("EOF inside quoted token");
*token_p++ = *script_p++;
if (token_p == &token[MAXTOKEN])
Error ("Token too large on line %i",scriptline);
Error ("Token too large on line %i", scriptline);
}
script_p++;
}
else while ( *script_p > 32 )
{
*token_p++ = *script_p++;
if (token_p == &token[MAXTOKEN])
Error ("Token too large on line %i",scriptline);
}
} else
while (*script_p > 32) {
*token_p++ = *script_p++;
if (token_p == &token[MAXTOKEN])
Error ("Token too large on line %i", scriptline);
}
*token_p = 0;
return true;
}
void UngetToken ()
void
UngetToken ()
{
unget = true;
}
@ -93,18 +88,19 @@ 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;
static char string[1024];
va_list argptr;
static char string[1024];
va_start (argptr, fmt);
vsprintf (string, fmt,argptr);
vsprintf (string, fmt, argptr);
va_end (argptr);
[g_cmd_out_i setStringValue: [NSString stringWithCString: string]];
//NSPing ();
[g_cmd_out_i setStringValue: [NSString stringWithCString:string]];
// NSPing ();
return;
}
@ -116,53 +112,55 @@ Error
For abnormal program terminations
=================
*/
BOOL in_error;
void Error (char *error, ...)
BOOL in_error;
void
Error (char *error, ...)
{
va_list argptr;
static char string[1024];
va_list argptr;
static char string[1024];
if (in_error)
[NSApp terminate: NULL];
[NSApp terminate:NULL];
in_error = YES;
va_start (argptr,error);
vsprintf (string,error,argptr);
va_start (argptr, error);
vsprintf (string, error, 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];
NSRunAlertPanel (@"Error", [NSString stringWithCString: string],NULL,NULL,NULL);
[NSApp terminate: NULL];
[map_i writeMapFile: FN_CRASHSAVE useRegion:NO];
NSRunAlertPanel (@"Error",[NSString stringWithCString:string], NULL, NULL,
NULL);
[NSApp terminate:NULL];
}
void CleanupName (char *in, char *out)
void
CleanupName (char *in, char *out)
{
int i;
for (i=0 ; i< 16 ; i++ )
{
int i;
for (i = 0; i < 16; i++) {
if (!in[i])
break;
out[i] = toupper(in[i]);
out[i] = toupper (in[i]);
}
for ( ; i< 16 ; i++ )
for (; i < 16; i++)
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"
,r->origin.x,r->origin.y,
r->size.width, r->size.height, r->origin.x+r->size.width,
r->origin.y+r->size.height);
printf ("(%4.0f, %4.0f) + (%4.0f, %4.0f) = (%4.0f,%4.0f)\n", r->origin.x,
r->origin.y, r->size.width, r->size.height,
r->origin.x + r->size.width, r->origin.y + r->size.height);
}
@ -173,13 +171,14 @@ FileTime
returns -1 if not present
============
*/
int FileTime (char *path)
int
FileTime (char *path)
{
struct stat buf;
if (stat (path,&buf) == -1)
struct stat buf;
if (stat (path, &buf) == -1)
return -1;
return buf.st_mtime;
}
@ -188,49 +187,49 @@ int FileTime (char *path)
CreatePath
============
*/
void CreatePath (char *path)
void
CreatePath (char *path)
{
char *ofs;
for (ofs = path+1 ; *ofs ; ofs++)
{
if (*ofs == '/')
{ // create the directory
char *ofs;
for (ofs = path + 1; *ofs; ofs++) {
if (*ofs == '/') { // create the directory
*ofs = 0;
mkdir (path,0777);
mkdir (path, 0777);
*ofs = '/';
}
}
}
int I_FileOpenRead (char *path, int *handle)
int
I_FileOpenRead (char *path, int *handle)
{
int h;
struct stat fileinfo;
int h;
struct stat fileinfo;
h = open (path, O_RDONLY, 0666);
*handle = h;
if (h == -1)
return -1;
if (fstat (h,&fileinfo) == -1)
if (fstat (h, &fileinfo) == -1)
Error ("Error fstating %s", path);
return fileinfo.st_size;
}
int I_FileOpenWrite (char *path)
int
I_FileOpenWrite (char *path)
{
int handle;
int handle;
umask (0);
handle = open(path,O_RDWR | O_CREAT | O_TRUNC
, 0666);
handle = open (path, O_RDWR | O_CREAT | O_TRUNC, 0666);
if (handle == -1)
Error ("Error opening %s: %s", path,strerror(errno));
Error ("Error opening %s: %s", path, strerror (errno));
return handle;
}
@ -242,32 +241,31 @@ Sys_UpdateFile
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 in, out, size;
char *buf;
int ltime, ntime;
int in, out, size;
char *buf;
ltime = FileTime (path);
ntime = FileTime (netpath);
if (ntime <= ltime)
return; // up to date
return; // up to date
// copy the file
printf ("UpdateFile: copying %s to %s...\n", netpath, path);
size = I_FileOpenRead (netpath, &in);
buf = malloc (size);
if (read (in, buf, size) != size)
Error ("UpdateFile: couldn't read all of %s", netpath);
close (in);
CreatePath (path);
CreatePath (path);
out = I_FileOpenWrite (path);
write (out, buf, size);
close (out);
}

View file

@ -1,44 +1,45 @@
#include "render.h"
extern vec3_t xy_viewnormal;
extern vec3_t xy_viewnormal;
//define NOLIGHT
//define NOLIGHT
vec3_t r_origin, r_matrix[3];
vec3_t r_origin, r_matrix[3];
int t_width, t_height;
unsigned *t_data;
int t_widthmask, t_heightmask, t_widthshift;
float t_widthadd, t_heightadd;
int t_width, t_height;
unsigned *t_data;
int t_widthmask, t_heightmask, t_widthshift;
float t_widthadd, t_heightadd;
int r_width, r_height;
float *r_zbuffer;
unsigned *r_picbuffer;
int r_width, r_height;
float *r_zbuffer;
unsigned *r_picbuffer;
vec5_t rightside, leftside, rightstep,leftstep;
vec5_t rightside, leftside, rightstep, leftstep;
face_t *r_face;
face_t *r_face;
BOOL r_drawflat;
BOOL r_drawflat;
pixel32_t r_flatcolor;
pixel32_t r_flatcolor;
int sy[20];
int sy[20];
/*
====================
REN_ClearBuffers
====================
*/
void REN_ClearBuffers (void)
void
REN_ClearBuffers (void)
{
int size;
size = r_width * r_height*4;
int size;
size = r_width * r_height * 4;
memset (r_zbuffer, 0, size);
memset (r_picbuffer, 0, size);
memset (r_picbuffer, 0, size);
}
@ -48,16 +49,17 @@ REN_SetTexture
====================
*/
void REN_SetTexture (face_t *face)
void
REN_SetTexture (face_t * face)
{
int i;
int t_heightshift;
qtexture_t *q;
int i;
int t_heightshift;
qtexture_t *q;
if (!face->qtexture)
face->qtexture = TEX_ForName (face->texture.texture); // try to load
q = face->qtexture;
t_width = q->width;
t_height = q->height;
t_data = q->data;
@ -66,30 +68,28 @@ void REN_SetTexture (face_t *face)
r_flatcolor.chan[0] *= r_face->light;
r_flatcolor.chan[1] *= r_face->light;
r_flatcolor.chan[2] *= r_face->light;
t_widthadd = t_width*1024;
t_heightadd = t_height*1024;
t_widthmask = t_width-1;
t_heightmask = t_height-1;
t_widthadd = t_width * 1024;
t_heightadd = t_height * 1024;
t_widthmask = t_width - 1;
t_heightmask = t_height - 1;
t_widthshift = 0;
i = t_width;
while (i >= 2)
{
while (i >= 2) {
t_widthshift++;
i>>=1;
i >>= 1;
}
t_heightshift = 0;
i = t_width;
while (i >= 2)
{
while (i >= 2) {
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
}
@ -98,82 +98,77 @@ void REN_SetTexture (face_t *face)
REN_DrawSpan
==================
*/
void REN_DrawSpan (int y)
void
REN_DrawSpan (int y)
{
int x, count;
int ofs;
int tx, ty;
int x1, x2;
float ufrac, vfrac, zfrac, lightfrac, ustep, vstep, zstep;
pixel32_t *in, *out;
float scale;
if (y<0 || y >= r_height)
int x, count;
int ofs;
int tx, ty;
int x1, x2;
float ufrac, vfrac, zfrac, lightfrac, ustep, vstep, zstep;
pixel32_t *in, *out;
float scale;
if (y < 0 || y >= r_height)
return;
x1 = (leftside[0]);
x2 = (rightside[0]);
count = x2 - x1;
if (count < 0)
return;
zfrac = leftside[2];
ufrac = leftside[3];
vfrac = leftside[4];
lightfrac = r_face->light;
if (!count)
scale = 1;
else
scale = 1.0/count;
zstep = (rightside[2] - zfrac)*scale;
ustep = (rightside[3] - ufrac)*scale;
vstep = (rightside[4] - vfrac)*scale;
if (x1 < 0)
{
ufrac -= x1*ustep;
vfrac -= x1*vstep;
zfrac -= x1*zstep;
scale = 1.0 / count;
zstep = (rightside[2] - zfrac) * scale;
ustep = (rightside[3] - ufrac) * scale;
vstep = (rightside[4] - vfrac) * scale;
if (x1 < 0) {
ufrac -= x1 * ustep;
vfrac -= x1 * vstep;
zfrac -= x1 * zstep;
x1 = 0;
}
if (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
for (x=x1 ; x < x2 ; x++)
{
if (r_zbuffer[ofs] <= zfrac)
{
scale = 1/zfrac;
for (x = x1; x < x2; x++) {
if (r_zbuffer[ofs] <= zfrac) {
scale = 1 / zfrac;
r_zbuffer[ofs] = zfrac;
if (t_widthshift)
{
tx = (int)((ufrac*scale)) & t_widthmask;
ty = (int)((vfrac*scale)) & t_heightmask;
in = (pixel32_t *)&t_data [(ty<<t_widthshift)+tx];
if (t_widthshift) {
tx = (int) ((ufrac * scale)) & t_widthmask;
ty = (int) ((vfrac * scale)) & t_heightmask;
in = (pixel32_t *) & t_data[(ty << t_widthshift) + tx];
} else {
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];
}
else
{
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
*out = *in;
#else
out->chan[0] = in->chan[0]*lightfrac;
out->chan[1] = in->chan[1]*lightfrac;
out->chan[2] = in->chan[2]*lightfrac;
out->chan[0] = in->chan[0] * lightfrac;
out->chan[1] = in->chan[1] * lightfrac;
out->chan[2] = in->chan[2] * lightfrac;
out->chan[3] = 0xff;
#endif
}
@ -190,46 +185,44 @@ void REN_DrawSpan (int y)
REN_DrawFlatSpan
==================
*/
void REN_DrawFlatSpan (int y)
void
REN_DrawFlatSpan (int y)
{
int x, count;
int ofs;
int x1, x2;
float zfrac, zstep;
int *out;
if (y<0 || y >= r_height)
int x, count;
int ofs;
int x1, x2;
float zfrac, zstep;
int *out;
if (y < 0 || y >= r_height)
return;
x1 = (leftside[0]);
x2 = (rightside[0]);
count = x2 - x1;
if (count < 0)
return;
zfrac = leftside[2];
zstep = (rightside[2] - zfrac)/count;
if (x1 < 0)
{
zfrac -= x1*zstep;
zstep = (rightside[2] - zfrac) / count;
if (x1 < 0) {
zfrac -= x1 * zstep;
x1 = 0;
}
if (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
for (x=x1 ; x < x2 ; x++)
{
if (r_zbuffer[ofs] <= zfrac)
{
for (x = x1; x < x2; x++) {
if (r_zbuffer[ofs] <= zfrac) {
r_zbuffer[ofs] = zfrac;
out = (int *)&r_picbuffer[ofs];
out = (int *) &r_picbuffer[ofs];
*out = r_flatcolor.p;
}
zfrac += zstep;
@ -244,14 +237,15 @@ REN_RasterizeFace
=====================
*/
void REN_RasterizeFace (winding_t *w)
void
REN_RasterizeFace (winding_t * w)
{
int y;
int i;
int top, bot;
int leftv, rightv;
int count;
int numvertex;
int y;
int i;
int top, bot;
int leftv, rightv;
int count;
int numvertex;
//
// find top vertex
@ -260,74 +254,66 @@ void REN_RasterizeFace (winding_t *w)
top = 0x7fffffff;
bot = 0x80000000;
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][4] *= w->points[i][2];
sy[i] = (int)w->points[i][1];
if (sy[i] < top)
{
sy[i] = (int) w->points[i][1];
if (sy[i] < top) {
top = sy[i];
leftv = i;
}
if (sy[i] > bot)
bot = sy[i];
}
rightv = leftv;
rightv = leftv;
if (top < 0 || bot > r_height || top > bot)
return; // shouldn't have to have this...
return; // shouldn't have to have this...
//
// render a trapezoid
//
y = top;
while (y < bot)
{
if (y >= sy[leftv])
{
do
{
for (i=0 ; i<5 ; i++)
while (y < bot) {
if (y >= sy[leftv]) {
do {
for (i = 0; i < 5; i++)
leftside[i] = w->points[leftv][i];
leftv--;
if (leftv == -1)
leftv = numvertex-1;
leftv = numvertex - 1;
} while (sy[leftv] <= y);
count = sy[leftv]-y;
for (i=0 ; i<5 ; i++)
leftstep[i] = (w->points[leftv][i] - leftside[i])/count;
count = sy[leftv] - y;
for (i = 0; i < 5; i++)
leftstep[i] = (w->points[leftv][i] - leftside[i]) / count;
}
if (y >= sy[rightv])
{
do
{
for (i=0 ; i<5 ; i++)
if (y >= sy[rightv]) {
do {
for (i = 0; i < 5; i++)
rightside[i] = w->points[rightv][i];
rightv++;
if (rightv == numvertex)
rightv = 0;
} while (sy[rightv] <= y);
count = sy[rightv]-y;
for (i=0 ; i<5 ; i++)
rightstep[i] = (w->points[rightv][i] - rightside[i])/count;
count = sy[rightv] - y;
for (i = 0; i < 5; i++)
rightstep[i] = (w->points[rightv][i] - rightside[i]) / count;
}
if (r_drawflat)
REN_DrawFlatSpan (y);
else
REN_DrawSpan (y);
for (i=0 ; i<5 ; i++)
{
for (i = 0; i < 5; i++) {
leftside[i] += leftstep[i];
rightside[i] += rightstep[i];
}
y++;
}
}
@ -339,73 +325,68 @@ void REN_RasterizeFace (winding_t *w)
REN_DrawSpanLinear
==================
*/
void REN_DrawSpanLinear (int y)
void
REN_DrawSpanLinear (int y)
{
int x, count;
int ofs;
int tx, ty;
int x1, x2;
float ufrac, vfrac, zfrac, ustep, vstep, zstep;
pixel32_t *in, *out;
float scale;
if (y<0 || y >= r_height)
int x, count;
int ofs;
int tx, ty;
int x1, x2;
float ufrac, vfrac, zfrac, ustep, vstep, zstep;
pixel32_t *in, *out;
float scale;
if (y < 0 || y >= r_height)
return;
x1 = (leftside[0]);
x2 = (rightside[0]);
count = x2 - x1;
if (count < 0)
return;
zfrac = leftside[2];
ufrac = leftside[3];
vfrac = leftside[4];
if (!count)
scale = 1;
else
scale = 1.0/count;
zstep = (rightside[2] - zfrac)*scale;
ustep = (rightside[3] - ufrac)*scale;
vstep = (rightside[4] - vfrac)*scale;
scale = 1.0 / count;
if (x1 < 0)
{
ufrac -= x1*ustep;
vfrac -= x1*vstep;
zfrac -= x1*zstep;
zstep = (rightside[2] - zfrac) * scale;
ustep = (rightside[3] - ufrac) * scale;
vstep = (rightside[4] - vfrac) * scale;
if (x1 < 0) {
ufrac -= x1 * ustep;
vfrac -= x1 * vstep;
zfrac -= x1 * zstep;
x1 = 0;
}
if (x2 > r_width)
x2 = r_width;
ofs = y*r_width+x1;
for (x=x1 ; x < x2 ; x++)
{
if (r_zbuffer[ofs] <= zfrac)
{
ofs = y * r_width + x1;
for (x = x1; x < x2; x++) {
if (r_zbuffer[ofs] <= zfrac) {
r_zbuffer[ofs] = zfrac;
if (t_widthshift)
{
tx = (int)ufrac & t_widthmask;
ty = (int)vfrac & t_heightmask;
in = (pixel32_t *)&t_data [(ty<<t_widthshift)+tx];
if (t_widthshift) {
tx = (int) ufrac & t_widthmask;
ty = (int) vfrac & t_heightmask;
in = (pixel32_t *) & t_data[(ty << t_widthshift) + tx];
} else {
tx = (int) (ufrac + t_widthadd) % t_width;
ty = (int) (vfrac + t_heightadd) % t_height;
in = (pixel32_t *) & t_data[ty * t_width + tx];
}
else
{
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;
}
ufrac += ustep;
@ -422,15 +403,16 @@ REN_RasterizeFaceLinear
=====================
*/
void REN_RasterizeFaceLinear (winding_t *w)
void
REN_RasterizeFaceLinear (winding_t * w)
{
int y;
int i;
int top, bot;
int leftv, rightv;
int count;
int numvertex;
int y;
int i;
int top, bot;
int leftv, rightv;
int count;
int numvertex;
//
// find top vertex
//
@ -439,67 +421,59 @@ void REN_RasterizeFaceLinear (winding_t *w)
bot = 0x80000000;
leftv = 0;
for (i=0 ; i<numvertex ; i++)
{
sy[i] = (int)w->points[i][1];
if (sy[i] < top)
{
for (i = 0; i < numvertex; i++) {
sy[i] = (int) w->points[i][1];
if (sy[i] < top) {
top = sy[i];
leftv = i;
}
if (sy[i] > bot)
bot = sy[i];
}
rightv = leftv;
rightv = leftv;
if (top < 0 || bot > r_height || top > bot)
return; // shouldn't have to have this...
return; // shouldn't have to have this...
//
// render a trapezoid
//
y = top;
while (y < bot)
{
if (y >= sy[leftv])
{
do
{
for (i=0 ; i<5 ; i++)
while (y < bot) {
if (y >= sy[leftv]) {
do {
for (i = 0; i < 5; i++)
leftside[i] = w->points[leftv][i];
leftv--;
if (leftv == -1)
leftv = numvertex-1;
leftv = numvertex - 1;
} while (sy[leftv] <= y);
count = sy[leftv]-y;
for (i=0 ; i<5 ; i++)
leftstep[i] = (w->points[leftv][i] - leftside[i])/count;
count = sy[leftv] - y;
for (i = 0; i < 5; i++)
leftstep[i] = (w->points[leftv][i] - leftside[i]) / count;
}
if (y >= sy[rightv])
{
do
{
for (i=0 ; i<5 ; i++)
if (y >= sy[rightv]) {
do {
for (i = 0; i < 5; i++)
rightside[i] = w->points[rightv][i];
rightv++;
if (rightv == numvertex)
rightv = 0;
} while (sy[rightv] <= y);
count = sy[rightv]-y;
for (i=0 ; i<5 ; i++)
rightstep[i] = (w->points[rightv][i] - rightside[i])/count;
count = sy[rightv] - y;
for (i = 0; i < 5; i++)
rightstep[i] = (w->points[rightv][i] - rightside[i]) / count;
}
REN_DrawSpanLinear (y);
for (i=0 ; i<5 ; i++)
{
for (i = 0; i < 5; i++) {
leftside[i] += leftstep[i];
rightside[i] += rightstep[i];
}
y++;
}
}
@ -511,15 +485,16 @@ void REN_RasterizeFaceLinear (winding_t *w)
REN_BeginCamera
===================
*/
float r_width_2, r_height_3;
plane_t rfrustum[5];
float r_width_2, r_height_3;
plane_t rfrustum[5];
void REN_BeginCamera (void)
void
REN_BeginCamera (void)
{
r_width_2 = (float)r_width / 2;
r_height_3 = (float)r_height / 3;
r_width_2 = (float) r_width / 2;
r_height_3 = (float) r_height / 3;
// clip to right side
rfrustum[0].normal[0] = -1;
rfrustum[0].normal[1] = 0;
@ -541,7 +516,7 @@ void REN_BeginCamera (void)
// clip to bottom side
rfrustum[3].normal[0] = 0;
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;
// near Z
@ -552,13 +527,14 @@ void REN_BeginCamera (void)
}
void REN_BeginXY (void)
void
REN_BeginXY (void)
{
rfrustum[0].normal[0] = 1;
rfrustum[0].normal[1] = 0;
rfrustum[0].normal[2] = 0;
rfrustum[0].dist = 0;
rfrustum[1].normal[0] = -1;
rfrustum[1].normal[1] = 0;
rfrustum[1].normal[2] = 0;
@ -580,17 +556,18 @@ void REN_BeginXY (void)
REN_DrawCameraFace
=====================
*/
void REN_DrawCameraFace (face_t *idpol)
void
REN_DrawCameraFace (face_t * idpol)
{
int i;
float scale;
int numvertex;
winding_t *w, *in;
vec3_t temp;
int i;
float scale;
int numvertex;
winding_t *w, *in;
vec3_t temp;
if (!idpol->w)
return; // overconstrained plane
return; // overconstrained plane
r_face = idpol;
//
@ -607,45 +584,42 @@ void REN_DrawCameraFace (face_t *idpol)
w = NewWinding (numvertex);
w->numpoints = numvertex;
for (i=0 ; i<numvertex ; i++)
{
for (i = 0; i < numvertex; i++) {
VectorSubtract (in->points[i], r_origin, temp);
w->points[i][0] = DotProduct(temp,r_matrix[0]);
w->points[i][1] = DotProduct(temp,r_matrix[1]);
w->points[i][2] = DotProduct(temp,r_matrix[2]);
w->points[i][0] = DotProduct (temp, r_matrix[0]);
w->points[i][1] = DotProduct (temp, r_matrix[1]);
w->points[i][2] = DotProduct (temp, r_matrix[2]);
w->points[i][3] = in->points[i][3];
w->points[i][4] = in->points[i][4];
}
//
// 3D clip
//
for (i=0 ; i<4 ; i++)
{
for (i = 0; i < 4; i++) {
w = ClipWinding (w, &rfrustum[i]);
if (!w)
return;
}
//
// 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];
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][0] = r_width_2 + scale * w->points[i][0];
w->points[i][1] = r_height_3 - scale * w->points[i][1];
w->points[i][2] = scale;
}
//
// draw it
//
REN_SetTexture (idpol);
REN_RasterizeFace (w);
free (w);
}
@ -656,19 +630,20 @@ void REN_DrawCameraFace (face_t *idpol)
REN_DrawXYFace
=====================
*/
void REN_DrawXYFace (face_t *idpol)
void
REN_DrawXYFace (face_t * idpol)
{
int i, j, numvertex;
winding_t *w, *in;
float *dest, *source;
float temp;
int i, j, numvertex;
winding_t *w, *in;
float *dest, *source;
float temp;
if (!idpol->w)
return; // overconstrained plane
return; // overconstrained plane
w = idpol->w;
r_face = idpol;
//
// back (and side) face cull
//
@ -684,31 +659,29 @@ void REN_DrawXYFace (face_t *idpol)
w = NewWinding (numvertex);
w->numpoints = numvertex;
for (i=0 ; i<numvertex ; i++)
{
// 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][1] = r_height - (in->points[i][1] - r_origin[1])*r_origin[2];
for (i = 0; i < numvertex; i++) {
// 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][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][3] = in->points[i][3];
w->points[i][4] = in->points[i][4];
}
//
// clip
//
for (i=0 ; i<4 ; i++)
{
for (i = 0; i < 4; i++) {
w = ClipWinding (w, &rfrustum[i]);
if (!w)
return;
}
//
// project to 2D
//
for (i=0 ; i<w->numpoints ; i++)
{
for (i = 0; i < w->numpoints; i++) {
dest = w->points[i];
if (dest[0] < 0)
dest[0] = 0;
@ -719,31 +692,27 @@ void REN_DrawXYFace (face_t *idpol)
if (dest[1] > r_height)
dest[1] = r_height;
if (xy_viewnormal[2] > 0)
dest[2] = 4096-dest[2];
dest[2] = 4096 - dest[2];
}
if (xy_viewnormal[2] > 0)
{ // flip order when upside down
for (i=0 ; i<w->numpoints/2 ; i++)
{
if (xy_viewnormal[2] > 0) { // flip order when upside down
for (i = 0; i < w->numpoints / 2; i++) {
dest = w->points[i];
source = w->points[w->numpoints-1-i];
for (j=0 ; j<5 ; j++)
{
source = w->points[w->numpoints - 1 - i];
for (j = 0; j < 5; j++) {
temp = dest[j];
dest[j] = source[j];
source[j] = temp;
}
}
}
REN_SetTexture (idpol);
//
// draw it
//
REN_RasterizeFaceLinear (w);
free (w);
}