diff --git a/tools/quake3/q3map2/autopk3.cpp b/tools/quake3/q3map2/autopk3.cpp index 2bf15c7d..2066ea2d 100644 --- a/tools/quake3/q3map2/autopk3.cpp +++ b/tools/quake3/q3map2/autopk3.cpp @@ -308,7 +308,7 @@ int pk3BSPMain( int argc, char **argv ){ } } - if ( ENT_READKV( &str, &entities[0], "music" ) ){ + if ( entities[ 0 ].read_keyvalue( str, "music" ) ){ FixDOSName( str ); DefaultExtension( str, ".wav" ); res2list( pk3Sounds, str ); @@ -316,25 +316,25 @@ int pk3BSPMain( int argc, char **argv ){ for ( const auto& e : entities ) { - if ( ENT_READKV( &str, &e, "noise" ) && str[0] != '*' ){ + if ( e.read_keyvalue( str, "noise" ) && str[0] != '*' ){ FixDOSName( str ); DefaultExtension( str, ".wav" ); res2list( pk3Sounds, str ); } - if ( ent_class_is( &e, "func_plat" ) ){ + if ( e.classname_is( "func_plat" ) ){ res2list( pk3Sounds, "sound/movers/plats/pt1_strt.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); } - if ( ent_class_is( &e, "target_push" ) ){ - if ( !( IntForKey( &e, "spawnflags") & 1 ) ){ + if ( e.classname_is( "target_push" ) ){ + if ( !( e.intForKey( "spawnflags") & 1 ) ){ res2list( pk3Sounds, "sound/misc/windfly.wav" ); } } - res2list( pk3Shaders, ValueForKey( &e, "targetShaderNewName" ) ); + res2list( pk3Shaders, e.valueForKey( "targetShaderNewName" ) ); - if ( ENT_READKV( &str, &e, "model2" ) ){ - Sys_Warning( "unhandled model2 key of %s: %s\n", ent_classname( &e ), str ); + if ( e.read_keyvalue( str, "model2" ) ){ + Sys_Warning( "unhandled model2 key of %s: %s\n", e.classname(), str ); } } @@ -981,7 +981,7 @@ int repackBSPMain( int argc, char **argv ){ res2list( pk3Shaders, str ); } } - if ( ENT_READKV( &str, &entities[0], "music" ) ){ + if ( entities[ 0 ].read_keyvalue( str, "music" ) ){ FixDOSName( str ); DefaultExtension( str, ".wav" ); res2list( pk3Sounds, str ); @@ -989,25 +989,25 @@ int repackBSPMain( int argc, char **argv ){ for ( const auto& e : entities ) { - if ( ENT_READKV( &str, &e, "noise" ) && str[0] != '*' ){ + if ( e.read_keyvalue( str, "noise" ) && str[0] != '*' ){ FixDOSName( str ); DefaultExtension( str, ".wav" ); res2list( pk3Sounds, str ); } - if ( ent_class_is( &e, "func_plat" ) ){ + if ( e.classname_is( "func_plat" ) ){ res2list( pk3Sounds, "sound/movers/plats/pt1_strt.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); } - if ( ent_class_is( &e, "target_push" ) ){ - if ( !( IntForKey( &e, "spawnflags") & 1 ) ){ + if ( e.classname_is( "target_push" ) ){ + if ( !( e.intForKey( "spawnflags") & 1 ) ){ res2list( pk3Sounds, "sound/misc/windfly.wav" ); } } - res2list( pk3Shaders, ValueForKey( &e, "targetShaderNewName" ) ); + res2list( pk3Shaders, e.valueForKey( "targetShaderNewName" ) ); - if ( ENT_READKV( &str, &e, "model2" ) ){ - Sys_Warning( "unhandled model2 key of %s: %s\n", ent_classname( &entities[i] ), str ); + if ( e.read_keyvalue( str, "model2" ) ){ + Sys_Warning( "unhandled model2 key of %s: %s\n", entities[i].classname(), str ); } } diff --git a/tools/quake3/q3map2/bsp.cpp b/tools/quake3/q3map2/bsp.cpp index b2f94682..9b76be72 100644 --- a/tools/quake3/q3map2/bsp.cpp +++ b/tools/quake3/q3map2/bsp.cpp @@ -105,16 +105,16 @@ static void ProcessAdvertisements( void ) { for ( const auto& e : entities ) { /* is an advertisement? */ - if ( ent_class_is( &e, "advertisement" ) ) { + if ( e.classname_is( "advertisement" ) ) { - modelKey = ValueForKey( &e, "model" ); + modelKey = e.valueForKey( "model" ); if ( strlen( modelKey ) > MAX_QPATH - 1 ) { Error( "Model Key for entity exceeds ad struct string length." ); } else { if ( numBSPAds < MAX_MAP_ADVERTISEMENTS ) { - bspAds[numBSPAds].cellId = IntForKey( &e, "cellId" ); + bspAds[numBSPAds].cellId = e.intForKey( "cellId" ); strncpy( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) ); modelKey++; @@ -180,12 +180,12 @@ static void SetCloneModelNumbers( void ){ } /* is this a clone? */ - if( ENT_READKV( &value, &entities[ i ], "_ins", "_instance", "_clone" ) ) + if( entities[ i ].read_keyvalue( value, "_ins", "_instance", "_clone" ) ) continue; /* add the model key */ sprintf( modelValue, "*%d", models ); - SetKeyValue( &entities[ i ], "model", modelValue ); + entities[ i ].setKeyValue( "model", modelValue ); /* increment model count */ models++; @@ -200,21 +200,21 @@ static void SetCloneModelNumbers( void ){ } /* isn't this a clone? */ - if( !ENT_READKV( &value, &entities[ i ], "_ins", "_instance", "_clone" ) ) + if( !entities[ i ].read_keyvalue( value, "_ins", "_instance", "_clone" ) ) continue; /* find an entity with matching clone name */ for ( std::size_t j = 0; j < entities.size(); ++j ) { /* is this a clone parent? */ - if ( !ENT_READKV( &value2, &entities[ j ], "_clonename" ) ) { + if ( !entities[ j ].read_keyvalue( value2, "_clonename" ) ) { continue; } /* do they match? */ if ( strEqual( value, value2 ) ) { /* get the model num */ - if ( !ENT_READKV( &value3, &entities[ j ], "model" ) ) { + if ( !entities[ j ].read_keyvalue( value3, "model" ) ) { Sys_Warning( "Cloned entity %s referenced entity without model\n", value2 ); continue; } @@ -222,7 +222,7 @@ static void SetCloneModelNumbers( void ){ /* add the model key */ sprintf( modelValue, "*%d", models ); - SetKeyValue( &entities[ i ], "model", modelValue ); + entities[ i ].setKeyValue( "model", modelValue ); /* nuke the brushes/patches for this entity (fixme: leak!) */ entities[ i ].brushes = NULL; @@ -297,7 +297,7 @@ void ProcessWorldModel( void ){ int leakStatus; /* sets integer blockSize from worldspawn "_blocksize" key if it exists */ - if( ENT_READKV( &value, &entities[ 0 ], "_blocksize", "blocksize", "chopsize" ) ) { /* "chopsize" : sof2 */ + if( entities[ 0 ].read_keyvalue( value, "_blocksize", "blocksize", "chopsize" ) ) { /* "chopsize" : sof2 */ /* scan 3 numbers */ const int s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] ); @@ -309,7 +309,7 @@ void ProcessWorldModel( void ){ Sys_Printf( "block size = { %d %d %d }\n", blockSize[ 0 ], blockSize[ 1 ], blockSize[ 2 ] ); /* sof2: ignore leaks? */ - const bool ignoreLeaks = BoolForKey( &entities[ 0 ], "_ignoreleaks", "ignoreleaks" ); + const bool ignoreLeaks = entities[ 0 ].boolForKey( "_ignoreleaks", "ignoreleaks" ); /* begin worldspawn model */ BeginModel(); @@ -440,7 +440,7 @@ void ProcessWorldModel( void ){ } /* ydnar: fog hull */ - if ( ENT_READKV( &value, &entities[ 0 ], "_foghull" ) ) { + if ( entities[ 0 ].read_keyvalue( value, "_foghull" ) ) { const auto shader = String64()( "textures/", value ); MakeFogHullSurfs( e, tree, shader ); } @@ -453,21 +453,21 @@ void ProcessWorldModel( void ){ vec3_t origin, targetOrigin, normal, color; /* get light */ - if ( ent_class_is( &light, "light" ) ) { + if ( light.classname_is( "light" ) ) { /* get flare shader */ const char *flareShader = NULL; - if ( ENT_READKV( &flareShader, &light, "_flareshader" ) || BoolForKey( &light, "_flare" ) ) { + if ( light.read_keyvalue( flareShader, "_flareshader" ) || light.boolForKey( "_flare" ) ) { /* get specifics */ - GetVectorForKey( &light, "origin", origin ); - GetVectorForKey( &light, "_color", color ); - const int lightStyle = IntForKey( &light, "_style", "style" ); + light.vectorForKey( "origin", origin ); + light.vectorForKey( "_color", color ); + const int lightStyle = light.intForKey( "_style", "style" ); /* handle directional spotlights */ - if ( ENT_READKV( &value, &light, "target" ) ) { + if ( light.read_keyvalue( value, "target" ) ) { /* get target light */ target = FindTargetEntity( value ); if ( target != NULL ) { - GetVectorForKey( target, "origin", targetOrigin ); + target->vectorForKey( "origin", targetOrigin ); VectorSubtract( targetOrigin, origin, normal ); VectorNormalize( normal, normal ); } @@ -659,9 +659,9 @@ void OnlyEnts( void ){ LoadBSPFile( out ); ParseEntities(); - 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 ) ); + strcpyQ( save_cmdline, entities[ 0 ].valueForKey( "_q3map2_cmdline" ), sizeof( save_cmdline ) ); + strcpyQ( save_version, entities[ 0 ].valueForKey( "_q3map2_version" ), sizeof( save_version ) ); + strcpyQ( save_gridsize, entities[ 0 ].valueForKey( "gridsize" ), sizeof( save_gridsize ) ); entities.clear(); @@ -671,13 +671,13 @@ void OnlyEnts( void ){ SetLightStyles(); if ( *save_cmdline ) { - SetKeyValue( &entities[0], "_q3map2_cmdline", save_cmdline ); + entities[0].setKeyValue( "_q3map2_cmdline", save_cmdline ); } if ( *save_version ) { - SetKeyValue( &entities[0], "_q3map2_version", save_version ); + entities[0].setKeyValue( "_q3map2_version", save_version ); } if ( *save_gridsize ) { - SetKeyValue( &entities[0], "gridsize", save_gridsize ); + entities[0].setKeyValue( "gridsize", save_gridsize ); } numBSPEntities = entities.size(); diff --git a/tools/quake3/q3map2/bspfile_abstract.cpp b/tools/quake3/q3map2/bspfile_abstract.cpp index 0d569d91..5086a6f2 100644 --- a/tools/quake3/q3map2/bspfile_abstract.cpp +++ b/tools/quake3/q3map2/bspfile_abstract.cpp @@ -601,7 +601,7 @@ void InjectCommandLine( char **argv, int beginArgs, int endArgs ){ if ( nocmdline ){ return; } - if ( ENT_READKV( &inpos, &entities[0], "_q3map2_cmdline" ) ) { // read previousCommandLine + if ( entities[ 0 ].read_keyvalue( inpos, "_q3map2_cmdline" ) ) { // read previousCommandLine while ( outpos != sentinel && *inpos ) *outpos++ = *inpos++; if ( outpos != sentinel ) { @@ -625,8 +625,8 @@ void InjectCommandLine( char **argv, int beginArgs, int endArgs ){ } *outpos = 0; - SetKeyValue( &entities[0], "_q3map2_cmdline", newCommandLine ); - SetKeyValue( &entities[0], "_q3map2_version", Q3MAP_VERSION ); + entities[0].setKeyValue( "_q3map2_cmdline", newCommandLine ); + entities[0].setKeyValue( "_q3map2_version", Q3MAP_VERSION ); } /* @@ -663,7 +663,7 @@ void UnparseEntities( void ){ continue; /* ent got removed */ } /* ydnar: certain entities get stripped from bsp file */ - const char *classname = ent_classname( e ); + const char *classname = e->classname(); if ( striEqual( classname, "misc_model" ) || striEqual( classname, "_decal" ) || striEqual( classname, "_skybox" ) ) { @@ -719,13 +719,13 @@ void PrintEntity( const entity_t *ent ){ /* - SetKeyValue() + setKeyValue() sets an epair in an entity */ -void SetKeyValue( entity_t *ent, const char *key, const char *value ){ +void entity_t::setKeyValue( const char *key, const char *value ){ /* check for existing epair */ - for ( auto& ep : ent->epairs ) + for ( auto& ep : epairs ) { if ( EPAIR_EQUAL( ep.key.c_str(), key ) ) { ep.value = value; @@ -734,23 +734,18 @@ void SetKeyValue( entity_t *ent, const char *key, const char *value ){ } /* create new epair */ - ent->epairs.emplace_back( epair_t{ key, value } ); + epairs.emplace_back( epair_t{ key, value } ); } /* - ValueForKey() + valueForKey() gets the value for an entity key */ -const char *ValueForKey( const entity_t *ent, const char *key ){ - /* dummy check */ - if ( ent == NULL ) { - return ""; - } - +const char *entity_t::valueForKey( const char *key ) const { /* walk epair list */ - for ( const auto& ep : ent->epairs ) + for ( const auto& ep : epairs ) { if ( EPAIR_EQUAL( ep.key.c_str(), key ) ) { return ep.value.c_str(); @@ -761,191 +756,73 @@ const char *ValueForKey( const entity_t *ent, const char *key ){ return ""; } -bool BoolForKey_impl( const entity_t *ent, ... ){ - va_list argptr; - va_start( argptr, ent ); - const char* key; - while( ( key = va_arg( argptr, const char* ) ) != NULL ){ - const char* value = ValueForKey( ent, key ); +bool entity_t::read_keyvalue_( bool &bool_value, std::initializer_list&& keys ) const { + for( const char* key : keys ){ + const char* value = valueForKey( key ); if( !strEmpty( value ) ){ - va_end( argptr ); - return value[0] == '1'; - } - } - va_end( argptr ); - return false; -} - -/* - IntForKey() - gets the integer point value for an entity key - */ - -int IntForKey_impl( const entity_t *ent, ... ){ - va_list argptr; - va_start( argptr, ent ); - const char* key; - while( ( key = va_arg( argptr, const char* ) ) != NULL ){ - const char* value = ValueForKey( ent, key ); - if( !strEmpty( value ) ){ - va_end( argptr ); - return atoi( value ); - } - } - va_end( argptr ); - return 0; -} - - - -/* - FloatForKey() - gets the floating point value for an entity key - */ - -vec_t FloatForKey_impl( const entity_t *ent, ... ){ - va_list argptr; - va_start( argptr, ent ); - const char* key; - while( ( key = va_arg( argptr, const char* ) ) != NULL ){ - const char* value = ValueForKey( ent, key ); - if( !strEmpty( value ) ){ - va_end( argptr ); - return atof( value ); - } - } - va_end( argptr ); - return 0; -} - - - -/* - GetVectorForKey() - gets a 3-element vector value for an entity key - */ - -void GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec ){ - /* scanf into doubles, then assign, so it is vec_t size independent */ - 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_keyvalue( bool *bool_value, const entity_t *entity, ... ){ - va_list argptr; - va_start( argptr, entity ); - const char* key; - while( ( key = va_arg( argptr, const char* ) ) != NULL ){ - const char* value = ValueForKey( entity, key ); - if( !strEmpty( value ) ){ - *bool_value = ( value[0] == '1' ); - va_end( argptr ); + bool_value = ( value[0] == '1' ); return true; } } - va_end( argptr ); return false; } -bool entity_read_keyvalue( int *int_value, const entity_t *entity, ... ){ - va_list argptr; - va_start( argptr, entity ); - const char* key; - while( ( key = va_arg( argptr, const char* ) ) != NULL ){ - const char* value = ValueForKey( entity, key ); +bool entity_t::read_keyvalue_( int &int_value, std::initializer_list&& keys ) const { + for( const char* key : keys ){ + const char* value = valueForKey( key ); if( !strEmpty( value ) ){ - *int_value = atoi( value ); - va_end( argptr ); + int_value = atoi( value ); return true; } } - va_end( argptr ); return false; } -bool entity_read_keyvalue( float *float_value, const entity_t *entity, ... ){ - va_list argptr; - va_start( argptr, entity ); - const char* key; - while( ( key = va_arg( argptr, const char* ) ) != NULL ){ - const char* value = ValueForKey( entity, key ); +bool entity_t::read_keyvalue_( float &float_value, std::initializer_list&& keys ) const { + for( const char* key : keys ){ + const char* value = valueForKey( key ); if( !strEmpty( value ) ){ - *float_value = atof( value ); - va_end( argptr ); + float_value = atof( value ); return true; } } - va_end( argptr ); return false; } -bool entity_read_keyvalue( float (*vector3_value)[3], const entity_t *entity, ... ){ - va_list argptr; - va_start( argptr, entity ); - const char* key; - while( ( key = va_arg( argptr, const char* ) ) != NULL ){ - const char* value = ValueForKey( entity, key ); +bool entity_t::read_keyvalue_( float (&vector3_value)[3], std::initializer_list&& keys ) const { + for( const char* key : keys ){ + const char* value = valueForKey( 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; - va_end( argptr ); + vector3_value[0] = v0; + vector3_value[1] = v1; + vector3_value[2] = v2; return true; } } } - va_end( argptr ); return false; } -bool entity_read_keyvalue( char (*string_value)[1024], const entity_t *entity, ... ){ - va_list argptr; - va_start( argptr, entity ); - const char* key; - while( ( key = va_arg( argptr, const char* ) ) != NULL ){ - const char* value = ValueForKey( entity, key ); +bool entity_t::read_keyvalue_( char (&string_value)[1024], std::initializer_list&& keys ) const { + for( const char* key : keys ){ + const char* value = valueForKey( key ); if( !strEmpty( value ) ){ - strcpy( *string_value, value ); - va_end( argptr ); + strcpy( string_value, value ); return true; } } - va_end( argptr ); return false; } -bool entity_read_keyvalue( const char **string_ptr_value, const entity_t *entity, ... ){ - va_list argptr; - va_start( argptr, entity ); - const char* key; - while( ( key = va_arg( argptr, const char* ) ) != NULL ){ - const char* value = ValueForKey( entity, key ); +bool entity_t::read_keyvalue_( const char *&string_ptr_value, std::initializer_list&& keys ) const { + for( const char* key : keys ){ + const char* value = valueForKey( key ); if( !strEmpty( value ) ){ - *string_ptr_value = value; - va_end( argptr ); + string_ptr_value = value; return true; } } - va_end( argptr ); 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 ); -} - - /* FindTargetEntity() finds an entity target @@ -955,7 +832,7 @@ entity_t *FindTargetEntity( const char *target ){ /* walk entity list */ for ( auto& e : entities ) { - if ( strEqual( ValueForKey( &e, "targetname" ), target ) ) { + if ( strEqual( e.valueForKey( "targetname" ), target ) ) { return &e; } } @@ -975,20 +852,20 @@ entity_t *FindTargetEntity( const char *target ){ void GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows ){ /* get cast shadows */ if ( castShadows != NULL ) { - ENT_READKV( castShadows, ent, "_castShadows", "_cs" ) || - ENT_READKV( castShadows, ent2, "_castShadows", "_cs" ); + ( ent != NULL && ent->read_keyvalue( *castShadows, "_castShadows", "_cs" ) ) || + ( ent2 != NULL && ent2->read_keyvalue( *castShadows, "_castShadows", "_cs" ) ); } /* receive */ if ( recvShadows != NULL ) { - ENT_READKV( recvShadows, ent, "_receiveShadows", "_rs" ) || - ENT_READKV( recvShadows, ent2, "_receiveShadows", "_rs" ); + ( ent != NULL && ent->read_keyvalue( *recvShadows, "_receiveShadows", "_rs" ) ) || + ( ent2 != NULL && ent2->read_keyvalue( *recvShadows, "_receiveShadows", "_rs" ) ); } /* vortex: game-specific default entity keys */ if ( striEqual( game->magic, "dq" ) || striEqual( game->magic, "prophecy" ) ) { /* vortex: deluxe quake default shadow flags */ - if ( ent_class_is( ent, "func_wall" ) ) { + if ( ent->classname_is( "func_wall" ) ) { if ( recvShadows != NULL ) { *recvShadows = 1; } diff --git a/tools/quake3/q3map2/convert_ase.cpp b/tools/quake3/q3map2/convert_ase.cpp index 3b16d5cc..de7475ed 100644 --- a/tools/quake3/q3map2/convert_ase.cpp +++ b/tools/quake3/q3map2/convert_ase.cpp @@ -402,7 +402,7 @@ int ConvertBSPToASE( char *bspName ){ } else { - const char *key = ValueForKey( e, "model" ); + const char *key = e->valueForKey( "model" ); if ( key[ 0 ] != '*' ) { continue; } @@ -412,7 +412,7 @@ int ConvertBSPToASE( char *bspName ){ /* get entity origin */ vec3_t origin; - GetVectorForKey( e, "origin", origin ); + e->vectorForKey( "origin", origin ); /* convert model */ ConvertModel( f, model, modelNum, origin, lmIndices ); diff --git a/tools/quake3/q3map2/convert_bsp.cpp b/tools/quake3/q3map2/convert_bsp.cpp index 104421f5..661864a9 100644 --- a/tools/quake3/q3map2/convert_bsp.cpp +++ b/tools/quake3/q3map2/convert_bsp.cpp @@ -465,21 +465,21 @@ int ScaleBSPMain( int argc, char **argv ){ for ( auto& e : entities ) { /* scale origin */ - if ( ENT_READKV( &vec, &e, "origin" ) ) { - if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { + if ( e.read_keyvalue( vec, "origin" ) ) { + if ( entities[i].classname_prefixed( "info_player_" ) ) { vec[2] += spawn_ref; } vec[0] *= scale[0]; vec[1] *= scale[1]; vec[2] *= scale[2]; - if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { + if ( entities[i].classname_prefixed( "info_player_" ) ) { vec[2] -= spawn_ref; } sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); - SetKeyValue( &e, "origin", str ); + e.setKeyValue( "origin", str ); } - a = FloatForKey( &e, "angle" ); + a = e.floatForKey( "angle" ); if ( a == -1 || a == -2 ) { // z scale axis = 2; } @@ -491,17 +491,17 @@ int ScaleBSPMain( int argc, char **argv ){ } /* scale door lip */ - if ( ENT_READKV( &f, &e, "lip" ) ) { + if ( e.read_keyvalue( f, "lip" ) ) { f *= scale[axis]; sprintf( str, "%f", f ); - SetKeyValue( &e, "lip", str ); + e.setKeyValue( "lip", str ); } /* scale plat height */ - if ( ENT_READKV( &f, &e, "height" ) ) { + if ( e.read_keyvalue( f, "height" ) ) { f *= scale[2]; sprintf( str, "%f", f ); - SetKeyValue( &e, "height", str ); + e.setKeyValue( "height", str ); } // TODO maybe allow a definition file for entities to specify which values are scaled how? @@ -617,14 +617,14 @@ int ScaleBSPMain( int argc, char **argv ){ } /* scale gridsize */ - if ( !ENT_READKV( &vec, &entities[ 0 ], "gridsize" ) ) { + if ( !entities[ 0 ].read_keyvalue( vec, "gridsize" ) ) { VectorCopy( gridSize, vec ); } vec[0] *= scale[0]; vec[1] *= scale[1]; vec[2] *= scale[2]; sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); - SetKeyValue( &entities[ 0 ], "gridsize", str ); + entities[ 0 ].setKeyValue( "gridsize", str ); /* inject command line parameters */ InjectCommandLine( argv, 0, argc - 1 ); @@ -700,18 +700,18 @@ int ShiftBSPMain( int argc, char **argv ){ for ( auto& e : entities ) { /* shift origin */ - if ( ENT_READKV( &vec, &e, "origin" ) ) { - if ( ent_class_prefixed( &e, "info_player_" ) ) { + if ( e.read_keyvalue( vec, "origin" ) ) { + if ( e.classname_prefixed( "info_player_" ) ) { vec[2] += spawn_ref; } vec[0] += scale[0]; vec[1] += scale[1]; vec[2] += scale[2]; - if ( ent_class_prefixed( &e, "info_player_" ) ) { + if ( e.classname_prefixed( "info_player_" ) ) { vec[2] -= spawn_ref; } sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); - SetKeyValue( &e, "origin", str ); + e.setKeyValue( "origin", str ); } } @@ -782,14 +782,14 @@ int ShiftBSPMain( int argc, char **argv ){ /* scale gridsize */ /* - if ( !ENT_READKV( &vec, &entities[ 0 ], "gridsize" ) ) { + if ( !entities[ 0 ].read_keyvalue( vec, "gridsize" ) ) { VectorCopy( gridSize, vec ); } vec[0] *= scale[0]; vec[1] *= scale[1]; vec[2] *= scale[2]; sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); - SetKeyValue( &entities[ 0 ], "gridsize", str ); + entities[ 0 ].setKeyValue( "gridsize", str ); */ /* inject command line parameters */ InjectCommandLine( argv, 0, argc - 1 ); @@ -835,7 +835,7 @@ void PseudoCompileBSP( bool need_tree ){ if ( i != 0 ) { sprintf( modelValue, "*%d", models++ ); - SetKeyValue( entity, "model", modelValue ); + entity->setKeyValue( "model", modelValue ); } /* process the model */ diff --git a/tools/quake3/q3map2/convert_map.cpp b/tools/quake3/q3map2/convert_map.cpp index 34da5549..9a5a00f6 100644 --- a/tools/quake3/q3map2/convert_map.cpp +++ b/tools/quake3/q3map2/convert_map.cpp @@ -1035,7 +1035,7 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){ } else { - value = ValueForKey( e, "model" ); + value = e->valueForKey( "model" ); if ( value[ 0 ] == '*' ) { modelNum = atoi( value + 1 ); } @@ -1055,7 +1055,7 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){ /* get entity origin */ vec3_t origin; - GetVectorForKey( e, "origin", origin ); + e->vectorForKey( "origin", origin ); /* convert model */ ConvertModel( f, model, modelNum, origin, brushPrimitives ); diff --git a/tools/quake3/q3map2/convert_obj.cpp b/tools/quake3/q3map2/convert_obj.cpp index 042f3504..ad9015b7 100644 --- a/tools/quake3/q3map2/convert_obj.cpp +++ b/tools/quake3/q3map2/convert_obj.cpp @@ -360,7 +360,7 @@ int ConvertBSPToOBJ( char *bspName ){ } else { - key = ValueForKey( e, "model" ); + key = e->valueForKey( "model" ); if ( key[ 0 ] != '*' ) { continue; } @@ -370,7 +370,7 @@ int ConvertBSPToOBJ( char *bspName ){ /* get entity origin */ vec3_t origin; - GetVectorForKey( e, "origin", origin ); + e->vectorForKey( "origin", origin ); /* convert model */ ConvertModelToOBJ( f, model, modelNum, origin, lmIndices ); diff --git a/tools/quake3/q3map2/decals.cpp b/tools/quake3/q3map2/decals.cpp index 611376d1..e3872509 100644 --- a/tools/quake3/q3map2/decals.cpp +++ b/tools/quake3/q3map2/decals.cpp @@ -415,7 +415,7 @@ void ProcessDecals( void ){ /* walk entity list */ for ( auto& e : entities ) { - if ( !ent_class_is( &e, "_decal" ) ) { + if ( !e.classname_is( "_decal" ) ) { continue; } @@ -427,7 +427,7 @@ void ProcessDecals( void ){ } /* find target */ - e2 = FindTargetEntity( ValueForKey( &e, "target" ) ); + e2 = FindTargetEntity( e.valueForKey( "target" ) ); /* no target? */ if ( e2 == NULL ) { diff --git a/tools/quake3/q3map2/fog.cpp b/tools/quake3/q3map2/fog.cpp index 64fd5f7f..78849fc2 100644 --- a/tools/quake3/q3map2/fog.cpp +++ b/tools/quake3/q3map2/fog.cpp @@ -763,7 +763,7 @@ void CreateMapFogs( void ){ /* ydnar: global fog */ const char *globalFog; - if ( ENT_READKV( &globalFog, &entities[ 0 ], "_fog", "fog" ) ) { + if ( entities[ 0 ].read_keyvalue( globalFog, "_fog", "fog" ) ) { /* 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/leakfile.cpp b/tools/quake3/q3map2/leakfile.cpp index 38171d8d..da4dbc5f 100644 --- a/tools/quake3/q3map2/leakfile.cpp +++ b/tools/quake3/q3map2/leakfile.cpp @@ -108,7 +108,7 @@ xmlNodePtr LeakFile( tree_t *tree ){ count++; } // add the occupant center - GetVectorForKey( node->occupant, "origin", mid ); + node->occupant->vectorForKey( "origin", mid ); fprintf( linefile, "%f %f %f\n", mid[0], mid[1], mid[2] ); point = xml_NodeForVec( mid ); diff --git a/tools/quake3/q3map2/light.cpp b/tools/quake3/q3map2/light.cpp index fecf141b..500adcfe 100644 --- a/tools/quake3/q3map2/light.cpp +++ b/tools/quake3/q3map2/light.cpp @@ -222,10 +222,10 @@ void CreateEntityLights( void ){ e = &entities[ i ]; /* ydnar: check for lightJunior */ bool junior; - if ( ent_class_is( e, "lightJunior" ) ) { + if ( e->classname_is( "lightJunior" ) ) { junior = true; } - else if ( ent_class_prefixed( e, "light" ) ) { + else if ( e->classname_prefixed( "light" ) ) { junior = false; } else{ @@ -233,7 +233,7 @@ void CreateEntityLights( void ){ } /* lights with target names (and therefore styles) are only parsed from BSP */ - if ( !strEmpty( ValueForKey( e, "targetname" ) ) && i >= numBSPEntities ) { + if ( !strEmpty( e->valueForKey( "targetname" ) ) && i >= numBSPEntities ) { continue; } @@ -244,7 +244,7 @@ void CreateEntityLights( void ){ lights = light; /* handle spawnflags */ - const int spawnflags = IntForKey( e, "spawnflags" ); + const int spawnflags = e->intForKey( "spawnflags" ); LightFlags flags; /* ydnar: quake 3+ light behavior */ @@ -316,55 +316,55 @@ void CreateEntityLights( void ){ /* ydnar: set fade key (from wolf) */ light->fade = 1.0f; if ( light->flags & LightFlags::AttenLinear ) { - light->fade = FloatForKey( e, "fade" ); + light->fade = e->floatForKey( "fade" ); if ( light->fade == 0.0f ) { light->fade = 1.0f; } } /* ydnar: set angle scaling (from vlight) */ - light->angleScale = FloatForKey( e, "_anglescale" ); + light->angleScale = e->floatForKey( "_anglescale" ); if ( light->angleScale != 0.0f ) { light->flags |= LightFlags::AttenAngle; } /* set origin */ - GetVectorForKey( e, "origin", light->origin ); - ENT_READKV( &light->style, e, "_style", "style" ); + e->vectorForKey( "origin", light->origin ); + e->read_keyvalue( light->style, "_style", "style" ); if ( light->style < LS_NORMAL || light->style >= LS_NONE ) { Error( "Invalid lightstyle (%d) on entity %zu", light->style, i ); } /* set light intensity */ float intensity = 300.f; - ENT_READKV( &intensity, e, "_light", "light" ); + e->read_keyvalue( intensity, "_light", "light" ); if ( intensity == 0.0f ) { intensity = 300.0f; } { /* ydnar: set light scale (sof2) */ float scale; - if( ENT_READKV( &scale, e, "scale" ) && scale != 0.f ) + if( e->read_keyvalue( scale, "scale" ) && scale != 0.f ) intensity *= scale; } /* ydnar: get deviance and samples */ - float deviance = FloatForKey( e, "_deviance", "_deviation", "_jitter" ); + float deviance = e->floatForKey( "_deviance", "_deviation", "_jitter" ); if ( deviance < 0.f ) deviance = 0.f; - int numSamples = IntForKey( e, "_samples" ); + int numSamples = e->intForKey( "_samples" ); if ( numSamples < 1 ) numSamples = 1; intensity /= numSamples; { /* ydnar: get filter radius */ - const float filterRadius = FloatForKey( e, "_filterradius", "_filteradius", "_filter" ); + const float filterRadius = e->floatForKey( "_filterradius", "_filteradius", "_filter" ); light->filterRadius = filterRadius < 0.f? 0.f : filterRadius; } /* set light color */ - if ( ENT_READKV( &light->color, e, "_color" ) ) { + if ( e->read_keyvalue( light->color, "_color" ) ) { if ( colorsRGB ) { light->color[0] = Image_LinearFloatFromsRGBFloat( light->color[0] ); light->color[1] = Image_LinearFloatFromsRGBFloat( light->color[1] ); @@ -379,7 +379,7 @@ void CreateEntityLights( void ){ } - if( !ENT_READKV( &light->extraDist, e, "_extradist" ) ) + if( !e->read_keyvalue( light->extraDist, "_extradist" ) ) light->extraDist = extraDist; light->photons = intensity; @@ -391,7 +391,7 @@ void CreateEntityLights( void ){ /* lights with a target will be spotlights */ const char *target; - if ( ENT_READKV( &target, e, "target" ) ) { + if ( e->read_keyvalue( target, "target" ) ) { /* get target */ e2 = FindTargetEntity( target ); if ( e2 == NULL ) { @@ -407,10 +407,10 @@ void CreateEntityLights( void ){ /* make a spotlight */ vec3_t dest; - GetVectorForKey( e2, "origin", dest ); + e2->vectorForKey( "origin", dest ); VectorSubtract( dest, light->origin, light->normal ); float dist = VectorNormalize( light->normal, light->normal ); - float radius = FloatForKey( e, "radius" ); + float radius = e->floatForKey( "radius" ); if ( !radius ) { radius = 64; } @@ -426,7 +426,7 @@ void CreateEntityLights( void ){ light->fade = 1.0f; /* ydnar: is this a sun? */ - if ( BoolForKey( e, "_sun" ) ) { + if ( e->boolForKey( "_sun" ) ) { /* not a spot light */ numSpotLights--; @@ -509,7 +509,7 @@ void CreateSurfaceLights( void ){ /* get sun shader supressor */ - const bool nss = BoolForKey( &entities[ 0 ], "_noshadersun" ); + const bool nss = entities[ 0 ].boolForKey( "_noshadersun" ); /* walk the list of surfaces */ for ( i = 0; i < numBSPDrawSurfaces; i++ ) @@ -614,7 +614,7 @@ void SetEntityOrigins( void ){ for ( const auto& e : entities ) { /* get entity and model */ - key = ValueForKey( &e, "model" ); + key = e.valueForKey( "model" ); if ( key[ 0 ] != '*' ) { continue; } @@ -623,7 +623,7 @@ void SetEntityOrigins( void ){ /* get entity origin */ vec3_t origin = { 0.f, 0.f, 0.f }; - if ( !ENT_READKV( &origin, &e, "origin" ) ) { + if ( !e.read_keyvalue( origin, "origin" ) ) { continue; } @@ -1766,7 +1766,7 @@ void SetupGrid( void ){ } /* ydnar: set grid size */ - ENT_READKV( &gridSize, &entities[ 0 ], "gridsize" ); + entities[ 0 ].read_keyvalue( gridSize, "gridsize" ); /* quantize it */ VectorCopy( gridSize, oldGridSize ); @@ -1801,7 +1801,7 @@ void SetupGrid( void ){ /* different? */ if ( !VectorCompare( gridSize, oldGridSize ) ) { sprintf( temp, "%.0f %.0f %.0f", gridSize[ 0 ], gridSize[ 1 ], gridSize[ 2 ] ); - SetKeyValue( &entities[ 0 ], "gridsize", (const char*) temp ); + entities[ 0 ].setKeyValue( "gridsize", (const char*) temp ); Sys_FPrintf( SYS_VRB, "Storing adjusted grid size\n" ); } @@ -1854,7 +1854,7 @@ void LightWorld( bool fastAllocate ){ } /* find the optional minimum lighting values */ - GetVectorForKey( &entities[ 0 ], "_color", color ); + entities[ 0 ].vectorForKey( "_color", color ); if ( colorsRGB ) { color[0] = Image_LinearFloatFromsRGBFloat( color[0] ); color[1] = Image_LinearFloatFromsRGBFloat( color[1] ); @@ -1865,21 +1865,21 @@ void LightWorld( bool fastAllocate ){ } /* ambient */ - f = FloatForKey( &entities[ 0 ], "_ambient", "ambient" ); + f = entities[ 0 ].floatForKey( "_ambient", "ambient" ); VectorScale( color, f, ambientColor ); /* minvertexlight */ - if ( ( minVertex = ENT_READKV( &f, &entities[ 0 ], "_minvertexlight" ) ) ) { + if ( ( minVertex = entities[ 0 ].read_keyvalue( f, "_minvertexlight" ) ) ) { VectorScale( color, f, minVertexLight ); } /* mingridlight */ - if ( ( minGrid = ENT_READKV( &f, &entities[ 0 ], "_mingridlight" ) ) ) { + if ( ( minGrid = entities[ 0 ].read_keyvalue( f, "_mingridlight" ) ) ) { VectorScale( color, f, minGridLight ); } /* minlight */ - if ( ENT_READKV( &f, &entities[ 0 ], "_minlight" ) ) { + if ( entities[ 0 ].read_keyvalue( f, "_minlight" ) ) { VectorScale( color, f, minLight ); if ( !minVertex ) VectorScale( color, f, minVertexLight ); @@ -1888,7 +1888,7 @@ void LightWorld( bool fastAllocate ){ } /* maxlight */ - if ( ENT_READKV( &f, &entities[ 0 ], "_maxlight" ) ) { + if ( entities[ 0 ].read_keyvalue( f, "_maxlight" ) ) { maxLight = f > 255? 255 : f < 0? 0 : f; } @@ -2961,7 +2961,7 @@ int LightMain( int argc, char **argv ){ InjectCommandLine( argv, 0, argc - 1 ); /* load map file */ - if ( !BoolForKey( &entities[ 0 ], "_keepLights" ) ) { + if ( !entities[ 0 ].boolForKey( "_keepLights" ) ) { LoadMapFile( name, true, false ); } diff --git a/tools/quake3/q3map2/light_trace.cpp b/tools/quake3/q3map2/light_trace.cpp index 9efae3a2..0234677f 100644 --- a/tools/quake3/q3map2/light_trace.cpp +++ b/tools/quake3/q3map2/light_trace.cpp @@ -1126,19 +1126,19 @@ static void PopulateTraceNodes( void ){ /* get entity origin */ vec3_t origin; - GetVectorForKey( e, "origin", origin ); + e->vectorForKey( "origin", origin ); /* get scale */ vec3_t scale = { 1.f, 1.f, 1.f }; - if( !ENT_READKV( &scale, e, "modelscale_vec" ) ) - if( ENT_READKV( &scale[0], e, "modelscale" ) ) + if( !e->read_keyvalue( scale, "modelscale_vec" ) ) + if( e->read_keyvalue( scale[0], "modelscale" ) ) scale[1] = scale[2] = scale[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( &value, e, "angles" ) || + if ( !e->read_keyvalue( value, "angles" ) || 3 != sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ) ) - ENT_READKV( &angles[ 2 ], e, "angle" ); + e->read_keyvalue( angles[ 2 ], "angle" ); /* set transform matrix (thanks spog) */ m4x4_identity( transform ); @@ -1150,7 +1150,7 @@ static void PopulateTraceNodes( void ){ //% m4x4_transpose( transform ); /* get model */ - value = ValueForKey( e, "model" ); + value = e->valueForKey( "model" ); /* switch on model type */ switch ( value[ 0 ] ) @@ -1171,7 +1171,7 @@ static void PopulateTraceNodes( void ){ /* external model */ default: { - model = LoadModel( value, IntForKey( e, "_frame", "frame" ) ); + model = LoadModel( value, e->intForKey( "_frame", "frame" ) ); if ( model == NULL ) { continue; } @@ -1181,7 +1181,7 @@ static void PopulateTraceNodes( void ){ } /* get model2 */ - value = ValueForKey( e, "model2" ); + value = e->valueForKey( "model2" ); /* switch on model type */ switch ( value[ 0 ] ) @@ -1201,7 +1201,7 @@ static void PopulateTraceNodes( void ){ /* external model */ default: - model = LoadModel( value, IntForKey( e, "_frame2" ) ); + model = LoadModel( value, e->intForKey( "_frame2" ) ); if ( model == NULL ) { continue; } diff --git a/tools/quake3/q3map2/light_ydnar.cpp b/tools/quake3/q3map2/light_ydnar.cpp index dfa7e3fe..da318aca 100644 --- a/tools/quake3/q3map2/light_ydnar.cpp +++ b/tools/quake3/q3map2/light_ydnar.cpp @@ -4131,7 +4131,7 @@ void SetupFloodLight( void ){ /* floodlight */ const char *value; - if ( ENT_READKV( &value, &entities[ 0 ], "_floodlight" ) ) { + if ( entities[ 0 ].read_keyvalue( value, "_floodlight" ) ) { double v1,v2,v3,v4,v5,v6; v1 = v2 = v3 = 0; v4 = floodlightDistance; diff --git a/tools/quake3/q3map2/lightmaps_ydnar.cpp b/tools/quake3/q3map2/lightmaps_ydnar.cpp index 61a81011..a905a6f5 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.cpp +++ b/tools/quake3/q3map2/lightmaps_ydnar.cpp @@ -3405,7 +3405,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ /* get rgbgen string */ if ( rgbGenValues[ style ] == NULL ) { sprintf( key, "_style%drgbgen", style ); - rgbGenValues[ style ] = ValueForKey( &entities[ 0 ], key ); + rgbGenValues[ style ] = entities[ 0 ].valueForKey( key ); if ( strEmpty( rgbGenValues[ style ] ) ) { rgbGenValues[ style ] = "wave noise 0.5 1 0 5.37"; } @@ -3421,7 +3421,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ /* get alphagen string */ if ( alphaGenValues[ style ] == NULL ) { sprintf( key, "_style%dalphagen", style ); - alphaGenValues[ style ] = ValueForKey( &entities[ 0 ], key ); + alphaGenValues[ style ] = entities[ 0 ].valueForKey( key ); } if ( !strEmpty( alphaGenValues[ style ] ) ) { sprintf( alphaGen, "\t\talphaGen %s // style %d\n", alphaGenValues[ style ], style ); diff --git a/tools/quake3/q3map2/map.cpp b/tools/quake3/q3map2/map.cpp index 3a0b24eb..4016b16a 100644 --- a/tools/quake3/q3map2/map.cpp +++ b/tools/quake3/q3map2/map.cpp @@ -846,14 +846,14 @@ static void MergeOrigin( entity_t *ent, vec3_t origin ){ char string[128]; /* we have not parsed the brush completely yet... */ - GetVectorForKey( ent, "origin", ent->origin ); + ent->vectorForKey( "origin", ent->origin ); VectorMA( origin, -1, ent->originbrush_origin, adjustment ); VectorAdd( adjustment, ent->origin, ent->origin ); VectorCopy( origin, ent->originbrush_origin ); sprintf( string, "%f %f %f", ent->origin[0], ent->origin[1], ent->origin[2] ); - SetKeyValue( ent, "origin", string ); + ent->setKeyValue( "origin", string ); } brush_t *FinishBrush( bool noCollapseGroups ){ @@ -871,7 +871,7 @@ brush_t *FinishBrush( bool noCollapseGroups ){ vec3_t origin; Sys_Printf( "Entity %i (%s), Brush %i: origin brush detected\n", - mapEnt->mapEntityNum, ent_classname( mapEnt ), entitySourceBrushes ); + mapEnt->mapEntityNum, mapEnt->classname(), entitySourceBrushes ); if ( entities.size() == 1 ) { Sys_FPrintf( SYS_WRN, "Entity %i, Brush %i: origin brushes not allowed in world\n", @@ -891,7 +891,7 @@ brush_t *FinishBrush( bool noCollapseGroups ){ /* determine if the brush is an area portal */ if ( buildBrush->compileFlags & C_AREAPORTAL ) { if ( entities.size() != 1 ) { - Sys_FPrintf( SYS_WRN, "Entity %zu (%s), Brush %i: areaportals only allowed in world\n", entities.size() - 1, ent_classname( mapEnt ), entitySourceBrushes ); + Sys_FPrintf( SYS_WRN, "Entity %zu (%s), Brush %i: areaportals only allowed in world\n", entities.size() - 1, mapEnt->classname(), entitySourceBrushes ); return NULL; } } @@ -1491,8 +1491,8 @@ void SetEntityBounds( entity_t *e ){ } /* try to find explicit min/max key */ - ENT_READKV( &mins, e, "min" ); - ENT_READKV( &maxs, e, "max" ); + e->read_keyvalue( mins, "min" ); + e->read_keyvalue( maxs, "max" ); /* store the bounds */ for ( b = e->brushes; b; b = b->next ) @@ -1530,11 +1530,11 @@ void LoadEntityIndexMap( entity_t *e ){ } /* determine if there is an index map (support legacy "alphamap" key as well) */ - if( !ENT_READKV( &indexMapFilename, e, "_indexmap", "alphamap" ) ) + if( !e->read_keyvalue( indexMapFilename, "_indexmap", "alphamap" ) ) return; /* get number of layers (support legacy "layers" key as well) */ - if( !ENT_READKV( &numLayers, e, "_layers", "layers" ) ){ + if( !e->read_keyvalue( numLayers, "_layers", "layers" ) ){ 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; @@ -1546,14 +1546,14 @@ void LoadEntityIndexMap( entity_t *e ){ } /* get base shader name (support legacy "shader" key as well) */ - if( !ENT_READKV( &shader, mapEnt, "_shader", "shader" ) ){ + if( !mapEnt->read_keyvalue( shader, "_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; } /* note it */ - Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->mapEntityNum, ent_classname( e ), indexMapFilename ); + Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->mapEntityNum, e->classname(), indexMapFilename ); /* handle tga image */ if ( striEqual( path_get_extension( indexMapFilename ), "tga" ) ) { @@ -1621,7 +1621,7 @@ void LoadEntityIndexMap( entity_t *e ){ /* get height offsets */ const char *offset; - if( ENT_READKV( &offset, mapEnt, "_offsets", "offsets" ) ){ + if( mapEnt->read_keyvalue( offset, "_offsets", "offsets" ) ){ /* value is a space-separated set of numbers */ /* get each value */ for ( i = 0; i < 256 && !strEmpty( offset ); i++ ) @@ -1734,7 +1734,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ } /* ydnar: get classname */ - const char *classname = ent_classname( mapEnt ); + const char *classname = mapEnt->classname(); /* ydnar: only lights? */ if ( onlyLights && !striEqualPrefix( classname, "light" ) ) { @@ -1762,7 +1762,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ GetEntityShadowFlags( mapEnt, NULL, &castShadows, &recvShadows ); /* ydnar: get lightmap scaling value for this entity */ - float lightmapScale = FloatForKey( mapEnt, "lightmapscale", "_lightmapscale", "_ls" ); + float lightmapScale = mapEnt->floatForKey( "lightmapscale", "_lightmapscale", "_ls" ); if ( lightmapScale < 0.0f ) lightmapScale = 0.0f; else if ( lightmapScale > 0.0f ) @@ -1771,8 +1771,8 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ /* ydnar: get cel shader :) for this entity */ shaderInfo_t *celShader; const char *value; - if( ENT_READKV( &value, mapEnt, "_celshader" ) || - ENT_READKV( &value, &entities[ 0 ], "_celshader" ) ){ + if( mapEnt->read_keyvalue( value, "_celshader" ) || + entities[ 0 ].read_keyvalue( value, "_celshader" ) ){ celShader = ShaderInfoForShader( String64()( "textures/", value ) ); Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader.c_str() ); } @@ -1781,7 +1781,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ } /* jal : entity based _shadeangle */ - float shadeAngle = FloatForKey( mapEnt, "_shadeangle", + float shadeAngle = mapEnt->floatForKey( "_shadeangle", "_smoothnormals", "_sn", "_sa", "_smooth" ); /* vortex' aliases */ if ( shadeAngle < 0.0f ) shadeAngle = 0.0f; @@ -1789,7 +1789,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ Sys_Printf( "Entity %d (%s) has shading angle of %.4f\n", mapEnt->mapEntityNum, classname, shadeAngle ); /* jal : entity based _samplesize */ - int lightmapSampleSize = IntForKey( mapEnt, "_lightmapsamplesize", "_samplesize", "_ss" ); + int lightmapSampleSize = mapEnt->intForKey( "_lightmapsamplesize", "_samplesize", "_ss" ); if ( lightmapSampleSize < 0 ) lightmapSampleSize = 0; else if ( lightmapSampleSize > 0 ) @@ -1824,7 +1824,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ LoadEntityIndexMap( mapEnt ); /* get entity origin and adjust brushes */ - GetVectorForKey( mapEnt, "origin", mapEnt->origin ); + mapEnt->vectorForKey( "origin", mapEnt->origin ); if ( mapEnt->originbrush_origin[ 0 ] || mapEnt->originbrush_origin[ 1 ] || mapEnt->originbrush_origin[ 2 ] ) { AdjustBrushesForOrigin( mapEnt ); } diff --git a/tools/quake3/q3map2/model.cpp b/tools/quake3/q3map2/model.cpp index 37a233e0..6a75e194 100644 --- a/tools/quake3/q3map2/model.cpp +++ b/tools/quake3/q3map2/model.cpp @@ -1347,7 +1347,7 @@ void AddTriangleModels( entity_t *eparent ){ targetName = ""; } else{ /* misc_model entities target non-worldspawn brush model entities */ - if ( !ENT_READKV( &targetName, eparent, "targetname" ) ) { + if ( !eparent->read_keyvalue( targetName, "targetname" ) ) { return; } } @@ -1359,24 +1359,24 @@ void AddTriangleModels( entity_t *eparent ){ entity_t *e = &entities[ i ]; /* convert misc_models into raw geometry */ - if ( !ent_class_is( e, "misc_model" ) ) { + if ( !e->classname_is( "misc_model" ) ) { continue; } /* ydnar: added support for md3 models on non-worldspawn models */ - if ( !strEqual( ValueForKey( e, "target" ), targetName ) ) { + if ( !strEqual( e->valueForKey( "target" ), targetName ) ) { continue; } /* get model name */ const char *model; - if ( !ENT_READKV( &model, e, "model" ) ) { + if ( !e->read_keyvalue( model, "model" ) ) { Sys_Warning( "entity#%d misc_model without a model key\n", e->mapEntityNum ); continue; } /* get model frame */ - const int frame = IntForKey( e, "_frame", "frame" ); + const int frame = e->intForKey( "_frame", "frame" ); int castShadows, recvShadows; if ( eparent == &entities[0] ) { /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */ @@ -1392,25 +1392,25 @@ void AddTriangleModels( entity_t *eparent ){ GetEntityShadowFlags( e, eparent, &castShadows, &recvShadows ); /* get spawnflags */ - const int spawnFlags = IntForKey( e, "spawnflags" ); + const int spawnFlags = e->intForKey( "spawnflags" ); /* get origin */ vec3_t origin; - GetVectorForKey( e, "origin", origin ); + e->vectorForKey( "origin", origin ); VectorSubtract( origin, eparent->origin, origin ); /* offset by parent */ /* get scale */ vec3_t scale = { 1.f, 1.f, 1.f }; - if( !ENT_READKV( &scale, e, "modelscale_vec" ) ) - if( ENT_READKV( &scale[0], e, "modelscale" ) ) + if( !e->read_keyvalue( scale, "modelscale_vec" ) ) + if( e->read_keyvalue( scale[0], "modelscale" ) ) scale[1] = scale[2] = scale[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( &value, e, "angles" ) || + if ( !e->read_keyvalue( value, "angles" ) || 3 != sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ) ) - ENT_READKV( &angles[ 2 ], e, "angle" ); + e->read_keyvalue( angles[ 2 ], "angle" ); /* set transform matrix (thanks spog) */ m4x4_t transform; @@ -1458,8 +1458,8 @@ void AddTriangleModels( entity_t *eparent ){ /* ydnar: cel shader support */ shaderInfo_t *celShader; - if( ENT_READKV( &value, e, "_celshader" ) || - ENT_READKV( &value, &entities[ 0 ], "_celshader" ) ){ + if( e->read_keyvalue( value, "_celshader" ) || + entities[ 0 ].read_keyvalue( value, "_celshader" ) ){ celShader = ShaderInfoForShader( String64()( "textures/", value ) ); } else{ @@ -1467,31 +1467,31 @@ void AddTriangleModels( entity_t *eparent ){ } /* jal : entity based _samplesize */ - int lightmapSampleSize = IntForKey( e, "_lightmapsamplesize", "_samplesize", "_ss" ); + int lightmapSampleSize = e->intForKey( "_lightmapsamplesize", "_samplesize", "_ss" ); if ( lightmapSampleSize < 0 ) lightmapSampleSize = 0; if ( lightmapSampleSize > 0 ) Sys_Printf( "misc_model has lightmap sample size of %.d\n", lightmapSampleSize ); /* get lightmap scale */ - float lightmapScale = FloatForKey( e, "lightmapscale", "_lightmapscale", "_ls" ); + float lightmapScale = e->floatForKey( "lightmapscale", "_lightmapscale", "_ls" ); 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 */ - float shadeAngle = FloatForKey( e, "_shadeangle", + float shadeAngle = e->floatForKey( "_shadeangle", "_smoothnormals", "_sn", "_sa", "_smooth" ); /* vortex' aliases */ if ( shadeAngle < 0.0f ) shadeAngle = 0.0f; else if ( shadeAngle > 0.0f ) Sys_Printf( "misc_model has shading angle of %.4f\n", shadeAngle ); - const int skin = IntForKey( e, "_skin", "skin" ); + const int skin = e->intForKey( "_skin", "skin" ); float clipDepth = clipDepthGlobal; - if ( ENT_READKV( &clipDepth, e, "_clipdepth" ) ) + if ( e->read_keyvalue( clipDepth, "_clipdepth" ) ) Sys_Printf( "misc_model %s has autoclip depth of %.3f\n", model, clipDepth ); diff --git a/tools/quake3/q3map2/portals.cpp b/tools/quake3/q3map2/portals.cpp index 3ebee884..0f0c4e3c 100644 --- a/tools/quake3/q3map2/portals.cpp +++ b/tools/quake3/q3map2/portals.cpp @@ -660,7 +660,7 @@ int FloodEntities( tree_t *tree ){ /* get origin */ vec3_t origin; - GetVectorForKey( e, "origin", origin ); + e->vectorForKey( "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 */ if ( VectorCompare( origin, vec3_origin ) ) { @@ -668,12 +668,12 @@ int FloodEntities( tree_t *tree ){ } #endif /* also allow bmodel entities outside, as they could be on a moving path that will go into the map */ - if ( e->brushes != NULL || e->patches != NULL || ent_class_is( e, "_decal" ) ) { //_decal primitive is freed at this point + if ( e->brushes != NULL || e->patches != NULL || e->classname_is( "_decal" ) ) { //_decal primitive is freed at this point continue; } /* handle skybox entities */ - if ( ent_class_is( e, "_skybox" ) ) { + if ( e->classname_is( "_skybox" ) ) { skybox = true; skyboxPresent = true; @@ -683,15 +683,15 @@ int FloodEntities( tree_t *tree ){ /* get scale */ vec3_t scale = { 64.0f, 64.0f, 64.0f }; - if( !ENT_READKV( &scale, e, "_scale" ) ) - if( ENT_READKV( &scale[0], e, "_scale" ) ) + if( !e->read_keyvalue( scale, "_scale" ) ) + if( e->read_keyvalue( scale[0], "_scale" ) ) scale[1] = scale[2] = scale[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( &value, e, "angles" ) || + if ( !e->read_keyvalue( value, "angles" ) || 3 != sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ) ) - ENT_READKV( &angles[ 2 ], e, "angle" ); + e->read_keyvalue( angles[ 2 ], "angle" ); /* set transform matrix (thanks spog) */ m4x4_identity( skyboxTransform ); @@ -714,7 +714,7 @@ int FloodEntities( tree_t *tree ){ inside = true; } if ( !r ) { - Sys_FPrintf( SYS_WRN, "Entity %i (%s): Entity in solid\n", e->mapEntityNum, ent_classname( e ) ); + Sys_FPrintf( SYS_WRN, "Entity %i (%s): Entity in solid\n", e->mapEntityNum, e->classname() ); } 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 fab360ea..1535d005 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -1035,6 +1035,57 @@ struct entity_t int firstBrush, numBrushes; /* only valid during BSP compile */ std::list epairs; vec3_t originbrush_origin; + + void setKeyValue( const char *key, const char *value ); + const char *valueForKey( const char *key ) const; + + template + bool boolForKey( Keys ... keys ) const { + bool bool_value = false; + read_keyvalue_( bool_value, { keys ... } ); + return bool_value; + } + template + int intForKey( Keys ... keys ) const { + int int_value = 0; + read_keyvalue_( int_value, { keys ... } ); + return int_value; + } + template + float floatForKey( Keys ... keys ) const { + float float_value = 0; + read_keyvalue_( float_value, { keys ... } ); + return float_value; + } + void vectorForKey( const char *key, vec3_t& vec ) const { + if( !read_keyvalue_( vec, { key } ) ) + VectorClear( vec ); + } + + const char *classname() const { + return valueForKey( "classname" ); + } + bool classname_is( const char *name ) const { + return striEqual( classname(), name ); + } + bool classname_prefixed( const char *prefix ) const { + return striEqualPrefix( classname(), prefix ); + } + + /* entity: read key value variadic template + returns true on successful read + returns false and does not modify value otherwise */ + template + bool read_keyvalue( T& value_ref, Keys ... keys ) const { + return read_keyvalue_( value_ref, { keys ... } ); + } +private: + bool read_keyvalue_( bool &bool_value, std::initializer_list&& keys ) const; + bool read_keyvalue_( int &int_value, std::initializer_list&& keys ) const; + bool read_keyvalue_( float &float_value, std::initializer_list&& keys ) const; + bool read_keyvalue_( float (&vector3_value)[3], std::initializer_list&& keys ) const; + bool read_keyvalue_( char (&string_value)[1024], std::initializer_list&& keys ) const; + bool read_keyvalue_( const char *&string_ptr_value, std::initializer_list&& keys ) const; }; @@ -1819,29 +1870,6 @@ void ParseEPair( std::list& epairs ); void ParseEntities( void ); void UnparseEntities( void ); void PrintEntity( const entity_t *ent ); -void SetKeyValue( entity_t *ent, const char *key, const char *value ); -const char *ValueForKey( const entity_t *ent, const char *key ); -bool BoolForKey_impl( const entity_t *ent, ... ); -#define BoolForKey( entity, keys... ) BoolForKey_impl( entity, keys, NULL ) -int IntForKey_impl( const entity_t *ent, ... ); -#define IntForKey( entity, keys... ) IntForKey_impl( entity, keys, NULL ) -vec_t FloatForKey_impl( const entity_t *ent, ... ); -#define FloatForKey( entity, keys... ) FloatForKey_impl( entity, keys, NULL ) -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_keyvalue( bool *bool_value, const entity_t *entity, ... ); -bool entity_read_keyvalue( int *int_value, const entity_t *entity, ... ); -bool entity_read_keyvalue( float *float_value, const entity_t *entity, ... ); // warning: float[3] may be passed here erroneously, if not written as &float[3] -bool entity_read_keyvalue( float (*vector3_value)[3], const entity_t *entity, ... ); -bool entity_read_keyvalue( char (*string_value)[1024], const entity_t *entity, ... ); // explicit pointer to array to avoid erroneous mix of char* and char** -bool entity_read_keyvalue( const char **string_ptr_value, const entity_t *entity, ... ); -#define ENT_READKV( value_ptr, entity, keys... ) entity_read_keyvalue( value_ptr, entity, keys, NULL ) - -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 ); diff --git a/tools/quake3/q3map2/shaders.cpp b/tools/quake3/q3map2/shaders.cpp index ff0ae1f6..02fb3fe6 100644 --- a/tools/quake3/q3map2/shaders.cpp +++ b/tools/quake3/q3map2/shaders.cpp @@ -592,7 +592,7 @@ void EmitVertexRemapShader( char *from, char *to ){ digest[ 8 ], digest[ 9 ], digest[ 10 ], digest[ 11 ], digest[ 12 ], digest[ 13 ], digest[ 14 ] ); /* no: digest[ 15 ] */ /* add key/value pair to worldspawn */ - SetKeyValue( &entities[ 0 ], key, value ); + entities[ 0 ].setKeyValue( key, value ); } diff --git a/tools/quake3/q3map2/surface.cpp b/tools/quake3/q3map2/surface.cpp index 5de1dbcc..a63dbbee 100644 --- a/tools/quake3/q3map2/surface.cpp +++ b/tools/quake3/q3map2/surface.cpp @@ -2564,7 +2564,7 @@ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){ int surfaceFlags, contentFlags; /* vortex: _patchMeta support */ - const bool forcePatchMeta = BoolForKey( e, "_patchMeta", "patchMeta" ); + const bool forcePatchMeta = e->boolForKey( "_patchMeta", "patchMeta" ); /* invert the surface if necessary */ if ( ds->backSide || ds->shaderInfo->invert ) { diff --git a/tools/quake3/q3map2/surface_meta.cpp b/tools/quake3/q3map2/surface_meta.cpp index 0138ee96..99b6332a 100644 --- a/tools/quake3/q3map2/surface_meta.cpp +++ b/tools/quake3/q3map2/surface_meta.cpp @@ -291,7 +291,7 @@ void TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds ){ mesh_t src, *subdivided, *mesh; /* vortex: _patchMeta, _patchQuality, _patchSubdivide support */ - const bool forcePatchMeta = BoolForKey( e, "_patchMeta", "patchMeta" ); + const bool forcePatchMeta = e->boolForKey( "_patchMeta", "patchMeta" ); /* try to early out */ if ( ds->numVerts == 0 || ds->type != ESurfaceType::Patch || ( !patchMeta && !forcePatchMeta ) ) { @@ -305,11 +305,11 @@ void TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds ){ int iterations; int patchSubdivision; - if ( ENT_READKV( &patchSubdivision, e, "_patchSubdivide", "patchSubdivide" ) ) { + if ( e->read_keyvalue( patchSubdivision, "_patchSubdivide", "patchSubdivide" ) ) { iterations = IterationsForCurve( ds->longestCurve, patchSubdivision ); } else{ - const int patchQuality = IntForKey( e, "_patchQuality", "patchQuality" ); + const int patchQuality = e->intForKey( "_patchQuality", "patchQuality" ); iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions / ( patchQuality == 0? 1 : patchQuality ) ); } diff --git a/tools/quake3/q3map2/vis.cpp b/tools/quake3/q3map2/vis.cpp index 92599f80..a2835015 100644 --- a/tools/quake3/q3map2/vis.cpp +++ b/tools/quake3/q3map2/vis.cpp @@ -295,7 +295,7 @@ void CalcVis( void ){ /* ydnar: rr2do2's farplane code */ const char *value; - if( ENT_READKV( &value, &entities[ 0 ], "_farplanedist", /* proper '_' prefixed key */ + if( entities[ 0 ].read_keyvalue( value, "_farplanedist", /* proper '_' prefixed key */ "fogclip", /* wolf compatibility */ "distancecull" ) ){ /* sof2 compatibility */ farPlaneDist = atof( value ); diff --git a/tools/quake3/q3map2/writebsp.cpp b/tools/quake3/q3map2/writebsp.cpp index 0f983656..4dc7fcd0 100644 --- a/tools/quake3/q3map2/writebsp.cpp +++ b/tools/quake3/q3map2/writebsp.cpp @@ -263,7 +263,7 @@ void SetModelNumbers( void ){ if ( entities[i].brushes || entities[i].patches ) { sprintf( value, "*%i", models ); models++; - SetKeyValue( &entities[i], "model", value ); + entities[i].setKeyValue( "model", value ); } } @@ -286,11 +286,11 @@ void SetLightStyles( void ){ /* -keeplights option: force lights to be kept and ignore what the map file says */ if ( keepLights ) { - SetKeyValue( &entities[0], "_keepLights", "1" ); + entities[0].setKeyValue( "_keepLights", "1" ); } /* ydnar: determine if we keep lights in the bsp */ - ENT_READKV( &keepLights, &entities[ 0 ], "_keepLights" ); + entities[ 0 ].read_keyvalue( keepLights, "_keepLights" ); /* any light that is controlled (has a targetname) must have a unique style number generated for it */ numStyles = 0; @@ -298,11 +298,11 @@ void SetLightStyles( void ){ { e = &entities[ i ]; - if ( !ent_class_prefixed( e, "light" ) ) { + if ( !e->classname_prefixed( "light" ) ) { continue; } const char *t; - if ( !ENT_READKV( &t, e, "targetname" ) ) { + if ( !e->read_keyvalue( t, "targetname" ) ) { /* ydnar: strip the light from the BSP file */ if ( !keepLights ) { e->epairs.clear(); @@ -314,7 +314,7 @@ void SetLightStyles( void ){ } /* get existing style */ - const int style = IntForKey( e, "style" ); + const int style = e->intForKey( "style" ); if ( style < LS_NORMAL || style > LS_NONE ) { Error( "Invalid lightstyle (%d) on entity %zu", style, i ); } @@ -337,12 +337,12 @@ void SetLightStyles( void ){ /* set explicit style */ sprintf( value, "%d", 32 + j ); - SetKeyValue( e, "style", value ); + e->setKeyValue( "style", value ); /* set old style */ if ( style != LS_NORMAL ) { sprintf( value, "%d", style ); - SetKeyValue( e, "switch_style", value ); + e->setKeyValue( "switch_style", value ); } }