diff --git a/tools/quake3/q3map2/autopk3.c b/tools/quake3/q3map2/autopk3.c index d8c969c2..fe846e50 100644 --- a/tools/quake3/q3map2/autopk3.c +++ b/tools/quake3/q3map2/autopk3.c @@ -314,8 +314,8 @@ int pk3BSPMain( int argc, char **argv ){ res2list( pk3Shaders, str ); } } - strcpy( str, ValueForKey( &entities[0], "music" ) ); - if ( !strEmpty( str ) ){ + + if ( ENT_READKV( &entities[0], "music", &str ) ){ FixDOSName( str ); DefaultExtension( str, ".wav" ); res2list( pk3Sounds, str ); @@ -323,18 +323,17 @@ int pk3BSPMain( int argc, char **argv ){ for ( i = 0; i < numBSPEntities && i < numEntities; ++i ) { - strcpy( str, ValueForKey( &entities[i], "noise" ) ); - if ( !strEmpty( str ) && *str != '*' ){ + if ( ENT_READKV( &entities[i], "noise", &str ) && str[0] != '*' ){ FixDOSName( str ); DefaultExtension( str, ".wav" ); res2list( pk3Sounds, str ); } - if ( striEqual( ValueForKey( &entities[i], "classname" ), "func_plat" ) ){ + if ( ent_class_is( &entities[i], "func_plat" ) ){ res2list( pk3Sounds, "sound/movers/plats/pt1_strt.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); } - if ( striEqual( ValueForKey( &entities[i], "classname" ), "target_push" ) ){ + if ( ent_class_is( &entities[i], "target_push" ) ){ if ( !( IntForKey( &entities[i], "spawnflags") & 1 ) ){ res2list( pk3Sounds, "sound/misc/windfly.wav" ); } @@ -986,8 +985,7 @@ int repackBSPMain( int argc, char **argv ){ res2list( pk3Shaders, str ); } } - strcpy( str, ValueForKey( &entities[0], "music" ) ); - if ( !strEmpty( str ) ){ + if ( ENT_READKV( &entities[0], "music", &str ) ){ FixDOSName( str ); DefaultExtension( str, ".wav" ); res2list( pk3Sounds, str ); @@ -995,18 +993,17 @@ int repackBSPMain( int argc, char **argv ){ for ( i = 0; i < numBSPEntities && i < numEntities; ++i ) { - strcpy( str, ValueForKey( &entities[i], "noise" ) ); - if ( !strEmpty( str ) && str[0] != '*' ){ + if ( ENT_READKV( &entities[i], "noise", &str ) && str[0] != '*' ){ FixDOSName( str ); DefaultExtension( str, ".wav" ); res2list( pk3Sounds, str ); } - if ( striEqual( ValueForKey( &entities[i], "classname" ), "func_plat" ) ){ + if ( ent_class_is( &entities[i], "func_plat" ) ){ res2list( pk3Sounds, "sound/movers/plats/pt1_strt.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); } - if ( striEqual( ValueForKey( &entities[i], "classname" ), "target_push" ) ){ + if ( ent_class_is( &entities[i], "target_push" ) ){ if ( !( IntForKey( &entities[i], "spawnflags") & 1 ) ){ res2list( pk3Sounds, "sound/misc/windfly.wav" ); } diff --git a/tools/quake3/q3map2/bsp.c b/tools/quake3/q3map2/bsp.c index 586c11b5..71d13043 100644 --- a/tools/quake3/q3map2/bsp.c +++ b/tools/quake3/q3map2/bsp.c @@ -101,7 +101,6 @@ static void autocaulk_write(){ static void ProcessAdvertisements( void ) { int i; - const char* className; const char* modelKey; int modelNum; bspModel_t* adModel; @@ -112,9 +111,7 @@ static void ProcessAdvertisements( void ) { for ( i = 0; i < numEntities; i++ ) { /* is an advertisement? */ - className = ValueForKey( &entities[ i ], "classname" ); - - if ( striEqual( "advertisement", className ) ) { + if ( ent_class_is( &entities[ i ], "advertisement" ) ) { modelKey = ValueForKey( &entities[ i ], "model" ); @@ -190,16 +187,10 @@ static void SetCloneModelNumbers( void ){ } /* is this a clone? */ - value = ValueForKey( &entities[ i ], "_ins" ); - if ( strEmpty( value ) ) { - value = ValueForKey( &entities[ i ], "_instance" ); - } - if ( strEmpty( value ) ) { - value = ValueForKey( &entities[ i ], "_clone" ); - } - if ( !strEmpty( value ) ) { + if( ENT_READKV( &entities[ i ], "_ins", &value ) || + ENT_READKV( &entities[ i ], "_instance", &value ) || + ENT_READKV( &entities[ i ], "_clone", &value ) ) continue; - } /* add the model key */ sprintf( modelValue, "*%d", models ); @@ -217,32 +208,24 @@ static void SetCloneModelNumbers( void ){ continue; } - /* is this a clone? */ - value = ValueForKey( &entities[ i ], "_ins" ); - if ( strEmpty( value ) ) { - value = ValueForKey( &entities[ i ], "_instance" ); - } - if ( strEmpty( value ) ) { - value = ValueForKey( &entities[ i ], "_clone" ); - } - if ( strEmpty( value ) ) { + /* isn't this a clone? */ + if( !ENT_READKV( &entities[ i ], "_ins", &value ) && + !ENT_READKV( &entities[ i ], "_instance", &value ) && + !ENT_READKV( &entities[ i ], "_clone", &value ) ) continue; - } /* find an entity with matching clone name */ for ( j = 0; j < numEntities; j++ ) { /* is this a clone parent? */ - value2 = ValueForKey( &entities[ j ], "_clonename" ); - if ( strEmpty( value2 ) ) { + if ( !ENT_READKV( &entities[ j ], "_clonename", &value2 ) ) { continue; } /* do they match? */ if ( strEqual( value, value2 ) ) { /* get the model num */ - value3 = ValueForKey( &entities[ j ], "model" ); - if ( strEmpty( value3 ) ) { + if ( !ENT_READKV( &entities[ j ], "model", &value3 ) ) { Sys_Warning( "Cloned entity %s referenced entity without model\n", value2 ); continue; } @@ -316,42 +299,32 @@ static void FixBrushSides( entity_t *e ){ */ void ProcessWorldModel( void ){ - int i, s; entity_t *e; tree_t *tree; face_t *faces; - bool ignoreLeaks, leaked; xmlNodePtr polyline, leaknode; - char level[ 2 ], shader[ 1024 ]; + char level[ 2 ]; const char *value; int leakStatus; /* sets integer blockSize from worldspawn "_blocksize" key if it exists */ - value = ValueForKey( &entities[ 0 ], "_blocksize" ); - if ( strEmpty( value ) ) { - value = ValueForKey( &entities[ 0 ], "blocksize" ); - } - if ( strEmpty( value ) ) { - value = ValueForKey( &entities[ 0 ], "chopsize" ); /* sof2 */ - } - if ( !strEmpty( value ) ) { + if( ENT_READKV( &entities[ 0 ], "_blocksize", &value ) || + ENT_READKV( &entities[ 0 ], "blocksize", &value ) || + ENT_READKV( &entities[ 0 ], "chopsize", &value ) ) { /* sof2 */ /* scan 3 numbers */ - s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] ); + const int s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] ); /* handle legacy case */ - if ( s == 1 ) { - blockSize[ 1 ] = blockSize[ 0 ]; - blockSize[ 2 ] = blockSize[ 0 ]; + if ( s == 1 || s == 2 ) { + blockSize[ 1 ] = blockSize[ 2 ] = blockSize[ 0 ]; } } Sys_Printf( "block size = { %d %d %d }\n", blockSize[ 0 ], blockSize[ 1 ], blockSize[ 2 ] ); /* sof2: ignore leaks? */ - value = ValueForKey( &entities[ 0 ], "_ignoreleaks" ); /* ydnar */ - if ( strEmpty( value ) ) { - value = ValueForKey( &entities[ 0 ], "ignoreleaks" ); - } - ignoreLeaks = ( value[ 0 ] == '1' ); + bool ignoreLeaks = false; + ENT_READKV( &entities[ 0 ], "_ignoreleaks", &ignoreLeaks ) || + ENT_READKV( &entities[ 0 ], "ignoreleaks", &ignoreLeaks ); /* begin worldspawn model */ BeginModel(); @@ -382,7 +355,7 @@ void ProcessWorldModel( void ){ } } - leaked = ( leakStatus != FLOODENTITIES_GOOD ); + const bool leaked = ( leakStatus != FLOODENTITIES_GOOD ); if( leaked ){ Sys_FPrintf( SYS_NOXMLflag | SYS_ERR, "**********************\n" ); Sys_FPrintf( SYS_NOXMLflag | SYS_ERR, "******* leaked *******\n" ); @@ -482,25 +455,22 @@ void ProcessWorldModel( void ){ } /* ydnar: fog hull */ - value = ValueForKey( &entities[ 0 ], "_foghull" ); - if ( !strEmpty( value ) ) { + if ( ENT_READKV( &entities[ 0 ], "_foghull", &value ) ) { + char shader[MAX_QPATH]; sprintf( shader, "textures/%s", value ); MakeFogHullSurfs( e, tree, shader ); } /* ydnar: bug 645: do flares for lights */ - for ( i = 0; i < numEntities && emitFlares; i++ ) + for ( int i = 0; i < numEntities && emitFlares; i++ ) { entity_t *light, *target; const char *value, *flareShader; vec3_t origin, targetOrigin, normal, color; - int lightStyle; - /* get light */ light = &entities[ i ]; - value = ValueForKey( light, "classname" ); - if ( strEqual( value, "light" ) ) { + if ( ent_class_is( light, "light" ) ) { /* get flare shader */ flareShader = ValueForKey( light, "_flareshader" ); value = ValueForKey( light, "_flare" ); @@ -508,14 +478,11 @@ void ProcessWorldModel( void ){ /* get specifics */ GetVectorForKey( light, "origin", origin ); GetVectorForKey( light, "_color", color ); - lightStyle = IntForKey( light, "_style" ); - if ( lightStyle == 0 ) { - lightStyle = IntForKey( light, "style" ); - } + int lightStyle = 0; + ENT_READKV( light, "_style", &lightStyle ) || ENT_READKV( light, "style", &lightStyle ); /* handle directional spotlights */ - value = ValueForKey( light, "target" ); - if ( !strEmpty( value ) ) { + if ( ENT_READKV( light, "target", &value ) ) { /* get target light */ target = FindTargetEntity( value ); if ( target != NULL ) { @@ -702,7 +669,6 @@ void OnlyEnts( void ){ char out[ 1024 ]; char save_cmdline[1024], save_version[1024], save_gridsize[1024]; - const char *p; /* note it */ Sys_Printf( "--- OnlyEnts ---\n" ); @@ -711,15 +677,9 @@ void OnlyEnts( void ){ LoadBSPFile( out ); ParseEntities(); - p = ValueForKey( &entities[0], "_q3map2_cmdline" ); - strncpy( save_cmdline, p, sizeof( save_cmdline ) ); - save_cmdline[sizeof( save_cmdline ) - 1] = 0; - p = ValueForKey( &entities[0], "_q3map2_version" ); - strncpy( save_version, p, sizeof( save_version ) ); - save_version[sizeof( save_version ) - 1] = 0; - p = ValueForKey( &entities[0], "gridsize" ); - strncpy( save_gridsize, p, sizeof( save_gridsize ) ); - save_gridsize[sizeof( save_gridsize ) - 1] = 0; + strcpyQ( save_cmdline, ValueForKey( &entities[0], "_q3map2_cmdline" ), sizeof( save_cmdline ) ); + strcpyQ( save_version, ValueForKey( &entities[0], "_q3map2_version" ), sizeof( save_version ) ); + strcpyQ( save_gridsize, ValueForKey( &entities[0], "gridsize" ), sizeof( save_gridsize ) ); numEntities = 0; diff --git a/tools/quake3/q3map2/bspfile_abstract.c b/tools/quake3/q3map2/bspfile_abstract.c index 37c72409..64f7f1c6 100644 --- a/tools/quake3/q3map2/bspfile_abstract.c +++ b/tools/quake3/q3map2/bspfile_abstract.c @@ -603,7 +603,6 @@ void ParseEntities( void ){ * must be called before UnparseEntities */ void InjectCommandLine( char **argv, int beginArgs, int endArgs ){ - const char *previousCommandLine; char newCommandLine[1024]; const char *inpos; char *outpos = newCommandLine; @@ -613,9 +612,7 @@ void InjectCommandLine( char **argv, int beginArgs, int endArgs ){ if ( nocmdline ){ return; } - previousCommandLine = ValueForKey( &entities[0], "_q3map2_cmdline" ); - if ( previousCommandLine && *previousCommandLine ) { - inpos = previousCommandLine; + if ( ENT_READKV( &entities[0], "_q3map2_cmdline", &inpos ) ) { // read previousCommandLine while ( outpos != sentinel && *inpos ) *outpos++ = *inpos++; if ( outpos != sentinel ) { @@ -651,12 +648,9 @@ void InjectCommandLine( char **argv, int beginArgs, int endArgs ){ */ void UnparseEntities( void ){ - int i; char *buf, *end; - epair_t *ep; char line[ 2048 ]; char key[ 1024 ], value[ 1024 ]; - const char *value2; /* setup */ @@ -665,7 +659,7 @@ void UnparseEntities( void ){ end = buf = bspEntData; /* run through entity list */ - for ( i = 0; i < numBSPEntities && i < numEntities; i++ ) + for ( int i = 0; i < numBSPEntities && i < numEntities; i++ ) { { int sz = end - buf; @@ -674,17 +668,17 @@ void UnparseEntities( void ){ end = buf + sz; } + entity_t *e = &entities[ i ]; /* get epair */ - ep = entities[ i ].epairs; - if ( ep == NULL ) { + if ( e->epairs == NULL ) { continue; /* ent got removed */ } /* ydnar: certain entities get stripped from bsp file */ - value2 = ValueForKey( &entities[ i ], "classname" ); - if ( striEqual( value2, "misc_model" ) || - striEqual( value2, "_decal" ) || - striEqual( value2, "_skybox" ) ) { + const char *classname = ent_classname( e ); + if ( striEqual( classname, "misc_model" ) || + striEqual( classname, "_decal" ) || + striEqual( classname, "_skybox" ) ) { continue; } @@ -693,7 +687,7 @@ void UnparseEntities( void ){ end += 2; /* walk epair list */ - for ( ep = entities[ i ].epairs; ep != NULL; ep = ep->next ) + for ( epair_t *ep = e->epairs; ep != NULL; ep = ep->next ) { /* copy and clean */ strcpy( key, ep->key ); @@ -767,25 +761,6 @@ void SetKeyValue( entity_t *ent, const char *key, const char *value ){ ep->value = copystring( value ); } -/* - KeyExists() - returns true if entity has this key - */ - -bool KeyExists( const entity_t *ent, const char *key ){ - epair_t *ep; - - /* walk epair list */ - for ( ep = ent->epairs; ep != NULL; ep = ep->next ) - { - if ( EPAIR_EQUAL( ep->key, key ) ) { - return true; - } - } - - /* no match */ - return false; -} /* ValueForKey() @@ -793,16 +768,13 @@ bool KeyExists( const entity_t *ent, const char *key ){ */ const char *ValueForKey( const entity_t *ent, const char *key ){ - epair_t *ep; - - /* dummy check */ if ( ent == NULL ) { return ""; } /* walk epair list */ - for ( ep = ent->epairs; ep != NULL; ep = ep->next ) + for ( epair_t *ep = ent->epairs; ep != NULL; ep = ep->next ) { if ( EPAIR_EQUAL( ep->key, key ) ) { return ep->value; @@ -813,7 +785,9 @@ const char *ValueForKey( const entity_t *ent, const char *key ){ return ""; } - +bool BoolForKey( const entity_t *ent, const char *key ){ + return ValueForKey( ent, key )[0] == '1'; +} /* IntForKey() @@ -821,11 +795,7 @@ const char *ValueForKey( const entity_t *ent, const char *key ){ */ int IntForKey( const entity_t *ent, const char *key ){ - const char *k; - - - k = ValueForKey( ent, key ); - return atoi( k ); + return atoi( ValueForKey( ent, key ) ); } @@ -836,11 +806,7 @@ int IntForKey( const entity_t *ent, const char *key ){ */ vec_t FloatForKey( const entity_t *ent, const char *key ){ - const char *k; - - - k = ValueForKey( ent, key ); - return atof( k ); + return atof( ValueForKey( ent, key ) ); } @@ -851,21 +817,82 @@ vec_t FloatForKey( const entity_t *ent, const char *key ){ */ void GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec ){ - const char *k; - double v1, v2, v3; - - - /* get value */ - k = ValueForKey( ent, key ); - /* scanf into doubles, then assign, so it is vec_t size independent */ - v1 = v2 = v3 = 0.0; - sscanf( k, "%lf %lf %lf", &v1, &v2, &v3 ); - vec[ 0 ] = v1; - vec[ 1 ] = v2; - vec[ 2 ] = v3; + double v1, v2, v3; + if( 3 == sscanf( ValueForKey( ent, key ), "%lf %lf %lf", &v1, &v2, &v3 ) ){ + vec[ 0 ] = v1; + vec[ 1 ] = v2; + vec[ 2 ] = v3; + } + else{ + VectorClear( vec ); + } } +bool entity_read_bool( const entity_t *entity, const char *key, bool *bool_value ){ + const char *value = ValueForKey( entity, key ); + if( !strEmpty( value ) ){ + *bool_value = ( value[0] == '1' ); + return true; + } + return false; +} +bool entity_read_int( const entity_t *entity, const char *key, int *int_value ){ + const char *value = ValueForKey( entity, key ); + if( !strEmpty( value ) ){ + *int_value = atoi( value ); + return true; + } + return false; +} +bool entity_read_float( const entity_t *entity, const char *key, float *float_value ){ + const char *value = ValueForKey( entity, key ); + if( !strEmpty( value ) ){ + *float_value = atof( value ); + return true; + } + return false; +} +bool entity_read_vector3( const entity_t *entity, const char *key, float (*vector3_value)[3] ){ + const char *value = ValueForKey( entity, key ); + if( !strEmpty( value ) ){ + float v0, v1, v2; + if( 3 == sscanf( value, "%f %f %f", &v0, &v1, &v2 ) ){ + (*vector3_value)[0] = v0; + (*vector3_value)[1] = v1; + (*vector3_value)[2] = v2; + return true; + } + } + return false; +} +bool entity_read_string( const entity_t *entity, const char *key, char (*string_value)[] ){ + const char *value = ValueForKey( entity, key ); + if( !strEmpty( value ) ){ + strcpy( *string_value, value ); + return true; + } + return false; +} +bool entity_read_string_ptr( const entity_t *entity, const char *key, const char **string_ptr_value ){ + const char *value = ValueForKey( entity, key ); + if( !strEmpty( value ) ){ + *string_ptr_value = value; + return true; + } + return false; +} + + +const char *ent_classname( const entity_t *entity ){ + return ValueForKey( entity, "classname" ); +} +bool ent_class_is( const entity_t *entity, const char *classname ){ + return striEqual( ent_classname( entity ), classname ); +} +bool ent_class_prefixed( const entity_t *entity, const char *prefix ){ + return striEqualPrefix( ent_classname( entity ), prefix ); +} /* @@ -874,15 +901,10 @@ void GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec ){ */ entity_t *FindTargetEntity( const char *target ){ - int i; - const char *n; - - /* walk entity list */ - for ( i = 0; i < numEntities; i++ ) + for ( int i = 0; i < numEntities; i++ ) { - n = ValueForKey( &entities[ i ], "targetname" ); - if ( strEqual( n, target ) ) { + if ( strEqual( ValueForKey( &entities[ i ], "targetname" ), target ) ) { return &entities[ i ]; } } @@ -900,47 +922,26 @@ entity_t *FindTargetEntity( const char *target ){ */ void GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows ){ - const char *value; - /* get cast shadows */ if ( castShadows != NULL ) { - value = ValueForKey( ent, "_castShadows" ); - if ( strEmpty( value ) ) { - value = ValueForKey( ent, "_cs" ); - } - if ( strEmpty( value ) ) { - value = ValueForKey( ent2, "_castShadows" ); - } - if ( strEmpty( value ) ) { - value = ValueForKey( ent2, "_cs" ); - } - if ( !strEmpty( value ) ) { - *castShadows = atoi( value ); - } + ENT_READKV( ent, "_castShadows", castShadows ) || + ENT_READKV( ent, "_cs", castShadows ) || + ENT_READKV( ent2, "_castShadows", castShadows ) || + ENT_READKV( ent2, "_cs", castShadows ); } /* receive */ if ( recvShadows != NULL ) { - value = ValueForKey( ent, "_receiveShadows" ); - if ( strEmpty( value ) ) { - value = ValueForKey( ent, "_rs" ); - } - if ( strEmpty( value ) ) { - value = ValueForKey( ent2, "_receiveShadows" ); - } - if ( strEmpty( value ) ) { - value = ValueForKey( ent2, "_rs" ); - } - if ( !strEmpty( value ) ) { - *recvShadows = atoi( value ); - } + ENT_READKV( ent, "_receiveShadows", recvShadows ) || + ENT_READKV( ent, "_rs", recvShadows ) || + ENT_READKV( ent2, "_receiveShadows", recvShadows ) || + ENT_READKV( ent2, "_rs", recvShadows ); } /* vortex: game-specific default entity keys */ - value = ValueForKey( ent, "classname" ); if ( striEqual( game->magic, "dq" ) || striEqual( game->magic, "prophecy" ) ) { /* vortex: deluxe quake default shadow flags */ - if ( striEqual( value, "func_wall" ) ) { + if ( ent_class_is( ent, "func_wall" ) ) { if ( recvShadows != NULL ) { *recvShadows = 1; } diff --git a/tools/quake3/q3map2/convert_ase.c b/tools/quake3/q3map2/convert_ase.c index 9cf86c1e..78271d40 100644 --- a/tools/quake3/q3map2/convert_ase.c +++ b/tools/quake3/q3map2/convert_ase.c @@ -342,8 +342,6 @@ int ConvertBSPToASE( char *bspName ){ bspShader_t *shader; bspModel_t *model; entity_t *e; - vec3_t origin; - const char *key; char name[ 1024 ], base[ 1024 ], dirname[ 1024 ]; int lmIndices[ numBSPShaders ]; @@ -409,7 +407,7 @@ int ConvertBSPToASE( char *bspName ){ } else { - key = ValueForKey( e, "model" ); + const char *key = ValueForKey( e, "model" ); if ( key[ 0 ] != '*' ) { continue; } @@ -418,13 +416,8 @@ int ConvertBSPToASE( char *bspName ){ model = &bspModels[ modelNum ]; /* get entity origin */ - key = ValueForKey( e, "origin" ); - if ( strEmpty( key ) ) { - VectorClear( origin ); - } - else{ - GetVectorForKey( e, "origin", origin ); - } + vec3_t origin; + GetVectorForKey( e, "origin", origin ); /* convert model */ ConvertModel( f, model, modelNum, origin, lmIndices ); diff --git a/tools/quake3/q3map2/convert_bsp.c b/tools/quake3/q3map2/convert_bsp.c index 33c39a8c..d00a81cf 100644 --- a/tools/quake3/q3map2/convert_bsp.c +++ b/tools/quake3/q3map2/convert_bsp.c @@ -460,15 +460,14 @@ int ScaleBSPMain( int argc, char **argv ){ for ( i = 0; i < numBSPEntities && i < numEntities; i++ ) { /* scale origin */ - GetVectorForKey( &entities[ i ], "origin", vec ); - if ( ( vec[ 0 ] || vec[ 1 ] || vec[ 2 ] ) ) { - if ( striEqualPrefix( ValueForKey( &entities[i], "classname" ), "info_player_" ) ) { + if ( ENT_READKV( &entities[ i ], "origin", &vec ) ) { + if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { vec[2] += spawn_ref; } vec[0] *= scale[0]; vec[1] *= scale[1]; vec[2] *= scale[2]; - if ( striEqualPrefix( ValueForKey( &entities[i], "classname" ), "info_player_" ) ) { + if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { vec[2] -= spawn_ref; } sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); @@ -487,16 +486,14 @@ int ScaleBSPMain( int argc, char **argv ){ } /* scale door lip */ - f = FloatForKey( &entities[ i ], "lip" ); - if ( f ) { + if ( ENT_READKV( &entities[ i ], "lip", &f ) ) { f *= scale[axis]; sprintf( str, "%f", f ); SetKeyValue( &entities[ i ], "lip", str ); } /* scale plat height */ - f = FloatForKey( &entities[ i ], "height" ); - if ( f ) { + if ( ENT_READKV( &entities[ i ], "height", &f ) ) { f *= scale[2]; sprintf( str, "%f", f ); SetKeyValue( &entities[ i ], "height", str ); @@ -616,8 +613,7 @@ int ScaleBSPMain( int argc, char **argv ){ } /* scale gridsize */ - GetVectorForKey( &entities[ 0 ], "gridsize", vec ); - if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) == 0.0f ) { + if ( !ENT_READKV( &entities[ 0 ], "gridsize", &vec ) ) { VectorCopy( gridSize, vec ); } vec[0] *= scale[0]; @@ -700,15 +696,14 @@ int ShiftBSPMain( int argc, char **argv ){ for ( i = 0; i < numBSPEntities && i < numEntities; i++ ) { /* shift origin */ - GetVectorForKey( &entities[ i ], "origin", vec ); - if ( ( vec[ 0 ] || vec[ 1 ] || vec[ 2 ] ) ) { - if ( striEqualPrefix( ValueForKey( &entities[i], "classname" ), "info_player_" ) ) { + if ( ENT_READKV( &entities[ i ], "origin", &vec ) ) { + if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { vec[2] += spawn_ref; } vec[0] += scale[0]; vec[1] += scale[1]; vec[2] += scale[2]; - if ( striEqualPrefix( ValueForKey( &entities[i], "classname" ), "info_player_" ) ) { + if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { vec[2] -= spawn_ref; } sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); @@ -783,8 +778,7 @@ int ShiftBSPMain( int argc, char **argv ){ /* scale gridsize */ /* - GetVectorForKey( &entities[ 0 ], "gridsize", vec ); - if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) == 0.0f ) { + if ( !ENT_READKV( &entities[ 0 ], "gridsize", &vec ) ) { VectorCopy( gridSize, vec ); } vec[0] *= scale[0]; diff --git a/tools/quake3/q3map2/convert_map.c b/tools/quake3/q3map2/convert_map.c index a4ba38a0..b6b1d940 100644 --- a/tools/quake3/q3map2/convert_map.c +++ b/tools/quake3/q3map2/convert_map.c @@ -1005,7 +1005,6 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){ FILE *f; bspModel_t *model; entity_t *e; - vec3_t origin; const char *value; char name[ 1024 ]; @@ -1062,13 +1061,8 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){ model = &bspModels[ modelNum ]; /* get entity origin */ - value = ValueForKey( e, "origin" ); - if ( strEmpty( value ) ) { - VectorClear( origin ); - } - else{ - GetVectorForKey( e, "origin", origin ); - } + vec3_t origin = { 0.f, 0.f, 0.f }; + ENT_READKV( e, "origin", &origin ); /* convert model */ ConvertModel( f, model, modelNum, origin, brushPrimitives ); diff --git a/tools/quake3/q3map2/convert_obj.c b/tools/quake3/q3map2/convert_obj.c index 1c637cee..c610d4ea 100644 --- a/tools/quake3/q3map2/convert_obj.c +++ b/tools/quake3/q3map2/convert_obj.c @@ -306,7 +306,6 @@ int ConvertBSPToOBJ( char *bspName ){ bspShader_t *shader; bspModel_t *model; entity_t *e; - vec3_t origin; const char *key; char name[ 1024 ], base[ 1024 ], mtlname[ 1024 ], dirname[ 1024 ]; int lmIndices[ numBSPShaders ]; @@ -375,13 +374,8 @@ int ConvertBSPToOBJ( char *bspName ){ model = &bspModels[ modelNum ]; /* get entity origin */ - key = ValueForKey( e, "origin" ); - if ( strEmpty( key ) ) { - VectorClear( origin ); - } - else{ - GetVectorForKey( e, "origin", origin ); - } + vec3_t origin = { 0.f, 0.f, 0.f }; + ENT_READKV( e, "origin", &origin ); /* convert model */ ConvertModelToOBJ( f, model, modelNum, origin, lmIndices ); diff --git a/tools/quake3/q3map2/decals.c b/tools/quake3/q3map2/decals.c index aa1069a1..bd6e526e 100644 --- a/tools/quake3/q3map2/decals.c +++ b/tools/quake3/q3map2/decals.c @@ -413,7 +413,6 @@ void ProcessDecals( void ){ parseMesh_t *p; mesh_t *mesh, *subdivided; bspDrawVert_t *dv[ 4 ]; - const char *value; /* note it */ @@ -424,8 +423,7 @@ void ProcessDecals( void ){ { /* get entity */ e = &entities[ i ]; - value = ValueForKey( e, "classname" ); - if ( !striEqual( value, "_decal" ) ) { + if ( !ent_class_is( e, "_decal" ) ) { continue; } @@ -437,8 +435,7 @@ void ProcessDecals( void ){ } /* find target */ - value = ValueForKey( e, "target" ); - e2 = FindTargetEntity( value ); + e2 = FindTargetEntity( ValueForKey( e, "target" ) ); /* no target? */ if ( e2 == NULL ) { diff --git a/tools/quake3/q3map2/fog.c b/tools/quake3/q3map2/fog.c index 3e6ffa81..12eaa735 100644 --- a/tools/quake3/q3map2/fog.c +++ b/tools/quake3/q3map2/fog.c @@ -717,7 +717,6 @@ void CreateMapFogs( void ){ brush_t *brush; fog_t *fog; vec3_t invFogDir; - const char *globalFog; /* skip? */ @@ -772,11 +771,8 @@ void CreateMapFogs( void ){ } /* ydnar: global fog */ - globalFog = ValueForKey( &entities[ 0 ], "_fog" ); - if ( strEmpty( globalFog ) ) { - globalFog = ValueForKey( &entities[ 0 ], "fog" ); - } - if ( !strEmpty( globalFog ) ) { + const char *globalFog; + if ( ENT_READKV( &entities[ 0 ], "_fog", &globalFog ) || ENT_READKV( &entities[ 0 ], "fog", &globalFog ) ) { /* test limit */ if ( numMapFogs >= MAX_MAP_FOGS ) { Error( "Exceeded MAX_MAP_FOGS (%d) trying to add global fog", MAX_MAP_FOGS ); diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 1cb69095..a50313f8 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -218,13 +218,6 @@ void CreateEntityLights( void ){ int i, j; light_t *light, *light2; entity_t *e, *e2; - const char *name; - const char *target; - vec3_t dest; - const char *_color; - float intensity, scale, deviance, filterRadius; - int spawnflags, flags, numSamples; - bool junior; /* go throught entity list and find lights */ @@ -232,13 +225,12 @@ void CreateEntityLights( void ){ { /* get entity */ e = &entities[ i ]; - name = ValueForKey( e, "classname" ); - /* ydnar: check for lightJunior */ - if ( striEqualPrefix( name, "lightJunior" ) ) { + bool junior; + if ( ent_class_is( e, "lightJunior" ) ) { junior = true; } - else if ( striEqualPrefix( name, "light" ) ) { + else if ( ent_class_prefixed( e, "light" ) ) { junior = false; } else{ @@ -246,8 +238,7 @@ void CreateEntityLights( void ){ } /* lights with target names (and therefore styles) are only parsed from BSP */ - target = ValueForKey( e, "targetname" ); - if ( !strEmpty( target ) && i >= numBSPEntities ) { + if ( !strEmpty( ValueForKey( e, "targetname" ) ) && i >= numBSPEntities ) { continue; } @@ -258,8 +249,9 @@ void CreateEntityLights( void ){ lights = light; /* handle spawnflags */ - spawnflags = IntForKey( e, "spawnflags" ); + const int spawnflags = IntForKey( e, "spawnflags" ); + int flags; /* ydnar: quake 3+ light behavior */ if ( !wolfLight ) { /* set default flags */ @@ -343,66 +335,47 @@ void CreateEntityLights( void ){ /* set origin */ GetVectorForKey( e, "origin", light->origin ); - light->style = IntForKey( e, "_style" ); - if ( light->style == LS_NORMAL ) { - light->style = IntForKey( e, "style" ); - } + ENT_READKV( e, "_style", &light->style ) || ENT_READKV( e, "style", &light->style ); if ( light->style < LS_NORMAL || light->style >= LS_NONE ) { Error( "Invalid lightstyle (%d) on entity %d", light->style, i ); } - if ( light->style != LS_NORMAL ) { - Sys_Warning( "Styled light found targeting %s\n **", target ); - } - /* set light intensity */ - intensity = FloatForKey( e, "_light" ); - if ( intensity == 0.0f ) { - intensity = FloatForKey( e, "light" ); - } + float intensity = 300.f; + ENT_READKV( e, "_light", &intensity ) || ENT_READKV( e, "light", &intensity ); if ( intensity == 0.0f ) { intensity = 300.0f; } - /* ydnar: set light scale (sof2) */ - scale = FloatForKey( e, "scale" ); - if ( scale == 0.0f ) { - scale = 1.0f; + { /* ydnar: set light scale (sof2) */ + float scale; + if( ENT_READKV( e, "scale", &scale ) && scale != 0.f ) + intensity *= scale; } - intensity *= scale; /* ydnar: get deviance and samples */ - deviance = FloatForKey( e, "_deviance" ); - if ( deviance == 0.0f ) { - deviance = FloatForKey( e, "_deviation" ); - } - if ( deviance == 0.0f ) { - deviance = FloatForKey( e, "_jitter" ); - } - numSamples = IntForKey( e, "_samples" ); - if ( deviance < 0.0f || numSamples < 1 ) { - deviance = 0.0f; + float deviance = 0.f; + ENT_READKV( e, "_deviance", &deviance ) || + ENT_READKV( e, "_deviation", &deviance ) || + ENT_READKV( e, "_jitter", &deviance ); + if ( deviance < 0.f ) + deviance = 0.f; + int numSamples = IntForKey( e, "_samples" ); + if ( numSamples < 1 ) numSamples = 1; - } + intensity /= numSamples; - /* ydnar: get filter radius */ - filterRadius = FloatForKey( e, "_filterradius" ); - if ( filterRadius == 0.0f ) { - filterRadius = FloatForKey( e, "_filteradius" ); + { /* ydnar: get filter radius */ + float filterRadius = 0.f; + ENT_READKV( e, "_filterradius", &filterRadius ) || + ENT_READKV( e, "_filteradius", &filterRadius ) || + ENT_READKV( e, "_filter", &filterRadius ); + light->filterRadius = filterRadius < 0.f? 0.f : filterRadius; } - if ( filterRadius == 0.0f ) { - filterRadius = FloatForKey( e, "_filter" ); - } - if ( filterRadius < 0.0f ) { - filterRadius = 0.0f; - } - light->filterRadius = filterRadius; /* set light color */ - _color = ValueForKey( e, "_color" ); - if ( _color && _color[ 0 ] ) { - sscanf( _color, "%f %f %f", &light->color[ 0 ], &light->color[ 1 ], &light->color[ 2 ] ); + if ( ENT_READKV( e, "_color", &light->color ) ) { if ( colorsRGB ) { light->color[0] = Image_LinearFloatFromsRGBFloat( light->color[0] ); light->color[1] = Image_LinearFloatFromsRGBFloat( light->color[1] ); @@ -413,13 +386,12 @@ void CreateEntityLights( void ){ } } else{ - light->color[ 0 ] = light->color[ 1 ] = light->color[ 2 ] = 1.0f; + VectorSet( light->color, 1.f, 1.f, 1.f ); } - light->extraDist = FloatForKey( e, "_extradist" ); - if ( light->extraDist == 0.0f ) { + + if( !ENT_READKV( e, "_extradist", &light->extraDist ) ) light->extraDist = extraDist; - } light->photons = intensity; @@ -429,14 +401,8 @@ void CreateEntityLights( void ){ light->falloffTolerance = falloffTolerance / numSamples; /* lights with a target will be spotlights */ - target = ValueForKey( e, "target" ); - if ( target[ 0 ] ) { - float radius; - float dist; - sun_t sun; - const char *_sun; - - + const char *target; + if ( ENT_READKV( e, "target", &target ) ) { /* get target */ e2 = FindTargetEntity( target ); if ( e2 == NULL ) { @@ -451,10 +417,11 @@ void CreateEntityLights( void ){ numSpotLights++; /* make a spotlight */ + vec3_t dest; GetVectorForKey( e2, "origin", dest ); VectorSubtract( dest, light->origin, light->normal ); - dist = VectorNormalize( light->normal, light->normal ); - radius = FloatForKey( e, "radius" ); + float dist = VectorNormalize( light->normal, light->normal ); + float radius = FloatForKey( e, "radius" ); if ( !radius ) { radius = 64; } @@ -470,8 +437,7 @@ void CreateEntityLights( void ){ light->fade = 1.0f; /* ydnar: is this a sun? */ - _sun = ValueForKey( e, "_sun" ); - if ( _sun[ 0 ] == '1' ) { + if ( BoolForKey( e, "_sun" ) ) { /* not a spot light */ numSpotLights--; @@ -479,6 +445,7 @@ void CreateEntityLights( void ){ lights = light->next; /* make a sun */ + sun_t sun; VectorScale( light->normal, -1.0f, sun.direction ); VectorCopy( light->color, sun.color ); sun.photons = intensity; @@ -550,11 +517,10 @@ void CreateSurfaceLights( void ){ float subdivide; vec3_t origin; clipWork_t cw; - const char *nss; /* get sun shader supressor */ - nss = ValueForKey( &entities[ 0 ], "_noshadersun" ); + const bool nss = BoolForKey( &entities[ 0 ], "_noshadersun" ); /* walk the list of surfaces */ for ( i = 0; i < numBSPDrawSurfaces; i++ ) @@ -565,7 +531,7 @@ void CreateSurfaceLights( void ){ si = info->si; /* sunlight? */ - if ( si->sun != NULL && nss[ 0 ] != '1' ) { + if ( si->sun != NULL && !nss ) { Sys_FPrintf( SYS_VRB, "Sun: %s\n", si->shader ); CreateSunLight( si->sun ); si->sun = NULL; /* FIXME: leak! */ @@ -646,7 +612,6 @@ void CreateSurfaceLights( void ){ void SetEntityOrigins( void ){ int i, j, k, f; entity_t *e; - vec3_t origin; const char *key; int modelnum; bspModel_t *dm; @@ -670,11 +635,10 @@ void SetEntityOrigins( void ){ dm = &bspModels[ modelnum ]; /* get entity origin */ - key = ValueForKey( e, "origin" ); - if ( strEmpty( key ) ) { + vec3_t origin = { 0.f, 0.f, 0.f }; + if ( !ENT_READKV( e, "origin", &origin ) ) { continue; } - GetVectorForKey( e, "origin", origin ); /* set origin for all surfaces for this model */ for ( j = 0; j < dm->numBSPSurfaces; j++ ) @@ -1798,7 +1762,6 @@ void TraceGrid( int num ){ void SetupGrid( void ){ int i, j; vec3_t maxs, oldGridSize; - const char *value; char temp[ 64 ]; @@ -1808,10 +1771,7 @@ void SetupGrid( void ){ } /* ydnar: set grid size */ - value = ValueForKey( &entities[ 0 ], "gridsize" ); - if ( !strEmpty( value ) ) { - sscanf( value, "%f %f %f", &gridSize[ 0 ], &gridSize[ 1 ], &gridSize[ 2 ] ); - } + ENT_READKV( &entities[ 0 ], "gridsize", &gridSize ); /* quantize it */ VectorCopy( gridSize, oldGridSize ); @@ -1888,7 +1848,6 @@ void LightWorld( bool fastAllocate ){ float f; int b, bt; bool minVertex, minGrid; - const char *value; /* ydnar: smooth normals */ @@ -1913,47 +1872,31 @@ void LightWorld( bool fastAllocate ){ } /* ambient */ - f = FloatForKey( &entities[ 0 ], "_ambient" ); - if ( f == 0.0f ) { - f = FloatForKey( &entities[ 0 ], "ambient" ); - } + f = 0.f; + ENT_READKV( &entities[ 0 ], "_ambient", &f ) || ENT_READKV( &entities[ 0 ], "ambient", &f ); VectorScale( color, f, ambientColor ); /* minvertexlight */ - minVertex = false; - value = ValueForKey( &entities[ 0 ], "_minvertexlight" ); - if ( !strEmpty( value ) ) { - minVertex = true; - f = atof( value ); + if ( ( minVertex = ENT_READKV( &entities[ 0 ], "_minvertexlight", &f ) ) ) { VectorScale( color, f, minVertexLight ); } /* mingridlight */ - minGrid = false; - value = ValueForKey( &entities[ 0 ], "_mingridlight" ); - if ( !strEmpty( value ) ) { - minGrid = true; - f = atof( value ); + if ( ( minGrid = ENT_READKV( &entities[ 0 ], "_mingridlight", &f ) ) ) { VectorScale( color, f, minGridLight ); } /* minlight */ - value = ValueForKey( &entities[ 0 ], "_minlight" ); - if ( !strEmpty( value ) ) { - f = atof( value ); + if ( ENT_READKV( &entities[ 0 ], "_minlight", &f ) ) { VectorScale( color, f, minLight ); - if ( !minVertex ) { + if ( !minVertex ) VectorScale( color, f, minVertexLight ); - } - if ( !minGrid ) { + if ( !minGrid ) VectorScale( color, f, minGridLight ); - } } /* maxlight */ - value = ValueForKey( &entities[ 0 ], "_maxlight" ); - if ( !strEmpty( value ) ) { - f = atof( value ); + if ( ENT_READKV( &entities[ 0 ], "_maxlight", &f ) ) { maxLight = f > 255? 255 : f < 0? 0 : f; } @@ -2109,7 +2052,6 @@ void LightWorld( bool fastAllocate ){ int LightMain( int argc, char **argv ){ int i; float f; - const char *value; int lightmapMergeSize = 0; bool lightSamplesInsist = false; bool fastAllocate = true; @@ -3017,8 +2959,7 @@ int LightMain( int argc, char **argv ){ InjectCommandLine( argv, 0, argc - 1 ); /* load map file */ - value = ValueForKey( &entities[ 0 ], "_keepLights" ); - if ( value[ 0 ] != '1' ) { + if ( !BoolForKey( &entities[ 0 ], "_keepLights" ) ) { LoadMapFile( name, true, false ); } diff --git a/tools/quake3/q3map2/light_trace.c b/tools/quake3/q3map2/light_trace.c index 854fc3d8..0bc90b11 100644 --- a/tools/quake3/q3map2/light_trace.c +++ b/tools/quake3/q3map2/light_trace.c @@ -1109,16 +1109,13 @@ static void PopulateWithPicoModel( int castShadows, picoModel_t *model, m4x4_t t */ static void PopulateTraceNodes( void ){ - int i, m, frame, castShadows; - float temp; - entity_t *e; + int i, m; const char *value; picoModel_t *model; - vec3_t origin, scale, angles; - m4x4_t transform; /* add worldspawn triangles */ + m4x4_t transform; m4x4_identity( transform ); PopulateWithBSPModel( &bspModels[ 0 ], transform ); @@ -1126,10 +1123,10 @@ static void PopulateTraceNodes( void ){ for ( i = 1; i < numEntities; i++ ) { /* get entity */ - e = &entities[ i ]; + entity_t *e = &entities[ i ]; /* get shadow flags */ - castShadows = ENTITY_CAST_SHADOWS; + int castShadows = ENTITY_CAST_SHADOWS; GetEntityShadowFlags( e, NULL, &castShadows, NULL ); /* early out? */ @@ -1138,26 +1135,20 @@ static void PopulateTraceNodes( void ){ } /* get entity origin */ + vec3_t origin; GetVectorForKey( e, "origin", origin ); /* get scale */ - scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = 1.0f; - temp = FloatForKey( e, "modelscale" ); - if ( temp != 0.0f ) { - scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = temp; - } - value = ValueForKey( e, "modelscale_vec" ); - if ( !strEmpty( value ) ) { - sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] ); - } + vec3_t scale = { 1.f, 1.f, 1.f }; + if( !ENT_READKV( e, "modelscale_vec", &scale ) ) + if( ENT_READKV( e, "modelscale", &scale[0] ) ) + scale[1] = scale[2] = scale[0]; - /* get "angle" (yaw) or "angles" (pitch yaw roll) */ - angles[ 0 ] = angles[ 1 ] = angles[ 2 ] = 0.0f; - angles[ 2 ] = FloatForKey( e, "angle" ); - value = ValueForKey( e, "angles" ); - if ( !strEmpty( value ) ) { - sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ); - } + /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */ + vec3_t angles = { 0.f, 0.f, 0.f }; + if ( !ENT_READKV( e, "angles", &value ) || + 3 != sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ) ) + ENT_READKV( e, "angle", &angles[ 2 ] ); /* set transform matrix (thanks spog) */ m4x4_identity( transform ); @@ -1189,18 +1180,15 @@ static void PopulateTraceNodes( void ){ /* external model */ default: - frame = 0; - if ( !strEmpty( ValueForKey( e, "_frame" ) ) ) { - frame = IntForKey( e, "_frame" ); + { + int frame = 0; + ENT_READKV( e, "_frame", &frame ) || ENT_READKV( e, "frame", &frame ); + model = LoadModel( value, frame ); + if ( model == NULL ) { + continue; + } + PopulateWithPicoModel( castShadows, model, transform ); } - else if ( !strEmpty( ValueForKey( e, "frame" ) ) ) { - frame = IntForKey( e, "frame" ); - } - model = LoadModel( value, frame ); - if ( model == NULL ) { - continue; - } - PopulateWithPicoModel( castShadows, model, transform ); continue; } @@ -1225,8 +1213,7 @@ static void PopulateTraceNodes( void ){ /* external model */ default: - frame = IntForKey( e, "_frame2" ); - model = LoadModel( value, frame ); + model = LoadModel( value, IntForKey( e, "_frame2" ) ); if ( model == NULL ) { continue; } diff --git a/tools/quake3/q3map2/light_ydnar.c b/tools/quake3/q3map2/light_ydnar.c index 99babcf4..3518a915 100644 --- a/tools/quake3/q3map2/light_ydnar.c +++ b/tools/quake3/q3map2/light_ydnar.c @@ -4103,8 +4103,6 @@ static int numFloodVectors = 0; void SetupFloodLight( void ){ int i, j; float angle, elevation, angleStep, elevationStep; - const char *value; - double v1,v2,v3,v4,v5,v6; /* note it */ Sys_FPrintf( SYS_VRB, "--- SetupFloodLight ---\n" ); @@ -4131,9 +4129,9 @@ void SetupFloodLight( void ){ Sys_FPrintf( SYS_VRB, "%9d numFloodVectors\n", numFloodVectors ); /* floodlight */ - value = ValueForKey( &entities[ 0 ], "_floodlight" ); - - if ( !strEmpty( value ) ) { + const char *value; + if ( ENT_READKV( &entities[ 0 ], "_floodlight", &value ) ) { + double v1,v2,v3,v4,v5,v6; v1 = v2 = v3 = 0; v4 = floodlightDistance; v5 = floodlightIntensity; diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index cbd3f50e..6ebaaf79 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -876,7 +876,7 @@ brush_t *FinishBrush( bool noCollapseGroups ){ vec3_t origin; Sys_Printf( "Entity %i (%s), Brush %i: origin brush detected\n", - mapEnt->mapEntityNum, ValueForKey( mapEnt, "classname" ), entitySourceBrushes ); + mapEnt->mapEntityNum, ent_classname( mapEnt ), entitySourceBrushes ); if ( numEntities == 1 ) { Sys_FPrintf( SYS_WRN, "Entity %i, Brush %i: origin brushes not allowed in world\n", @@ -896,7 +896,7 @@ brush_t *FinishBrush( bool noCollapseGroups ){ /* determine if the brush is an area portal */ if ( buildBrush->compileFlags & C_AREAPORTAL ) { if ( numEntities != 1 ) { - Sys_FPrintf( SYS_WRN, "Entity %i (%s), Brush %i: areaportals only allowed in world\n", numEntities - 1, ValueForKey( mapEnt, "classname" ), entitySourceBrushes ); + Sys_FPrintf( SYS_WRN, "Entity %i (%s), Brush %i: areaportals only allowed in world\n", numEntities - 1, ent_classname( mapEnt ), entitySourceBrushes ); return NULL; } } @@ -1499,12 +1499,8 @@ void SetEntityBounds( entity_t *e ){ } /* try to find explicit min/max key */ - if ( !strEmpty( ValueForKey( e, "min" ) ) ) { - GetVectorForKey( e, "min", mins ); - } - if ( !strEmpty( ValueForKey( e, "max" ) ) ) { - GetVectorForKey( e, "max", maxs ); - } + ENT_READKV( e, "min", &mins ); + ENT_READKV( e, "max", &maxs ); /* store the bounds */ for ( b = e->brushes; b; b = b->next ) @@ -1528,8 +1524,7 @@ void SetEntityBounds( entity_t *e ){ void LoadEntityIndexMap( entity_t *e ){ int i, size, numLayers, w, h; - const char *value, *indexMapFilename, *shader; - char offset[ 4096 ], *search, *space; + const char *indexMapFilename, *shader; byte *pixels; unsigned int *pixels32; indexMap_t *im; @@ -1543,26 +1538,17 @@ void LoadEntityIndexMap( entity_t *e ){ } /* determine if there is an index map (support legacy "alphamap" key as well) */ - value = ValueForKey( e, "_indexmap" ); - if ( strEmpty( value ) ) { - value = ValueForKey( e, "alphamap" ); - } - if ( strEmpty( value ) ) { + if( !ENT_READKV( e, "_indexmap", &indexMapFilename ) && + !ENT_READKV( e, "alphamap", &indexMapFilename ) ) return; - } - indexMapFilename = value; /* get number of layers (support legacy "layers" key as well) */ - value = ValueForKey( e, "_layers" ); - if ( strEmpty( value ) ) { - value = ValueForKey( e, "layers" ); - } - if ( strEmpty( value ) ) { + if( !ENT_READKV( e, "_layers", &numLayers ) && + !ENT_READKV( e, "layers", &numLayers ) ){ Sys_Warning( "Entity with index/alpha map \"%s\" has missing \"_layers\" or \"layers\" key\n", indexMapFilename ); Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" ); return; } - numLayers = atoi( value ); if ( numLayers < 1 ) { Sys_Warning( "Entity with index/alpha map \"%s\" has < 1 layer (%d)\n", indexMapFilename, numLayers ); Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" ); @@ -1570,19 +1556,15 @@ void LoadEntityIndexMap( entity_t *e ){ } /* get base shader name (support legacy "shader" key as well) */ - value = ValueForKey( mapEnt, "_shader" ); - if ( strEmpty( value ) ) { - value = ValueForKey( e, "shader" ); - } - if ( strEmpty( value ) ) { + if( !ENT_READKV( mapEnt, "_shader", &shader ) && + !ENT_READKV( mapEnt, "shader", &shader ) ){ Sys_Warning( "Entity with index/alpha map \"%s\" has missing \"_shader\" or \"shader\" key\n", indexMapFilename ); Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" ); return; } - shader = value; /* note it */ - Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->mapEntityNum, ValueForKey( e, "classname" ), indexMapFilename ); + Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->mapEntityNum, ent_classname( e ), indexMapFilename ); /* handle tga image */ if ( striEqual( path_get_extension( indexMapFilename ), "tga" ) ) { @@ -1649,19 +1631,15 @@ void LoadEntityIndexMap( entity_t *e ){ im->pixels = pixels; /* get height offsets */ - value = ValueForKey( mapEnt, "_offsets" ); - if ( strEmpty( value ) ) { - value = ValueForKey( e, "offsets" ); - } - if ( !strEmpty( value ) ) { - /* value is a space-seperated set of numbers */ - strcpy( offset, value ); - search = offset; - + char offset[ 4096 ]; + if( ENT_READKV( mapEnt, "_offsets", &offset ) || + ENT_READKV( mapEnt, "offsets", &offset ) ){ + /* value is a space-separated set of numbers */ + char *search = offset; /* get each value */ for ( i = 0; i < 256 && !strEmpty( search ); i++ ) { - space = strchr( search, ' ' ); + char *space = strchr( search, ' ' ); if ( space != NULL ) { strClear( space ); } @@ -1693,16 +1671,8 @@ void LoadEntityIndexMap( entity_t *e ){ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ epair_t *ep; - const char *classname, *value; - float lightmapScale, shadeAngle; - int lightmapSampleSize; - char shader[ MAX_QPATH ]; - shaderInfo_t *celShader = NULL; brush_t *brush; parseMesh_t *patch; - bool funcGroup; - int castShadows, recvShadows; - /* eof check */ if ( !GetToken( true ) ) { @@ -1788,7 +1758,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ } /* ydnar: get classname */ - classname = ValueForKey( mapEnt, "classname" ); + const char *classname = ent_classname( mapEnt ); /* ydnar: only lights? */ if ( onlyLights && !striEqualPrefix( classname, "light" ) ) { @@ -1797,18 +1767,16 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ } /* ydnar: determine if this is a func_group */ - funcGroup = striEqual( "func_group", classname ); + const bool funcGroup = striEqual( "func_group", classname ); /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */ + int castShadows, recvShadows; if ( funcGroup || mapEnt->mapEntityNum == 0 ) { //% Sys_Printf( "World: %d\n", mapEnt->mapEntityNum ); castShadows = WORLDSPAWN_CAST_SHADOWS; recvShadows = WORLDSPAWN_RECV_SHADOWS; } - - /* other entities don't cast any shadows, but recv worldspawn shadows */ - else - { + else{ /* other entities don't cast any shadows, but recv worldspawn shadows */ //% Sys_Printf( "Entity: %d\n", mapEnt->mapEntityNum ); castShadows = ENTITY_CAST_SHADOWS; recvShadows = ENTITY_RECV_SHADOWS; @@ -1817,94 +1785,51 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ /* get explicit shadow flags */ GetEntityShadowFlags( mapEnt, NULL, &castShadows, &recvShadows ); - /* vortex: added _ls key (short name of lightmapscale) */ /* ydnar: get lightmap scaling value for this entity */ - lightmapScale = 0.0f; - if ( !strEmpty( ValueForKey( mapEnt, "lightmapscale" ) ) || - !strEmpty( ValueForKey( mapEnt, "_lightmapscale" ) ) || - !strEmpty( ValueForKey( mapEnt, "_ls" ) ) ) { - /* get lightmap scale from entity */ - lightmapScale = FloatForKey( mapEnt, "lightmapscale" ); - if ( lightmapScale <= 0.0f ) { - lightmapScale = FloatForKey( mapEnt, "_lightmapscale" ); - } - if ( lightmapScale <= 0.0f ) { - lightmapScale = FloatForKey( mapEnt, "_ls" ); - } - if ( lightmapScale < 0.0f ) { - lightmapScale = 0.0f; - } - if ( lightmapScale > 0.0f ) { - Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale ); - } - } + float lightmapScale = 0.0f; + ENT_READKV( mapEnt, "lightmapscale", &lightmapScale ) || + ENT_READKV( mapEnt, "_lightmapscale", &lightmapScale ) || + ENT_READKV( mapEnt, "_ls", &lightmapScale ); + if ( lightmapScale < 0.0f ) + lightmapScale = 0.0f; + else if ( lightmapScale > 0.0f ) + Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale ); /* ydnar: get cel shader :) for this entity */ - value = ValueForKey( mapEnt, "_celshader" ); - if ( strEmpty( value ) ) { - value = ValueForKey( &entities[ 0 ], "_celshader" ); - } - if ( !strEmpty( value ) ) { - if ( !strEqual( value, "none" ) ) { - sprintf( shader, "textures/%s", value ); - celShader = ShaderInfoForShader( shader ); - Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader ); - } - else - { - celShader = NULL; - } + shaderInfo_t *celShader; + const char *value; + if( ENT_READKV( mapEnt, "_celshader", &value ) || + ENT_READKV( &entities[ 0 ], "_celshader", &value ) ){ + char shader[ MAX_QPATH ]; + sprintf( shader, "textures/%s", value ); + celShader = ShaderInfoForShader( shader ); + Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader ); } else{ - celShader = ( *globalCelShader ? ShaderInfoForShader( globalCelShader ) : NULL ); + celShader = !strEmpty( globalCelShader ) ? ShaderInfoForShader( globalCelShader ) : NULL; } /* jal : entity based _shadeangle */ - shadeAngle = 0.0f; - if ( !strEmpty( ValueForKey( mapEnt, "_shadeangle" ) ) ) { - shadeAngle = FloatForKey( mapEnt, "_shadeangle" ); - } - /* vortex' aliases */ - else if ( !strEmpty( ValueForKey( mapEnt, "_smoothnormals" ) ) ) { - shadeAngle = FloatForKey( mapEnt, "_smoothnormals" ); - } - else if ( !strEmpty( ValueForKey( mapEnt, "_sn" ) ) ) { - shadeAngle = FloatForKey( mapEnt, "_sn" ); - } - else if ( !strEmpty( ValueForKey( mapEnt, "_sa" ) ) ) { - shadeAngle = FloatForKey( mapEnt, "_sa" ); - } - else if ( !strEmpty( ValueForKey( mapEnt, "_smooth" ) ) ) { - shadeAngle = FloatForKey( mapEnt, "_smooth" ); - } - - if ( shadeAngle < 0.0f ) { + float shadeAngle = 0.0f; + ENT_READKV( mapEnt, "_shadeangle", &shadeAngle ) || + ENT_READKV( mapEnt, "_smoothnormals", &shadeAngle ) || /* vortex' aliases */ + ENT_READKV( mapEnt, "_sn", &shadeAngle ) || + ENT_READKV( mapEnt, "_sa", &shadeAngle ) || + ENT_READKV( mapEnt, "_smooth", &shadeAngle ); + if ( shadeAngle < 0.0f ) shadeAngle = 0.0f; - } - - if ( shadeAngle > 0.0f ) { + else if ( shadeAngle > 0.0f ) Sys_Printf( "Entity %d (%s) has shading angle of %.4f\n", mapEnt->mapEntityNum, classname, shadeAngle ); - } /* jal : entity based _samplesize */ - lightmapSampleSize = 0; - if ( !strEmpty( ValueForKey( mapEnt, "_lightmapsamplesize" ) ) ) { - lightmapSampleSize = IntForKey( mapEnt, "_lightmapsamplesize" ); - } - else if ( !strEmpty( ValueForKey( mapEnt, "_samplesize" ) ) ) { - lightmapSampleSize = IntForKey( mapEnt, "_samplesize" ); - } - else if ( !strEmpty( ValueForKey( mapEnt, "_ss" ) ) ) { - lightmapSampleSize = IntForKey( mapEnt, "_ss" ); - } - - if ( lightmapSampleSize < 0 ) { + int lightmapSampleSize = 0; + ENT_READKV( mapEnt, "_lightmapsamplesize", &lightmapSampleSize ) || + ENT_READKV( mapEnt, "_samplesize", &lightmapSampleSize ) || + ENT_READKV( mapEnt, "_ss", &lightmapSampleSize ); + if ( lightmapSampleSize < 0 ) lightmapSampleSize = 0; - } - - if ( lightmapSampleSize > 0 ) { + else if ( lightmapSampleSize > 0 ) Sys_Printf( "Entity %d (%s) has lightmap sample size of %d\n", mapEnt->mapEntityNum, classname, lightmapSampleSize ); - } /* attach stuff to everything in the entity */ for ( brush = mapEnt->brushes; brush != NULL; brush = brush->next ) diff --git a/tools/quake3/q3map2/model.c b/tools/quake3/q3map2/model.c index 2a3b5982..826bcce4 100644 --- a/tools/quake3/q3map2/model.c +++ b/tools/quake3/q3map2/model.c @@ -1353,105 +1353,53 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap */ void AddTriangleModels( entity_t *e ){ - int num, frame, skin, castShadows, recvShadows, spawnFlags; - entity_t *e2; - const char *targetName; - const char *target, *model, *value; - char shader[ MAX_QPATH ]; - shaderInfo_t *celShader; - float temp, baseLightmapScale, lightmapScale, clipDepth; - float shadeAngle; - int lightmapSampleSize; - vec3_t origin, scale, angles; - m4x4_t transform; - epair_t *ep; - remap_t *remap, *remap2; - char *split; - - /* note it */ Sys_FPrintf( SYS_VRB, "--- AddTriangleModels ---\n" ); - /* get current brush entity targetname */ + const char *targetName; if ( e == entities ) { targetName = ""; } - else - { - targetName = ValueForKey( e, "targetname" ); - - /* misc_model entities target non-worldspawn brush model entities */ - if ( strEmpty( targetName ) ) { + else{ /* misc_model entities target non-worldspawn brush model entities */ + if ( !ENT_READKV( e, "targetname", &targetName ) ) { return; } } - /* get lightmap scale */ - /* vortex: added _ls key (short name of lightmapscale) */ - baseLightmapScale = 0.0f; - if ( !strEmpty( ValueForKey( e, "lightmapscale" ) ) || - !strEmpty( ValueForKey( e, "_lightmapscale" ) ) || - !strEmpty( ValueForKey( e, "_ls" ) ) ) { - baseLightmapScale = FloatForKey( e, "lightmapscale" ); - if ( baseLightmapScale <= 0.0f ) { - baseLightmapScale = FloatForKey( e, "_lightmapscale" ); - } - if ( baseLightmapScale <= 0.0f ) { - baseLightmapScale = FloatForKey( e, "_ls" ); - } - if ( baseLightmapScale < 0.0f ) { - baseLightmapScale = 0.0f; - } - if ( baseLightmapScale > 0.0f ) { - Sys_Printf( "World Entity has lightmap scale of %.4f\n", baseLightmapScale ); - } - } - - /* walk the entity list */ - for ( num = 1; num < numEntities; num++ ) + for ( int num = 1; num < numEntities; num++ ) { /* get e2 */ - e2 = &entities[ num ]; + entity_t *e2 = &entities[ num ]; /* convert misc_models into raw geometry */ - if ( !striEqual( "misc_model", ValueForKey( e2, "classname" ) ) ) { + if ( !ent_class_is( e2, "misc_model" ) ) { continue; } /* ydnar: added support for md3 models on non-worldspawn models */ - target = ValueForKey( e2, "target" ); - if ( !strEqual( target, targetName ) ) { + if ( !strEqual( ValueForKey( e2, "target" ), targetName ) ) { continue; } /* get model name */ - model = ValueForKey( e2, "model" ); - if ( strEmpty( model ) ) { - Sys_Warning( "misc_model at %i %i %i without a model key\n", - (int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] ); + const char *model; + if ( !ENT_READKV( e2, "model", &model ) ) { + Sys_Warning( "entity#%d misc_model without a model key\n", e2->mapEntityNum ); continue; } /* get model frame */ - frame = 0; - if ( !strEmpty( ValueForKey( e2, "_frame" ) ) ) { - frame = IntForKey( e2, "_frame" ); - } - else if ( !strEmpty( ValueForKey( e2, "frame" ) ) ) { - frame = IntForKey( e2, "frame" ); - } + int frame = 0; + ENT_READKV( e2, "_frame", &frame ) || ENT_READKV( e2, "frame", &frame ); - /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */ - if ( e == entities ) { + int castShadows, recvShadows; + if ( e == entities ) { /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */ castShadows = WORLDSPAWN_CAST_SHADOWS; recvShadows = WORLDSPAWN_RECV_SHADOWS; } - - /* other entities don't cast any shadows, but recv worldspawn shadows */ - else - { + else{ /* other entities don't cast any shadows, but recv worldspawn shadows */ castShadows = ENTITY_CAST_SHADOWS; recvShadows = ENTITY_RECV_SHADOWS; } @@ -1460,38 +1408,34 @@ void AddTriangleModels( entity_t *e ){ GetEntityShadowFlags( e2, e, &castShadows, &recvShadows ); /* get spawnflags */ - spawnFlags = IntForKey( e2, "spawnflags" ); + const int spawnFlags = IntForKey( e2, "spawnflags" ); /* get origin */ - GetVectorForKey( e2, "origin", origin ); + vec3_t origin = { 0.f, 0.f, 0.f }; + ENT_READKV( e2, "origin", &origin ); VectorSubtract( origin, e->origin, origin ); /* offset by parent */ /* get scale */ - scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = 1.0f; - temp = FloatForKey( e2, "modelscale" ); - if ( temp != 0.0f ) { - scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = temp; - } - value = ValueForKey( e2, "modelscale_vec" ); - if ( !strEmpty( value ) ) { - sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] ); - } + vec3_t scale = { 1.f, 1.f, 1.f }; + if( !ENT_READKV( e2, "modelscale_vec", &scale ) ) + if( ENT_READKV( e2, "modelscale", &scale[0] ) ) + scale[1] = scale[2] = scale[0]; - /* get "angle" (yaw) or "angles" (pitch yaw roll) */ - angles[ 0 ] = angles[ 1 ] = angles[ 2 ] = 0.0f; - angles[ 2 ] = FloatForKey( e2, "angle" ); - value = ValueForKey( e2, "angles" ); - if ( !strEmpty( value ) ) { - sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ); - } + /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */ + const char *value; + vec3_t angles = { 0.f, 0.f, 0.f }; + if ( !ENT_READKV( e2, "angles", &value ) || + 3 != sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ) ) + ENT_READKV( e2, "angle", &angles[ 2 ] ); /* set transform matrix (thanks spog) */ + m4x4_t transform; m4x4_identity( transform ); m4x4_pivoted_transform_by_vec3( transform, origin, angles, eXYZ, scale, vec3_origin ); /* get shader remappings */ - remap = NULL; - for ( ep = e2->epairs; ep != NULL; ep = ep->next ) + remap_t *remap = NULL, *remap2; + for ( epair_t *ep = e2->epairs; ep != NULL; ep = ep->next ) { /* look for keys prefixed with "_remap" */ if ( !strEmptyOrNull( ep->key ) && !strEmptyOrNull( ep->value ) && @@ -1503,7 +1447,7 @@ void AddTriangleModels( entity_t *e ){ strcpy( remap->from, ep->value ); /* split the string */ - split = strchr( remap->from, ';' ); + char *split = strchr( remap->from, ';' ); if ( split == NULL ) { Sys_Warning( "Shader _remap key found in misc_model without a ; character: '%s'\n", remap->from ); } @@ -1536,99 +1480,55 @@ void AddTriangleModels( entity_t *e ){ } /* ydnar: cel shader support */ - value = ValueForKey( e2, "_celshader" ); - if ( strEmpty( value ) ) { - value = ValueForKey( &entities[ 0 ], "_celshader" ); - } - if ( !strEmpty( value ) ) { + shaderInfo_t *celShader; + if( ENT_READKV( e2, "_celshader", &value ) || + ENT_READKV( &entities[ 0 ], "_celshader", &value ) ){ + char shader[ MAX_QPATH ]; sprintf( shader, "textures/%s", value ); celShader = ShaderInfoForShader( shader ); } else{ - celShader = *globalCelShader ? ShaderInfoForShader( globalCelShader ) : NULL; + celShader = !strEmpty( globalCelShader ) ? ShaderInfoForShader( globalCelShader ) : NULL; } /* jal : entity based _samplesize */ - lightmapSampleSize = 0; - if ( !strEmpty( ValueForKey( e2, "_lightmapsamplesize" ) ) ) { - lightmapSampleSize = IntForKey( e2, "_lightmapsamplesize" ); - } - else if ( !strEmpty( ValueForKey( e2, "_samplesize" ) ) ) { - lightmapSampleSize = IntForKey( e2, "_samplesize" ); - } - else if ( !strEmpty( ValueForKey( e2, "_ss" ) ) ) { - lightmapSampleSize = IntForKey( e2, "_ss" ); - } - - if ( lightmapSampleSize < 0 ) { + int lightmapSampleSize = 0; + ENT_READKV( e2, "_lightmapsamplesize", &lightmapSampleSize ) || + ENT_READKV( e2, "_samplesize", &lightmapSampleSize ) || + ENT_READKV( e2, "_ss", &lightmapSampleSize ); + if ( lightmapSampleSize < 0 ) lightmapSampleSize = 0; - } - - if ( lightmapSampleSize > 0.0f ) { + if ( lightmapSampleSize > 0 ) Sys_Printf( "misc_model has lightmap sample size of %.d\n", lightmapSampleSize ); - } /* get lightmap scale */ - /* vortex: added _ls key (short name of lightmapscale) */ - lightmapScale = 0.0f; - if ( !strEmpty( ValueForKey( e2, "lightmapscale" ) ) || - !strEmpty( ValueForKey( e2, "_lightmapscale" ) ) || - !strEmpty( ValueForKey( e2, "_ls" ) ) ) { - lightmapScale = FloatForKey( e2, "lightmapscale" ); - if ( lightmapScale <= 0.0f ) { - lightmapScale = FloatForKey( e2, "_lightmapscale" ); - } - if ( lightmapScale <= 0.0f ) { - lightmapScale = FloatForKey( e2, "_ls" ); - } - if ( lightmapScale < 0.0f ) { - lightmapScale = 0.0f; - } - if ( lightmapScale > 0.0f ) { - Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale ); - } - } + float lightmapScale = 0.0f; + ENT_READKV( e2, "lightmapscale", &lightmapScale ) || + ENT_READKV( e2, "_lightmapscale", &lightmapScale ) || + ENT_READKV( e2, "_ls", &lightmapScale ); + if ( lightmapScale < 0.0f ) + lightmapScale = 0.0f; + else if ( lightmapScale > 0.0f ) + Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale ); /* jal : entity based _shadeangle */ - shadeAngle = 0.0f; - if ( !strEmpty( ValueForKey( e2, "_shadeangle" ) ) ) { - shadeAngle = FloatForKey( e2, "_shadeangle" ); - } - /* vortex' aliases */ - else if ( !strEmpty( ValueForKey( e2, "_smoothnormals" ) ) ) { - shadeAngle = FloatForKey( e2, "_smoothnormals" ); - } - else if ( !strEmpty( ValueForKey( e2, "_sn" ) ) ) { - shadeAngle = FloatForKey( e2, "_sn" ); - } - else if ( !strEmpty( ValueForKey( e2, "_sa" ) ) ) { - shadeAngle = FloatForKey( e2, "_sa" ); - } - else if ( !strEmpty( ValueForKey( e2, "_smooth" ) ) ) { - shadeAngle = FloatForKey( e2, "_smooth" ); - } - - if ( shadeAngle < 0.0f ) { + float shadeAngle = 0.0f; + ENT_READKV( e2, "_shadeangle", &shadeAngle ) || + ENT_READKV( e2, "_smoothnormals", &shadeAngle ) || /* vortex' aliases */ + ENT_READKV( e2, "_sn", &shadeAngle ) || + ENT_READKV( e2, "_sa", &shadeAngle ) || + ENT_READKV( e2, "_smooth", &shadeAngle ); + if ( shadeAngle < 0.0f ) shadeAngle = 0.0f; - } - - if ( shadeAngle > 0.0f ) { + else if ( shadeAngle > 0.0f ) Sys_Printf( "misc_model has shading angle of %.4f\n", shadeAngle ); - } - skin = 0; - if ( !strEmpty( ValueForKey( e2, "_skin" ) ) ) { - skin = IntForKey( e2, "_skin" ); - } - else if ( !strEmpty( ValueForKey( e2, "skin" ) ) ) { - skin = IntForKey( e2, "skin" ); - } + int skin = 0; + ENT_READKV( e2, "_skin", &skin ) || ENT_READKV( e2, "skin", &skin ); - clipDepth = clipDepthGlobal; - if ( !strEmpty( ValueForKey( e2, "_clipdepth" ) ) ) { - clipDepth = FloatForKey( e2, "_clipdepth" ); - Sys_Printf( "misc_model has autoclip depth of %.3f\n", clipDepth ); - } + float clipDepth = clipDepthGlobal; + if ( ENT_READKV( e2, "_clipdepth", &clipDepth ) ) + Sys_Printf( "misc_model %s has autoclip depth of %.3f\n", model, clipDepth ); /* insert the model */ diff --git a/tools/quake3/q3map2/portals.c b/tools/quake3/q3map2/portals.c index 025de9be..c7ff31b6 100644 --- a/tools/quake3/q3map2/portals.c +++ b/tools/quake3/q3map2/portals.c @@ -644,8 +644,6 @@ bool PlaceOccupant( node_t *headnode, vec3_t origin, entity_t *occupant, bool sk */ int FloodEntities( tree_t *tree ){ - int i, s; - vec3_t origin, offset, scale, angles; bool r, inside, skybox; node_t *headnode; entity_t *e, *tripped; @@ -660,12 +658,13 @@ int FloodEntities( tree_t *tree ){ tripped = NULL; c_floodedleafs = 0; - for ( i = 1; i < numEntities; i++ ) + for ( int i = 1; i < numEntities; i++ ) { /* get entity */ e = &entities[ i ]; /* get origin */ + vec3_t origin; GetVectorForKey( e, "origin", origin ); #if 0 //allow maps with only point entity@( 0, 0, 0 ); assuming that entities, containing no primitives are point ones /* as a special case, allow origin-less entities */ @@ -679,32 +678,25 @@ int FloodEntities( tree_t *tree ){ } /* handle skybox entities */ - value = ValueForKey( e, "classname" ); - if ( striEqual( value, "_skybox" ) ) { + if ( ent_class_is( e, "_skybox" ) ) { skybox = true; skyboxPresent = true; /* invert origin */ + vec3_t offset; VectorScale( origin, -1.0f, offset ); /* get scale */ - VectorSet( scale, 64.0f, 64.0f, 64.0f ); - value = ValueForKey( e, "_scale" ); - if ( !strEmpty( value ) ) { - s = sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] ); - if ( s == 1 ) { - scale[ 1 ] = scale[ 0 ]; - scale[ 2 ] = scale[ 0 ]; - } - } + vec3_t scale = { 64.0f, 64.0f, 64.0f }; + if( !ENT_READKV( e, "_scale", &scale ) ) + if( ENT_READKV( e, "_scale", &scale[0] ) ) + scale[1] = scale[2] = scale[0]; - /* get "angle" (yaw) or "angles" (pitch yaw roll) */ - VectorClear( angles ); - angles[ 2 ] = FloatForKey( e, "angle" ); - value = ValueForKey( e, "angles" ); - if ( !strEmpty( value ) ) { - sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ); - } + /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */ + vec3_t angles = { 0.f, 0.f, 0.f }; + if ( !ENT_READKV( e, "angles", &value ) || + 3 != sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ) ) + ENT_READKV( e, "angle", &angles[ 2 ] ); /* set transform matrix (thanks spog) */ m4x4_identity( skyboxTransform ); @@ -727,7 +719,7 @@ int FloodEntities( tree_t *tree ){ inside = true; } if ( !r ) { - Sys_FPrintf( SYS_WRN, "Entity %i (%s): Entity in solid\n", e->mapEntityNum, ValueForKey( e, "classname" ) ); + Sys_FPrintf( SYS_WRN, "Entity %i (%s): Entity in solid\n", e->mapEntityNum, ent_classname( e ) ); } else if ( tree->outside_node.occupied ) { if ( !tripped || tree->outside_node.occupied < tripcount ) { diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index bb9e54ea..a7668ad0 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1902,11 +1902,33 @@ void ParseEntities( void ); void UnparseEntities( void ); void PrintEntity( const entity_t *ent ); void SetKeyValue( entity_t *ent, const char *key, const char *value ); -bool KeyExists( const entity_t *ent, const char *key ); /* VorteX: check if key exists */ const char *ValueForKey( const entity_t *ent, const char *key ); +bool BoolForKey( const entity_t *ent, const char *key ); int IntForKey( const entity_t *ent, const char *key ); vec_t FloatForKey( const entity_t *ent, const char *key ); void GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec ); +/* entity: read key value generic macro + returns true on successful read + returns false and does not modify value otherwise */ +bool entity_read_bool( const entity_t *entity, const char *key, bool *bool_value ); +bool entity_read_int( const entity_t *entity, const char *key, int *int_value ); +bool entity_read_float( const entity_t *entity, const char *key, float *float_value ); // warning: float[3] may be passed here erroneously, if not written as &float[3] +bool entity_read_vector3( const entity_t *entity, const char *key, float (*vector3_value)[3] ); +bool entity_read_string( const entity_t *entity, const char *key, char (*string_value)[] ); // explicit pointer to array to avoid erroneous mix of char* and char** +bool entity_read_string_ptr( const entity_t *entity, const char *key, const char **string_ptr_value ); +#define ENT_READKV( entity, key, value_ptr ) _Generic( ( value_ptr ), \ + bool*: entity_read_bool, \ + int*: entity_read_int, \ + float*: entity_read_float, \ + float (*)[3]: entity_read_vector3,\ + char (*)[]: entity_read_string, \ + const char**: entity_read_string_ptr\ + )( entity, key, value_ptr ) + +const char *ent_classname( const entity_t *entity ); +bool ent_class_is( const entity_t *entity, const char *classname ); +bool ent_class_prefixed( const entity_t *entity, const char *prefix ); + entity_t *FindTargetEntity( const char *target ); void GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows ); void InjectCommandLine( char **argv, int beginArgs, int endArgs ); @@ -2193,8 +2215,8 @@ Q_EXTERN bool hint; /* ydnar */ Q_EXTERN char inbase[ MAX_QPATH ]; Q_EXTERN char globalCelShader[ MAX_QPATH ]; -Q_EXTERN float farPlaneDist; /* rr2do2, rf, mre, ydnar all contributed to this one... */ -Q_EXTERN int farPlaneDistMode; +Q_EXTERN float farPlaneDist Q_ASSIGN( 0.0f ); /* rr2do2, rf, mre, ydnar all contributed to this one... */ +Q_EXTERN int farPlaneDistMode Q_ASSIGN( 0 ); Q_EXTERN int numportals; Q_EXTERN int portalclusters; diff --git a/tools/quake3/q3map2/surface.c b/tools/quake3/q3map2/surface.c index f90ade4c..7b9a0b00 100644 --- a/tools/quake3/q3map2/surface.c +++ b/tools/quake3/q3map2/surface.c @@ -2596,13 +2596,10 @@ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){ int i, j; bspDrawSurface_t *out; int surfaceFlags, contentFlags; - int forcePatchMeta; /* vortex: _patchMeta support */ - forcePatchMeta = IntForKey( e, "_patchMeta" ); - if ( !forcePatchMeta ) { - forcePatchMeta = IntForKey( e, "patchMeta" ); - } + bool forcePatchMeta = false; + ENT_READKV( e, "_patchMeta", &forcePatchMeta ) || ENT_READKV( e, "patchMeta", &forcePatchMeta ); /* invert the surface if necessary */ if ( ds->backSide || ds->shaderInfo->invert ) { diff --git a/tools/quake3/q3map2/surface_meta.c b/tools/quake3/q3map2/surface_meta.c index e0c23582..6aae6337 100644 --- a/tools/quake3/q3map2/surface_meta.c +++ b/tools/quake3/q3map2/surface_meta.c @@ -291,29 +291,13 @@ static void SurfaceToMetaTriangles( mapDrawSurface_t *ds ){ */ void TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds ){ - int iterations, x, y, pw[ 5 ], r; + int x, y, pw[ 5 ], r; mapDrawSurface_t *dsNew; mesh_t src, *subdivided, *mesh; - bool forcePatchMeta; - int patchQuality; - int patchSubdivision; /* vortex: _patchMeta, _patchQuality, _patchSubdivide support */ - forcePatchMeta = IntForKey( e, "_patchMeta" ); - if ( !forcePatchMeta ) { - forcePatchMeta = IntForKey( e, "patchMeta" ); - } - patchQuality = IntForKey( e, "_patchQuality" ); - if ( !patchQuality ) { - patchQuality = IntForKey( e, "patchQuality" ); - } - if ( !patchQuality ) { - patchQuality = 1.0; - } - patchSubdivision = IntForKey( e, "_patchSubdivide" ); - if ( !patchSubdivision ) { - patchSubdivision = IntForKey( e, "patchSubdivide" ); - } + bool forcePatchMeta = false; + ENT_READKV( e, "_patchMeta", &forcePatchMeta ) || ENT_READKV( e, "patchMeta", &forcePatchMeta ); /* try to early out */ if ( ds->numVerts == 0 || ds->type != SURFACE_PATCH || ( !patchMeta && !forcePatchMeta ) ) { @@ -324,11 +308,16 @@ void TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds ){ src.height = ds->patchHeight; src.verts = ds->verts; //% subdivided = SubdivideMesh( src, 8, 999 ); - if ( patchSubdivision ) { + + int iterations; + int patchSubdivision; + if ( ENT_READKV( e, "_patchSubdivide", &patchSubdivision ) || ENT_READKV( e, "patchSubdivide", &patchSubdivision ) ) { iterations = IterationsForCurve( ds->longestCurve, patchSubdivision ); } else{ - iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions / patchQuality ); + int patchQuality = 0; + ENT_READKV( e, "_patchQuality", &patchQuality ) || ENT_READKV( e, "patchQuality", &patchQuality ); + iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions / ( patchQuality == 0? 1 : patchQuality ) ); } subdivided = SubdivideMesh2( src, iterations ); //% ds->maxIterations diff --git a/tools/quake3/q3map2/vis.c b/tools/quake3/q3map2/vis.c index 67c9b3f6..47dda26e 100644 --- a/tools/quake3/q3map2/vis.c +++ b/tools/quake3/q3map2/vis.c @@ -295,22 +295,16 @@ void CalcFastVis( void ){ */ void CalcVis( void ){ int i, minvis, maxvis; - const char *value; double mu, sigma, totalvis, totalvis2; /* ydnar: rr2do2's farplane code */ - farPlaneDist = 0.0f; - value = ValueForKey( &entities[ 0 ], "_farplanedist" ); /* proper '_' prefixed key */ - if ( strEmpty( value ) ) { - value = ValueForKey( &entities[ 0 ], "fogclip" ); /* wolf compatibility */ - } - if ( strEmpty( value ) ) { - value = ValueForKey( &entities[ 0 ], "distancecull" ); /* sof2 compatibility */ - } - if ( !strEmpty( value ) ) { + const char *value; + if( ENT_READKV( &entities[ 0 ], "_farplanedist", &value ) || /* proper '_' prefixed key */ + ENT_READKV( &entities[ 0 ], "fogclip", &value ) || /* wolf compatibility */ + ENT_READKV( &entities[ 0 ], "distancecull", &value ) ){ /* sof2 compatibility */ farPlaneDist = atof( value ); - farPlaneDistMode = value[strlen(value) - 1 ]; + farPlaneDistMode = value[strlen( value ) - 1 ]; if ( farPlaneDist != 0.0f ) { Sys_Printf( "farplane distance = %.1f\n", farPlaneDist ); if ( farPlaneDistMode == 'o' ) @@ -322,9 +316,6 @@ void CalcVis( void ){ } } - - - Sys_Printf( "\n--- BasePortalVis (%d) ---\n", numportals * 2 ); RunThreadsOnIndividual( numportals * 2, true, BasePortalVis ); diff --git a/tools/quake3/q3map2/writebsp.c b/tools/quake3/q3map2/writebsp.c index 2cd34a9b..d016c86b 100644 --- a/tools/quake3/q3map2/writebsp.c +++ b/tools/quake3/q3map2/writebsp.c @@ -283,8 +283,7 @@ void SetModelNumbers( void ){ */ void SetLightStyles( void ){ - int i, j, style, numStyles; - const char *t; + int i, j, numStyles; entity_t *e; epair_t *ep, *next; char value[ 10 ]; @@ -297,10 +296,7 @@ void SetLightStyles( void ){ } /* ydnar: determine if we keep lights in the bsp */ - if ( KeyExists( &entities[ 0 ], "_keepLights" ) ) { - t = ValueForKey( &entities[ 0 ], "_keepLights" ); - keepLights = ( t[ 0 ] == '1' ); - } + ENT_READKV( &entities[ 0 ], "_keepLights", &keepLights ); /* any light that is controlled (has a targetname) must have a unique style number generated for it */ numStyles = 0; @@ -308,12 +304,11 @@ void SetLightStyles( void ){ { e = &entities[ i ]; - t = ValueForKey( e, "classname" ); - if ( !striEqualPrefix( t, "light" ) ) { + if ( !ent_class_prefixed( e, "light" ) ) { continue; } - t = ValueForKey( e, "targetname" ); - if ( strEmpty( t ) ) { + const char *t; + if ( !ENT_READKV( e, "targetname", &t ) ) { /* ydnar: strip the light from the BSP file */ if ( !keepLights ) { ep = e->epairs; @@ -334,7 +329,7 @@ void SetLightStyles( void ){ } /* get existing style */ - style = IntForKey( e, "style" ); + const int style = IntForKey( e, "style" ); if ( style < LS_NORMAL || style > LS_NONE ) { Error( "Invalid lightstyle (%d) on entity %d", style, i ); }