refactor entity key values routines

This commit is contained in:
Garux 2021-01-30 16:23:31 +03:00
parent 8425ce3c3e
commit 99a5ef0416
23 changed files with 264 additions and 359 deletions

View File

@ -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 ); FixDOSName( str );
DefaultExtension( str, ".wav" ); DefaultExtension( str, ".wav" );
res2list( pk3Sounds, str ); res2list( pk3Sounds, str );
@ -316,25 +316,25 @@ int pk3BSPMain( int argc, char **argv ){
for ( const auto& e : entities ) for ( const auto& e : entities )
{ {
if ( ENT_READKV( &str, &e, "noise" ) && str[0] != '*' ){ if ( e.read_keyvalue( str, "noise" ) && str[0] != '*' ){
FixDOSName( str ); FixDOSName( str );
DefaultExtension( str, ".wav" ); DefaultExtension( str, ".wav" );
res2list( pk3Sounds, str ); 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_strt.wav" );
res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" );
} }
if ( ent_class_is( &e, "target_push" ) ){ if ( e.classname_is( "target_push" ) ){
if ( !( IntForKey( &e, "spawnflags") & 1 ) ){ if ( !( e.intForKey( "spawnflags") & 1 ) ){
res2list( pk3Sounds, "sound/misc/windfly.wav" ); res2list( pk3Sounds, "sound/misc/windfly.wav" );
} }
} }
res2list( pk3Shaders, ValueForKey( &e, "targetShaderNewName" ) ); res2list( pk3Shaders, e.valueForKey( "targetShaderNewName" ) );
if ( ENT_READKV( &str, &e, "model2" ) ){ if ( e.read_keyvalue( str, "model2" ) ){
Sys_Warning( "unhandled model2 key of %s: %s\n", ent_classname( &e ), str ); 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 ); res2list( pk3Shaders, str );
} }
} }
if ( ENT_READKV( &str, &entities[0], "music" ) ){ if ( entities[ 0 ].read_keyvalue( str, "music" ) ){
FixDOSName( str ); FixDOSName( str );
DefaultExtension( str, ".wav" ); DefaultExtension( str, ".wav" );
res2list( pk3Sounds, str ); res2list( pk3Sounds, str );
@ -989,25 +989,25 @@ int repackBSPMain( int argc, char **argv ){
for ( const auto& e : entities ) for ( const auto& e : entities )
{ {
if ( ENT_READKV( &str, &e, "noise" ) && str[0] != '*' ){ if ( e.read_keyvalue( str, "noise" ) && str[0] != '*' ){
FixDOSName( str ); FixDOSName( str );
DefaultExtension( str, ".wav" ); DefaultExtension( str, ".wav" );
res2list( pk3Sounds, str ); 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_strt.wav" );
res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" );
} }
if ( ent_class_is( &e, "target_push" ) ){ if ( e.classname_is( "target_push" ) ){
if ( !( IntForKey( &e, "spawnflags") & 1 ) ){ if ( !( e.intForKey( "spawnflags") & 1 ) ){
res2list( pk3Sounds, "sound/misc/windfly.wav" ); res2list( pk3Sounds, "sound/misc/windfly.wav" );
} }
} }
res2list( pk3Shaders, ValueForKey( &e, "targetShaderNewName" ) ); res2list( pk3Shaders, e.valueForKey( "targetShaderNewName" ) );
if ( ENT_READKV( &str, &e, "model2" ) ){ if ( e.read_keyvalue( str, "model2" ) ){
Sys_Warning( "unhandled model2 key of %s: %s\n", ent_classname( &entities[i] ), str ); Sys_Warning( "unhandled model2 key of %s: %s\n", entities[i].classname(), str );
} }
} }

View File

@ -105,16 +105,16 @@ static void ProcessAdvertisements( void ) {
for ( const auto& e : entities ) { for ( const auto& e : entities ) {
/* is an advertisement? */ /* 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 ) { if ( strlen( modelKey ) > MAX_QPATH - 1 ) {
Error( "Model Key for entity exceeds ad struct string length." ); Error( "Model Key for entity exceeds ad struct string length." );
} }
else { else {
if ( numBSPAds < MAX_MAP_ADVERTISEMENTS ) { 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 ) ); strncpy( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) );
modelKey++; modelKey++;
@ -180,12 +180,12 @@ static void SetCloneModelNumbers( void ){
} }
/* is this a clone? */ /* is this a clone? */
if( ENT_READKV( &value, &entities[ i ], "_ins", "_instance", "_clone" ) ) if( entities[ i ].read_keyvalue( value, "_ins", "_instance", "_clone" ) )
continue; continue;
/* add the model key */ /* add the model key */
sprintf( modelValue, "*%d", models ); sprintf( modelValue, "*%d", models );
SetKeyValue( &entities[ i ], "model", modelValue ); entities[ i ].setKeyValue( "model", modelValue );
/* increment model count */ /* increment model count */
models++; models++;
@ -200,21 +200,21 @@ static void SetCloneModelNumbers( void ){
} }
/* isn't this a clone? */ /* isn't this a clone? */
if( !ENT_READKV( &value, &entities[ i ], "_ins", "_instance", "_clone" ) ) if( !entities[ i ].read_keyvalue( value, "_ins", "_instance", "_clone" ) )
continue; continue;
/* find an entity with matching clone name */ /* find an entity with matching clone name */
for ( std::size_t j = 0; j < entities.size(); ++j ) for ( std::size_t j = 0; j < entities.size(); ++j )
{ {
/* is this a clone parent? */ /* is this a clone parent? */
if ( !ENT_READKV( &value2, &entities[ j ], "_clonename" ) ) { if ( !entities[ j ].read_keyvalue( value2, "_clonename" ) ) {
continue; continue;
} }
/* do they match? */ /* do they match? */
if ( strEqual( value, value2 ) ) { if ( strEqual( value, value2 ) ) {
/* get the model num */ /* 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 ); Sys_Warning( "Cloned entity %s referenced entity without model\n", value2 );
continue; continue;
} }
@ -222,7 +222,7 @@ static void SetCloneModelNumbers( void ){
/* add the model key */ /* add the model key */
sprintf( modelValue, "*%d", models ); sprintf( modelValue, "*%d", models );
SetKeyValue( &entities[ i ], "model", modelValue ); entities[ i ].setKeyValue( "model", modelValue );
/* nuke the brushes/patches for this entity (fixme: leak!) */ /* nuke the brushes/patches for this entity (fixme: leak!) */
entities[ i ].brushes = NULL; entities[ i ].brushes = NULL;
@ -297,7 +297,7 @@ void ProcessWorldModel( void ){
int leakStatus; int leakStatus;
/* sets integer blockSize from worldspawn "_blocksize" key if it exists */ /* 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 */ /* scan 3 numbers */
const int 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 ] );
@ -309,7 +309,7 @@ void ProcessWorldModel( void ){
Sys_Printf( "block size = { %d %d %d }\n", blockSize[ 0 ], blockSize[ 1 ], blockSize[ 2 ] ); Sys_Printf( "block size = { %d %d %d }\n", blockSize[ 0 ], blockSize[ 1 ], blockSize[ 2 ] );
/* sof2: ignore leaks? */ /* sof2: ignore leaks? */
const bool ignoreLeaks = BoolForKey( &entities[ 0 ], "_ignoreleaks", "ignoreleaks" ); const bool ignoreLeaks = entities[ 0 ].boolForKey( "_ignoreleaks", "ignoreleaks" );
/* begin worldspawn model */ /* begin worldspawn model */
BeginModel(); BeginModel();
@ -440,7 +440,7 @@ void ProcessWorldModel( void ){
} }
/* ydnar: fog hull */ /* ydnar: fog hull */
if ( ENT_READKV( &value, &entities[ 0 ], "_foghull" ) ) { if ( entities[ 0 ].read_keyvalue( value, "_foghull" ) ) {
const auto shader = String64()( "textures/", value ); const auto shader = String64()( "textures/", value );
MakeFogHullSurfs( e, tree, shader ); MakeFogHullSurfs( e, tree, shader );
} }
@ -453,21 +453,21 @@ void ProcessWorldModel( void ){
vec3_t origin, targetOrigin, normal, color; vec3_t origin, targetOrigin, normal, color;
/* get light */ /* get light */
if ( ent_class_is( &light, "light" ) ) { if ( light.classname_is( "light" ) ) {
/* get flare shader */ /* get flare shader */
const char *flareShader = NULL; const char *flareShader = NULL;
if ( ENT_READKV( &flareShader, &light, "_flareshader" ) || BoolForKey( &light, "_flare" ) ) { if ( light.read_keyvalue( flareShader, "_flareshader" ) || light.boolForKey( "_flare" ) ) {
/* get specifics */ /* get specifics */
GetVectorForKey( &light, "origin", origin ); light.vectorForKey( "origin", origin );
GetVectorForKey( &light, "_color", color ); light.vectorForKey( "_color", color );
const int lightStyle = IntForKey( &light, "_style", "style" ); const int lightStyle = light.intForKey( "_style", "style" );
/* handle directional spotlights */ /* handle directional spotlights */
if ( ENT_READKV( &value, &light, "target" ) ) { if ( light.read_keyvalue( value, "target" ) ) {
/* get target light */ /* get target light */
target = FindTargetEntity( value ); target = FindTargetEntity( value );
if ( target != NULL ) { if ( target != NULL ) {
GetVectorForKey( target, "origin", targetOrigin ); target->vectorForKey( "origin", targetOrigin );
VectorSubtract( targetOrigin, origin, normal ); VectorSubtract( targetOrigin, origin, normal );
VectorNormalize( normal, normal ); VectorNormalize( normal, normal );
} }
@ -659,9 +659,9 @@ void OnlyEnts( void ){
LoadBSPFile( out ); LoadBSPFile( out );
ParseEntities(); ParseEntities();
strcpyQ( save_cmdline, ValueForKey( &entities[0], "_q3map2_cmdline" ), sizeof( save_cmdline ) ); strcpyQ( save_cmdline, entities[ 0 ].valueForKey( "_q3map2_cmdline" ), sizeof( save_cmdline ) );
strcpyQ( save_version, ValueForKey( &entities[0], "_q3map2_version" ), sizeof( save_version ) ); strcpyQ( save_version, entities[ 0 ].valueForKey( "_q3map2_version" ), sizeof( save_version ) );
strcpyQ( save_gridsize, ValueForKey( &entities[0], "gridsize" ), sizeof( save_gridsize ) ); strcpyQ( save_gridsize, entities[ 0 ].valueForKey( "gridsize" ), sizeof( save_gridsize ) );
entities.clear(); entities.clear();
@ -671,13 +671,13 @@ void OnlyEnts( void ){
SetLightStyles(); SetLightStyles();
if ( *save_cmdline ) { if ( *save_cmdline ) {
SetKeyValue( &entities[0], "_q3map2_cmdline", save_cmdline ); entities[0].setKeyValue( "_q3map2_cmdline", save_cmdline );
} }
if ( *save_version ) { if ( *save_version ) {
SetKeyValue( &entities[0], "_q3map2_version", save_version ); entities[0].setKeyValue( "_q3map2_version", save_version );
} }
if ( *save_gridsize ) { if ( *save_gridsize ) {
SetKeyValue( &entities[0], "gridsize", save_gridsize ); entities[0].setKeyValue( "gridsize", save_gridsize );
} }
numBSPEntities = entities.size(); numBSPEntities = entities.size();

View File

@ -601,7 +601,7 @@ void InjectCommandLine( char **argv, int beginArgs, int endArgs ){
if ( nocmdline ){ if ( nocmdline ){
return; 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 ) while ( outpos != sentinel && *inpos )
*outpos++ = *inpos++; *outpos++ = *inpos++;
if ( outpos != sentinel ) { if ( outpos != sentinel ) {
@ -625,8 +625,8 @@ void InjectCommandLine( char **argv, int beginArgs, int endArgs ){
} }
*outpos = 0; *outpos = 0;
SetKeyValue( &entities[0], "_q3map2_cmdline", newCommandLine ); entities[0].setKeyValue( "_q3map2_cmdline", newCommandLine );
SetKeyValue( &entities[0], "_q3map2_version", Q3MAP_VERSION ); entities[0].setKeyValue( "_q3map2_version", Q3MAP_VERSION );
} }
/* /*
@ -663,7 +663,7 @@ void UnparseEntities( void ){
continue; /* ent got removed */ continue; /* ent got removed */
} }
/* ydnar: certain entities get stripped from bsp file */ /* ydnar: certain entities get stripped from bsp file */
const char *classname = ent_classname( e ); const char *classname = e->classname();
if ( striEqual( classname, "misc_model" ) || if ( striEqual( classname, "misc_model" ) ||
striEqual( classname, "_decal" ) || striEqual( classname, "_decal" ) ||
striEqual( classname, "_skybox" ) ) { striEqual( classname, "_skybox" ) ) {
@ -719,13 +719,13 @@ void PrintEntity( const entity_t *ent ){
/* /*
SetKeyValue() setKeyValue()
sets an epair in an entity 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 */ /* check for existing epair */
for ( auto& ep : ent->epairs ) for ( auto& ep : epairs )
{ {
if ( EPAIR_EQUAL( ep.key.c_str(), key ) ) { if ( EPAIR_EQUAL( ep.key.c_str(), key ) ) {
ep.value = value; ep.value = value;
@ -734,23 +734,18 @@ void SetKeyValue( entity_t *ent, const char *key, const char *value ){
} }
/* create new epair */ /* 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 gets the value for an entity key
*/ */
const char *ValueForKey( const entity_t *ent, const char *key ){ const char *entity_t::valueForKey( const char *key ) const {
/* dummy check */
if ( ent == NULL ) {
return "";
}
/* walk epair list */ /* walk epair list */
for ( const auto& ep : ent->epairs ) for ( const auto& ep : epairs )
{ {
if ( EPAIR_EQUAL( ep.key.c_str(), key ) ) { if ( EPAIR_EQUAL( ep.key.c_str(), key ) ) {
return ep.value.c_str(); return ep.value.c_str();
@ -761,191 +756,73 @@ const char *ValueForKey( const entity_t *ent, const char *key ){
return ""; return "";
} }
bool BoolForKey_impl( const entity_t *ent, ... ){ bool entity_t::read_keyvalue_( bool &bool_value, std::initializer_list<const char*>&& keys ) const {
va_list argptr; for( const char* key : keys ){
va_start( argptr, ent ); const char* value = valueForKey( key );
const char* key;
while( ( key = va_arg( argptr, const char* ) ) != NULL ){
const char* value = ValueForKey( ent, key );
if( !strEmpty( value ) ){ if( !strEmpty( value ) ){
va_end( argptr ); bool_value = ( value[0] == '1' );
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 );
return true; return true;
} }
} }
va_end( argptr );
return false; return false;
} }
bool entity_read_keyvalue( int *int_value, const entity_t *entity, ... ){ bool entity_t::read_keyvalue_( int &int_value, std::initializer_list<const char*>&& keys ) const {
va_list argptr; for( const char* key : keys ){
va_start( argptr, entity ); const char* value = valueForKey( key );
const char* key;
while( ( key = va_arg( argptr, const char* ) ) != NULL ){
const char* value = ValueForKey( entity, key );
if( !strEmpty( value ) ){ if( !strEmpty( value ) ){
*int_value = atoi( value ); int_value = atoi( value );
va_end( argptr );
return true; return true;
} }
} }
va_end( argptr );
return false; return false;
} }
bool entity_read_keyvalue( float *float_value, const entity_t *entity, ... ){ bool entity_t::read_keyvalue_( float &float_value, std::initializer_list<const char*>&& keys ) const {
va_list argptr; for( const char* key : keys ){
va_start( argptr, entity ); const char* value = valueForKey( key );
const char* key;
while( ( key = va_arg( argptr, const char* ) ) != NULL ){
const char* value = ValueForKey( entity, key );
if( !strEmpty( value ) ){ if( !strEmpty( value ) ){
*float_value = atof( value ); float_value = atof( value );
va_end( argptr );
return true; return true;
} }
} }
va_end( argptr );
return false; return false;
} }
bool entity_read_keyvalue( float (*vector3_value)[3], const entity_t *entity, ... ){ bool entity_t::read_keyvalue_( float (&vector3_value)[3], std::initializer_list<const char*>&& keys ) const {
va_list argptr; for( const char* key : keys ){
va_start( argptr, entity ); const char* value = valueForKey( key );
const char* key;
while( ( key = va_arg( argptr, const char* ) ) != NULL ){
const char* value = ValueForKey( entity, key );
if( !strEmpty( value ) ){ if( !strEmpty( value ) ){
float v0, v1, v2; float v0, v1, v2;
if( 3 == sscanf( value, "%f %f %f", &v0, &v1, &v2 ) ){ if( 3 == sscanf( value, "%f %f %f", &v0, &v1, &v2 ) ){
(*vector3_value)[0] = v0; vector3_value[0] = v0;
(*vector3_value)[1] = v1; vector3_value[1] = v1;
(*vector3_value)[2] = v2; vector3_value[2] = v2;
va_end( argptr );
return true; return true;
} }
} }
} }
va_end( argptr );
return false; return false;
} }
bool entity_read_keyvalue( char (*string_value)[1024], const entity_t *entity, ... ){ bool entity_t::read_keyvalue_( char (&string_value)[1024], std::initializer_list<const char*>&& keys ) const {
va_list argptr; for( const char* key : keys ){
va_start( argptr, entity ); const char* value = valueForKey( key );
const char* key;
while( ( key = va_arg( argptr, const char* ) ) != NULL ){
const char* value = ValueForKey( entity, key );
if( !strEmpty( value ) ){ if( !strEmpty( value ) ){
strcpy( *string_value, value ); strcpy( string_value, value );
va_end( argptr );
return true; return true;
} }
} }
va_end( argptr );
return false; return false;
} }
bool entity_read_keyvalue( const char **string_ptr_value, const entity_t *entity, ... ){ bool entity_t::read_keyvalue_( const char *&string_ptr_value, std::initializer_list<const char*>&& keys ) const {
va_list argptr; for( const char* key : keys ){
va_start( argptr, entity ); const char* value = valueForKey( key );
const char* key;
while( ( key = va_arg( argptr, const char* ) ) != NULL ){
const char* value = ValueForKey( entity, key );
if( !strEmpty( value ) ){ if( !strEmpty( value ) ){
*string_ptr_value = value; string_ptr_value = value;
va_end( argptr );
return true; return true;
} }
} }
va_end( argptr );
return false; 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() FindTargetEntity()
finds an entity target finds an entity target
@ -955,7 +832,7 @@ entity_t *FindTargetEntity( const char *target ){
/* walk entity list */ /* walk entity list */
for ( auto& e : entities ) for ( auto& e : entities )
{ {
if ( strEqual( ValueForKey( &e, "targetname" ), target ) ) { if ( strEqual( e.valueForKey( "targetname" ), target ) ) {
return &e; 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 ){ void GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows ){
/* get cast shadows */ /* get cast shadows */
if ( castShadows != NULL ) { if ( castShadows != NULL ) {
ENT_READKV( castShadows, ent, "_castShadows", "_cs" ) || ( ent != NULL && ent->read_keyvalue( *castShadows, "_castShadows", "_cs" ) ) ||
ENT_READKV( castShadows, ent2, "_castShadows", "_cs" ); ( ent2 != NULL && ent2->read_keyvalue( *castShadows, "_castShadows", "_cs" ) );
} }
/* receive */ /* receive */
if ( recvShadows != NULL ) { if ( recvShadows != NULL ) {
ENT_READKV( recvShadows, ent, "_receiveShadows", "_rs" ) || ( ent != NULL && ent->read_keyvalue( *recvShadows, "_receiveShadows", "_rs" ) ) ||
ENT_READKV( recvShadows, ent2, "_receiveShadows", "_rs" ); ( ent2 != NULL && ent2->read_keyvalue( *recvShadows, "_receiveShadows", "_rs" ) );
} }
/* vortex: game-specific default entity keys */ /* vortex: game-specific default entity keys */
if ( striEqual( game->magic, "dq" ) || striEqual( game->magic, "prophecy" ) ) { if ( striEqual( game->magic, "dq" ) || striEqual( game->magic, "prophecy" ) ) {
/* vortex: deluxe quake default shadow flags */ /* vortex: deluxe quake default shadow flags */
if ( ent_class_is( ent, "func_wall" ) ) { if ( ent->classname_is( "func_wall" ) ) {
if ( recvShadows != NULL ) { if ( recvShadows != NULL ) {
*recvShadows = 1; *recvShadows = 1;
} }

View File

@ -402,7 +402,7 @@ int ConvertBSPToASE( char *bspName ){
} }
else else
{ {
const char *key = ValueForKey( e, "model" ); const char *key = e->valueForKey( "model" );
if ( key[ 0 ] != '*' ) { if ( key[ 0 ] != '*' ) {
continue; continue;
} }
@ -412,7 +412,7 @@ int ConvertBSPToASE( char *bspName ){
/* get entity origin */ /* get entity origin */
vec3_t origin; vec3_t origin;
GetVectorForKey( e, "origin", origin ); e->vectorForKey( "origin", origin );
/* convert model */ /* convert model */
ConvertModel( f, model, modelNum, origin, lmIndices ); ConvertModel( f, model, modelNum, origin, lmIndices );

View File

@ -465,21 +465,21 @@ int ScaleBSPMain( int argc, char **argv ){
for ( auto& e : entities ) for ( auto& e : entities )
{ {
/* scale origin */ /* scale origin */
if ( ENT_READKV( &vec, &e, "origin" ) ) { if ( e.read_keyvalue( vec, "origin" ) ) {
if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { if ( entities[i].classname_prefixed( "info_player_" ) ) {
vec[2] += spawn_ref; vec[2] += spawn_ref;
} }
vec[0] *= scale[0]; vec[0] *= scale[0];
vec[1] *= scale[1]; vec[1] *= scale[1];
vec[2] *= scale[2]; vec[2] *= scale[2];
if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { if ( entities[i].classname_prefixed( "info_player_" ) ) {
vec[2] -= spawn_ref; vec[2] -= spawn_ref;
} }
sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); 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 if ( a == -1 || a == -2 ) { // z scale
axis = 2; axis = 2;
} }
@ -491,17 +491,17 @@ int ScaleBSPMain( int argc, char **argv ){
} }
/* scale door lip */ /* scale door lip */
if ( ENT_READKV( &f, &e, "lip" ) ) { if ( e.read_keyvalue( f, "lip" ) ) {
f *= scale[axis]; f *= scale[axis];
sprintf( str, "%f", f ); sprintf( str, "%f", f );
SetKeyValue( &e, "lip", str ); e.setKeyValue( "lip", str );
} }
/* scale plat height */ /* scale plat height */
if ( ENT_READKV( &f, &e, "height" ) ) { if ( e.read_keyvalue( f, "height" ) ) {
f *= scale[2]; f *= scale[2];
sprintf( str, "%f", f ); 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? // 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 */ /* scale gridsize */
if ( !ENT_READKV( &vec, &entities[ 0 ], "gridsize" ) ) { if ( !entities[ 0 ].read_keyvalue( vec, "gridsize" ) ) {
VectorCopy( gridSize, vec ); VectorCopy( gridSize, vec );
} }
vec[0] *= scale[0]; vec[0] *= scale[0];
vec[1] *= scale[1]; vec[1] *= scale[1];
vec[2] *= scale[2]; vec[2] *= scale[2];
sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 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 */ /* inject command line parameters */
InjectCommandLine( argv, 0, argc - 1 ); InjectCommandLine( argv, 0, argc - 1 );
@ -700,18 +700,18 @@ int ShiftBSPMain( int argc, char **argv ){
for ( auto& e : entities ) for ( auto& e : entities )
{ {
/* shift origin */ /* shift origin */
if ( ENT_READKV( &vec, &e, "origin" ) ) { if ( e.read_keyvalue( vec, "origin" ) ) {
if ( ent_class_prefixed( &e, "info_player_" ) ) { if ( e.classname_prefixed( "info_player_" ) ) {
vec[2] += spawn_ref; vec[2] += spawn_ref;
} }
vec[0] += scale[0]; vec[0] += scale[0];
vec[1] += scale[1]; vec[1] += scale[1];
vec[2] += scale[2]; vec[2] += scale[2];
if ( ent_class_prefixed( &e, "info_player_" ) ) { if ( e.classname_prefixed( "info_player_" ) ) {
vec[2] -= spawn_ref; vec[2] -= spawn_ref;
} }
sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); 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 */ /* scale gridsize */
/* /*
if ( !ENT_READKV( &vec, &entities[ 0 ], "gridsize" ) ) { if ( !entities[ 0 ].read_keyvalue( vec, "gridsize" ) ) {
VectorCopy( gridSize, vec ); VectorCopy( gridSize, vec );
} }
vec[0] *= scale[0]; vec[0] *= scale[0];
vec[1] *= scale[1]; vec[1] *= scale[1];
vec[2] *= scale[2]; vec[2] *= scale[2];
sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 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 */ /* inject command line parameters */
InjectCommandLine( argv, 0, argc - 1 ); InjectCommandLine( argv, 0, argc - 1 );
@ -835,7 +835,7 @@ void PseudoCompileBSP( bool need_tree ){
if ( i != 0 ) { if ( i != 0 ) {
sprintf( modelValue, "*%d", models++ ); sprintf( modelValue, "*%d", models++ );
SetKeyValue( entity, "model", modelValue ); entity->setKeyValue( "model", modelValue );
} }
/* process the model */ /* process the model */

View File

@ -1035,7 +1035,7 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){
} }
else else
{ {
value = ValueForKey( e, "model" ); value = e->valueForKey( "model" );
if ( value[ 0 ] == '*' ) { if ( value[ 0 ] == '*' ) {
modelNum = atoi( value + 1 ); modelNum = atoi( value + 1 );
} }
@ -1055,7 +1055,7 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){
/* get entity origin */ /* get entity origin */
vec3_t origin; vec3_t origin;
GetVectorForKey( e, "origin", origin ); e->vectorForKey( "origin", origin );
/* convert model */ /* convert model */
ConvertModel( f, model, modelNum, origin, brushPrimitives ); ConvertModel( f, model, modelNum, origin, brushPrimitives );

View File

@ -360,7 +360,7 @@ int ConvertBSPToOBJ( char *bspName ){
} }
else else
{ {
key = ValueForKey( e, "model" ); key = e->valueForKey( "model" );
if ( key[ 0 ] != '*' ) { if ( key[ 0 ] != '*' ) {
continue; continue;
} }
@ -370,7 +370,7 @@ int ConvertBSPToOBJ( char *bspName ){
/* get entity origin */ /* get entity origin */
vec3_t origin; vec3_t origin;
GetVectorForKey( e, "origin", origin ); e->vectorForKey( "origin", origin );
/* convert model */ /* convert model */
ConvertModelToOBJ( f, model, modelNum, origin, lmIndices ); ConvertModelToOBJ( f, model, modelNum, origin, lmIndices );

View File

@ -415,7 +415,7 @@ void ProcessDecals( void ){
/* walk entity list */ /* walk entity list */
for ( auto& e : entities ) for ( auto& e : entities )
{ {
if ( !ent_class_is( &e, "_decal" ) ) { if ( !e.classname_is( "_decal" ) ) {
continue; continue;
} }
@ -427,7 +427,7 @@ void ProcessDecals( void ){
} }
/* find target */ /* find target */
e2 = FindTargetEntity( ValueForKey( &e, "target" ) ); e2 = FindTargetEntity( e.valueForKey( "target" ) );
/* no target? */ /* no target? */
if ( e2 == NULL ) { if ( e2 == NULL ) {

View File

@ -763,7 +763,7 @@ void CreateMapFogs( void ){
/* ydnar: global fog */ /* ydnar: global fog */
const char *globalFog; const char *globalFog;
if ( ENT_READKV( &globalFog, &entities[ 0 ], "_fog", "fog" ) ) { if ( entities[ 0 ].read_keyvalue( globalFog, "_fog", "fog" ) ) {
/* test limit */ /* test limit */
if ( numMapFogs >= MAX_MAP_FOGS ) { if ( numMapFogs >= MAX_MAP_FOGS ) {
Error( "Exceeded MAX_MAP_FOGS (%d) trying to add global fog", MAX_MAP_FOGS ); Error( "Exceeded MAX_MAP_FOGS (%d) trying to add global fog", MAX_MAP_FOGS );

View File

@ -108,7 +108,7 @@ xmlNodePtr LeakFile( tree_t *tree ){
count++; count++;
} }
// add the occupant center // 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] ); fprintf( linefile, "%f %f %f\n", mid[0], mid[1], mid[2] );
point = xml_NodeForVec( mid ); point = xml_NodeForVec( mid );

View File

@ -222,10 +222,10 @@ void CreateEntityLights( void ){
e = &entities[ i ]; e = &entities[ i ];
/* ydnar: check for lightJunior */ /* ydnar: check for lightJunior */
bool junior; bool junior;
if ( ent_class_is( e, "lightJunior" ) ) { if ( e->classname_is( "lightJunior" ) ) {
junior = true; junior = true;
} }
else if ( ent_class_prefixed( e, "light" ) ) { else if ( e->classname_prefixed( "light" ) ) {
junior = false; junior = false;
} }
else{ else{
@ -233,7 +233,7 @@ void CreateEntityLights( void ){
} }
/* lights with target names (and therefore styles) are only parsed from BSP */ /* 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; continue;
} }
@ -244,7 +244,7 @@ void CreateEntityLights( void ){
lights = light; lights = light;
/* handle spawnflags */ /* handle spawnflags */
const int spawnflags = IntForKey( e, "spawnflags" ); const int spawnflags = e->intForKey( "spawnflags" );
LightFlags flags; LightFlags flags;
/* ydnar: quake 3+ light behavior */ /* ydnar: quake 3+ light behavior */
@ -316,55 +316,55 @@ void CreateEntityLights( void ){
/* ydnar: set fade key (from wolf) */ /* ydnar: set fade key (from wolf) */
light->fade = 1.0f; light->fade = 1.0f;
if ( light->flags & LightFlags::AttenLinear ) { if ( light->flags & LightFlags::AttenLinear ) {
light->fade = FloatForKey( e, "fade" ); light->fade = e->floatForKey( "fade" );
if ( light->fade == 0.0f ) { if ( light->fade == 0.0f ) {
light->fade = 1.0f; light->fade = 1.0f;
} }
} }
/* ydnar: set angle scaling (from vlight) */ /* ydnar: set angle scaling (from vlight) */
light->angleScale = FloatForKey( e, "_anglescale" ); light->angleScale = e->floatForKey( "_anglescale" );
if ( light->angleScale != 0.0f ) { if ( light->angleScale != 0.0f ) {
light->flags |= LightFlags::AttenAngle; light->flags |= LightFlags::AttenAngle;
} }
/* set origin */ /* set origin */
GetVectorForKey( e, "origin", light->origin ); e->vectorForKey( "origin", light->origin );
ENT_READKV( &light->style, e, "_style", "style" ); e->read_keyvalue( light->style, "_style", "style" );
if ( light->style < LS_NORMAL || light->style >= LS_NONE ) { if ( light->style < LS_NORMAL || light->style >= LS_NONE ) {
Error( "Invalid lightstyle (%d) on entity %zu", light->style, i ); Error( "Invalid lightstyle (%d) on entity %zu", light->style, i );
} }
/* set light intensity */ /* set light intensity */
float intensity = 300.f; float intensity = 300.f;
ENT_READKV( &intensity, e, "_light", "light" ); e->read_keyvalue( intensity, "_light", "light" );
if ( intensity == 0.0f ) { if ( intensity == 0.0f ) {
intensity = 300.0f; intensity = 300.0f;
} }
{ /* ydnar: set light scale (sof2) */ { /* ydnar: set light scale (sof2) */
float scale; float scale;
if( ENT_READKV( &scale, e, "scale" ) && scale != 0.f ) if( e->read_keyvalue( scale, "scale" ) && scale != 0.f )
intensity *= scale; intensity *= scale;
} }
/* ydnar: get deviance and samples */ /* ydnar: get deviance and samples */
float deviance = FloatForKey( e, "_deviance", "_deviation", "_jitter" ); float deviance = e->floatForKey( "_deviance", "_deviation", "_jitter" );
if ( deviance < 0.f ) if ( deviance < 0.f )
deviance = 0.f; deviance = 0.f;
int numSamples = IntForKey( e, "_samples" ); int numSamples = e->intForKey( "_samples" );
if ( numSamples < 1 ) if ( numSamples < 1 )
numSamples = 1; numSamples = 1;
intensity /= numSamples; intensity /= numSamples;
{ /* ydnar: get filter radius */ { /* 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; light->filterRadius = filterRadius < 0.f? 0.f : filterRadius;
} }
/* set light color */ /* set light color */
if ( ENT_READKV( &light->color, e, "_color" ) ) { if ( e->read_keyvalue( light->color, "_color" ) ) {
if ( colorsRGB ) { if ( colorsRGB ) {
light->color[0] = Image_LinearFloatFromsRGBFloat( light->color[0] ); light->color[0] = Image_LinearFloatFromsRGBFloat( light->color[0] );
light->color[1] = Image_LinearFloatFromsRGBFloat( light->color[1] ); 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->extraDist = extraDist;
light->photons = intensity; light->photons = intensity;
@ -391,7 +391,7 @@ void CreateEntityLights( void ){
/* lights with a target will be spotlights */ /* lights with a target will be spotlights */
const char *target; const char *target;
if ( ENT_READKV( &target, e, "target" ) ) { if ( e->read_keyvalue( target, "target" ) ) {
/* get target */ /* get target */
e2 = FindTargetEntity( target ); e2 = FindTargetEntity( target );
if ( e2 == NULL ) { if ( e2 == NULL ) {
@ -407,10 +407,10 @@ void CreateEntityLights( void ){
/* make a spotlight */ /* make a spotlight */
vec3_t dest; vec3_t dest;
GetVectorForKey( e2, "origin", dest ); e2->vectorForKey( "origin", dest );
VectorSubtract( dest, light->origin, light->normal ); VectorSubtract( dest, light->origin, light->normal );
float dist = VectorNormalize( light->normal, light->normal ); float dist = VectorNormalize( light->normal, light->normal );
float radius = FloatForKey( e, "radius" ); float radius = e->floatForKey( "radius" );
if ( !radius ) { if ( !radius ) {
radius = 64; radius = 64;
} }
@ -426,7 +426,7 @@ void CreateEntityLights( void ){
light->fade = 1.0f; light->fade = 1.0f;
/* ydnar: is this a sun? */ /* ydnar: is this a sun? */
if ( BoolForKey( e, "_sun" ) ) { if ( e->boolForKey( "_sun" ) ) {
/* not a spot light */ /* not a spot light */
numSpotLights--; numSpotLights--;
@ -509,7 +509,7 @@ void CreateSurfaceLights( void ){
/* get sun shader supressor */ /* get sun shader supressor */
const bool nss = BoolForKey( &entities[ 0 ], "_noshadersun" ); const bool nss = entities[ 0 ].boolForKey( "_noshadersun" );
/* walk the list of surfaces */ /* walk the list of surfaces */
for ( i = 0; i < numBSPDrawSurfaces; i++ ) for ( i = 0; i < numBSPDrawSurfaces; i++ )
@ -614,7 +614,7 @@ void SetEntityOrigins( void ){
for ( const auto& e : entities ) for ( const auto& e : entities )
{ {
/* get entity and model */ /* get entity and model */
key = ValueForKey( &e, "model" ); key = e.valueForKey( "model" );
if ( key[ 0 ] != '*' ) { if ( key[ 0 ] != '*' ) {
continue; continue;
} }
@ -623,7 +623,7 @@ void SetEntityOrigins( void ){
/* get entity origin */ /* get entity origin */
vec3_t origin = { 0.f, 0.f, 0.f }; vec3_t origin = { 0.f, 0.f, 0.f };
if ( !ENT_READKV( &origin, &e, "origin" ) ) { if ( !e.read_keyvalue( origin, "origin" ) ) {
continue; continue;
} }
@ -1766,7 +1766,7 @@ void SetupGrid( void ){
} }
/* ydnar: set grid size */ /* ydnar: set grid size */
ENT_READKV( &gridSize, &entities[ 0 ], "gridsize" ); entities[ 0 ].read_keyvalue( gridSize, "gridsize" );
/* quantize it */ /* quantize it */
VectorCopy( gridSize, oldGridSize ); VectorCopy( gridSize, oldGridSize );
@ -1801,7 +1801,7 @@ void SetupGrid( void ){
/* different? */ /* different? */
if ( !VectorCompare( gridSize, oldGridSize ) ) { if ( !VectorCompare( gridSize, oldGridSize ) ) {
sprintf( temp, "%.0f %.0f %.0f", gridSize[ 0 ], gridSize[ 1 ], gridSize[ 2 ] ); 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" ); Sys_FPrintf( SYS_VRB, "Storing adjusted grid size\n" );
} }
@ -1854,7 +1854,7 @@ void LightWorld( bool fastAllocate ){
} }
/* find the optional minimum lighting values */ /* find the optional minimum lighting values */
GetVectorForKey( &entities[ 0 ], "_color", color ); entities[ 0 ].vectorForKey( "_color", color );
if ( colorsRGB ) { if ( colorsRGB ) {
color[0] = Image_LinearFloatFromsRGBFloat( color[0] ); color[0] = Image_LinearFloatFromsRGBFloat( color[0] );
color[1] = Image_LinearFloatFromsRGBFloat( color[1] ); color[1] = Image_LinearFloatFromsRGBFloat( color[1] );
@ -1865,21 +1865,21 @@ void LightWorld( bool fastAllocate ){
} }
/* ambient */ /* ambient */
f = FloatForKey( &entities[ 0 ], "_ambient", "ambient" ); f = entities[ 0 ].floatForKey( "_ambient", "ambient" );
VectorScale( color, f, ambientColor ); VectorScale( color, f, ambientColor );
/* minvertexlight */ /* minvertexlight */
if ( ( minVertex = ENT_READKV( &f, &entities[ 0 ], "_minvertexlight" ) ) ) { if ( ( minVertex = entities[ 0 ].read_keyvalue( f, "_minvertexlight" ) ) ) {
VectorScale( color, f, minVertexLight ); VectorScale( color, f, minVertexLight );
} }
/* mingridlight */ /* mingridlight */
if ( ( minGrid = ENT_READKV( &f, &entities[ 0 ], "_mingridlight" ) ) ) { if ( ( minGrid = entities[ 0 ].read_keyvalue( f, "_mingridlight" ) ) ) {
VectorScale( color, f, minGridLight ); VectorScale( color, f, minGridLight );
} }
/* minlight */ /* minlight */
if ( ENT_READKV( &f, &entities[ 0 ], "_minlight" ) ) { if ( entities[ 0 ].read_keyvalue( f, "_minlight" ) ) {
VectorScale( color, f, minLight ); VectorScale( color, f, minLight );
if ( !minVertex ) if ( !minVertex )
VectorScale( color, f, minVertexLight ); VectorScale( color, f, minVertexLight );
@ -1888,7 +1888,7 @@ void LightWorld( bool fastAllocate ){
} }
/* maxlight */ /* maxlight */
if ( ENT_READKV( &f, &entities[ 0 ], "_maxlight" ) ) { if ( entities[ 0 ].read_keyvalue( f, "_maxlight" ) ) {
maxLight = f > 255? 255 : f < 0? 0 : f; maxLight = f > 255? 255 : f < 0? 0 : f;
} }
@ -2961,7 +2961,7 @@ int LightMain( int argc, char **argv ){
InjectCommandLine( argv, 0, argc - 1 ); InjectCommandLine( argv, 0, argc - 1 );
/* load map file */ /* load map file */
if ( !BoolForKey( &entities[ 0 ], "_keepLights" ) ) { if ( !entities[ 0 ].boolForKey( "_keepLights" ) ) {
LoadMapFile( name, true, false ); LoadMapFile( name, true, false );
} }

View File

@ -1126,19 +1126,19 @@ static void PopulateTraceNodes( void ){
/* get entity origin */ /* get entity origin */
vec3_t origin; vec3_t origin;
GetVectorForKey( e, "origin", origin ); e->vectorForKey( "origin", origin );
/* get scale */ /* get scale */
vec3_t scale = { 1.f, 1.f, 1.f }; vec3_t scale = { 1.f, 1.f, 1.f };
if( !ENT_READKV( &scale, e, "modelscale_vec" ) ) if( !e->read_keyvalue( scale, "modelscale_vec" ) )
if( ENT_READKV( &scale[0], e, "modelscale" ) ) if( e->read_keyvalue( scale[0], "modelscale" ) )
scale[1] = scale[2] = scale[0]; scale[1] = scale[2] = scale[0];
/* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */ /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */
vec3_t angles = { 0.f, 0.f, 0.f }; 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 ] ) ) 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) */ /* set transform matrix (thanks spog) */
m4x4_identity( transform ); m4x4_identity( transform );
@ -1150,7 +1150,7 @@ static void PopulateTraceNodes( void ){
//% m4x4_transpose( transform ); //% m4x4_transpose( transform );
/* get model */ /* get model */
value = ValueForKey( e, "model" ); value = e->valueForKey( "model" );
/* switch on model type */ /* switch on model type */
switch ( value[ 0 ] ) switch ( value[ 0 ] )
@ -1171,7 +1171,7 @@ static void PopulateTraceNodes( void ){
/* external model */ /* external model */
default: default:
{ {
model = LoadModel( value, IntForKey( e, "_frame", "frame" ) ); model = LoadModel( value, e->intForKey( "_frame", "frame" ) );
if ( model == NULL ) { if ( model == NULL ) {
continue; continue;
} }
@ -1181,7 +1181,7 @@ static void PopulateTraceNodes( void ){
} }
/* get model2 */ /* get model2 */
value = ValueForKey( e, "model2" ); value = e->valueForKey( "model2" );
/* switch on model type */ /* switch on model type */
switch ( value[ 0 ] ) switch ( value[ 0 ] )
@ -1201,7 +1201,7 @@ static void PopulateTraceNodes( void ){
/* external model */ /* external model */
default: default:
model = LoadModel( value, IntForKey( e, "_frame2" ) ); model = LoadModel( value, e->intForKey( "_frame2" ) );
if ( model == NULL ) { if ( model == NULL ) {
continue; continue;
} }

View File

@ -4131,7 +4131,7 @@ void SetupFloodLight( void ){
/* floodlight */ /* floodlight */
const char *value; const char *value;
if ( ENT_READKV( &value, &entities[ 0 ], "_floodlight" ) ) { if ( entities[ 0 ].read_keyvalue( value, "_floodlight" ) ) {
double v1,v2,v3,v4,v5,v6; double v1,v2,v3,v4,v5,v6;
v1 = v2 = v3 = 0; v1 = v2 = v3 = 0;
v4 = floodlightDistance; v4 = floodlightDistance;

View File

@ -3405,7 +3405,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){
/* get rgbgen string */ /* get rgbgen string */
if ( rgbGenValues[ style ] == NULL ) { if ( rgbGenValues[ style ] == NULL ) {
sprintf( key, "_style%drgbgen", style ); sprintf( key, "_style%drgbgen", style );
rgbGenValues[ style ] = ValueForKey( &entities[ 0 ], key ); rgbGenValues[ style ] = entities[ 0 ].valueForKey( key );
if ( strEmpty( rgbGenValues[ style ] ) ) { if ( strEmpty( rgbGenValues[ style ] ) ) {
rgbGenValues[ style ] = "wave noise 0.5 1 0 5.37"; rgbGenValues[ style ] = "wave noise 0.5 1 0 5.37";
} }
@ -3421,7 +3421,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){
/* get alphagen string */ /* get alphagen string */
if ( alphaGenValues[ style ] == NULL ) { if ( alphaGenValues[ style ] == NULL ) {
sprintf( key, "_style%dalphagen", style ); sprintf( key, "_style%dalphagen", style );
alphaGenValues[ style ] = ValueForKey( &entities[ 0 ], key ); alphaGenValues[ style ] = entities[ 0 ].valueForKey( key );
} }
if ( !strEmpty( alphaGenValues[ style ] ) ) { if ( !strEmpty( alphaGenValues[ style ] ) ) {
sprintf( alphaGen, "\t\talphaGen %s // style %d\n", alphaGenValues[ style ], style ); sprintf( alphaGen, "\t\talphaGen %s // style %d\n", alphaGenValues[ style ], style );

View File

@ -846,14 +846,14 @@ static void MergeOrigin( entity_t *ent, vec3_t origin ){
char string[128]; char string[128];
/* we have not parsed the brush completely yet... */ /* 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 ); VectorMA( origin, -1, ent->originbrush_origin, adjustment );
VectorAdd( adjustment, ent->origin, ent->origin ); VectorAdd( adjustment, ent->origin, ent->origin );
VectorCopy( origin, ent->originbrush_origin ); VectorCopy( origin, ent->originbrush_origin );
sprintf( string, "%f %f %f", ent->origin[0], ent->origin[1], ent->origin[2] ); 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 ){ brush_t *FinishBrush( bool noCollapseGroups ){
@ -871,7 +871,7 @@ brush_t *FinishBrush( bool noCollapseGroups ){
vec3_t origin; vec3_t origin;
Sys_Printf( "Entity %i (%s), Brush %i: origin brush detected\n", 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 ) { if ( entities.size() == 1 ) {
Sys_FPrintf( SYS_WRN, "Entity %i, Brush %i: origin brushes not allowed in world\n", 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 */ /* determine if the brush is an area portal */
if ( buildBrush->compileFlags & C_AREAPORTAL ) { if ( buildBrush->compileFlags & C_AREAPORTAL ) {
if ( entities.size() != 1 ) { 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; return NULL;
} }
} }
@ -1491,8 +1491,8 @@ void SetEntityBounds( entity_t *e ){
} }
/* try to find explicit min/max key */ /* try to find explicit min/max key */
ENT_READKV( &mins, e, "min" ); e->read_keyvalue( mins, "min" );
ENT_READKV( &maxs, e, "max" ); e->read_keyvalue( maxs, "max" );
/* store the bounds */ /* store the bounds */
for ( b = e->brushes; b; b = b->next ) 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) */ /* 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; return;
/* get number of layers (support legacy "layers" key as well) */ /* 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_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" ); Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
return; return;
@ -1546,14 +1546,14 @@ void LoadEntityIndexMap( entity_t *e ){
} }
/* get base shader name (support legacy "shader" key as well) */ /* 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_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" ); Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
return; return;
} }
/* note it */ /* 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 */ /* handle tga image */
if ( striEqual( path_get_extension( indexMapFilename ), "tga" ) ) { if ( striEqual( path_get_extension( indexMapFilename ), "tga" ) ) {
@ -1621,7 +1621,7 @@ void LoadEntityIndexMap( entity_t *e ){
/* get height offsets */ /* get height offsets */
const char *offset; 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 */ /* value is a space-separated set of numbers */
/* get each value */ /* get each value */
for ( i = 0; i < 256 && !strEmpty( offset ); i++ ) for ( i = 0; i < 256 && !strEmpty( offset ); i++ )
@ -1734,7 +1734,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
} }
/* ydnar: get classname */ /* ydnar: get classname */
const char *classname = ent_classname( mapEnt ); const char *classname = mapEnt->classname();
/* ydnar: only lights? */ /* ydnar: only lights? */
if ( onlyLights && !striEqualPrefix( classname, "light" ) ) { if ( onlyLights && !striEqualPrefix( classname, "light" ) ) {
@ -1762,7 +1762,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
GetEntityShadowFlags( mapEnt, NULL, &castShadows, &recvShadows ); GetEntityShadowFlags( mapEnt, NULL, &castShadows, &recvShadows );
/* ydnar: get lightmap scaling value for this entity */ /* 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 ) if ( lightmapScale < 0.0f )
lightmapScale = 0.0f; lightmapScale = 0.0f;
else if ( 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 */ /* ydnar: get cel shader :) for this entity */
shaderInfo_t *celShader; shaderInfo_t *celShader;
const char *value; const char *value;
if( ENT_READKV( &value, mapEnt, "_celshader" ) || if( mapEnt->read_keyvalue( value, "_celshader" ) ||
ENT_READKV( &value, &entities[ 0 ], "_celshader" ) ){ entities[ 0 ].read_keyvalue( value, "_celshader" ) ){
celShader = ShaderInfoForShader( String64()( "textures/", value ) ); celShader = ShaderInfoForShader( String64()( "textures/", value ) );
Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader.c_str() ); 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 */ /* jal : entity based _shadeangle */
float shadeAngle = FloatForKey( mapEnt, "_shadeangle", float shadeAngle = mapEnt->floatForKey( "_shadeangle",
"_smoothnormals", "_sn", "_sa", "_smooth" ); /* vortex' aliases */ "_smoothnormals", "_sn", "_sa", "_smooth" ); /* vortex' aliases */
if ( shadeAngle < 0.0f ) if ( shadeAngle < 0.0f )
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 ); Sys_Printf( "Entity %d (%s) has shading angle of %.4f\n", mapEnt->mapEntityNum, classname, shadeAngle );
/* jal : entity based _samplesize */ /* jal : entity based _samplesize */
int lightmapSampleSize = IntForKey( mapEnt, "_lightmapsamplesize", "_samplesize", "_ss" ); int lightmapSampleSize = mapEnt->intForKey( "_lightmapsamplesize", "_samplesize", "_ss" );
if ( lightmapSampleSize < 0 ) if ( lightmapSampleSize < 0 )
lightmapSampleSize = 0; lightmapSampleSize = 0;
else if ( lightmapSampleSize > 0 ) else if ( lightmapSampleSize > 0 )
@ -1824,7 +1824,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
LoadEntityIndexMap( mapEnt ); LoadEntityIndexMap( mapEnt );
/* get entity origin and adjust brushes */ /* 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 ] ) { if ( mapEnt->originbrush_origin[ 0 ] || mapEnt->originbrush_origin[ 1 ] || mapEnt->originbrush_origin[ 2 ] ) {
AdjustBrushesForOrigin( mapEnt ); AdjustBrushesForOrigin( mapEnt );
} }

View File

@ -1347,7 +1347,7 @@ void AddTriangleModels( entity_t *eparent ){
targetName = ""; targetName = "";
} }
else{ /* misc_model entities target non-worldspawn brush model entities */ else{ /* misc_model entities target non-worldspawn brush model entities */
if ( !ENT_READKV( &targetName, eparent, "targetname" ) ) { if ( !eparent->read_keyvalue( targetName, "targetname" ) ) {
return; return;
} }
} }
@ -1359,24 +1359,24 @@ void AddTriangleModels( entity_t *eparent ){
entity_t *e = &entities[ i ]; entity_t *e = &entities[ i ];
/* convert misc_models into raw geometry */ /* convert misc_models into raw geometry */
if ( !ent_class_is( e, "misc_model" ) ) { if ( !e->classname_is( "misc_model" ) ) {
continue; continue;
} }
/* ydnar: added support for md3 models on non-worldspawn models */ /* ydnar: added support for md3 models on non-worldspawn models */
if ( !strEqual( ValueForKey( e, "target" ), targetName ) ) { if ( !strEqual( e->valueForKey( "target" ), targetName ) ) {
continue; continue;
} }
/* get model name */ /* get model name */
const char *model; 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 ); Sys_Warning( "entity#%d misc_model without a model key\n", e->mapEntityNum );
continue; continue;
} }
/* get model frame */ /* get model frame */
const int frame = IntForKey( e, "_frame", "frame" ); const int frame = e->intForKey( "_frame", "frame" );
int castShadows, recvShadows; int castShadows, recvShadows;
if ( eparent == &entities[0] ) { /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */ 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 ); GetEntityShadowFlags( e, eparent, &castShadows, &recvShadows );
/* get spawnflags */ /* get spawnflags */
const int spawnFlags = IntForKey( e, "spawnflags" ); const int spawnFlags = e->intForKey( "spawnflags" );
/* get origin */ /* get origin */
vec3_t origin; vec3_t origin;
GetVectorForKey( e, "origin", origin ); e->vectorForKey( "origin", origin );
VectorSubtract( origin, eparent->origin, origin ); /* offset by parent */ VectorSubtract( origin, eparent->origin, origin ); /* offset by parent */
/* get scale */ /* get scale */
vec3_t scale = { 1.f, 1.f, 1.f }; vec3_t scale = { 1.f, 1.f, 1.f };
if( !ENT_READKV( &scale, e, "modelscale_vec" ) ) if( !e->read_keyvalue( scale, "modelscale_vec" ) )
if( ENT_READKV( &scale[0], e, "modelscale" ) ) if( e->read_keyvalue( scale[0], "modelscale" ) )
scale[1] = scale[2] = scale[0]; scale[1] = scale[2] = scale[0];
/* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */ /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */
const char *value; const char *value;
vec3_t angles = { 0.f, 0.f, 0.f }; 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 ] ) ) 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) */ /* set transform matrix (thanks spog) */
m4x4_t transform; m4x4_t transform;
@ -1458,8 +1458,8 @@ void AddTriangleModels( entity_t *eparent ){
/* ydnar: cel shader support */ /* ydnar: cel shader support */
shaderInfo_t *celShader; shaderInfo_t *celShader;
if( ENT_READKV( &value, e, "_celshader" ) || if( e->read_keyvalue( value, "_celshader" ) ||
ENT_READKV( &value, &entities[ 0 ], "_celshader" ) ){ entities[ 0 ].read_keyvalue( value, "_celshader" ) ){
celShader = ShaderInfoForShader( String64()( "textures/", value ) ); celShader = ShaderInfoForShader( String64()( "textures/", value ) );
} }
else{ else{
@ -1467,31 +1467,31 @@ void AddTriangleModels( entity_t *eparent ){
} }
/* jal : entity based _samplesize */ /* jal : entity based _samplesize */
int lightmapSampleSize = IntForKey( e, "_lightmapsamplesize", "_samplesize", "_ss" ); int lightmapSampleSize = e->intForKey( "_lightmapsamplesize", "_samplesize", "_ss" );
if ( lightmapSampleSize < 0 ) if ( lightmapSampleSize < 0 )
lightmapSampleSize = 0; lightmapSampleSize = 0;
if ( lightmapSampleSize > 0 ) if ( lightmapSampleSize > 0 )
Sys_Printf( "misc_model has lightmap sample size of %.d\n", lightmapSampleSize ); Sys_Printf( "misc_model has lightmap sample size of %.d\n", lightmapSampleSize );
/* get lightmap scale */ /* get lightmap scale */
float lightmapScale = FloatForKey( e, "lightmapscale", "_lightmapscale", "_ls" ); float lightmapScale = e->floatForKey( "lightmapscale", "_lightmapscale", "_ls" );
if ( lightmapScale < 0.0f ) if ( lightmapScale < 0.0f )
lightmapScale = 0.0f; lightmapScale = 0.0f;
else if ( lightmapScale > 0.0f ) else if ( lightmapScale > 0.0f )
Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale ); Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale );
/* jal : entity based _shadeangle */ /* jal : entity based _shadeangle */
float shadeAngle = FloatForKey( e, "_shadeangle", float shadeAngle = e->floatForKey( "_shadeangle",
"_smoothnormals", "_sn", "_sa", "_smooth" ); /* vortex' aliases */ "_smoothnormals", "_sn", "_sa", "_smooth" ); /* vortex' aliases */
if ( shadeAngle < 0.0f ) if ( shadeAngle < 0.0f )
shadeAngle = 0.0f; shadeAngle = 0.0f;
else if ( shadeAngle > 0.0f ) else if ( shadeAngle > 0.0f )
Sys_Printf( "misc_model has shading angle of %.4f\n", shadeAngle ); 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; 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 ); Sys_Printf( "misc_model %s has autoclip depth of %.3f\n", model, clipDepth );

View File

@ -660,7 +660,7 @@ int FloodEntities( tree_t *tree ){
/* get origin */ /* get origin */
vec3_t 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 #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 */ /* as a special case, allow origin-less entities */
if ( VectorCompare( origin, vec3_origin ) ) { if ( VectorCompare( origin, vec3_origin ) ) {
@ -668,12 +668,12 @@ int FloodEntities( tree_t *tree ){
} }
#endif #endif
/* also allow bmodel entities outside, as they could be on a moving path that will go into the map */ /* 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; continue;
} }
/* handle skybox entities */ /* handle skybox entities */
if ( ent_class_is( e, "_skybox" ) ) { if ( e->classname_is( "_skybox" ) ) {
skybox = true; skybox = true;
skyboxPresent = true; skyboxPresent = true;
@ -683,15 +683,15 @@ int FloodEntities( tree_t *tree ){
/* get scale */ /* get scale */
vec3_t scale = { 64.0f, 64.0f, 64.0f }; vec3_t scale = { 64.0f, 64.0f, 64.0f };
if( !ENT_READKV( &scale, e, "_scale" ) ) if( !e->read_keyvalue( scale, "_scale" ) )
if( ENT_READKV( &scale[0], e, "_scale" ) ) if( e->read_keyvalue( scale[0], "_scale" ) )
scale[1] = scale[2] = scale[0]; scale[1] = scale[2] = scale[0];
/* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */ /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */
vec3_t angles = { 0.f, 0.f, 0.f }; 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 ] ) ) 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) */ /* set transform matrix (thanks spog) */
m4x4_identity( skyboxTransform ); m4x4_identity( skyboxTransform );
@ -714,7 +714,7 @@ int FloodEntities( tree_t *tree ){
inside = true; inside = true;
} }
if ( !r ) { 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 ) { else if ( tree->outside_node.occupied ) {
if ( !tripped || tree->outside_node.occupied < tripcount ) { if ( !tripped || tree->outside_node.occupied < tripcount ) {

View File

@ -1035,6 +1035,57 @@ struct entity_t
int firstBrush, numBrushes; /* only valid during BSP compile */ int firstBrush, numBrushes; /* only valid during BSP compile */
std::list<epair_t> epairs; std::list<epair_t> epairs;
vec3_t originbrush_origin; vec3_t originbrush_origin;
void setKeyValue( const char *key, const char *value );
const char *valueForKey( const char *key ) const;
template<typename ... Keys>
bool boolForKey( Keys ... keys ) const {
bool bool_value = false;
read_keyvalue_( bool_value, { keys ... } );
return bool_value;
}
template<typename ... Keys>
int intForKey( Keys ... keys ) const {
int int_value = 0;
read_keyvalue_( int_value, { keys ... } );
return int_value;
}
template<typename ... Keys>
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<typename T, typename ... Keys>
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<const char*>&& keys ) const;
bool read_keyvalue_( int &int_value, std::initializer_list<const char*>&& keys ) const;
bool read_keyvalue_( float &float_value, std::initializer_list<const char*>&& keys ) const;
bool read_keyvalue_( float (&vector3_value)[3], std::initializer_list<const char*>&& keys ) const;
bool read_keyvalue_( char (&string_value)[1024], std::initializer_list<const char*>&& keys ) const;
bool read_keyvalue_( const char *&string_ptr_value, std::initializer_list<const char*>&& keys ) const;
}; };
@ -1819,29 +1870,6 @@ void ParseEPair( std::list<epair_t>& epairs );
void ParseEntities( void ); void ParseEntities( void );
void UnparseEntities( void ); void UnparseEntities( void );
void PrintEntity( const entity_t *ent ); 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 ); entity_t *FindTargetEntity( const char *target );
void GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows ); void GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows );

View File

@ -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 ] */ digest[ 8 ], digest[ 9 ], digest[ 10 ], digest[ 11 ], digest[ 12 ], digest[ 13 ], digest[ 14 ] ); /* no: digest[ 15 ] */
/* add key/value pair to worldspawn */ /* add key/value pair to worldspawn */
SetKeyValue( &entities[ 0 ], key, value ); entities[ 0 ].setKeyValue( key, value );
} }

View File

@ -2564,7 +2564,7 @@ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
int surfaceFlags, contentFlags; int surfaceFlags, contentFlags;
/* vortex: _patchMeta support */ /* vortex: _patchMeta support */
const bool forcePatchMeta = BoolForKey( e, "_patchMeta", "patchMeta" ); const bool forcePatchMeta = e->boolForKey( "_patchMeta", "patchMeta" );
/* invert the surface if necessary */ /* invert the surface if necessary */
if ( ds->backSide || ds->shaderInfo->invert ) { if ( ds->backSide || ds->shaderInfo->invert ) {

View File

@ -291,7 +291,7 @@ void TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds ){
mesh_t src, *subdivided, *mesh; mesh_t src, *subdivided, *mesh;
/* vortex: _patchMeta, _patchQuality, _patchSubdivide support */ /* vortex: _patchMeta, _patchQuality, _patchSubdivide support */
const bool forcePatchMeta = BoolForKey( e, "_patchMeta", "patchMeta" ); const bool forcePatchMeta = e->boolForKey( "_patchMeta", "patchMeta" );
/* try to early out */ /* try to early out */
if ( ds->numVerts == 0 || ds->type != ESurfaceType::Patch || ( !patchMeta && !forcePatchMeta ) ) { 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 iterations;
int patchSubdivision; int patchSubdivision;
if ( ENT_READKV( &patchSubdivision, e, "_patchSubdivide", "patchSubdivide" ) ) { if ( e->read_keyvalue( patchSubdivision, "_patchSubdivide", "patchSubdivide" ) ) {
iterations = IterationsForCurve( ds->longestCurve, patchSubdivision ); iterations = IterationsForCurve( ds->longestCurve, patchSubdivision );
} }
else{ else{
const int patchQuality = IntForKey( e, "_patchQuality", "patchQuality" ); const int patchQuality = e->intForKey( "_patchQuality", "patchQuality" );
iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions / ( patchQuality == 0? 1 : patchQuality ) ); iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions / ( patchQuality == 0? 1 : patchQuality ) );
} }

View File

@ -295,7 +295,7 @@ void CalcVis( void ){
/* ydnar: rr2do2's farplane code */ /* ydnar: rr2do2's farplane code */
const char *value; 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 */ "fogclip", /* wolf compatibility */
"distancecull" ) ){ /* sof2 compatibility */ "distancecull" ) ){ /* sof2 compatibility */
farPlaneDist = atof( value ); farPlaneDist = atof( value );

View File

@ -263,7 +263,7 @@ void SetModelNumbers( void ){
if ( entities[i].brushes || entities[i].patches ) { if ( entities[i].brushes || entities[i].patches ) {
sprintf( value, "*%i", models ); sprintf( value, "*%i", models );
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 */ /* -keeplights option: force lights to be kept and ignore what the map file says */
if ( keepLights ) { if ( keepLights ) {
SetKeyValue( &entities[0], "_keepLights", "1" ); entities[0].setKeyValue( "_keepLights", "1" );
} }
/* ydnar: determine if we keep lights in the bsp */ /* 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 */ /* any light that is controlled (has a targetname) must have a unique style number generated for it */
numStyles = 0; numStyles = 0;
@ -298,11 +298,11 @@ void SetLightStyles( void ){
{ {
e = &entities[ i ]; e = &entities[ i ];
if ( !ent_class_prefixed( e, "light" ) ) { if ( !e->classname_prefixed( "light" ) ) {
continue; continue;
} }
const char *t; const char *t;
if ( !ENT_READKV( &t, e, "targetname" ) ) { if ( !e->read_keyvalue( t, "targetname" ) ) {
/* ydnar: strip the light from the BSP file */ /* ydnar: strip the light from the BSP file */
if ( !keepLights ) { if ( !keepLights ) {
e->epairs.clear(); e->epairs.clear();
@ -314,7 +314,7 @@ void SetLightStyles( void ){
} }
/* get existing style */ /* get existing style */
const int style = IntForKey( e, "style" ); const int style = e->intForKey( "style" );
if ( style < LS_NORMAL || style > LS_NONE ) { if ( style < LS_NORMAL || style > LS_NONE ) {
Error( "Invalid lightstyle (%d) on entity %zu", style, i ); Error( "Invalid lightstyle (%d) on entity %zu", style, i );
} }
@ -337,12 +337,12 @@ void SetLightStyles( void ){
/* set explicit style */ /* set explicit style */
sprintf( value, "%d", 32 + j ); sprintf( value, "%d", 32 + j );
SetKeyValue( e, "style", value ); e->setKeyValue( "style", value );
/* set old style */ /* set old style */
if ( style != LS_NORMAL ) { if ( style != LS_NORMAL ) {
sprintf( value, "%d", style ); sprintf( value, "%d", style );
SetKeyValue( e, "switch_style", value ); e->setKeyValue( "switch_style", value );
} }
} }