X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=tools%2Fquake3%2Fq3data%2Fp3dlib.c;h=2da1ae9b6aed31e5b3a64791d518cb2f5709c667;hp=0c3b6026e1fef6a5191ff0ad258a57b1dee5d168;hb=e4287c28bb2dafedc81c66e63951d947cfbeb225;hpb=ab3a99dbbe84a0d130fea4d0ceb7b79d7ed07eb7 diff --git a/tools/quake3/q3data/p3dlib.c b/tools/quake3/q3data/p3dlib.c index 0c3b6026..2da1ae9b 100644 --- a/tools/quake3/q3data/p3dlib.c +++ b/tools/quake3/q3data/p3dlib.c @@ -1,6 +1,27 @@ +/* + Copyright (C) 1999-2006 Id Software, Inc. and contributors. + For a list of contributors, see the accompanying CONTRIBUTORS file. + + 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 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 + */ + #include "p3dlib.h" -#ifdef _WIN32 +#ifdef WIN32 #include #endif #include @@ -9,7 +30,7 @@ #define MAX_POLYSETS 64 -#if defined (__linux__) || defined (__APPLE__) +#if defined ( __linux__ ) || defined ( __APPLE__ ) #define _strcmpi Q_stricmp #define filelength Q_filelength #define strlwr strlower @@ -18,7 +39,7 @@ typedef struct { long len; - int numPairs; + int numPairs; char polysetNames[MAX_POLYSETS][256]; char shaders[MAX_POLYSETS][256]; @@ -31,18 +52,18 @@ static int P3DProcess(); static int P3DGetToken( int restOfLine ); static char s_token[1024]; -static int s_curpair; +static int s_curpair; /* ** P3DLoad ** */ -int P3DLoad( const char *filename ) -{ +int P3DLoad( const char *filename ){ FILE *fp = fopen( filename, "rb" ); - if ( !fp ) + if ( !fp ) { return 0; + } memset( &p3d, 0, sizeof( p3d ) ); @@ -50,8 +71,7 @@ int P3DLoad( const char *filename ) p3d.curpos = p3d.buffer = malloc( p3d.len ); - if ( fread( p3d.buffer, p3d.len, 1, fp ) != 1 ) - { + if ( fread( p3d.buffer, p3d.len, 1, fp ) != 1 ) { fclose( fp ); return 0; } @@ -65,28 +85,26 @@ int P3DLoad( const char *filename ) ** P3DClose ** */ -void P3DClose() -{ - if ( p3d.buffer ) - { +void P3DClose(){ + if ( p3d.buffer ) { free( p3d.buffer ); p3d.buffer = 0; } } -int CharIsTokenDelimiter( int ch ) -{ - if ( ch <= 32 ) +int CharIsTokenDelimiter( int ch ){ + if ( ch <= 32 ) { return 1; + } return 0; } -int P3DSkipToToken( const char *name ) -{ +int P3DSkipToToken( const char *name ){ while ( P3DGetToken( 0 ) ) { - if ( !_strcmpi( s_token, name ) ) + if ( !_strcmpi( s_token, name ) ) { return 1; + } } return 0; @@ -96,19 +114,20 @@ int P3DSkipToToken( const char *name ) ** P3DGetToken ** */ -int P3DGetToken( int restOfLine ) -{ +int P3DGetToken( int restOfLine ){ int i = 0; - if ( p3d.buffer == 0 ) + if ( p3d.buffer == 0 ) { return 0; + } - if ( ( p3d.curpos - p3d.buffer ) == p3d.len ) + if ( ( p3d.curpos - p3d.buffer ) == p3d.len ) { return 0; + } // skip over crap while ( ( ( p3d.curpos - p3d.buffer ) < p3d.len ) && - ( *p3d.curpos <= 32 ) ) + ( *p3d.curpos <= 32 ) ) { p3d.curpos++; } @@ -120,10 +139,9 @@ int P3DGetToken( int restOfLine ) p3d.curpos++; i++; - if ( ( CharIsTokenDelimiter( s_token[i-1] ) && !restOfLine ) || - ( ( s_token[i-1] == '\n' ) ) ) - { - s_token[i-1] = 0; + if ( ( CharIsTokenDelimiter( s_token[i - 1] ) && !restOfLine ) || + ( ( s_token[i - 1] == '\n' ) ) ) { + s_token[i - 1] = 0; break; } } @@ -133,10 +151,8 @@ int P3DGetToken( int restOfLine ) return 1; } -int P3DGetNextPair( char **psetName, char **associatedShader ) -{ - if ( s_curpair < p3d.numPairs ) - { +int P3DGetNextPair( char **psetName, char **associatedShader ){ + if ( s_curpair < p3d.numPairs ) { *psetName = p3d.polysetNames[s_curpair]; *associatedShader = p3d.shaders[s_curpair]; s_curpair++; @@ -146,22 +162,23 @@ int P3DGetNextPair( char **psetName, char **associatedShader ) return 0; } -int P3DSkipToTokenInBlock( const char *name ) -{ +int P3DSkipToTokenInBlock( const char *name ){ int iLevel = 0; - while ( P3DGetToken( 0 ) ) + while ( P3DGetToken( 0 ) ) { - if ( !_strcmpi( s_token, "}" ) ) + if ( !_strcmpi( s_token, "}" ) ) { iLevel--; - else if ( !_strcmpi( s_token, "{" ) ) + } + else if ( !_strcmpi( s_token, "{" ) ) { iLevel++; + } - if ( !_strcmpi( s_token, name ) ) + if ( !_strcmpi( s_token, name ) ) { return 1; + } - if ( iLevel == 0 ) - { + if ( iLevel == 0 ) { return 0; } } @@ -174,37 +191,34 @@ int P3DSkipToTokenInBlock( const char *name ) ** ** Nothing fancy here. */ -int P3DProcess() -{ +int P3DProcess(){ s_curpair = 0; // first token should be a string - P3DGetToken( 1 ); // Voodoo Ascii File + P3DGetToken( 1 ); // Voodoo Ascii File // skip to the first Obj declaration while ( P3DGetToken( 0 ) ) { - if ( !_strcmpi( s_token, "Obj" ) ) - { + if ( !_strcmpi( s_token, "Obj" ) ) { int j = 0, k = 0; - if ( P3DSkipToToken( "Text" ) ) - { - if ( P3DSkipToTokenInBlock( "TMap" ) ) - { + if ( P3DSkipToToken( "Text" ) ) { + if ( P3DSkipToTokenInBlock( "TMap" ) ) { char *p; - if ( !P3DSkipToToken( "Path" ) ) + if ( !P3DSkipToToken( "Path" ) ) { return 0; + } - if ( !P3DGetToken( 1 ) ) + if ( !P3DGetToken( 1 ) ) { return 0; + } while ( s_token[j] != 0 ) { - if ( s_token[j] == '\\' ) - { + if ( s_token[j] == '\\' ) { j++; p3d.shaders[p3d.numPairs][k] = '/'; } @@ -220,12 +234,10 @@ int P3DProcess() // // strip off any explicit extensions // - if ( ( p = strrchr( p3d.shaders[p3d.numPairs], '/' ) ) != 0 ) - { + if ( ( p = strrchr( p3d.shaders[p3d.numPairs], '/' ) ) != 0 ) { while ( *p ) { - if ( *p == '.' ) - { + if ( *p == '.' ) { *p = 0; break; } @@ -236,16 +248,18 @@ int P3DProcess() // // skip to the end of the Object and grab its name // - if ( !P3DSkipToToken( "Name" ) ) + if ( !P3DSkipToToken( "Name" ) ) { return 0; + } - if ( P3DGetToken( 0 ) ) - { + if ( P3DGetToken( 0 ) ) { // strip off leading 'Obj_' if it exists - if ( strstr( s_token, "Obj_" ) == s_token ) + if ( strstr( s_token, "Obj_" ) == s_token ) { strcpy( p3d.polysetNames[p3d.numPairs], s_token + strlen( "Obj_" ) ); - else + } + else{ strcpy( p3d.polysetNames[p3d.numPairs], s_token ); + } // strip off trailing unused color information // if ( strrchr( p3d.polysetNames[p3d.numPairs], '_' ) != 0 ) @@ -268,8 +282,7 @@ int P3DProcess() } #if 0 -void SkinFromP3D( const char *file ) -{ +void SkinFromP3D( const char *file ){ char filename[1024]; char *psetName, *associatedShader; @@ -285,8 +298,9 @@ void SkinFromP3D( const char *file ) */ sprintf( filename, "%s/%s", g_cddir, file ); - if ( !P3DLoad( filename ) ) + if ( !P3DLoad( filename ) ) { Error( "unable to load '%s'", filename ); + } while ( P3DGetNextPair( &psetName, &associatedShader ) ) { @@ -296,12 +310,10 @@ void SkinFromP3D( const char *file ) // corresponds to and append the shader to it for ( i = 0; i < g_data.model.numSurfaces; i++ ) { - if ( !_strcmpi( g_data.surfData[i].header.name, psetName) ) - { + if ( !_strcmpi( g_data.surfData[i].header.name, psetName ) ) { char *p; - if ( strstr( associatedShader, gamedir + 1 ) ) - { + if ( strstr( associatedShader, gamedir + 1 ) ) { p = strstr( associatedShader, gamedir + 1 ) + strlen( gamedir ) - 1; } else @@ -320,5 +332,3 @@ void SkinFromP3D( const char *file ) P3DClose(); } #endif - -