diff --git a/tools/qfmodelgen/source/cmdlib.c b/tools/qfmodelgen/source/cmdlib.c index 2827245b5..f4d088ef2 100644 --- a/tools/qfmodelgen/source/cmdlib.c +++ b/tools/qfmodelgen/source/cmdlib.c @@ -19,7 +19,7 @@ // cmdlib.c -# include "config.h" +#include "config.h" #ifdef HAVE_UNISTD_H # include #endif @@ -48,7 +48,6 @@ qboolean com_eof; qboolean archive; char archivedir[1024]; - /* ================= Error @@ -56,35 +55,34 @@ Error For abnormal program terminations ================= */ -void Error (char *error, ...) +void +Error (char *error, ...) { va_list argptr; printf ("************ ERROR ************\n"); - va_start (argptr,error); - vprintf (error,argptr); + va_start (argptr, error); + vprintf (error, argptr); va_end (argptr); printf ("\n"); exit (1); } - /* - qdir will hold the path up to the quake directory, including the slash f:\quake\ /raid/quake/ gamedir will hold qdir + the game directory (id1, id2, etc) - - */ +*/ char qdir[1024]; char gamedir[1024]; -void SetQdirFromPath (char *path) +void +SetQdirFromPath (char *path) { char temp[1024]; char *c; @@ -99,15 +97,12 @@ void SetQdirFromPath (char *path) // search for "quake" in path for (c=path ; *c ; c++) - if (!Q_strncasecmp (c, "quake", 5)) - { + if (!Q_strncasecmp (c, "quake", 5)) { strncpy (qdir, path, c+6-path); printf ("qdir: %s\n", qdir); c += 6; - while (*c) - { - if (*c == '/' || *c == '\\') - { + while (*c) { + if (*c == '/' || *c == '\\') { strncpy (gamedir, path, c+1-path); printf ("gamedir: %s\n", gamedir); return; @@ -117,12 +112,14 @@ void SetQdirFromPath (char *path) Error ("No gamedir in %s", path); return; } - Error ("SeetQdirFromPath: no 'quake' in %s", path); + Error ("SetQdirFromPath: no 'quake' in %s", path); } -char *ExpandPath (char *path) +char * +ExpandPath (char *path) { static char full[1024]; + if (!qdir) Error ("ExpandPath called without qdir set"); if (path[0] == '/' || path[0] == '\\' || path[1] == ':') @@ -131,74 +128,69 @@ char *ExpandPath (char *path) return full; } -char *ExpandPathAndArchive (char *path) +char * +ExpandPathAndArchive (char *path) { char *expanded; - char archivename[1024]; + char archivename[1024]; expanded = ExpandPath (path); - if (archive) - { + if (archive) { sprintf (archivename, "%s/%s", archivedir, path); CopyFile (expanded, archivename); } return expanded; } - -char *copystring(char *s) +char * +copystring(char *s) { char *b; - b = malloc(strlen(s)+1); + + b = malloc (strlen (s) + 1); strcpy (b, s); return b; } - - -/* -================ -I_FloatTime -================ -*/ -double I_FloatTime (void) +double +I_FloatTime (void) { time_t t; - + time (&t); - + return t; #if 0 // more precise, less portable - struct timeval tp; - struct timezone tzp; + struct timeval tp; + struct timezone tzp; static int secbase; - gettimeofday(&tp, &tzp); - - if (!secbase) - { + gettimeofday (&tp, &tzp); + + if (!secbase) { secbase = tp.tv_sec; return tp.tv_usec/1000000.0; } - - return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0; + + return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0; #endif } -void Q_getwd (char *out) +void +Q_getwd (char *out) { #ifdef WIN32 - _getcwd (out, 256); - strcat (out, "\\"); + _getcwd (out, 256); + strcat (out, "\\"); #else - getcwd (out, 256); + getcwd (out, 256); #endif } - -void Q_mkdir (char *path) +void +Q_mkdir (char *path) { #ifdef WIN32 if (_mkdir (path) != -1) @@ -218,31 +210,30 @@ FileTime returns -1 if not present ============ */ -int FileTime (char *path) +int +FileTime (char *path) { - struct stat buf; - + struct stat buf; + if (stat (path,&buf) == -1) return -1; - + return buf.st_mtime; } - -int Q_strncasecmp (char *s1, char *s2, int n) +int +Q_strncasecmp (char *s1, char *s2, int n) { int c1, c2; - - while (1) - { + + while (1) { c1 = *s1++; c2 = *s2++; if (!n--) return 0; // strings are equal until end point - if (c1 != c2) - { + if (c1 != c2) { if (c1 >= 'a' && c1 <= 'z') c1 -= ('a' - 'A'); if (c2 >= 'a' && c2 <= 'z') @@ -253,23 +244,24 @@ int Q_strncasecmp (char *s1, char *s2, int n) if (!c1) return 0; // strings are equal } - + return -1; } -int Q_strcasecmp (char *s1, char *s2) +int +Q_strcasecmp (char *s1, char *s2) { return Q_strncasecmp (s1, s2, 99999); } - -char *strupr (char *start) +char * +strupr (char *start) { char *in; + in = start; - while (*in) - { - *in = toupper(*in); + while (*in) { + *in = toupper (*in); in++; } return start; @@ -278,16 +270,15 @@ char *strupr (char *start) char *strlower (char *start) { char *in; + in = start; - while (*in) - { - *in = tolower(*in); + while (*in) { + *in = tolower (*in); in++; } return start; } - /* ============================================================================= @@ -296,7 +287,6 @@ char *strlower (char *start) ============================================================================= */ - /* ================= CheckParm @@ -305,21 +295,21 @@ Checks for the given parameter in the program's command line arguments Returns the argument number (1 to argc-1) or 0 if not present ================= */ -int CheckParm (char *check) +int +CheckParm (char *check) { - int i; + int i; - for (i = 1;i 0 && path[length] != PATHSEPERATOR) length--; path[length] = 0; } -void StripExtension (char *path) +void +StripExtension (char *path) { int length; - length = strlen(path)-1; - while (length > 0 && path[length] != '.') - { + length = strlen (path) - 1; + while (length > 0 && path[length] != '.') { length--; if (path[length] == '/') return; // no extension @@ -431,21 +416,19 @@ void StripExtension (char *path) path[length] = 0; } - /* ==================== Extract file parts ==================== */ -void ExtractFilePath (char *path, char *dest) +void +ExtractFilePath (char *path, char *dest) { char *src; src = path + strlen(path) - 1; -// // back up until a \ or the start -// while (src != path && *(src-1) != PATHSEPERATOR) src--; @@ -453,38 +436,34 @@ void ExtractFilePath (char *path, char *dest) dest[src-path] = 0; } -void ExtractFileBase (char *path, char *dest) +void +ExtractFileBase (char *path, char *dest) { char *src; src = path + strlen(path) - 1; -// // back up until a \ or the start -// while (src != path && *(src-1) != PATHSEPERATOR) src--; - while (*src && *src != '.') - { + while (*src && *src != '.') { *dest++ = *src++; } *dest = 0; } -void ExtractFileExtension (char *path, char *dest) +void +ExtractFileExtension (char *path, char *dest) { char *src; src = path + strlen(path) - 1; -// // back up until a . or the start -// while (src != path && *(src-1) != '.') src--; - if (src == path) - { + if (src == path) { *dest = 0; // no extension return; } @@ -492,29 +471,23 @@ void ExtractFileExtension (char *path, char *dest) strcpy (dest,src); } - -/* -============== -ParseNum / ParseHex -============== -*/ -int ParseHex (char *hex) +int +ParseHex (char *hex) { - char *str; - int num; + char *str; + int num; num = 0; str = hex; - while (*str) - { + while (*str) { num <<= 4; if (*str >= '0' && *str <= '9') - num += *str-'0'; + num += *str - '0'; else if (*str >= 'a' && *str <= 'f') - num += 10 + *str-'a'; + num += 10 + *str - 'a'; else if (*str >= 'A' && *str <= 'F') - num += 10 + *str-'A'; + num += 10 + *str - 'A'; else Error ("Bad hex number: %s",hex); str++; @@ -523,18 +496,16 @@ int ParseHex (char *hex) return num; } - -int ParseNum (char *str) +int +ParseNum (char *str) { if (str[0] == '$') - return ParseHex (str+1); + return ParseHex (str + 1); if (str[0] == '0' && str[1] == 'x') - return ParseHex (str+2); + return ParseHex (str + 2); return atol (str); } - - /* ============================================================================ @@ -549,7 +520,8 @@ int ParseNum (char *str) #ifdef __BIG_ENDIAN__ -short LittleShort (short l) +short +LittleShort (short l) { byte b1,b2; @@ -559,13 +531,14 @@ short LittleShort (short l) return (b1<<8) + b2; } -short BigShort (short l) +short +BigShort (short l) { return l; } - -int LittleLong (int l) +int +LittleLong (int l) { byte b1,b2,b3,b4; @@ -577,13 +550,14 @@ int LittleLong (int l) return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4; } -int BigLong (int l) +int +BigLong (int l) { return l; } - -float LittleFloat (float l) +float +LittleFloat (float l) { union {byte b[4]; float f;} in, out; @@ -596,16 +570,16 @@ float LittleFloat (float l) return out.f; } -float BigFloat (float l) +float +BigFloat (float l) { return l; } - #else - -short BigShort (short l) +short +BigShort (short l) { byte b1,b2; @@ -615,13 +589,15 @@ short BigShort (short l) return (b1<<8) + b2; } -short LittleShort (short l) +short +LittleShort (short l) { return l; } -int BigLong (int l) +int +BigLong (int l) { byte b1,b2,b3,b4; @@ -633,12 +609,14 @@ int BigLong (int l) return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4; } -int LittleLong (int l) +int +LittleLong (int l) { return l; } -float BigFloat (float l) +float +BigFloat (float l) { union {byte b[4]; float f;} in, out; @@ -651,15 +629,14 @@ float BigFloat (float l) return out.f; } -float LittleFloat (float l) +float +LittleFloat (float l) { return l; } - #endif - //======================================================= @@ -708,33 +685,32 @@ static unsigned short crctable[256] = 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 }; -void CRC_Init(unsigned short *crcvalue) +void +CRC_Init (unsigned short *crcvalue) { *crcvalue = CRC_INIT_VALUE; } -void CRC_ProcessByte(unsigned short *crcvalue, byte data) +void +CRC_ProcessByte (unsigned short *crcvalue, byte data) { *crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data]; } -unsigned short CRC_Value(unsigned short crcvalue) +unsigned short +CRC_Value (unsigned short crcvalue) { return crcvalue ^ CRC_XOR_VALUE; } + //============================================================================= -/* -============ -CreatePath -============ -*/ -void CreatePath (char *path) +void +CreatePath (char *path) { char *ofs, c; - - for (ofs = path+1 ; *ofs ; ofs++) - { + + for (ofs = path+1 ; *ofs ; ofs++) { c = *ofs; if (c == '/' || c == '\\') { // create the directory @@ -745,7 +721,6 @@ void CreatePath (char *path) } } - /* ============ CopyFile @@ -753,7 +728,8 @@ CopyFile Used to archive source files ============ */ -void CopyFile (char *from, char *to) +void +CopyFile (char *from, char *to) { void *buffer; int length; diff --git a/tools/qfmodelgen/source/lbmlib.c b/tools/qfmodelgen/source/lbmlib.c index 3cdc6e715..bdec69932 100644 --- a/tools/qfmodelgen/source/lbmlib.c +++ b/tools/qfmodelgen/source/lbmlib.c @@ -24,8 +24,6 @@ #include "cmdlib.h" #include "lbmlib.h" - - /* ============================================================================ @@ -34,7 +32,6 @@ ============================================================================ */ - #define FORMID ('F'+('O'<<8)+((int)'R'<<16)+((int)'M'<<24)) #define ILBMID ('I'+('L'<<8)+((int)'B'<<16)+((int)'M'<<24)) #define PBMID ('P'+('B'<<8)+((int)'M'<<16)+((int)' '<<24)) @@ -45,92 +42,81 @@ bmhd_t bmhd; -int Align (int l) +int +Align (int l) { if (l&1) return l+1; return l; } - - /* ================ -= -= LBMRLEdecompress -= -= Source must be evenly aligned! -= +LBMRLEdecompress + +Source must be evenly aligned! ================ */ - -byte *LBMRLEDecompress (byte *source,byte *unpacked, int bpwidth) +byte * +LBMRLEDecompress (byte *source, byte *unpacked, int bpwidth) { int count; - byte b,rept; + byte b, rept; count = 0; - do - { + do { rept = *source++; - if (rept > 0x80) - { - rept = (rept^0xff)+2; + if (rept > 0x80) { + rept = (rept ^ 0xff) + 2; b = *source++; - memset(unpacked,b,rept); + memset (unpacked, b, rept); unpacked += rept; - } - else if (rept < 0x80) - { + } else if (rept < 0x80) { rept++; - memcpy(unpacked,source,rept); + memcpy (unpacked, source, rept); unpacked += rept; source += rept; - } - else + } else rept = 0; // rept of 0x80 is NOP count += rept; - } while (countbpwidth) + if (count > bpwidth) Error ("Decompression exceeded width!\n"); return source; } - #define BPLANESIZE 128 byte bitplanes[9][BPLANESIZE]; // max size 1024 by 9 bit planes - /* ================= -= -= MungeBitPlanes8 -= -= Asm version destroys the bit plane data! -= +MungeBitPlanes8 + +Asm version destroys the bit plane data! ================= */ - -void MungeBitPlanes8 (int width, byte *dest) +void +MungeBitPlanes8 (int width, byte *dest) { - int i, ind = 0; + int i, ind = 0; + while (width--) { for (i = 0; i < 8; i++) { *dest++ = (((bitplanes[7][ind] << i) & 128) >> 0) - | (((bitplanes[6][ind] << i) & 128) >> 1) - | (((bitplanes[5][ind] << i) & 128) >> 2) - | (((bitplanes[4][ind] << i) & 128) >> 3) - | (((bitplanes[3][ind] << i) & 128) >> 4) - | (((bitplanes[2][ind] << i) & 128) >> 5) - | (((bitplanes[1][ind] << i) & 128) >> 6) - | (((bitplanes[0][ind] << i) & 128) >> 7); + | (((bitplanes[6][ind] << i) & 128) >> 1) + | (((bitplanes[5][ind] << i) & 128) >> 2) + | (((bitplanes[4][ind] << i) & 128) >> 3) + | (((bitplanes[3][ind] << i) & 128) >> 4) + | (((bitplanes[2][ind] << i) & 128) >> 5) + | (((bitplanes[1][ind] << i) & 128) >> 6) + | (((bitplanes[0][ind] << i) & 128) >> 7); } ind++; } @@ -169,16 +155,17 @@ done: #endif } - -void MungeBitPlanes4 (int width, byte *dest) +void +MungeBitPlanes4 (int width, byte *dest) { - int i, ind = 0; + int i, ind = 0; + while (width--) { for (i = 0; i < 8; i++) { *dest++ = (((bitplanes[3][ind] << i) & 128) >> 4) - | (((bitplanes[2][ind] << i) & 128) >> 5) - | (((bitplanes[1][ind] << i) & 128) >> 6) - | (((bitplanes[0][ind] << i) & 128) >> 7); + | (((bitplanes[2][ind] << i) & 128) >> 5) + | (((bitplanes[1][ind] << i) & 128) >> 6) + | (((bitplanes[0][ind] << i) & 128) >> 7); } ind++; } @@ -211,10 +198,11 @@ done: #endif } - -void MungeBitPlanes2 (int width, byte *dest) +void +MungeBitPlanes2 (int width, byte *dest) { - int i, ind = 0; + int i, ind = 0; + while (width--) { for (i = 0; i < 8; i++) { *dest++ = (((bitplanes[1][ind] << i) & 128) >> 6) @@ -246,10 +234,11 @@ done: #endif } - -void MungeBitPlanes1 (int width, byte *dest) +void +MungeBitPlanes1 (int width, byte *dest) { - int i, ind = 0; + int i, ind = 0; + while (width--) { for (i = 0; i < 8; i++) { *dest++ = (((bitplanes[0][ind] << i) & 128) >> 7); @@ -278,79 +267,65 @@ done: #endif } - -/* -================= -= -= LoadLBM -= -================= -*/ - -void LoadLBM (char *filename, byte **picture, byte **palette) +void +LoadLBM (char *filename, byte **picture, byte **palette) { byte *LBMbuffer, *picbuffer, *cmapbuffer; - int y,p,planes; byte *LBM_P, *LBMEND_P; byte *pic_p; byte *body_p; - unsigned rowsize; + unsigned rowsize; + int y, p, planes; + int formtype, formlength; + int chunktype, chunklength; - int formtype,formlength; - int chunktype,chunklength; - void (*mungecall) (int, byte *); + void (*mungecall) (int, byte *); -// qiet compiler warnings +// quiet compiler warnings picbuffer = NULL; cmapbuffer = NULL; mungecall = NULL; -// // load the LBM -// - LoadFile (filename, (void **)&LBMbuffer); + LoadFile (filename, (void **) &LBMbuffer); -// // parse the LBM header -// LBM_P = LBMbuffer; - if ( *(int *)LBMbuffer != LittleLong(FORMID) ) + if (*(int *) LBMbuffer != LittleLong (FORMID)) Error ("No FORM ID at start of file!\n"); LBM_P += 4; - formlength = BigLong( *(int *)LBM_P ); + formlength = BigLong (*(int *) LBM_P ); LBM_P += 4; - LBMEND_P = LBM_P + Align(formlength); + LBMEND_P = LBM_P + Align (formlength); - formtype = LittleLong(*(int *)LBM_P); + formtype = LittleLong (*(int *) LBM_P); if (formtype != ILBMID && formtype != PBMID) - Error ("Unrecognized form type: %c%c%c%c\n", formtype&0xff - ,(formtype>>8)&0xff,(formtype>>16)&0xff,(formtype>>24)&0xff); + Error ("Unrecognized form type: %c%c%c%c\n", formtype & 0xff, + (formtype >> 8) & 0xff, (formtype >> 16) & 0xff, + (formtype >> 24) & 0xff); LBM_P += 4; -// // parse chunks -// - - while (LBM_P < LBMEND_P) - { - chunktype = LBM_P[0] + (LBM_P[1]<<8) + (LBM_P[2]<<16) + (LBM_P[3]<<24); + while (LBM_P < LBMEND_P) { + chunktype = LBM_P[0] + (LBM_P[1] << 8) + (LBM_P[2] << 16) + + (LBM_P[3] << 24); LBM_P += 4; - chunklength = LBM_P[3] + (LBM_P[2]<<8) + (LBM_P[1]<<16) + (LBM_P[0]<<24); + chunklength = LBM_P[3] + (LBM_P[2] << 8) + (LBM_P[1] << 16) + + (LBM_P[0] << 24); LBM_P += 4; - switch ( chunktype ) - { + switch (chunktype) { case BMHDID: - memcpy (&bmhd,LBM_P,sizeof(bmhd)); - bmhd.w = BigShort(bmhd.w); - bmhd.h = BigShort(bmhd.h); - bmhd.x = BigShort(bmhd.x); - bmhd.y = BigShort(bmhd.y); - bmhd.pageWidth = BigShort(bmhd.pageWidth); - bmhd.pageHeight = BigShort(bmhd.pageHeight); + memcpy (&bmhd, LBM_P, sizeof (bmhd)); + bmhd.w = BigShort (bmhd.w); + bmhd.h = BigShort (bmhd.h); + bmhd.x = BigShort (bmhd.x); + bmhd.y = BigShort (bmhd.y); + bmhd.pageWidth = BigShort (bmhd.pageWidth); + bmhd.pageHeight = BigShort (bmhd.pageHeight); break; case CMAPID: @@ -362,36 +337,25 @@ void LoadLBM (char *filename, byte **picture, byte **palette) case BODYID: body_p = LBM_P; - pic_p = picbuffer = malloc (bmhd.w*bmhd.h); - if (formtype == PBMID) - { - // + pic_p = picbuffer = malloc (bmhd.w * bmhd.h); + if (formtype == PBMID) { // unpack PBM - // - for (y=0 ; y.mdl. -// //#include #include @@ -62,7 +60,6 @@ typedef struct { float normals[20][3]; } vertexnormals; - typedef struct { vec3_t v; int lightnormalindex; @@ -93,7 +90,6 @@ stvert_t stverts[MAXVERTS]; dtriangle_t triangles[MAXTRIANGLES]; int degenerate[MAXTRIANGLES]; - char cdpartial[256]; char cddir[256]; @@ -116,9 +112,10 @@ trivertx_t tarray[MAXVERTS]; char outname[1024]; -void ClearModel (void) +void +ClearModel (void) { - memset (&model, 0, sizeof(model)); + memset (&model, 0, sizeof (model)); model.synctype = ST_RAND; // default framecount = skincount = 0; @@ -137,13 +134,8 @@ void ClearModel (void) totsize = 0.0; } - -/* -============ -WriteFrame -============ -*/ -void WriteFrame (QFile *modelouthandle, int framenum) +void +WriteFrame (QFile *modelouthandle, int framenum) { int j, k; trivert_t *pframe; @@ -154,38 +146,29 @@ void WriteFrame (QFile *modelouthandle, int framenum) strcpy (aframe.name, frames[framenum].name); - for (j=0 ; j<3 ; j++) - { + for (j = 0; j < 3; j++) { aframe.bboxmin.v[j] = 255; aframe.bboxmax.v[j] = 0; } - for (j=0 ; j NUMVERTEXNORMALS) Error ("invalid lightnormalindex %d\n", - tarray[j].lightnormalindex); + tarray[j].lightnormalindex); - for (k=0 ; k<3 ; k++) - { + for (k = 0; k < 3; k++) { // scale to byte values & min/max check v = (pframe[j].v[k] - model.scale_origin[k]) / model.scale[k]; tarray[j].v[k] = v; if (tarray[j].v[k] < aframe.bboxmin.v[k]) - { aframe.bboxmin.v[k] = tarray[j].v[k]; - } if (tarray[j].v[k] > aframe.bboxmax.v[k]) - { aframe.bboxmax.v[k] = tarray[j].v[k]; - } - - } } @@ -194,38 +177,28 @@ void WriteFrame (QFile *modelouthandle, int framenum) Qwrite (modelouthandle, &tarray[0], model.numverts * sizeof(tarray[0])); } - -/* -============ -WriteGroupBBox -============ -*/ -void WriteGroupBBox (QFile *modelouthandle, int numframes, int curframe) +void +WriteGroupBBox (QFile *modelouthandle, int numframes, int curframe) { int i, j, k; daliasgroup_t dagroup; trivert_t *pframe; - dagroup.numframes = LittleLong (numframes); - for (i=0 ; i<3 ; i++) - { + for (i = 0; i < 3; i++) { dagroup.bboxmin.v[i] = 255; dagroup.bboxmax.v[i] = 0; } - for (i=0 ; i dagroup.bboxmax.v[k]) @@ -239,21 +212,15 @@ void WriteGroupBBox (QFile *modelouthandle, int numframes, int curframe) Qwrite (modelouthandle, &dagroup, sizeof(dagroup)); } - -/* -============ -WriteModel -============ -*/ -void WriteModelFile (QFile *modelouthandle) +void +WriteModelFile (QFile *modelouthandle) { int i, curframe, curskin; float dist[3]; mdl_t modeltemp; // Calculate the bounding box for this model - for (i=0 ; i<3 ; i++) - { + for (i = 0; i < 3; i++) { printf ("framesmins[%d]: %f, framesmaxs[%d]: %f\n", i, framesmins[i], i, framesmaxs[i]); if (fabs (framesmins[i]) > fabs (framesmaxs[i])) @@ -265,23 +232,20 @@ void WriteModelFile (QFile *modelouthandle) model.scale_origin[i] = framesmins[i]; } - model.boundingradius = sqrt(dist[0] * dist[0] + - dist[1] * dist[1] + - dist[2] * dist[2]); + model.boundingradius = sqrt (dist[0] * dist[0] + + dist[1] * dist[1] + + dist[2] * dist[2]); -// // write out the model header -// modeltemp.ident = LittleLong (IDPOLYHEADER); modeltemp.version = LittleLong (ALIAS_VERSION); modeltemp.boundingradius = LittleFloat (model.boundingradius); - for (i=0 ; i<3 ; i++) - { + for (i = 0; i < 3; i++) { modeltemp.scale[i] = LittleFloat (model.scale[i]); modeltemp.scale_origin[i] = LittleFloat (model.scale_origin[i]); modeltemp.eyeposition[i] = LittleFloat (model.eyeposition[i] + - adjust[i]); + adjust[i]); } modeltemp.flags = LittleLong (model.flags); @@ -295,17 +259,14 @@ void WriteModelFile (QFile *modelouthandle) averagesize = totsize / model.numtris; modeltemp.size = LittleFloat (averagesize); - Qwrite (modelouthandle, &modeltemp, sizeof(model)); + Qwrite (modelouthandle, &modeltemp, sizeof (model)); -// // write out the skins -// curskin = 0; - for (i=0 ; i= 150) @@ -510,15 +433,12 @@ void SetSkinValues (void) scale = 190.0 / height; iwidth = ceil(width*scale) + 4; iheight = ceil(height*scale) + 4; + + printf ("scale: %f\n", scale); + printf ("iwidth: %i iheight: %i\n", iwidth, iheight); - printf ("scale: %f\n",scale); - printf ("iwidth: %i iheight: %i\n",iwidth, iheight); - -// // determine which side of each triangle to map the texture to -// - for (i=0 ; i 0) - { + if (normal[1] > 0) { basex = iwidth + 2; triangles[i].facesfront = 0; - } - else - { + } else { basex = 2; triangles[i].facesfront = 1; } basey = 2; - - for (j=0 ; j<3 ; j++) - { + + for (j = 0; j < 3; j++) { float *pbasevert; stvert_t *pstvert; pbasevert = baseverts[triangles[i].vertindex[j]]; pstvert = &stverts[triangles[i].vertindex[j]]; - if (triangles[i].facesfront) - { + if (triangles[i].facesfront) { pstvert->onseam |= 1; - } - else - { + } else { pstvert->onseam |= 2; } - if ((triangles[i].facesfront) || ((pstvert->onseam & 1) == 0)) - { + if ((triangles[i].facesfront) || ((pstvert->onseam & 1) == 0)) { // we want the front s value for seam vertices pstvert->s = ((pbasevert[0] - mins[0]) * scale + basex) + 0.5; pstvert->t = ((maxs[2] - pbasevert[2]) * scale + basey) + 0.5; @@ -578,17 +490,11 @@ void SetSkinValues (void) model.skinwidth, skinwidth, model.skinheight); } - -/* -================= -Cmd_Base -================= -*/ -void Cmd_Base (void) +void +Cmd_Base (void) { triangle_t *ptri; - int i, j, k; - int time1; + int time1, i, j, k; GetToken (false); strcpy (qbasename, token); @@ -601,43 +507,30 @@ void Cmd_Base (void) if (time1 == -1) Error ("%s doesn't exist", file1); -// // load the base triangles -// LoadTriangleList (file1, &ptri, &model.numtris); printf("NUMBER OF TRIANGLES (including degenerate triangles): %d\n", model.numtris); -// -// run through all the base triangles, storing each unique vertex in the -// base vertex list and setting the indirect triangles to point to the base -// vertices -// - for (i=0 ; i 0) - { - for (j=0 ; j<3 ; j++) - { + if (vnorms[i].numnormals > 0) { + for (j = 0; j < 3; j++) { int k; v[j] = 0; - for (k=0 ; k maxdot) - { + if (dot > maxdot) { maxdot = dot; maxdotindex = j; } @@ -914,15 +756,10 @@ void GrabFrame (char *frame, int isgroup) firstframe = 0; } -/* -=============== -Cmd_Frame -=============== -*/ -void Cmd_Frame (int isgroup) +void +Cmd_Frame (int isgroup) { - while (TokenAvailable()) - { + while (TokenAvailable ()) { GetToken (false); GrabFrame (token, isgroup); @@ -931,12 +768,8 @@ void Cmd_Frame (int isgroup) } } -/* -=============== -Cmd_SkinGroupStart -=============== -*/ -void Cmd_SkinGroupStart (void) +void +Cmd_SkinGroupStart (void) { int groupskin; @@ -947,39 +780,27 @@ void Cmd_SkinGroupStart (void) skins[groupskin].type = ALIAS_SKIN_GROUP; skins[groupskin].numgroupskins = 0; - while (1) - { + while (1) { GetToken (true); if (endofscript) Error ("End of file during group"); - if (!strcmp (token, "$skin")) - { + if (!strcmp (token, "$skin")) { Cmd_Skin (); skins[groupskin].numgroupskins++; - } - else if (!strcmp (token, "$skingroupend")) - { + } else if (!strcmp (token, "$skingroupend")) { break; - } - else - { + } else { Error ("$skin or $skingroupend expected\n"); } - } if (skins[groupskin].numgroupskins == 0) Error ("Empty group\n"); } - -/* -=============== -Cmd_FrameGroupStart -=============== -*/ -void Cmd_FrameGroupStart (void) +void +Cmd_FrameGroupStart (void) { int groupframe; @@ -990,25 +811,18 @@ void Cmd_FrameGroupStart (void) frames[groupframe].type = ALIAS_GROUP; frames[groupframe].numgroupframes = 0; - while (1) - { + while (1) { GetToken (true); if (endofscript) Error ("End of file during group"); - if (!strcmp (token, "$frame")) - { + if (!strcmp (token, "$frame")) { Cmd_Frame (1); - } - else if (!strcmp (token, "$framegroupend")) - { + } else if (!strcmp (token, "$framegroupend")) { break; - } - else - { + } else { Error ("$frame or $framegroupend expected\n"); } - } frames[groupframe].numgroupframes += framecount - groupframe - 1; @@ -1017,15 +831,9 @@ void Cmd_FrameGroupStart (void) Error ("Empty group\n"); } - -/* -================= -Cmd_Origin -================= -*/ -void Cmd_Origin (void) +void +Cmd_Origin (void) { - // rotate points into frame of reference so model points down the positive x // axis GetToken (false); @@ -1038,15 +846,9 @@ void Cmd_Origin (void) adjust[2] = -atof (token); } - -/* -================= -Cmd_Eyeposition -================= -*/ -void Cmd_Eyeposition (void) +void +Cmd_Eyeposition (void) { - // rotate points into frame of reference so model points down the positive x // axis GetToken (false); @@ -1059,55 +861,33 @@ void Cmd_Eyeposition (void) model.eyeposition[2] = atof (token); } - -/* -================= -Cmd_ScaleUp -================= -*/ -void Cmd_ScaleUp (void) +void +Cmd_ScaleUp (void) { - GetToken (false); scale_up = atof (token); } -/* -================= -Cmd_Flags -================= -*/ -void Cmd_Flags (void) +void +Cmd_Flags (void) { GetToken (false); model.flags = atoi (token); } - -/* -================= -Cmd_Modelname -================= -*/ -void Cmd_Modelname (void) +void +Cmd_Modelname (void) { WriteModel (); GetToken (false); strcpy (outname, token); } - -/* -=============== -ParseScript -=============== -*/ -void ParseScript (void) +void +ParseScript (void) { - while (1) - { - do - { // look for a line starting with a $ command + while (1) { + do { // look for a line starting with a $ command GetToken (true); if (endofscript) return; @@ -1117,76 +897,46 @@ void ParseScript (void) GetToken (false); } while (1); - if (!strcmp (token, "$modelname")) - { + if (!strcmp (token, "$modelname")) { Cmd_Modelname (); - } - else if (!strcmp (token, "$base")) - { + } else if (!strcmp (token, "$base")) { Cmd_Base (); - } - else if (!strcmp (token, "$cd")) - { + } else if (!strcmp (token, "$cd")) { if (cdset) Error ("Two $cd in one model"); cdset = true; GetToken (false); strcpy (cdpartial, token); strcpy (cddir, ExpandPath(token)); - } - else if (!strcmp (token, "$sync")) - { + } else if (!strcmp (token, "$sync")) { model.synctype = ST_SYNC; - } - else if (!strcmp (token, "$origin")) - { + } else if (!strcmp (token, "$origin")) { Cmd_Origin (); - } - else if (!strcmp (token, "$eyeposition")) - { + } else if (!strcmp (token, "$eyeposition")) { Cmd_Eyeposition (); - } - else if (!strcmp (token, "$scale")) - { + } else if (!strcmp (token, "$scale")) { Cmd_ScaleUp (); - } - else if (!strcmp (token, "$flags")) - { + } else if (!strcmp (token, "$flags")) { Cmd_Flags (); - } - else if (!strcmp (token, "$frame")) - { + } else if (!strcmp (token, "$frame")) { Cmd_Frame (0); - } - else if (!strcmp (token, "$skin")) - { + } else if (!strcmp (token, "$skin")) { Cmd_Skin (); model.numskins++; - } - else if (!strcmp (token, "$framegroupstart")) - { + } else if (!strcmp (token, "$framegroupstart")) { Cmd_FrameGroupStart (); model.numframes++; - } - else if (!strcmp (token, "$skingroupstart")) - { + } else if (!strcmp (token, "$skingroupstart")) { Cmd_SkinGroupStart (); model.numskins++; - } - else - { + } else { Error ("bad command %s\n", token); } - } } -/* -============== -main -============== -*/ -int main (int argc, char **argv) +int +main (int argc, char **argv) { int i; char path[1024]; @@ -1194,42 +944,33 @@ int main (int argc, char **argv) if (argc != 2 && argc != 4) Error ("usage: modelgen [-archive directory] file.qc"); - if (!strcmp(argv[1], "-archive")) - { + if (!strcmp(argv[1], "-archive")) { archive = true; strcpy (archivedir, argv[2]); printf ("Archiving source to: %s\n", archivedir); i = 3; - } - else + } else i = 1; -// // load the script -// strcpy (path, argv[i]); DefaultExtension (path, ".qc"); SetQdirFromPath (path); LoadScriptFile (path); -// // parse it -// - memset (&model, 0, sizeof(model)); + memset (&model, 0, sizeof (model)); - for (i=0 ; i<3 ; i++) - { + for (i = 0; i < 3; i++) { framesmins[i] = 9999999; framesmaxs[i] = -9999999; } - ClearModel (); strcpy (outname, argv[1]); ParseScript (); WriteModel (); - + return 0; } - diff --git a/tools/qfmodelgen/source/scriplib.c b/tools/qfmodelgen/source/scriplib.c index de6c483ea..57d5d01a6 100644 --- a/tools/qfmodelgen/source/scriplib.c +++ b/tools/qfmodelgen/source/scriplib.c @@ -37,19 +37,12 @@ int scriptline; qboolean endofscript; qboolean tokenready; // only true if UnGetToken was just called -/* -============== -= -= LoadScriptFile -= -============== -*/ - -void LoadScriptFile (char *filename) +void +LoadScriptFile (char *filename) { int size; - size = LoadFile (filename, (void **)&scriptbuffer); + size = LoadFile (filename, (void **) &scriptbuffer); script_p = scriptbuffer; scriptend_p = script_p + size; @@ -58,102 +51,81 @@ void LoadScriptFile (char *filename) tokenready = false; } - /* ============== -= -= UnGetToken -= -= Signals that the current token was not used, and should be reported -= for the next GetToken. Note that +UnGetToken +Signals that the current token was not used, and should be reported +for the next GetToken. Note that GetToken (true); UnGetToken (); GetToken (false); -= could cross a line boundary. -= +could cross a line boundary. ============== */ - -void UnGetToken (void) +void +UnGetToken (void) { tokenready = true; } - -/* -============== -GetToken -============== -*/ -qboolean GetToken (qboolean crossline) +qboolean +GetToken (qboolean crossline) { char *token_p; - if (tokenready) // is a token allready waiting? - { + if (tokenready) { // is a token allready waiting? tokenready = false; return true; } - if (script_p >= scriptend_p) - { + if (script_p >= scriptend_p) { if (!crossline) Error ("Line %i is incomplete\n",scriptline); endofscript = true; return false; } -// // skip space -// skipspace: - while (*script_p <= 32) - { - if (script_p >= scriptend_p) - { + while (*script_p <= 32) { + if (script_p >= scriptend_p) { if (!crossline) Error ("Line %i is incomplete\n",scriptline); endofscript = true; return true; } - if (*script_p++ == '\n') - { + if (*script_p++ == '\n') { if (!crossline) Error ("Line %i is incomplete\n",scriptline); scriptline++; } } - if (script_p >= scriptend_p) - { + if (script_p >= scriptend_p) { if (!crossline) Error ("Line %i is incomplete\n",scriptline); endofscript = true; return true; } - if (*script_p == ';' || *script_p == '#') // semicolon is comment field - { // also make # a comment field + if (*script_p == ';' || *script_p == '#') { // semicolon is comment field + // also make # a comment field if (!crossline) Error ("Line %i is incomplete\n",scriptline); while (*script_p++ != '\n') - if (script_p >= scriptend_p) - { + if (script_p >= scriptend_p) { endofscript = true; return false; } goto skipspace; } -// // copy token -// token_p = token; - while ( *script_p > 32 && *script_p != ';') - { + while ( *script_p > 32 && *script_p != ';') { *token_p++ = *script_p++; if (script_p == scriptend_p) break; @@ -165,18 +137,15 @@ skipspace: return true; } - /* ============== -= -= TokenAvailable -= -= Returns true if there is another token on the line -= +TokenAvailable + +Returns true if there is another token on the line ============== */ - -qboolean TokenAvailable (void) +qboolean +TokenAvailable (void) { char *search_p; @@ -185,14 +154,12 @@ qboolean TokenAvailable (void) if (search_p >= scriptend_p) return false; - while ( *search_p <= 32) - { + while (*search_p <= 32) { if (*search_p == '\n') return false; search_p++; if (search_p == scriptend_p) return false; - } if (*search_p == ';') @@ -200,5 +167,3 @@ qboolean TokenAvailable (void) return true; } - - diff --git a/tools/qfmodelgen/source/trilib.c b/tools/qfmodelgen/source/trilib.c index cf8c90035..0a3d7726f 100644 --- a/tools/qfmodelgen/source/trilib.c +++ b/tools/qfmodelgen/source/trilib.c @@ -17,9 +17,7 @@ See file, 'COPYING', for details. */ -// // trilib.c: library for loading triangles from an Alias triangle file -// #include #include @@ -33,7 +31,6 @@ // on disk representation of a face - #define FLOAT_START 99999.0 #define FLOAT_END -FLOAT_START #define MAGIC 123322 @@ -58,103 +55,97 @@ typedef struct { } tf_triangle; -void ByteSwapTri (tf_triangle *tri) +void +ByteSwapTri (tf_triangle *tri) { int i; - for (i=0 ; iverts[j][k] = tri.pt[j].p.v[k]; } } @@ -191,4 +178,3 @@ void LoadTriangleList (char *filename, triangle_t **pptri, int *numtriangles) Qclose (input); } -