X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=tools%2Fquake3%2Fcommon%2Fl3dslib.c;h=5e340b9da166c4dbef7349ebd9d904f4efe813dc;hb=830125fad042fad35dc029b6eb57c8156ad7e176;hp=0620f9b47f80f8b0f23e9bab408b062065e6796c;hpb=99980506540d9546dad31223a6eadf126ba68121;p=xonotic%2Fnetradiant.git diff --git a/tools/quake3/common/l3dslib.c b/tools/quake3/common/l3dslib.c index 0620f9b4..5e340b9d 100644 --- a/tools/quake3/common/l3dslib.c +++ b/tools/quake3/common/l3dslib.c @@ -1,23 +1,23 @@ /* -Copyright (C) 1999-2007 id Software, Inc. and contributors. -For a list of contributors, see the accompanying CONTRIBUTORS file. + Copyright (C) 1999-2007 id Software, Inc. and contributors. + For a list of contributors, see the accompanying CONTRIBUTORS file. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant 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 General Public License for more details. + GtkRadiant 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 General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ // // l3dslib.c: library for loading triangles from an Alias triangle file @@ -36,43 +36,43 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define TRI_VERTEXL 0x4110 #define TRI_FACEL1 0x4120 -#define MAXVERTS 2000 -#define MAXTRIANGLES 750 +#define MAXVERTS 2000 +#define MAXTRIANGLES 750 typedef struct { - int v[4]; + int v[4]; } tri; -float fverts[MAXVERTS][3]; -tri tris[MAXTRIANGLES]; +float fverts[MAXVERTS][3]; +tri tris[MAXTRIANGLES]; -int bytesread, level, numtris, totaltris; -int vertsfound, trisfound; +int bytesread, level, numtris, totaltris; +int vertsfound, trisfound; -triangle_t *ptri; +triangle_t *ptri; // Alias stores triangles as 3 explicit vertices in .tri files, so even though we // start out with a vertex pool and vertex indices for triangles, we have to convert // to raw, explicit triangles -void StoreAliasTriangles (void) -{ - int i, j, k; +void StoreAliasTriangles( void ){ + int i, j, k; - if ((totaltris + numtris) > MAXTRIANGLES) - Error ("Error: Too many triangles"); + if ( ( totaltris + numtris ) > MAXTRIANGLES ) { + Error( "Error: Too many triangles" ); + } - for (i=0; i MAXVERTS) - Error ("Error: Too many vertices"); + if ( numverts > MAXVERTS ) { + Error( "Error: Too many vertices" ); + } - for (i=0 ; i MAXTRIANGLES) - Error ("Error: Too many triangles"); + if ( numtris > MAXTRIANGLES ) { + Error( "Error: Too many triangles" ); + } - for (i=0 ; i 0) + while ( w > 0 ) { - w -= ParseChunk (input); + w -= ParseChunk( input ); } retval = length; goto Done; default: - // skip other chunks - while (w > 0) + // skip other chunks + while ( w > 0 ) { t = w; - if (t > BLOCK_SIZE) + if ( t > BLOCK_SIZE ) { t = BLOCK_SIZE; + } - if (feof(input)) - Error ("Error: unexpected end of file"); + if ( feof( input ) ) { + Error( "Error: unexpected end of file" ); + } - fread (&temp, t, 1, input); + fread( &temp, t, 1, input ); bytesread += t; w -= t; @@ -254,10 +266,9 @@ Done: } -void Load3DSTriangleList (char *filename, triangle_t **pptri, int *numtriangles) -{ +void Load3DSTriangleList( char *filename, triangle_t **pptri, int *numtriangles ){ FILE *input; - short int tshort; + short int tshort; bytesread = 0; level = 0; @@ -266,36 +277,36 @@ void Load3DSTriangleList (char *filename, triangle_t **pptri, int *numtriangles) vertsfound = 0; trisfound = 0; - if ((input = fopen(filename, "rb")) == 0) { - fprintf(stderr,"reader: could not open file '%s'\n", filename); - exit(0); + if ( ( input = fopen( filename, "rb" ) ) == 0 ) { + fprintf( stderr,"reader: could not open file '%s'\n", filename ); + exit( 0 ); } - fread(&tshort, sizeof(tshort), 1, input); + fread( &tshort, sizeof( tshort ), 1, input ); // should only be MAIN3DS, but some files seem to start with EDIT3DS, with // no MAIN3DS - if ((tshort != MAIN3DS) && (tshort != EDIT3DS)) { - fprintf(stderr,"File is not a 3DS file.\n"); - exit(0); + if ( ( tshort != MAIN3DS ) && ( tshort != EDIT3DS ) ) { + fprintf( stderr,"File is not a 3DS file.\n" ); + exit( 0 ); } // back to top of file so we can parse the first chunk descriptor - fseek(input, 0, SEEK_SET); + fseek( input, 0, SEEK_SET ); - ptri = safe_malloc (MAXTRIANGLES * sizeof(triangle_t)); + ptri = safe_malloc( MAXTRIANGLES * sizeof( triangle_t ) ); *pptri = ptri; // parse through looking for the relevant chunk tree (MAIN3DS | EDIT3DS | EDIT_OBJECT | // OBJ_TRIMESH | {TRI_VERTEXL, TRI_FACEL1}) and skipping other chunks - ParseChunk (input); + ParseChunk( input ); - if (vertsfound || trisfound) - Error ("Incomplete triangle set"); + if ( vertsfound || trisfound ) { + Error( "Incomplete triangle set" ); + } *numtriangles = totaltris; - fclose (input); + fclose( input ); } -