manage entity key value reading routines

This commit is contained in:
Garux 2020-01-24 02:47:33 +03:00
parent ebf88b0842
commit 433b9e776b
20 changed files with 418 additions and 755 deletions

View File

@ -314,8 +314,8 @@ int pk3BSPMain( int argc, char **argv ){
res2list( pk3Shaders, str ); res2list( pk3Shaders, str );
} }
} }
strcpy( str, ValueForKey( &entities[0], "music" ) );
if ( !strEmpty( str ) ){ if ( ENT_READKV( &entities[0], "music", &str ) ){
FixDOSName( str ); FixDOSName( str );
DefaultExtension( str, ".wav" ); DefaultExtension( str, ".wav" );
res2list( pk3Sounds, str ); res2list( pk3Sounds, str );
@ -323,18 +323,17 @@ int pk3BSPMain( int argc, char **argv ){
for ( i = 0; i < numBSPEntities && i < numEntities; ++i ) for ( i = 0; i < numBSPEntities && i < numEntities; ++i )
{ {
strcpy( str, ValueForKey( &entities[i], "noise" ) ); if ( ENT_READKV( &entities[i], "noise", &str ) && str[0] != '*' ){
if ( !strEmpty( str ) && *str != '*' ){
FixDOSName( str ); FixDOSName( str );
DefaultExtension( str, ".wav" ); DefaultExtension( str, ".wav" );
res2list( pk3Sounds, str ); res2list( pk3Sounds, str );
} }
if ( striEqual( ValueForKey( &entities[i], "classname" ), "func_plat" ) ){ if ( ent_class_is( &entities[i], "func_plat" ) ){
res2list( pk3Sounds, "sound/movers/plats/pt1_strt.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_strt.wav" );
res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" );
} }
if ( striEqual( ValueForKey( &entities[i], "classname" ), "target_push" ) ){ if ( ent_class_is( &entities[i], "target_push" ) ){
if ( !( IntForKey( &entities[i], "spawnflags") & 1 ) ){ if ( !( IntForKey( &entities[i], "spawnflags") & 1 ) ){
res2list( pk3Sounds, "sound/misc/windfly.wav" ); res2list( pk3Sounds, "sound/misc/windfly.wav" );
} }
@ -986,8 +985,7 @@ int repackBSPMain( int argc, char **argv ){
res2list( pk3Shaders, str ); res2list( pk3Shaders, str );
} }
} }
strcpy( str, ValueForKey( &entities[0], "music" ) ); if ( ENT_READKV( &entities[0], "music", &str ) ){
if ( !strEmpty( str ) ){
FixDOSName( str ); FixDOSName( str );
DefaultExtension( str, ".wav" ); DefaultExtension( str, ".wav" );
res2list( pk3Sounds, str ); res2list( pk3Sounds, str );
@ -995,18 +993,17 @@ int repackBSPMain( int argc, char **argv ){
for ( i = 0; i < numBSPEntities && i < numEntities; ++i ) for ( i = 0; i < numBSPEntities && i < numEntities; ++i )
{ {
strcpy( str, ValueForKey( &entities[i], "noise" ) ); if ( ENT_READKV( &entities[i], "noise", &str ) && str[0] != '*' ){
if ( !strEmpty( str ) && str[0] != '*' ){
FixDOSName( str ); FixDOSName( str );
DefaultExtension( str, ".wav" ); DefaultExtension( str, ".wav" );
res2list( pk3Sounds, str ); res2list( pk3Sounds, str );
} }
if ( striEqual( ValueForKey( &entities[i], "classname" ), "func_plat" ) ){ if ( ent_class_is( &entities[i], "func_plat" ) ){
res2list( pk3Sounds, "sound/movers/plats/pt1_strt.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_strt.wav" );
res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" );
} }
if ( striEqual( ValueForKey( &entities[i], "classname" ), "target_push" ) ){ if ( ent_class_is( &entities[i], "target_push" ) ){
if ( !( IntForKey( &entities[i], "spawnflags") & 1 ) ){ if ( !( IntForKey( &entities[i], "spawnflags") & 1 ) ){
res2list( pk3Sounds, "sound/misc/windfly.wav" ); res2list( pk3Sounds, "sound/misc/windfly.wav" );
} }

View File

@ -101,7 +101,6 @@ static void autocaulk_write(){
static void ProcessAdvertisements( void ) { static void ProcessAdvertisements( void ) {
int i; int i;
const char* className;
const char* modelKey; const char* modelKey;
int modelNum; int modelNum;
bspModel_t* adModel; bspModel_t* adModel;
@ -112,9 +111,7 @@ static void ProcessAdvertisements( void ) {
for ( i = 0; i < numEntities; i++ ) { for ( i = 0; i < numEntities; i++ ) {
/* is an advertisement? */ /* is an advertisement? */
className = ValueForKey( &entities[ i ], "classname" ); if ( ent_class_is( &entities[ i ], "advertisement" ) ) {
if ( striEqual( "advertisement", className ) ) {
modelKey = ValueForKey( &entities[ i ], "model" ); modelKey = ValueForKey( &entities[ i ], "model" );
@ -190,16 +187,10 @@ static void SetCloneModelNumbers( void ){
} }
/* is this a clone? */ /* is this a clone? */
value = ValueForKey( &entities[ i ], "_ins" ); if( ENT_READKV( &entities[ i ], "_ins", &value ) ||
if ( strEmpty( value ) ) { ENT_READKV( &entities[ i ], "_instance", &value ) ||
value = ValueForKey( &entities[ i ], "_instance" ); ENT_READKV( &entities[ i ], "_clone", &value ) )
}
if ( strEmpty( value ) ) {
value = ValueForKey( &entities[ i ], "_clone" );
}
if ( !strEmpty( value ) ) {
continue; continue;
}
/* add the model key */ /* add the model key */
sprintf( modelValue, "*%d", models ); sprintf( modelValue, "*%d", models );
@ -217,32 +208,24 @@ static void SetCloneModelNumbers( void ){
continue; continue;
} }
/* is this a clone? */ /* isn't this a clone? */
value = ValueForKey( &entities[ i ], "_ins" ); if( !ENT_READKV( &entities[ i ], "_ins", &value ) &&
if ( strEmpty( value ) ) { !ENT_READKV( &entities[ i ], "_instance", &value ) &&
value = ValueForKey( &entities[ i ], "_instance" ); !ENT_READKV( &entities[ i ], "_clone", &value ) )
}
if ( strEmpty( value ) ) {
value = ValueForKey( &entities[ i ], "_clone" );
}
if ( strEmpty( value ) ) {
continue; continue;
}
/* find an entity with matching clone name */ /* find an entity with matching clone name */
for ( j = 0; j < numEntities; j++ ) for ( j = 0; j < numEntities; j++ )
{ {
/* is this a clone parent? */ /* is this a clone parent? */
value2 = ValueForKey( &entities[ j ], "_clonename" ); if ( !ENT_READKV( &entities[ j ], "_clonename", &value2 ) ) {
if ( strEmpty( value2 ) ) {
continue; continue;
} }
/* do they match? */ /* do they match? */
if ( strEqual( value, value2 ) ) { if ( strEqual( value, value2 ) ) {
/* get the model num */ /* get the model num */
value3 = ValueForKey( &entities[ j ], "model" ); if ( !ENT_READKV( &entities[ j ], "model", &value3 ) ) {
if ( strEmpty( value3 ) ) {
Sys_Warning( "Cloned entity %s referenced entity without model\n", value2 ); Sys_Warning( "Cloned entity %s referenced entity without model\n", value2 );
continue; continue;
} }
@ -316,42 +299,32 @@ static void FixBrushSides( entity_t *e ){
*/ */
void ProcessWorldModel( void ){ void ProcessWorldModel( void ){
int i, s;
entity_t *e; entity_t *e;
tree_t *tree; tree_t *tree;
face_t *faces; face_t *faces;
bool ignoreLeaks, leaked;
xmlNodePtr polyline, leaknode; xmlNodePtr polyline, leaknode;
char level[ 2 ], shader[ 1024 ]; char level[ 2 ];
const char *value; const char *value;
int leakStatus; int leakStatus;
/* sets integer blockSize from worldspawn "_blocksize" key if it exists */ /* sets integer blockSize from worldspawn "_blocksize" key if it exists */
value = ValueForKey( &entities[ 0 ], "_blocksize" ); if( ENT_READKV( &entities[ 0 ], "_blocksize", &value ) ||
if ( strEmpty( value ) ) { ENT_READKV( &entities[ 0 ], "blocksize", &value ) ||
value = ValueForKey( &entities[ 0 ], "blocksize" ); ENT_READKV( &entities[ 0 ], "chopsize", &value ) ) { /* sof2 */
}
if ( strEmpty( value ) ) {
value = ValueForKey( &entities[ 0 ], "chopsize" ); /* sof2 */
}
if ( !strEmpty( value ) ) {
/* scan 3 numbers */ /* scan 3 numbers */
s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] ); const int s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] );
/* handle legacy case */ /* handle legacy case */
if ( s == 1 ) { if ( s == 1 || s == 2 ) {
blockSize[ 1 ] = blockSize[ 0 ]; blockSize[ 1 ] = blockSize[ 2 ] = blockSize[ 0 ];
blockSize[ 2 ] = blockSize[ 0 ];
} }
} }
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? */
value = ValueForKey( &entities[ 0 ], "_ignoreleaks" ); /* ydnar */ bool ignoreLeaks = false;
if ( strEmpty( value ) ) { ENT_READKV( &entities[ 0 ], "_ignoreleaks", &ignoreLeaks ) ||
value = ValueForKey( &entities[ 0 ], "ignoreleaks" ); ENT_READKV( &entities[ 0 ], "ignoreleaks", &ignoreLeaks );
}
ignoreLeaks = ( value[ 0 ] == '1' );
/* begin worldspawn model */ /* begin worldspawn model */
BeginModel(); BeginModel();
@ -382,7 +355,7 @@ void ProcessWorldModel( void ){
} }
} }
leaked = ( leakStatus != FLOODENTITIES_GOOD ); const bool leaked = ( leakStatus != FLOODENTITIES_GOOD );
if( leaked ){ if( leaked ){
Sys_FPrintf( SYS_NOXMLflag | SYS_ERR, "**********************\n" ); Sys_FPrintf( SYS_NOXMLflag | SYS_ERR, "**********************\n" );
Sys_FPrintf( SYS_NOXMLflag | SYS_ERR, "******* leaked *******\n" ); Sys_FPrintf( SYS_NOXMLflag | SYS_ERR, "******* leaked *******\n" );
@ -482,25 +455,22 @@ void ProcessWorldModel( void ){
} }
/* ydnar: fog hull */ /* ydnar: fog hull */
value = ValueForKey( &entities[ 0 ], "_foghull" ); if ( ENT_READKV( &entities[ 0 ], "_foghull", &value ) ) {
if ( !strEmpty( value ) ) { char shader[MAX_QPATH];
sprintf( shader, "textures/%s", value ); sprintf( shader, "textures/%s", value );
MakeFogHullSurfs( e, tree, shader ); MakeFogHullSurfs( e, tree, shader );
} }
/* ydnar: bug 645: do flares for lights */ /* ydnar: bug 645: do flares for lights */
for ( i = 0; i < numEntities && emitFlares; i++ ) for ( int i = 0; i < numEntities && emitFlares; i++ )
{ {
entity_t *light, *target; entity_t *light, *target;
const char *value, *flareShader; const char *value, *flareShader;
vec3_t origin, targetOrigin, normal, color; vec3_t origin, targetOrigin, normal, color;
int lightStyle;
/* get light */ /* get light */
light = &entities[ i ]; light = &entities[ i ];
value = ValueForKey( light, "classname" ); if ( ent_class_is( light, "light" ) ) {
if ( strEqual( value, "light" ) ) {
/* get flare shader */ /* get flare shader */
flareShader = ValueForKey( light, "_flareshader" ); flareShader = ValueForKey( light, "_flareshader" );
value = ValueForKey( light, "_flare" ); value = ValueForKey( light, "_flare" );
@ -508,14 +478,11 @@ void ProcessWorldModel( void ){
/* get specifics */ /* get specifics */
GetVectorForKey( light, "origin", origin ); GetVectorForKey( light, "origin", origin );
GetVectorForKey( light, "_color", color ); GetVectorForKey( light, "_color", color );
lightStyle = IntForKey( light, "_style" ); int lightStyle = 0;
if ( lightStyle == 0 ) { ENT_READKV( light, "_style", &lightStyle ) || ENT_READKV( light, "style", &lightStyle );
lightStyle = IntForKey( light, "style" );
}
/* handle directional spotlights */ /* handle directional spotlights */
value = ValueForKey( light, "target" ); if ( ENT_READKV( light, "target", &value ) ) {
if ( !strEmpty( value ) ) {
/* get target light */ /* get target light */
target = FindTargetEntity( value ); target = FindTargetEntity( value );
if ( target != NULL ) { if ( target != NULL ) {
@ -702,7 +669,6 @@ void OnlyEnts( void ){
char out[ 1024 ]; char out[ 1024 ];
char save_cmdline[1024], save_version[1024], save_gridsize[1024]; char save_cmdline[1024], save_version[1024], save_gridsize[1024];
const char *p;
/* note it */ /* note it */
Sys_Printf( "--- OnlyEnts ---\n" ); Sys_Printf( "--- OnlyEnts ---\n" );
@ -711,15 +677,9 @@ void OnlyEnts( void ){
LoadBSPFile( out ); LoadBSPFile( out );
ParseEntities(); ParseEntities();
p = ValueForKey( &entities[0], "_q3map2_cmdline" ); strcpyQ( save_cmdline, ValueForKey( &entities[0], "_q3map2_cmdline" ), sizeof( save_cmdline ) );
strncpy( save_cmdline, p, sizeof( save_cmdline ) ); strcpyQ( save_version, ValueForKey( &entities[0], "_q3map2_version" ), sizeof( save_version ) );
save_cmdline[sizeof( save_cmdline ) - 1] = 0; strcpyQ( save_gridsize, ValueForKey( &entities[0], "gridsize" ), sizeof( save_gridsize ) );
p = ValueForKey( &entities[0], "_q3map2_version" );
strncpy( save_version, p, sizeof( save_version ) );
save_version[sizeof( save_version ) - 1] = 0;
p = ValueForKey( &entities[0], "gridsize" );
strncpy( save_gridsize, p, sizeof( save_gridsize ) );
save_gridsize[sizeof( save_gridsize ) - 1] = 0;
numEntities = 0; numEntities = 0;

View File

@ -603,7 +603,6 @@ void ParseEntities( void ){
* must be called before UnparseEntities * must be called before UnparseEntities
*/ */
void InjectCommandLine( char **argv, int beginArgs, int endArgs ){ void InjectCommandLine( char **argv, int beginArgs, int endArgs ){
const char *previousCommandLine;
char newCommandLine[1024]; char newCommandLine[1024];
const char *inpos; const char *inpos;
char *outpos = newCommandLine; char *outpos = newCommandLine;
@ -613,9 +612,7 @@ void InjectCommandLine( char **argv, int beginArgs, int endArgs ){
if ( nocmdline ){ if ( nocmdline ){
return; return;
} }
previousCommandLine = ValueForKey( &entities[0], "_q3map2_cmdline" ); if ( ENT_READKV( &entities[0], "_q3map2_cmdline", &inpos ) ) { // read previousCommandLine
if ( previousCommandLine && *previousCommandLine ) {
inpos = previousCommandLine;
while ( outpos != sentinel && *inpos ) while ( outpos != sentinel && *inpos )
*outpos++ = *inpos++; *outpos++ = *inpos++;
if ( outpos != sentinel ) { if ( outpos != sentinel ) {
@ -651,12 +648,9 @@ void InjectCommandLine( char **argv, int beginArgs, int endArgs ){
*/ */
void UnparseEntities( void ){ void UnparseEntities( void ){
int i;
char *buf, *end; char *buf, *end;
epair_t *ep;
char line[ 2048 ]; char line[ 2048 ];
char key[ 1024 ], value[ 1024 ]; char key[ 1024 ], value[ 1024 ];
const char *value2;
/* setup */ /* setup */
@ -665,7 +659,7 @@ void UnparseEntities( void ){
end = buf = bspEntData; end = buf = bspEntData;
/* run through entity list */ /* run through entity list */
for ( i = 0; i < numBSPEntities && i < numEntities; i++ ) for ( int i = 0; i < numBSPEntities && i < numEntities; i++ )
{ {
{ {
int sz = end - buf; int sz = end - buf;
@ -674,17 +668,17 @@ void UnparseEntities( void ){
end = buf + sz; end = buf + sz;
} }
entity_t *e = &entities[ i ];
/* get epair */ /* get epair */
ep = entities[ i ].epairs; if ( e->epairs == NULL ) {
if ( ep == NULL ) {
continue; /* ent got removed */ continue; /* ent got removed */
} }
/* ydnar: certain entities get stripped from bsp file */ /* ydnar: certain entities get stripped from bsp file */
value2 = ValueForKey( &entities[ i ], "classname" ); const char *classname = ent_classname( e );
if ( striEqual( value2, "misc_model" ) || if ( striEqual( classname, "misc_model" ) ||
striEqual( value2, "_decal" ) || striEqual( classname, "_decal" ) ||
striEqual( value2, "_skybox" ) ) { striEqual( classname, "_skybox" ) ) {
continue; continue;
} }
@ -693,7 +687,7 @@ void UnparseEntities( void ){
end += 2; end += 2;
/* walk epair list */ /* walk epair list */
for ( ep = entities[ i ].epairs; ep != NULL; ep = ep->next ) for ( epair_t *ep = e->epairs; ep != NULL; ep = ep->next )
{ {
/* copy and clean */ /* copy and clean */
strcpy( key, ep->key ); strcpy( key, ep->key );
@ -767,25 +761,6 @@ void SetKeyValue( entity_t *ent, const char *key, const char *value ){
ep->value = copystring( value ); ep->value = copystring( value );
} }
/*
KeyExists()
returns true if entity has this key
*/
bool KeyExists( const entity_t *ent, const char *key ){
epair_t *ep;
/* walk epair list */
for ( ep = ent->epairs; ep != NULL; ep = ep->next )
{
if ( EPAIR_EQUAL( ep->key, key ) ) {
return true;
}
}
/* no match */
return false;
}
/* /*
ValueForKey() ValueForKey()
@ -793,16 +768,13 @@ bool KeyExists( const entity_t *ent, const char *key ){
*/ */
const char *ValueForKey( const entity_t *ent, const char *key ){ const char *ValueForKey( const entity_t *ent, const char *key ){
epair_t *ep;
/* dummy check */ /* dummy check */
if ( ent == NULL ) { if ( ent == NULL ) {
return ""; return "";
} }
/* walk epair list */ /* walk epair list */
for ( ep = ent->epairs; ep != NULL; ep = ep->next ) for ( epair_t *ep = ent->epairs; ep != NULL; ep = ep->next )
{ {
if ( EPAIR_EQUAL( ep->key, key ) ) { if ( EPAIR_EQUAL( ep->key, key ) ) {
return ep->value; return ep->value;
@ -813,7 +785,9 @@ const char *ValueForKey( const entity_t *ent, const char *key ){
return ""; return "";
} }
bool BoolForKey( const entity_t *ent, const char *key ){
return ValueForKey( ent, key )[0] == '1';
}
/* /*
IntForKey() IntForKey()
@ -821,11 +795,7 @@ const char *ValueForKey( const entity_t *ent, const char *key ){
*/ */
int IntForKey( const entity_t *ent, const char *key ){ int IntForKey( const entity_t *ent, const char *key ){
const char *k; return atoi( ValueForKey( ent, key ) );
k = ValueForKey( ent, key );
return atoi( k );
} }
@ -836,11 +806,7 @@ int IntForKey( const entity_t *ent, const char *key ){
*/ */
vec_t FloatForKey( const entity_t *ent, const char *key ){ vec_t FloatForKey( const entity_t *ent, const char *key ){
const char *k; return atof( ValueForKey( ent, key ) );
k = ValueForKey( ent, key );
return atof( k );
} }
@ -851,21 +817,82 @@ vec_t FloatForKey( const entity_t *ent, const char *key ){
*/ */
void GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec ){ void GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec ){
const char *k;
double v1, v2, v3;
/* get value */
k = ValueForKey( ent, key );
/* scanf into doubles, then assign, so it is vec_t size independent */ /* scanf into doubles, then assign, so it is vec_t size independent */
v1 = v2 = v3 = 0.0; double v1, v2, v3;
sscanf( k, "%lf %lf %lf", &v1, &v2, &v3 ); if( 3 == sscanf( ValueForKey( ent, key ), "%lf %lf %lf", &v1, &v2, &v3 ) ){
vec[ 0 ] = v1; vec[ 0 ] = v1;
vec[ 1 ] = v2; vec[ 1 ] = v2;
vec[ 2 ] = v3; vec[ 2 ] = v3;
}
else{
VectorClear( vec );
}
} }
bool entity_read_bool( const entity_t *entity, const char *key, bool *bool_value ){
const char *value = ValueForKey( entity, key );
if( !strEmpty( value ) ){
*bool_value = ( value[0] == '1' );
return true;
}
return false;
}
bool entity_read_int( const entity_t *entity, const char *key, int *int_value ){
const char *value = ValueForKey( entity, key );
if( !strEmpty( value ) ){
*int_value = atoi( value );
return true;
}
return false;
}
bool entity_read_float( const entity_t *entity, const char *key, float *float_value ){
const char *value = ValueForKey( entity, key );
if( !strEmpty( value ) ){
*float_value = atof( value );
return true;
}
return false;
}
bool entity_read_vector3( const entity_t *entity, const char *key, float (*vector3_value)[3] ){
const char *value = ValueForKey( entity, key );
if( !strEmpty( value ) ){
float v0, v1, v2;
if( 3 == sscanf( value, "%f %f %f", &v0, &v1, &v2 ) ){
(*vector3_value)[0] = v0;
(*vector3_value)[1] = v1;
(*vector3_value)[2] = v2;
return true;
}
}
return false;
}
bool entity_read_string( const entity_t *entity, const char *key, char (*string_value)[] ){
const char *value = ValueForKey( entity, key );
if( !strEmpty( value ) ){
strcpy( *string_value, value );
return true;
}
return false;
}
bool entity_read_string_ptr( const entity_t *entity, const char *key, const char **string_ptr_value ){
const char *value = ValueForKey( entity, key );
if( !strEmpty( value ) ){
*string_ptr_value = value;
return true;
}
return false;
}
const char *ent_classname( const entity_t *entity ){
return ValueForKey( entity, "classname" );
}
bool ent_class_is( const entity_t *entity, const char *classname ){
return striEqual( ent_classname( entity ), classname );
}
bool ent_class_prefixed( const entity_t *entity, const char *prefix ){
return striEqualPrefix( ent_classname( entity ), prefix );
}
/* /*
@ -874,15 +901,10 @@ void GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec ){
*/ */
entity_t *FindTargetEntity( const char *target ){ entity_t *FindTargetEntity( const char *target ){
int i;
const char *n;
/* walk entity list */ /* walk entity list */
for ( i = 0; i < numEntities; i++ ) for ( int i = 0; i < numEntities; i++ )
{ {
n = ValueForKey( &entities[ i ], "targetname" ); if ( strEqual( ValueForKey( &entities[ i ], "targetname" ), target ) ) {
if ( strEqual( n, target ) ) {
return &entities[ i ]; return &entities[ i ];
} }
} }
@ -900,47 +922,26 @@ entity_t *FindTargetEntity( const char *target ){
*/ */
void GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows ){ void GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows ){
const char *value;
/* get cast shadows */ /* get cast shadows */
if ( castShadows != NULL ) { if ( castShadows != NULL ) {
value = ValueForKey( ent, "_castShadows" ); ENT_READKV( ent, "_castShadows", castShadows ) ||
if ( strEmpty( value ) ) { ENT_READKV( ent, "_cs", castShadows ) ||
value = ValueForKey( ent, "_cs" ); ENT_READKV( ent2, "_castShadows", castShadows ) ||
} ENT_READKV( ent2, "_cs", castShadows );
if ( strEmpty( value ) ) {
value = ValueForKey( ent2, "_castShadows" );
}
if ( strEmpty( value ) ) {
value = ValueForKey( ent2, "_cs" );
}
if ( !strEmpty( value ) ) {
*castShadows = atoi( value );
}
} }
/* receive */ /* receive */
if ( recvShadows != NULL ) { if ( recvShadows != NULL ) {
value = ValueForKey( ent, "_receiveShadows" ); ENT_READKV( ent, "_receiveShadows", recvShadows ) ||
if ( strEmpty( value ) ) { ENT_READKV( ent, "_rs", recvShadows ) ||
value = ValueForKey( ent, "_rs" ); ENT_READKV( ent2, "_receiveShadows", recvShadows ) ||
} ENT_READKV( ent2, "_rs", recvShadows );
if ( strEmpty( value ) ) {
value = ValueForKey( ent2, "_receiveShadows" );
}
if ( strEmpty( value ) ) {
value = ValueForKey( ent2, "_rs" );
}
if ( !strEmpty( value ) ) {
*recvShadows = atoi( value );
}
} }
/* vortex: game-specific default entity keys */ /* vortex: game-specific default entity keys */
value = ValueForKey( ent, "classname" );
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 ( striEqual( value, "func_wall" ) ) { if ( ent_class_is( ent, "func_wall" ) ) {
if ( recvShadows != NULL ) { if ( recvShadows != NULL ) {
*recvShadows = 1; *recvShadows = 1;
} }

View File

@ -342,8 +342,6 @@ int ConvertBSPToASE( char *bspName ){
bspShader_t *shader; bspShader_t *shader;
bspModel_t *model; bspModel_t *model;
entity_t *e; entity_t *e;
vec3_t origin;
const char *key;
char name[ 1024 ], base[ 1024 ], dirname[ 1024 ]; char name[ 1024 ], base[ 1024 ], dirname[ 1024 ];
int lmIndices[ numBSPShaders ]; int lmIndices[ numBSPShaders ];
@ -409,7 +407,7 @@ int ConvertBSPToASE( char *bspName ){
} }
else else
{ {
key = ValueForKey( e, "model" ); const char *key = ValueForKey( e, "model" );
if ( key[ 0 ] != '*' ) { if ( key[ 0 ] != '*' ) {
continue; continue;
} }
@ -418,13 +416,8 @@ int ConvertBSPToASE( char *bspName ){
model = &bspModels[ modelNum ]; model = &bspModels[ modelNum ];
/* get entity origin */ /* get entity origin */
key = ValueForKey( e, "origin" ); vec3_t origin;
if ( strEmpty( key ) ) {
VectorClear( origin );
}
else{
GetVectorForKey( e, "origin", origin ); GetVectorForKey( e, "origin", origin );
}
/* convert model */ /* convert model */
ConvertModel( f, model, modelNum, origin, lmIndices ); ConvertModel( f, model, modelNum, origin, lmIndices );

View File

@ -460,15 +460,14 @@ int ScaleBSPMain( int argc, char **argv ){
for ( i = 0; i < numBSPEntities && i < numEntities; i++ ) for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
{ {
/* scale origin */ /* scale origin */
GetVectorForKey( &entities[ i ], "origin", vec ); if ( ENT_READKV( &entities[ i ], "origin", &vec ) ) {
if ( ( vec[ 0 ] || vec[ 1 ] || vec[ 2 ] ) ) { if ( ent_class_prefixed( &entities[i], "info_player_" ) ) {
if ( striEqualPrefix( ValueForKey( &entities[i], "classname" ), "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 ( striEqualPrefix( ValueForKey( &entities[i], "classname" ), "info_player_" ) ) { if ( ent_class_prefixed( &entities[i], "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 ] );
@ -487,16 +486,14 @@ int ScaleBSPMain( int argc, char **argv ){
} }
/* scale door lip */ /* scale door lip */
f = FloatForKey( &entities[ i ], "lip" ); if ( ENT_READKV( &entities[ i ], "lip", &f ) ) {
if ( f ) {
f *= scale[axis]; f *= scale[axis];
sprintf( str, "%f", f ); sprintf( str, "%f", f );
SetKeyValue( &entities[ i ], "lip", str ); SetKeyValue( &entities[ i ], "lip", str );
} }
/* scale plat height */ /* scale plat height */
f = FloatForKey( &entities[ i ], "height" ); if ( ENT_READKV( &entities[ i ], "height", &f ) ) {
if ( f ) {
f *= scale[2]; f *= scale[2];
sprintf( str, "%f", f ); sprintf( str, "%f", f );
SetKeyValue( &entities[ i ], "height", str ); SetKeyValue( &entities[ i ], "height", str );
@ -616,8 +613,7 @@ int ScaleBSPMain( int argc, char **argv ){
} }
/* scale gridsize */ /* scale gridsize */
GetVectorForKey( &entities[ 0 ], "gridsize", vec ); if ( !ENT_READKV( &entities[ 0 ], "gridsize", &vec ) ) {
if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) == 0.0f ) {
VectorCopy( gridSize, vec ); VectorCopy( gridSize, vec );
} }
vec[0] *= scale[0]; vec[0] *= scale[0];
@ -700,15 +696,14 @@ int ShiftBSPMain( int argc, char **argv ){
for ( i = 0; i < numBSPEntities && i < numEntities; i++ ) for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
{ {
/* shift origin */ /* shift origin */
GetVectorForKey( &entities[ i ], "origin", vec ); if ( ENT_READKV( &entities[ i ], "origin", &vec ) ) {
if ( ( vec[ 0 ] || vec[ 1 ] || vec[ 2 ] ) ) { if ( ent_class_prefixed( &entities[i], "info_player_" ) ) {
if ( striEqualPrefix( ValueForKey( &entities[i], "classname" ), "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 ( striEqualPrefix( ValueForKey( &entities[i], "classname" ), "info_player_" ) ) { if ( ent_class_prefixed( &entities[i], "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 ] );
@ -783,8 +778,7 @@ int ShiftBSPMain( int argc, char **argv ){
/* scale gridsize */ /* scale gridsize */
/* /*
GetVectorForKey( &entities[ 0 ], "gridsize", vec ); if ( !ENT_READKV( &entities[ 0 ], "gridsize", &vec ) ) {
if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) == 0.0f ) {
VectorCopy( gridSize, vec ); VectorCopy( gridSize, vec );
} }
vec[0] *= scale[0]; vec[0] *= scale[0];

View File

@ -1005,7 +1005,6 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){
FILE *f; FILE *f;
bspModel_t *model; bspModel_t *model;
entity_t *e; entity_t *e;
vec3_t origin;
const char *value; const char *value;
char name[ 1024 ]; char name[ 1024 ];
@ -1062,13 +1061,8 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){
model = &bspModels[ modelNum ]; model = &bspModels[ modelNum ];
/* get entity origin */ /* get entity origin */
value = ValueForKey( e, "origin" ); vec3_t origin = { 0.f, 0.f, 0.f };
if ( strEmpty( value ) ) { ENT_READKV( e, "origin", &origin );
VectorClear( origin );
}
else{
GetVectorForKey( e, "origin", origin );
}
/* convert model */ /* convert model */
ConvertModel( f, model, modelNum, origin, brushPrimitives ); ConvertModel( f, model, modelNum, origin, brushPrimitives );

View File

@ -306,7 +306,6 @@ int ConvertBSPToOBJ( char *bspName ){
bspShader_t *shader; bspShader_t *shader;
bspModel_t *model; bspModel_t *model;
entity_t *e; entity_t *e;
vec3_t origin;
const char *key; const char *key;
char name[ 1024 ], base[ 1024 ], mtlname[ 1024 ], dirname[ 1024 ]; char name[ 1024 ], base[ 1024 ], mtlname[ 1024 ], dirname[ 1024 ];
int lmIndices[ numBSPShaders ]; int lmIndices[ numBSPShaders ];
@ -375,13 +374,8 @@ int ConvertBSPToOBJ( char *bspName ){
model = &bspModels[ modelNum ]; model = &bspModels[ modelNum ];
/* get entity origin */ /* get entity origin */
key = ValueForKey( e, "origin" ); vec3_t origin = { 0.f, 0.f, 0.f };
if ( strEmpty( key ) ) { ENT_READKV( e, "origin", &origin );
VectorClear( origin );
}
else{
GetVectorForKey( e, "origin", origin );
}
/* convert model */ /* convert model */
ConvertModelToOBJ( f, model, modelNum, origin, lmIndices ); ConvertModelToOBJ( f, model, modelNum, origin, lmIndices );

View File

@ -413,7 +413,6 @@ void ProcessDecals( void ){
parseMesh_t *p; parseMesh_t *p;
mesh_t *mesh, *subdivided; mesh_t *mesh, *subdivided;
bspDrawVert_t *dv[ 4 ]; bspDrawVert_t *dv[ 4 ];
const char *value;
/* note it */ /* note it */
@ -424,8 +423,7 @@ void ProcessDecals( void ){
{ {
/* get entity */ /* get entity */
e = &entities[ i ]; e = &entities[ i ];
value = ValueForKey( e, "classname" ); if ( !ent_class_is( e, "_decal" ) ) {
if ( !striEqual( value, "_decal" ) ) {
continue; continue;
} }
@ -437,8 +435,7 @@ void ProcessDecals( void ){
} }
/* find target */ /* find target */
value = ValueForKey( e, "target" ); e2 = FindTargetEntity( ValueForKey( e, "target" ) );
e2 = FindTargetEntity( value );
/* no target? */ /* no target? */
if ( e2 == NULL ) { if ( e2 == NULL ) {

View File

@ -717,7 +717,6 @@ void CreateMapFogs( void ){
brush_t *brush; brush_t *brush;
fog_t *fog; fog_t *fog;
vec3_t invFogDir; vec3_t invFogDir;
const char *globalFog;
/* skip? */ /* skip? */
@ -772,11 +771,8 @@ void CreateMapFogs( void ){
} }
/* ydnar: global fog */ /* ydnar: global fog */
globalFog = ValueForKey( &entities[ 0 ], "_fog" ); const char *globalFog;
if ( strEmpty( globalFog ) ) { if ( ENT_READKV( &entities[ 0 ], "_fog", &globalFog ) || ENT_READKV( &entities[ 0 ], "fog", &globalFog ) ) {
globalFog = ValueForKey( &entities[ 0 ], "fog" );
}
if ( !strEmpty( globalFog ) ) {
/* 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

@ -218,13 +218,6 @@ void CreateEntityLights( void ){
int i, j; int i, j;
light_t *light, *light2; light_t *light, *light2;
entity_t *e, *e2; entity_t *e, *e2;
const char *name;
const char *target;
vec3_t dest;
const char *_color;
float intensity, scale, deviance, filterRadius;
int spawnflags, flags, numSamples;
bool junior;
/* go throught entity list and find lights */ /* go throught entity list and find lights */
@ -232,13 +225,12 @@ void CreateEntityLights( void ){
{ {
/* get entity */ /* get entity */
e = &entities[ i ]; e = &entities[ i ];
name = ValueForKey( e, "classname" );
/* ydnar: check for lightJunior */ /* ydnar: check for lightJunior */
if ( striEqualPrefix( name, "lightJunior" ) ) { bool junior;
if ( ent_class_is( e, "lightJunior" ) ) {
junior = true; junior = true;
} }
else if ( striEqualPrefix( name, "light" ) ) { else if ( ent_class_prefixed( e, "light" ) ) {
junior = false; junior = false;
} }
else{ else{
@ -246,8 +238,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 */
target = ValueForKey( e, "targetname" ); if ( !strEmpty( ValueForKey( e, "targetname" ) ) && i >= numBSPEntities ) {
if ( !strEmpty( target ) && i >= numBSPEntities ) {
continue; continue;
} }
@ -258,8 +249,9 @@ void CreateEntityLights( void ){
lights = light; lights = light;
/* handle spawnflags */ /* handle spawnflags */
spawnflags = IntForKey( e, "spawnflags" ); const int spawnflags = IntForKey( e, "spawnflags" );
int flags;
/* ydnar: quake 3+ light behavior */ /* ydnar: quake 3+ light behavior */
if ( !wolfLight ) { if ( !wolfLight ) {
/* set default flags */ /* set default flags */
@ -343,66 +335,47 @@ void CreateEntityLights( void ){
/* set origin */ /* set origin */
GetVectorForKey( e, "origin", light->origin ); GetVectorForKey( e, "origin", light->origin );
light->style = IntForKey( e, "_style" ); ENT_READKV( e, "_style", &light->style ) || ENT_READKV( e, "style", &light->style );
if ( light->style == LS_NORMAL ) {
light->style = IntForKey( e, "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 %d", light->style, i ); Error( "Invalid lightstyle (%d) on entity %d", light->style, i );
} }
if ( light->style != LS_NORMAL ) {
Sys_Warning( "Styled light found targeting %s\n **", target );
}
/* set light intensity */ /* set light intensity */
intensity = FloatForKey( e, "_light" ); float intensity = 300.f;
if ( intensity == 0.0f ) { ENT_READKV( e, "_light", &intensity ) || ENT_READKV( e, "light", &intensity );
intensity = FloatForKey( e, "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) */
scale = FloatForKey( e, "scale" ); float scale;
if ( scale == 0.0f ) { if( ENT_READKV( e, "scale", &scale ) && scale != 0.f )
scale = 1.0f;
}
intensity *= scale; intensity *= scale;
}
/* ydnar: get deviance and samples */ /* ydnar: get deviance and samples */
deviance = FloatForKey( e, "_deviance" ); float deviance = 0.f;
if ( deviance == 0.0f ) { ENT_READKV( e, "_deviance", &deviance ) ||
deviance = FloatForKey( e, "_deviation" ); ENT_READKV( e, "_deviation", &deviance ) ||
} ENT_READKV( e, "_jitter", &deviance );
if ( deviance == 0.0f ) { if ( deviance < 0.f )
deviance = FloatForKey( e, "_jitter" ); deviance = 0.f;
} int numSamples = IntForKey( e, "_samples" );
numSamples = IntForKey( e, "_samples" ); if ( numSamples < 1 )
if ( deviance < 0.0f || numSamples < 1 ) {
deviance = 0.0f;
numSamples = 1; numSamples = 1;
}
intensity /= numSamples; intensity /= numSamples;
/* ydnar: get filter radius */ { /* ydnar: get filter radius */
filterRadius = FloatForKey( e, "_filterradius" ); float filterRadius = 0.f;
if ( filterRadius == 0.0f ) { ENT_READKV( e, "_filterradius", &filterRadius ) ||
filterRadius = FloatForKey( e, "_filteradius" ); ENT_READKV( e, "_filteradius", &filterRadius ) ||
ENT_READKV( e, "_filter", &filterRadius );
light->filterRadius = filterRadius < 0.f? 0.f : filterRadius;
} }
if ( filterRadius == 0.0f ) {
filterRadius = FloatForKey( e, "_filter" );
}
if ( filterRadius < 0.0f ) {
filterRadius = 0.0f;
}
light->filterRadius = filterRadius;
/* set light color */ /* set light color */
_color = ValueForKey( e, "_color" ); if ( ENT_READKV( e, "_color", &light->color ) ) {
if ( _color && _color[ 0 ] ) {
sscanf( _color, "%f %f %f", &light->color[ 0 ], &light->color[ 1 ], &light->color[ 2 ] );
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] );
@ -413,13 +386,12 @@ void CreateEntityLights( void ){
} }
} }
else{ else{
light->color[ 0 ] = light->color[ 1 ] = light->color[ 2 ] = 1.0f; VectorSet( light->color, 1.f, 1.f, 1.f );
} }
light->extraDist = FloatForKey( e, "_extradist" );
if ( light->extraDist == 0.0f ) { if( !ENT_READKV( e, "_extradist", &light->extraDist ) )
light->extraDist = extraDist; light->extraDist = extraDist;
}
light->photons = intensity; light->photons = intensity;
@ -429,14 +401,8 @@ void CreateEntityLights( void ){
light->falloffTolerance = falloffTolerance / numSamples; light->falloffTolerance = falloffTolerance / numSamples;
/* lights with a target will be spotlights */ /* lights with a target will be spotlights */
target = ValueForKey( e, "target" ); const char *target;
if ( target[ 0 ] ) { if ( ENT_READKV( e, "target", &target ) ) {
float radius;
float dist;
sun_t sun;
const char *_sun;
/* get target */ /* get target */
e2 = FindTargetEntity( target ); e2 = FindTargetEntity( target );
if ( e2 == NULL ) { if ( e2 == NULL ) {
@ -451,10 +417,11 @@ void CreateEntityLights( void ){
numSpotLights++; numSpotLights++;
/* make a spotlight */ /* make a spotlight */
vec3_t dest;
GetVectorForKey( e2, "origin", dest ); GetVectorForKey( e2, "origin", dest );
VectorSubtract( dest, light->origin, light->normal ); VectorSubtract( dest, light->origin, light->normal );
dist = VectorNormalize( light->normal, light->normal ); float dist = VectorNormalize( light->normal, light->normal );
radius = FloatForKey( e, "radius" ); float radius = FloatForKey( e, "radius" );
if ( !radius ) { if ( !radius ) {
radius = 64; radius = 64;
} }
@ -470,8 +437,7 @@ void CreateEntityLights( void ){
light->fade = 1.0f; light->fade = 1.0f;
/* ydnar: is this a sun? */ /* ydnar: is this a sun? */
_sun = ValueForKey( e, "_sun" ); if ( BoolForKey( e, "_sun" ) ) {
if ( _sun[ 0 ] == '1' ) {
/* not a spot light */ /* not a spot light */
numSpotLights--; numSpotLights--;
@ -479,6 +445,7 @@ void CreateEntityLights( void ){
lights = light->next; lights = light->next;
/* make a sun */ /* make a sun */
sun_t sun;
VectorScale( light->normal, -1.0f, sun.direction ); VectorScale( light->normal, -1.0f, sun.direction );
VectorCopy( light->color, sun.color ); VectorCopy( light->color, sun.color );
sun.photons = intensity; sun.photons = intensity;
@ -550,11 +517,10 @@ void CreateSurfaceLights( void ){
float subdivide; float subdivide;
vec3_t origin; vec3_t origin;
clipWork_t cw; clipWork_t cw;
const char *nss;
/* get sun shader supressor */ /* get sun shader supressor */
nss = ValueForKey( &entities[ 0 ], "_noshadersun" ); const bool nss = BoolForKey( &entities[ 0 ], "_noshadersun" );
/* walk the list of surfaces */ /* walk the list of surfaces */
for ( i = 0; i < numBSPDrawSurfaces; i++ ) for ( i = 0; i < numBSPDrawSurfaces; i++ )
@ -565,7 +531,7 @@ void CreateSurfaceLights( void ){
si = info->si; si = info->si;
/* sunlight? */ /* sunlight? */
if ( si->sun != NULL && nss[ 0 ] != '1' ) { if ( si->sun != NULL && !nss ) {
Sys_FPrintf( SYS_VRB, "Sun: %s\n", si->shader ); Sys_FPrintf( SYS_VRB, "Sun: %s\n", si->shader );
CreateSunLight( si->sun ); CreateSunLight( si->sun );
si->sun = NULL; /* FIXME: leak! */ si->sun = NULL; /* FIXME: leak! */
@ -646,7 +612,6 @@ void CreateSurfaceLights( void ){
void SetEntityOrigins( void ){ void SetEntityOrigins( void ){
int i, j, k, f; int i, j, k, f;
entity_t *e; entity_t *e;
vec3_t origin;
const char *key; const char *key;
int modelnum; int modelnum;
bspModel_t *dm; bspModel_t *dm;
@ -670,11 +635,10 @@ void SetEntityOrigins( void ){
dm = &bspModels[ modelnum ]; dm = &bspModels[ modelnum ];
/* get entity origin */ /* get entity origin */
key = ValueForKey( e, "origin" ); vec3_t origin = { 0.f, 0.f, 0.f };
if ( strEmpty( key ) ) { if ( !ENT_READKV( e, "origin", &origin ) ) {
continue; continue;
} }
GetVectorForKey( e, "origin", origin );
/* set origin for all surfaces for this model */ /* set origin for all surfaces for this model */
for ( j = 0; j < dm->numBSPSurfaces; j++ ) for ( j = 0; j < dm->numBSPSurfaces; j++ )
@ -1798,7 +1762,6 @@ void TraceGrid( int num ){
void SetupGrid( void ){ void SetupGrid( void ){
int i, j; int i, j;
vec3_t maxs, oldGridSize; vec3_t maxs, oldGridSize;
const char *value;
char temp[ 64 ]; char temp[ 64 ];
@ -1808,10 +1771,7 @@ void SetupGrid( void ){
} }
/* ydnar: set grid size */ /* ydnar: set grid size */
value = ValueForKey( &entities[ 0 ], "gridsize" ); ENT_READKV( &entities[ 0 ], "gridsize", &gridSize );
if ( !strEmpty( value ) ) {
sscanf( value, "%f %f %f", &gridSize[ 0 ], &gridSize[ 1 ], &gridSize[ 2 ] );
}
/* quantize it */ /* quantize it */
VectorCopy( gridSize, oldGridSize ); VectorCopy( gridSize, oldGridSize );
@ -1888,7 +1848,6 @@ void LightWorld( bool fastAllocate ){
float f; float f;
int b, bt; int b, bt;
bool minVertex, minGrid; bool minVertex, minGrid;
const char *value;
/* ydnar: smooth normals */ /* ydnar: smooth normals */
@ -1913,47 +1872,31 @@ void LightWorld( bool fastAllocate ){
} }
/* ambient */ /* ambient */
f = FloatForKey( &entities[ 0 ], "_ambient" ); f = 0.f;
if ( f == 0.0f ) { ENT_READKV( &entities[ 0 ], "_ambient", &f ) || ENT_READKV( &entities[ 0 ], "ambient", &f );
f = FloatForKey( &entities[ 0 ], "ambient" );
}
VectorScale( color, f, ambientColor ); VectorScale( color, f, ambientColor );
/* minvertexlight */ /* minvertexlight */
minVertex = false; if ( ( minVertex = ENT_READKV( &entities[ 0 ], "_minvertexlight", &f ) ) ) {
value = ValueForKey( &entities[ 0 ], "_minvertexlight" );
if ( !strEmpty( value ) ) {
minVertex = true;
f = atof( value );
VectorScale( color, f, minVertexLight ); VectorScale( color, f, minVertexLight );
} }
/* mingridlight */ /* mingridlight */
minGrid = false; if ( ( minGrid = ENT_READKV( &entities[ 0 ], "_mingridlight", &f ) ) ) {
value = ValueForKey( &entities[ 0 ], "_mingridlight" );
if ( !strEmpty( value ) ) {
minGrid = true;
f = atof( value );
VectorScale( color, f, minGridLight ); VectorScale( color, f, minGridLight );
} }
/* minlight */ /* minlight */
value = ValueForKey( &entities[ 0 ], "_minlight" ); if ( ENT_READKV( &entities[ 0 ], "_minlight", &f ) ) {
if ( !strEmpty( value ) ) {
f = atof( value );
VectorScale( color, f, minLight ); VectorScale( color, f, minLight );
if ( !minVertex ) { if ( !minVertex )
VectorScale( color, f, minVertexLight ); VectorScale( color, f, minVertexLight );
} if ( !minGrid )
if ( !minGrid ) {
VectorScale( color, f, minGridLight ); VectorScale( color, f, minGridLight );
} }
}
/* maxlight */ /* maxlight */
value = ValueForKey( &entities[ 0 ], "_maxlight" ); if ( ENT_READKV( &entities[ 0 ], "_maxlight", &f ) ) {
if ( !strEmpty( value ) ) {
f = atof( value );
maxLight = f > 255? 255 : f < 0? 0 : f; maxLight = f > 255? 255 : f < 0? 0 : f;
} }
@ -2109,7 +2052,6 @@ void LightWorld( bool fastAllocate ){
int LightMain( int argc, char **argv ){ int LightMain( int argc, char **argv ){
int i; int i;
float f; float f;
const char *value;
int lightmapMergeSize = 0; int lightmapMergeSize = 0;
bool lightSamplesInsist = false; bool lightSamplesInsist = false;
bool fastAllocate = true; bool fastAllocate = true;
@ -3017,8 +2959,7 @@ int LightMain( int argc, char **argv ){
InjectCommandLine( argv, 0, argc - 1 ); InjectCommandLine( argv, 0, argc - 1 );
/* load map file */ /* load map file */
value = ValueForKey( &entities[ 0 ], "_keepLights" ); if ( !BoolForKey( &entities[ 0 ], "_keepLights" ) ) {
if ( value[ 0 ] != '1' ) {
LoadMapFile( name, true, false ); LoadMapFile( name, true, false );
} }

View File

@ -1109,16 +1109,13 @@ static void PopulateWithPicoModel( int castShadows, picoModel_t *model, m4x4_t t
*/ */
static void PopulateTraceNodes( void ){ static void PopulateTraceNodes( void ){
int i, m, frame, castShadows; int i, m;
float temp;
entity_t *e;
const char *value; const char *value;
picoModel_t *model; picoModel_t *model;
vec3_t origin, scale, angles;
m4x4_t transform;
/* add worldspawn triangles */ /* add worldspawn triangles */
m4x4_t transform;
m4x4_identity( transform ); m4x4_identity( transform );
PopulateWithBSPModel( &bspModels[ 0 ], transform ); PopulateWithBSPModel( &bspModels[ 0 ], transform );
@ -1126,10 +1123,10 @@ static void PopulateTraceNodes( void ){
for ( i = 1; i < numEntities; i++ ) for ( i = 1; i < numEntities; i++ )
{ {
/* get entity */ /* get entity */
e = &entities[ i ]; entity_t *e = &entities[ i ];
/* get shadow flags */ /* get shadow flags */
castShadows = ENTITY_CAST_SHADOWS; int castShadows = ENTITY_CAST_SHADOWS;
GetEntityShadowFlags( e, NULL, &castShadows, NULL ); GetEntityShadowFlags( e, NULL, &castShadows, NULL );
/* early out? */ /* early out? */
@ -1138,26 +1135,20 @@ static void PopulateTraceNodes( void ){
} }
/* get entity origin */ /* get entity origin */
vec3_t origin;
GetVectorForKey( e, "origin", origin ); GetVectorForKey( e, "origin", origin );
/* get scale */ /* get scale */
scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = 1.0f; vec3_t scale = { 1.f, 1.f, 1.f };
temp = FloatForKey( e, "modelscale" ); if( !ENT_READKV( e, "modelscale_vec", &scale ) )
if ( temp != 0.0f ) { if( ENT_READKV( e, "modelscale", &scale[0] ) )
scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = temp; scale[1] = scale[2] = scale[0];
}
value = ValueForKey( e, "modelscale_vec" );
if ( !strEmpty( value ) ) {
sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] );
}
/* get "angle" (yaw) or "angles" (pitch yaw roll) */ /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */
angles[ 0 ] = angles[ 1 ] = angles[ 2 ] = 0.0f; vec3_t angles = { 0.f, 0.f, 0.f };
angles[ 2 ] = FloatForKey( e, "angle" ); if ( !ENT_READKV( e, "angles", &value ) ||
value = ValueForKey( e, "angles" ); 3 != sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ) )
if ( !strEmpty( value ) ) { ENT_READKV( e, "angle", &angles[ 2 ] );
sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] );
}
/* set transform matrix (thanks spog) */ /* set transform matrix (thanks spog) */
m4x4_identity( transform ); m4x4_identity( transform );
@ -1189,18 +1180,15 @@ static void PopulateTraceNodes( void ){
/* external model */ /* external model */
default: default:
frame = 0; {
if ( !strEmpty( ValueForKey( e, "_frame" ) ) ) { int frame = 0;
frame = IntForKey( e, "_frame" ); ENT_READKV( e, "_frame", &frame ) || ENT_READKV( e, "frame", &frame );
}
else if ( !strEmpty( ValueForKey( e, "frame" ) ) ) {
frame = IntForKey( e, "frame" );
}
model = LoadModel( value, frame ); model = LoadModel( value, frame );
if ( model == NULL ) { if ( model == NULL ) {
continue; continue;
} }
PopulateWithPicoModel( castShadows, model, transform ); PopulateWithPicoModel( castShadows, model, transform );
}
continue; continue;
} }
@ -1225,8 +1213,7 @@ static void PopulateTraceNodes( void ){
/* external model */ /* external model */
default: default:
frame = IntForKey( e, "_frame2" ); model = LoadModel( value, IntForKey( e, "_frame2" ) );
model = LoadModel( value, frame );
if ( model == NULL ) { if ( model == NULL ) {
continue; continue;
} }

View File

@ -4103,8 +4103,6 @@ static int numFloodVectors = 0;
void SetupFloodLight( void ){ void SetupFloodLight( void ){
int i, j; int i, j;
float angle, elevation, angleStep, elevationStep; float angle, elevation, angleStep, elevationStep;
const char *value;
double v1,v2,v3,v4,v5,v6;
/* note it */ /* note it */
Sys_FPrintf( SYS_VRB, "--- SetupFloodLight ---\n" ); Sys_FPrintf( SYS_VRB, "--- SetupFloodLight ---\n" );
@ -4131,9 +4129,9 @@ void SetupFloodLight( void ){
Sys_FPrintf( SYS_VRB, "%9d numFloodVectors\n", numFloodVectors ); Sys_FPrintf( SYS_VRB, "%9d numFloodVectors\n", numFloodVectors );
/* floodlight */ /* floodlight */
value = ValueForKey( &entities[ 0 ], "_floodlight" ); const char *value;
if ( ENT_READKV( &entities[ 0 ], "_floodlight", &value ) ) {
if ( !strEmpty( value ) ) { double v1,v2,v3,v4,v5,v6;
v1 = v2 = v3 = 0; v1 = v2 = v3 = 0;
v4 = floodlightDistance; v4 = floodlightDistance;
v5 = floodlightIntensity; v5 = floodlightIntensity;

View File

@ -876,7 +876,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, ValueForKey( mapEnt, "classname" ), entitySourceBrushes ); mapEnt->mapEntityNum, ent_classname( mapEnt ), entitySourceBrushes );
if ( numEntities == 1 ) { if ( numEntities == 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",
@ -896,7 +896,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 ( numEntities != 1 ) { if ( numEntities != 1 ) {
Sys_FPrintf( SYS_WRN, "Entity %i (%s), Brush %i: areaportals only allowed in world\n", numEntities - 1, ValueForKey( mapEnt, "classname" ), entitySourceBrushes ); Sys_FPrintf( SYS_WRN, "Entity %i (%s), Brush %i: areaportals only allowed in world\n", numEntities - 1, ent_classname( mapEnt ), entitySourceBrushes );
return NULL; return NULL;
} }
} }
@ -1499,12 +1499,8 @@ void SetEntityBounds( entity_t *e ){
} }
/* try to find explicit min/max key */ /* try to find explicit min/max key */
if ( !strEmpty( ValueForKey( e, "min" ) ) ) { ENT_READKV( e, "min", &mins );
GetVectorForKey( e, "min", mins ); ENT_READKV( e, "max", &maxs );
}
if ( !strEmpty( ValueForKey( e, "max" ) ) ) {
GetVectorForKey( e, "max", maxs );
}
/* store the bounds */ /* store the bounds */
for ( b = e->brushes; b; b = b->next ) for ( b = e->brushes; b; b = b->next )
@ -1528,8 +1524,7 @@ void SetEntityBounds( entity_t *e ){
void LoadEntityIndexMap( entity_t *e ){ void LoadEntityIndexMap( entity_t *e ){
int i, size, numLayers, w, h; int i, size, numLayers, w, h;
const char *value, *indexMapFilename, *shader; const char *indexMapFilename, *shader;
char offset[ 4096 ], *search, *space;
byte *pixels; byte *pixels;
unsigned int *pixels32; unsigned int *pixels32;
indexMap_t *im; indexMap_t *im;
@ -1543,26 +1538,17 @@ void LoadEntityIndexMap( entity_t *e ){
} }
/* determine if there is an index map (support legacy "alphamap" key as well) */ /* determine if there is an index map (support legacy "alphamap" key as well) */
value = ValueForKey( e, "_indexmap" ); if( !ENT_READKV( e, "_indexmap", &indexMapFilename ) &&
if ( strEmpty( value ) ) { !ENT_READKV( e, "alphamap", &indexMapFilename ) )
value = ValueForKey( e, "alphamap" );
}
if ( strEmpty( value ) ) {
return; return;
}
indexMapFilename = value;
/* get number of layers (support legacy "layers" key as well) */ /* get number of layers (support legacy "layers" key as well) */
value = ValueForKey( e, "_layers" ); if( !ENT_READKV( e, "_layers", &numLayers ) &&
if ( strEmpty( value ) ) { !ENT_READKV( e, "layers", &numLayers ) ){
value = ValueForKey( e, "layers" );
}
if ( strEmpty( value ) ) {
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;
} }
numLayers = atoi( value );
if ( numLayers < 1 ) { if ( numLayers < 1 ) {
Sys_Warning( "Entity with index/alpha map \"%s\" has < 1 layer (%d)\n", indexMapFilename, numLayers ); Sys_Warning( "Entity with index/alpha map \"%s\" has < 1 layer (%d)\n", indexMapFilename, numLayers );
Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" ); Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
@ -1570,19 +1556,15 @@ void LoadEntityIndexMap( entity_t *e ){
} }
/* get base shader name (support legacy "shader" key as well) */ /* get base shader name (support legacy "shader" key as well) */
value = ValueForKey( mapEnt, "_shader" ); if( !ENT_READKV( mapEnt, "_shader", &shader ) &&
if ( strEmpty( value ) ) { !ENT_READKV( mapEnt, "shader", &shader ) ){
value = ValueForKey( e, "shader" );
}
if ( strEmpty( value ) ) {
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;
} }
shader = value;
/* note it */ /* note it */
Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->mapEntityNum, ValueForKey( e, "classname" ), indexMapFilename ); Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->mapEntityNum, ent_classname( e ), indexMapFilename );
/* handle tga image */ /* handle tga image */
if ( striEqual( path_get_extension( indexMapFilename ), "tga" ) ) { if ( striEqual( path_get_extension( indexMapFilename ), "tga" ) ) {
@ -1649,19 +1631,15 @@ void LoadEntityIndexMap( entity_t *e ){
im->pixels = pixels; im->pixels = pixels;
/* get height offsets */ /* get height offsets */
value = ValueForKey( mapEnt, "_offsets" ); char offset[ 4096 ];
if ( strEmpty( value ) ) { if( ENT_READKV( mapEnt, "_offsets", &offset ) ||
value = ValueForKey( e, "offsets" ); ENT_READKV( mapEnt, "offsets", &offset ) ){
} /* value is a space-separated set of numbers */
if ( !strEmpty( value ) ) { char *search = offset;
/* value is a space-seperated set of numbers */
strcpy( offset, value );
search = offset;
/* get each value */ /* get each value */
for ( i = 0; i < 256 && !strEmpty( search ); i++ ) for ( i = 0; i < 256 && !strEmpty( search ); i++ )
{ {
space = strchr( search, ' ' ); char *space = strchr( search, ' ' );
if ( space != NULL ) { if ( space != NULL ) {
strClear( space ); strClear( space );
} }
@ -1693,16 +1671,8 @@ void LoadEntityIndexMap( entity_t *e ){
static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
epair_t *ep; epair_t *ep;
const char *classname, *value;
float lightmapScale, shadeAngle;
int lightmapSampleSize;
char shader[ MAX_QPATH ];
shaderInfo_t *celShader = NULL;
brush_t *brush; brush_t *brush;
parseMesh_t *patch; parseMesh_t *patch;
bool funcGroup;
int castShadows, recvShadows;
/* eof check */ /* eof check */
if ( !GetToken( true ) ) { if ( !GetToken( true ) ) {
@ -1788,7 +1758,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
} }
/* ydnar: get classname */ /* ydnar: get classname */
classname = ValueForKey( mapEnt, "classname" ); const char *classname = ent_classname( mapEnt );
/* ydnar: only lights? */ /* ydnar: only lights? */
if ( onlyLights && !striEqualPrefix( classname, "light" ) ) { if ( onlyLights && !striEqualPrefix( classname, "light" ) ) {
@ -1797,18 +1767,16 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
} }
/* ydnar: determine if this is a func_group */ /* ydnar: determine if this is a func_group */
funcGroup = striEqual( "func_group", classname ); const bool funcGroup = striEqual( "func_group", classname );
/* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */ /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
int castShadows, recvShadows;
if ( funcGroup || mapEnt->mapEntityNum == 0 ) { if ( funcGroup || mapEnt->mapEntityNum == 0 ) {
//% Sys_Printf( "World: %d\n", mapEnt->mapEntityNum ); //% Sys_Printf( "World: %d\n", mapEnt->mapEntityNum );
castShadows = WORLDSPAWN_CAST_SHADOWS; castShadows = WORLDSPAWN_CAST_SHADOWS;
recvShadows = WORLDSPAWN_RECV_SHADOWS; recvShadows = WORLDSPAWN_RECV_SHADOWS;
} }
else{ /* other entities don't cast any shadows, but recv worldspawn shadows */
/* other entities don't cast any shadows, but recv worldspawn shadows */
else
{
//% Sys_Printf( "Entity: %d\n", mapEnt->mapEntityNum ); //% Sys_Printf( "Entity: %d\n", mapEnt->mapEntityNum );
castShadows = ENTITY_CAST_SHADOWS; castShadows = ENTITY_CAST_SHADOWS;
recvShadows = ENTITY_RECV_SHADOWS; recvShadows = ENTITY_RECV_SHADOWS;
@ -1817,94 +1785,51 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
/* get explicit shadow flags */ /* get explicit shadow flags */
GetEntityShadowFlags( mapEnt, NULL, &castShadows, &recvShadows ); GetEntityShadowFlags( mapEnt, NULL, &castShadows, &recvShadows );
/* vortex: added _ls key (short name of lightmapscale) */
/* ydnar: get lightmap scaling value for this entity */ /* ydnar: get lightmap scaling value for this entity */
float lightmapScale = 0.0f;
ENT_READKV( mapEnt, "lightmapscale", &lightmapScale ) ||
ENT_READKV( mapEnt, "_lightmapscale", &lightmapScale ) ||
ENT_READKV( mapEnt, "_ls", &lightmapScale );
if ( lightmapScale < 0.0f )
lightmapScale = 0.0f; lightmapScale = 0.0f;
if ( !strEmpty( ValueForKey( mapEnt, "lightmapscale" ) ) || else if ( lightmapScale > 0.0f )
!strEmpty( ValueForKey( mapEnt, "_lightmapscale" ) ) ||
!strEmpty( ValueForKey( mapEnt, "_ls" ) ) ) {
/* get lightmap scale from entity */
lightmapScale = FloatForKey( mapEnt, "lightmapscale" );
if ( lightmapScale <= 0.0f ) {
lightmapScale = FloatForKey( mapEnt, "_lightmapscale" );
}
if ( lightmapScale <= 0.0f ) {
lightmapScale = FloatForKey( mapEnt, "_ls" );
}
if ( lightmapScale < 0.0f ) {
lightmapScale = 0.0f;
}
if ( lightmapScale > 0.0f ) {
Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale ); Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale );
}
}
/* ydnar: get cel shader :) for this entity */ /* ydnar: get cel shader :) for this entity */
value = ValueForKey( mapEnt, "_celshader" ); shaderInfo_t *celShader;
if ( strEmpty( value ) ) { const char *value;
value = ValueForKey( &entities[ 0 ], "_celshader" ); if( ENT_READKV( mapEnt, "_celshader", &value ) ||
} ENT_READKV( &entities[ 0 ], "_celshader", &value ) ){
if ( !strEmpty( value ) ) { char shader[ MAX_QPATH ];
if ( !strEqual( value, "none" ) ) {
sprintf( shader, "textures/%s", value ); sprintf( shader, "textures/%s", value );
celShader = ShaderInfoForShader( shader ); celShader = ShaderInfoForShader( shader );
Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader ); Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader );
} }
else
{
celShader = NULL;
}
}
else{ else{
celShader = ( *globalCelShader ? ShaderInfoForShader( globalCelShader ) : NULL ); celShader = !strEmpty( globalCelShader ) ? ShaderInfoForShader( globalCelShader ) : NULL;
} }
/* jal : entity based _shadeangle */ /* jal : entity based _shadeangle */
float shadeAngle = 0.0f;
ENT_READKV( mapEnt, "_shadeangle", &shadeAngle ) ||
ENT_READKV( mapEnt, "_smoothnormals", &shadeAngle ) || /* vortex' aliases */
ENT_READKV( mapEnt, "_sn", &shadeAngle ) ||
ENT_READKV( mapEnt, "_sa", &shadeAngle ) ||
ENT_READKV( mapEnt, "_smooth", &shadeAngle );
if ( shadeAngle < 0.0f )
shadeAngle = 0.0f; shadeAngle = 0.0f;
if ( !strEmpty( ValueForKey( mapEnt, "_shadeangle" ) ) ) { else if ( shadeAngle > 0.0f )
shadeAngle = FloatForKey( mapEnt, "_shadeangle" );
}
/* vortex' aliases */
else if ( !strEmpty( ValueForKey( mapEnt, "_smoothnormals" ) ) ) {
shadeAngle = FloatForKey( mapEnt, "_smoothnormals" );
}
else if ( !strEmpty( ValueForKey( mapEnt, "_sn" ) ) ) {
shadeAngle = FloatForKey( mapEnt, "_sn" );
}
else if ( !strEmpty( ValueForKey( mapEnt, "_sa" ) ) ) {
shadeAngle = FloatForKey( mapEnt, "_sa" );
}
else if ( !strEmpty( ValueForKey( mapEnt, "_smooth" ) ) ) {
shadeAngle = FloatForKey( mapEnt, "_smooth" );
}
if ( shadeAngle < 0.0f ) {
shadeAngle = 0.0f;
}
if ( shadeAngle > 0.0f ) {
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 = 0;
ENT_READKV( mapEnt, "_lightmapsamplesize", &lightmapSampleSize ) ||
ENT_READKV( mapEnt, "_samplesize", &lightmapSampleSize ) ||
ENT_READKV( mapEnt, "_ss", &lightmapSampleSize );
if ( lightmapSampleSize < 0 )
lightmapSampleSize = 0; lightmapSampleSize = 0;
if ( !strEmpty( ValueForKey( mapEnt, "_lightmapsamplesize" ) ) ) { else if ( lightmapSampleSize > 0 )
lightmapSampleSize = IntForKey( mapEnt, "_lightmapsamplesize" );
}
else if ( !strEmpty( ValueForKey( mapEnt, "_samplesize" ) ) ) {
lightmapSampleSize = IntForKey( mapEnt, "_samplesize" );
}
else if ( !strEmpty( ValueForKey( mapEnt, "_ss" ) ) ) {
lightmapSampleSize = IntForKey( mapEnt, "_ss" );
}
if ( lightmapSampleSize < 0 ) {
lightmapSampleSize = 0;
}
if ( lightmapSampleSize > 0 ) {
Sys_Printf( "Entity %d (%s) has lightmap sample size of %d\n", mapEnt->mapEntityNum, classname, lightmapSampleSize ); Sys_Printf( "Entity %d (%s) has lightmap sample size of %d\n", mapEnt->mapEntityNum, classname, lightmapSampleSize );
}
/* attach stuff to everything in the entity */ /* attach stuff to everything in the entity */
for ( brush = mapEnt->brushes; brush != NULL; brush = brush->next ) for ( brush = mapEnt->brushes; brush != NULL; brush = brush->next )

View File

@ -1353,105 +1353,53 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
*/ */
void AddTriangleModels( entity_t *e ){ void AddTriangleModels( entity_t *e ){
int num, frame, skin, castShadows, recvShadows, spawnFlags;
entity_t *e2;
const char *targetName;
const char *target, *model, *value;
char shader[ MAX_QPATH ];
shaderInfo_t *celShader;
float temp, baseLightmapScale, lightmapScale, clipDepth;
float shadeAngle;
int lightmapSampleSize;
vec3_t origin, scale, angles;
m4x4_t transform;
epair_t *ep;
remap_t *remap, *remap2;
char *split;
/* note it */ /* note it */
Sys_FPrintf( SYS_VRB, "--- AddTriangleModels ---\n" ); Sys_FPrintf( SYS_VRB, "--- AddTriangleModels ---\n" );
/* get current brush entity targetname */ /* get current brush entity targetname */
const char *targetName;
if ( e == entities ) { if ( e == entities ) {
targetName = ""; targetName = "";
} }
else else{ /* misc_model entities target non-worldspawn brush model entities */
{ if ( !ENT_READKV( e, "targetname", &targetName ) ) {
targetName = ValueForKey( e, "targetname" );
/* misc_model entities target non-worldspawn brush model entities */
if ( strEmpty( targetName ) ) {
return; return;
} }
} }
/* get lightmap scale */
/* vortex: added _ls key (short name of lightmapscale) */
baseLightmapScale = 0.0f;
if ( !strEmpty( ValueForKey( e, "lightmapscale" ) ) ||
!strEmpty( ValueForKey( e, "_lightmapscale" ) ) ||
!strEmpty( ValueForKey( e, "_ls" ) ) ) {
baseLightmapScale = FloatForKey( e, "lightmapscale" );
if ( baseLightmapScale <= 0.0f ) {
baseLightmapScale = FloatForKey( e, "_lightmapscale" );
}
if ( baseLightmapScale <= 0.0f ) {
baseLightmapScale = FloatForKey( e, "_ls" );
}
if ( baseLightmapScale < 0.0f ) {
baseLightmapScale = 0.0f;
}
if ( baseLightmapScale > 0.0f ) {
Sys_Printf( "World Entity has lightmap scale of %.4f\n", baseLightmapScale );
}
}
/* walk the entity list */ /* walk the entity list */
for ( num = 1; num < numEntities; num++ ) for ( int num = 1; num < numEntities; num++ )
{ {
/* get e2 */ /* get e2 */
e2 = &entities[ num ]; entity_t *e2 = &entities[ num ];
/* convert misc_models into raw geometry */ /* convert misc_models into raw geometry */
if ( !striEqual( "misc_model", ValueForKey( e2, "classname" ) ) ) { if ( !ent_class_is( e2, "misc_model" ) ) {
continue; continue;
} }
/* ydnar: added support for md3 models on non-worldspawn models */ /* ydnar: added support for md3 models on non-worldspawn models */
target = ValueForKey( e2, "target" ); if ( !strEqual( ValueForKey( e2, "target" ), targetName ) ) {
if ( !strEqual( target, targetName ) ) {
continue; continue;
} }
/* get model name */ /* get model name */
model = ValueForKey( e2, "model" ); const char *model;
if ( strEmpty( model ) ) { if ( !ENT_READKV( e2, "model", &model ) ) {
Sys_Warning( "misc_model at %i %i %i without a model key\n", Sys_Warning( "entity#%d misc_model without a model key\n", e2->mapEntityNum );
(int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] );
continue; continue;
} }
/* get model frame */ /* get model frame */
frame = 0; int frame = 0;
if ( !strEmpty( ValueForKey( e2, "_frame" ) ) ) { ENT_READKV( e2, "_frame", &frame ) || ENT_READKV( e2, "frame", &frame );
frame = IntForKey( e2, "_frame" );
}
else if ( !strEmpty( ValueForKey( e2, "frame" ) ) ) {
frame = IntForKey( e2, "frame" );
}
/* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */ int castShadows, recvShadows;
if ( e == entities ) { if ( e == entities ) { /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
castShadows = WORLDSPAWN_CAST_SHADOWS; castShadows = WORLDSPAWN_CAST_SHADOWS;
recvShadows = WORLDSPAWN_RECV_SHADOWS; recvShadows = WORLDSPAWN_RECV_SHADOWS;
} }
else{ /* other entities don't cast any shadows, but recv worldspawn shadows */
/* other entities don't cast any shadows, but recv worldspawn shadows */
else
{
castShadows = ENTITY_CAST_SHADOWS; castShadows = ENTITY_CAST_SHADOWS;
recvShadows = ENTITY_RECV_SHADOWS; recvShadows = ENTITY_RECV_SHADOWS;
} }
@ -1460,38 +1408,34 @@ void AddTriangleModels( entity_t *e ){
GetEntityShadowFlags( e2, e, &castShadows, &recvShadows ); GetEntityShadowFlags( e2, e, &castShadows, &recvShadows );
/* get spawnflags */ /* get spawnflags */
spawnFlags = IntForKey( e2, "spawnflags" ); const int spawnFlags = IntForKey( e2, "spawnflags" );
/* get origin */ /* get origin */
GetVectorForKey( e2, "origin", origin ); vec3_t origin = { 0.f, 0.f, 0.f };
ENT_READKV( e2, "origin", &origin );
VectorSubtract( origin, e->origin, origin ); /* offset by parent */ VectorSubtract( origin, e->origin, origin ); /* offset by parent */
/* get scale */ /* get scale */
scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = 1.0f; vec3_t scale = { 1.f, 1.f, 1.f };
temp = FloatForKey( e2, "modelscale" ); if( !ENT_READKV( e2, "modelscale_vec", &scale ) )
if ( temp != 0.0f ) { if( ENT_READKV( e2, "modelscale", &scale[0] ) )
scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = temp; scale[1] = scale[2] = scale[0];
}
value = ValueForKey( e2, "modelscale_vec" );
if ( !strEmpty( value ) ) {
sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] );
}
/* get "angle" (yaw) or "angles" (pitch yaw roll) */ /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */
angles[ 0 ] = angles[ 1 ] = angles[ 2 ] = 0.0f; const char *value;
angles[ 2 ] = FloatForKey( e2, "angle" ); vec3_t angles = { 0.f, 0.f, 0.f };
value = ValueForKey( e2, "angles" ); if ( !ENT_READKV( e2, "angles", &value ) ||
if ( !strEmpty( value ) ) { 3 != sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ) )
sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ); ENT_READKV( e2, "angle", &angles[ 2 ] );
}
/* set transform matrix (thanks spog) */ /* set transform matrix (thanks spog) */
m4x4_t transform;
m4x4_identity( transform ); m4x4_identity( transform );
m4x4_pivoted_transform_by_vec3( transform, origin, angles, eXYZ, scale, vec3_origin ); m4x4_pivoted_transform_by_vec3( transform, origin, angles, eXYZ, scale, vec3_origin );
/* get shader remappings */ /* get shader remappings */
remap = NULL; remap_t *remap = NULL, *remap2;
for ( ep = e2->epairs; ep != NULL; ep = ep->next ) for ( epair_t *ep = e2->epairs; ep != NULL; ep = ep->next )
{ {
/* look for keys prefixed with "_remap" */ /* look for keys prefixed with "_remap" */
if ( !strEmptyOrNull( ep->key ) && !strEmptyOrNull( ep->value ) && if ( !strEmptyOrNull( ep->key ) && !strEmptyOrNull( ep->value ) &&
@ -1503,7 +1447,7 @@ void AddTriangleModels( entity_t *e ){
strcpy( remap->from, ep->value ); strcpy( remap->from, ep->value );
/* split the string */ /* split the string */
split = strchr( remap->from, ';' ); char *split = strchr( remap->from, ';' );
if ( split == NULL ) { if ( split == NULL ) {
Sys_Warning( "Shader _remap key found in misc_model without a ; character: '%s'\n", remap->from ); Sys_Warning( "Shader _remap key found in misc_model without a ; character: '%s'\n", remap->from );
} }
@ -1536,99 +1480,55 @@ void AddTriangleModels( entity_t *e ){
} }
/* ydnar: cel shader support */ /* ydnar: cel shader support */
value = ValueForKey( e2, "_celshader" ); shaderInfo_t *celShader;
if ( strEmpty( value ) ) { if( ENT_READKV( e2, "_celshader", &value ) ||
value = ValueForKey( &entities[ 0 ], "_celshader" ); ENT_READKV( &entities[ 0 ], "_celshader", &value ) ){
} char shader[ MAX_QPATH ];
if ( !strEmpty( value ) ) {
sprintf( shader, "textures/%s", value ); sprintf( shader, "textures/%s", value );
celShader = ShaderInfoForShader( shader ); celShader = ShaderInfoForShader( shader );
} }
else{ else{
celShader = *globalCelShader ? ShaderInfoForShader( globalCelShader ) : NULL; celShader = !strEmpty( globalCelShader ) ? ShaderInfoForShader( globalCelShader ) : NULL;
} }
/* jal : entity based _samplesize */ /* jal : entity based _samplesize */
int lightmapSampleSize = 0;
ENT_READKV( e2, "_lightmapsamplesize", &lightmapSampleSize ) ||
ENT_READKV( e2, "_samplesize", &lightmapSampleSize ) ||
ENT_READKV( e2, "_ss", &lightmapSampleSize );
if ( lightmapSampleSize < 0 )
lightmapSampleSize = 0; lightmapSampleSize = 0;
if ( !strEmpty( ValueForKey( e2, "_lightmapsamplesize" ) ) ) { if ( lightmapSampleSize > 0 )
lightmapSampleSize = IntForKey( e2, "_lightmapsamplesize" );
}
else if ( !strEmpty( ValueForKey( e2, "_samplesize" ) ) ) {
lightmapSampleSize = IntForKey( e2, "_samplesize" );
}
else if ( !strEmpty( ValueForKey( e2, "_ss" ) ) ) {
lightmapSampleSize = IntForKey( e2, "_ss" );
}
if ( lightmapSampleSize < 0 ) {
lightmapSampleSize = 0;
}
if ( lightmapSampleSize > 0.0f ) {
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 */
/* vortex: added _ls key (short name of lightmapscale) */ float lightmapScale = 0.0f;
ENT_READKV( e2, "lightmapscale", &lightmapScale ) ||
ENT_READKV( e2, "_lightmapscale", &lightmapScale ) ||
ENT_READKV( e2, "_ls", &lightmapScale );
if ( lightmapScale < 0.0f )
lightmapScale = 0.0f; lightmapScale = 0.0f;
if ( !strEmpty( ValueForKey( e2, "lightmapscale" ) ) || else if ( lightmapScale > 0.0f )
!strEmpty( ValueForKey( e2, "_lightmapscale" ) ) ||
!strEmpty( ValueForKey( e2, "_ls" ) ) ) {
lightmapScale = FloatForKey( e2, "lightmapscale" );
if ( lightmapScale <= 0.0f ) {
lightmapScale = FloatForKey( e2, "_lightmapscale" );
}
if ( lightmapScale <= 0.0f ) {
lightmapScale = FloatForKey( e2, "_ls" );
}
if ( lightmapScale < 0.0f ) {
lightmapScale = 0.0f;
}
if ( lightmapScale > 0.0f ) {
Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale ); Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale );
}
}
/* jal : entity based _shadeangle */ /* jal : entity based _shadeangle */
float shadeAngle = 0.0f;
ENT_READKV( e2, "_shadeangle", &shadeAngle ) ||
ENT_READKV( e2, "_smoothnormals", &shadeAngle ) || /* vortex' aliases */
ENT_READKV( e2, "_sn", &shadeAngle ) ||
ENT_READKV( e2, "_sa", &shadeAngle ) ||
ENT_READKV( e2, "_smooth", &shadeAngle );
if ( shadeAngle < 0.0f )
shadeAngle = 0.0f; shadeAngle = 0.0f;
if ( !strEmpty( ValueForKey( e2, "_shadeangle" ) ) ) { else if ( shadeAngle > 0.0f )
shadeAngle = FloatForKey( e2, "_shadeangle" );
}
/* vortex' aliases */
else if ( !strEmpty( ValueForKey( e2, "_smoothnormals" ) ) ) {
shadeAngle = FloatForKey( e2, "_smoothnormals" );
}
else if ( !strEmpty( ValueForKey( e2, "_sn" ) ) ) {
shadeAngle = FloatForKey( e2, "_sn" );
}
else if ( !strEmpty( ValueForKey( e2, "_sa" ) ) ) {
shadeAngle = FloatForKey( e2, "_sa" );
}
else if ( !strEmpty( ValueForKey( e2, "_smooth" ) ) ) {
shadeAngle = FloatForKey( e2, "_smooth" );
}
if ( shadeAngle < 0.0f ) {
shadeAngle = 0.0f;
}
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 );
}
skin = 0; int skin = 0;
if ( !strEmpty( ValueForKey( e2, "_skin" ) ) ) { ENT_READKV( e2, "_skin", &skin ) || ENT_READKV( e2, "skin", &skin );
skin = IntForKey( e2, "_skin" );
}
else if ( !strEmpty( ValueForKey( e2, "skin" ) ) ) {
skin = IntForKey( e2, "skin" );
}
clipDepth = clipDepthGlobal; float clipDepth = clipDepthGlobal;
if ( !strEmpty( ValueForKey( e2, "_clipdepth" ) ) ) { if ( ENT_READKV( e2, "_clipdepth", &clipDepth ) )
clipDepth = FloatForKey( e2, "_clipdepth" ); Sys_Printf( "misc_model %s has autoclip depth of %.3f\n", model, clipDepth );
Sys_Printf( "misc_model has autoclip depth of %.3f\n", clipDepth );
}
/* insert the model */ /* insert the model */

View File

@ -644,8 +644,6 @@ bool PlaceOccupant( node_t *headnode, vec3_t origin, entity_t *occupant, bool sk
*/ */
int FloodEntities( tree_t *tree ){ int FloodEntities( tree_t *tree ){
int i, s;
vec3_t origin, offset, scale, angles;
bool r, inside, skybox; bool r, inside, skybox;
node_t *headnode; node_t *headnode;
entity_t *e, *tripped; entity_t *e, *tripped;
@ -660,12 +658,13 @@ int FloodEntities( tree_t *tree ){
tripped = NULL; tripped = NULL;
c_floodedleafs = 0; c_floodedleafs = 0;
for ( i = 1; i < numEntities; i++ ) for ( int i = 1; i < numEntities; i++ )
{ {
/* get entity */ /* get entity */
e = &entities[ i ]; e = &entities[ i ];
/* get origin */ /* get origin */
vec3_t origin;
GetVectorForKey( e, "origin", origin ); GetVectorForKey( e, "origin", origin );
#if 0 //allow maps with only point entity@( 0, 0, 0 ); assuming that entities, containing no primitives are point ones #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 */
@ -679,32 +678,25 @@ int FloodEntities( tree_t *tree ){
} }
/* handle skybox entities */ /* handle skybox entities */
value = ValueForKey( e, "classname" ); if ( ent_class_is( e, "_skybox" ) ) {
if ( striEqual( value, "_skybox" ) ) {
skybox = true; skybox = true;
skyboxPresent = true; skyboxPresent = true;
/* invert origin */ /* invert origin */
vec3_t offset;
VectorScale( origin, -1.0f, offset ); VectorScale( origin, -1.0f, offset );
/* get scale */ /* get scale */
VectorSet( scale, 64.0f, 64.0f, 64.0f ); vec3_t scale = { 64.0f, 64.0f, 64.0f };
value = ValueForKey( e, "_scale" ); if( !ENT_READKV( e, "_scale", &scale ) )
if ( !strEmpty( value ) ) { if( ENT_READKV( e, "_scale", &scale[0] ) )
s = sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] ); scale[1] = scale[2] = scale[0];
if ( s == 1 ) {
scale[ 1 ] = scale[ 0 ];
scale[ 2 ] = scale[ 0 ];
}
}
/* get "angle" (yaw) or "angles" (pitch yaw roll) */ /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */
VectorClear( angles ); vec3_t angles = { 0.f, 0.f, 0.f };
angles[ 2 ] = FloatForKey( e, "angle" ); if ( !ENT_READKV( e, "angles", &value ) ||
value = ValueForKey( e, "angles" ); 3 != sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ) )
if ( !strEmpty( value ) ) { ENT_READKV( e, "angle", &angles[ 2 ] );
sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] );
}
/* set transform matrix (thanks spog) */ /* set transform matrix (thanks spog) */
m4x4_identity( skyboxTransform ); m4x4_identity( skyboxTransform );
@ -727,7 +719,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, ValueForKey( e, "classname" ) ); Sys_FPrintf( SYS_WRN, "Entity %i (%s): Entity in solid\n", e->mapEntityNum, ent_classname( e ) );
} }
else if ( tree->outside_node.occupied ) { else if ( tree->outside_node.occupied ) {
if ( !tripped || tree->outside_node.occupied < tripcount ) { if ( !tripped || tree->outside_node.occupied < tripcount ) {

View File

@ -1902,11 +1902,33 @@ 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 ); void SetKeyValue( entity_t *ent, const char *key, const char *value );
bool KeyExists( const entity_t *ent, const char *key ); /* VorteX: check if key exists */
const char *ValueForKey( const entity_t *ent, const char *key ); const char *ValueForKey( const entity_t *ent, const char *key );
bool BoolForKey( const entity_t *ent, const char *key );
int IntForKey( const entity_t *ent, const char *key ); int IntForKey( const entity_t *ent, const char *key );
vec_t FloatForKey( const entity_t *ent, const char *key ); vec_t FloatForKey( const entity_t *ent, const char *key );
void GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec ); void GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec );
/* entity: read key value generic macro
returns true on successful read
returns false and does not modify value otherwise */
bool entity_read_bool( const entity_t *entity, const char *key, bool *bool_value );
bool entity_read_int( const entity_t *entity, const char *key, int *int_value );
bool entity_read_float( const entity_t *entity, const char *key, float *float_value ); // warning: float[3] may be passed here erroneously, if not written as &float[3]
bool entity_read_vector3( const entity_t *entity, const char *key, float (*vector3_value)[3] );
bool entity_read_string( const entity_t *entity, const char *key, char (*string_value)[] ); // explicit pointer to array to avoid erroneous mix of char* and char**
bool entity_read_string_ptr( const entity_t *entity, const char *key, const char **string_ptr_value );
#define ENT_READKV( entity, key, value_ptr ) _Generic( ( value_ptr ), \
bool*: entity_read_bool, \
int*: entity_read_int, \
float*: entity_read_float, \
float (*)[3]: entity_read_vector3,\
char (*)[]: entity_read_string, \
const char**: entity_read_string_ptr\
)( entity, key, value_ptr )
const char *ent_classname( const entity_t *entity );
bool ent_class_is( const entity_t *entity, const char *classname );
bool ent_class_prefixed( const entity_t *entity, const char *prefix );
entity_t *FindTargetEntity( const char *target ); 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 );
void InjectCommandLine( char **argv, int beginArgs, int endArgs ); void InjectCommandLine( char **argv, int beginArgs, int endArgs );
@ -2193,8 +2215,8 @@ Q_EXTERN bool hint; /* ydnar */
Q_EXTERN char inbase[ MAX_QPATH ]; Q_EXTERN char inbase[ MAX_QPATH ];
Q_EXTERN char globalCelShader[ MAX_QPATH ]; Q_EXTERN char globalCelShader[ MAX_QPATH ];
Q_EXTERN float farPlaneDist; /* rr2do2, rf, mre, ydnar all contributed to this one... */ Q_EXTERN float farPlaneDist Q_ASSIGN( 0.0f ); /* rr2do2, rf, mre, ydnar all contributed to this one... */
Q_EXTERN int farPlaneDistMode; Q_EXTERN int farPlaneDistMode Q_ASSIGN( 0 );
Q_EXTERN int numportals; Q_EXTERN int numportals;
Q_EXTERN int portalclusters; Q_EXTERN int portalclusters;

View File

@ -2596,13 +2596,10 @@ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
int i, j; int i, j;
bspDrawSurface_t *out; bspDrawSurface_t *out;
int surfaceFlags, contentFlags; int surfaceFlags, contentFlags;
int forcePatchMeta;
/* vortex: _patchMeta support */ /* vortex: _patchMeta support */
forcePatchMeta = IntForKey( e, "_patchMeta" ); bool forcePatchMeta = false;
if ( !forcePatchMeta ) { ENT_READKV( e, "_patchMeta", &forcePatchMeta ) || ENT_READKV( e, "patchMeta", &forcePatchMeta );
forcePatchMeta = IntForKey( e, "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,29 +291,13 @@ static void SurfaceToMetaTriangles( mapDrawSurface_t *ds ){
*/ */
void TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds ){ void TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds ){
int iterations, x, y, pw[ 5 ], r; int x, y, pw[ 5 ], r;
mapDrawSurface_t *dsNew; mapDrawSurface_t *dsNew;
mesh_t src, *subdivided, *mesh; mesh_t src, *subdivided, *mesh;
bool forcePatchMeta;
int patchQuality;
int patchSubdivision;
/* vortex: _patchMeta, _patchQuality, _patchSubdivide support */ /* vortex: _patchMeta, _patchQuality, _patchSubdivide support */
forcePatchMeta = IntForKey( e, "_patchMeta" ); bool forcePatchMeta = false;
if ( !forcePatchMeta ) { ENT_READKV( e, "_patchMeta", &forcePatchMeta ) || ENT_READKV( e, "patchMeta", &forcePatchMeta );
forcePatchMeta = IntForKey( e, "patchMeta" );
}
patchQuality = IntForKey( e, "_patchQuality" );
if ( !patchQuality ) {
patchQuality = IntForKey( e, "patchQuality" );
}
if ( !patchQuality ) {
patchQuality = 1.0;
}
patchSubdivision = IntForKey( e, "_patchSubdivide" );
if ( !patchSubdivision ) {
patchSubdivision = IntForKey( e, "patchSubdivide" );
}
/* try to early out */ /* try to early out */
if ( ds->numVerts == 0 || ds->type != SURFACE_PATCH || ( !patchMeta && !forcePatchMeta ) ) { if ( ds->numVerts == 0 || ds->type != SURFACE_PATCH || ( !patchMeta && !forcePatchMeta ) ) {
@ -324,11 +308,16 @@ void TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds ){
src.height = ds->patchHeight; src.height = ds->patchHeight;
src.verts = ds->verts; src.verts = ds->verts;
//% subdivided = SubdivideMesh( src, 8, 999 ); //% subdivided = SubdivideMesh( src, 8, 999 );
if ( patchSubdivision ) {
int iterations;
int patchSubdivision;
if ( ENT_READKV( e, "_patchSubdivide", &patchSubdivision ) || ENT_READKV( e, "patchSubdivide", &patchSubdivision ) ) {
iterations = IterationsForCurve( ds->longestCurve, patchSubdivision ); iterations = IterationsForCurve( ds->longestCurve, patchSubdivision );
} }
else{ else{
iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions / patchQuality ); int patchQuality = 0;
ENT_READKV( e, "_patchQuality", &patchQuality ) || ENT_READKV( e, "patchQuality", &patchQuality );
iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions / ( patchQuality == 0? 1 : patchQuality ) );
} }
subdivided = SubdivideMesh2( src, iterations ); //% ds->maxIterations subdivided = SubdivideMesh2( src, iterations ); //% ds->maxIterations

View File

@ -295,22 +295,16 @@ void CalcFastVis( void ){
*/ */
void CalcVis( void ){ void CalcVis( void ){
int i, minvis, maxvis; int i, minvis, maxvis;
const char *value;
double mu, sigma, totalvis, totalvis2; double mu, sigma, totalvis, totalvis2;
/* ydnar: rr2do2's farplane code */ /* ydnar: rr2do2's farplane code */
farPlaneDist = 0.0f; const char *value;
value = ValueForKey( &entities[ 0 ], "_farplanedist" ); /* proper '_' prefixed key */ if( ENT_READKV( &entities[ 0 ], "_farplanedist", &value ) || /* proper '_' prefixed key */
if ( strEmpty( value ) ) { ENT_READKV( &entities[ 0 ], "fogclip", &value ) || /* wolf compatibility */
value = ValueForKey( &entities[ 0 ], "fogclip" ); /* wolf compatibility */ ENT_READKV( &entities[ 0 ], "distancecull", &value ) ){ /* sof2 compatibility */
}
if ( strEmpty( value ) ) {
value = ValueForKey( &entities[ 0 ], "distancecull" ); /* sof2 compatibility */
}
if ( !strEmpty( value ) ) {
farPlaneDist = atof( value ); farPlaneDist = atof( value );
farPlaneDistMode = value[strlen(value) - 1 ]; farPlaneDistMode = value[strlen( value ) - 1 ];
if ( farPlaneDist != 0.0f ) { if ( farPlaneDist != 0.0f ) {
Sys_Printf( "farplane distance = %.1f\n", farPlaneDist ); Sys_Printf( "farplane distance = %.1f\n", farPlaneDist );
if ( farPlaneDistMode == 'o' ) if ( farPlaneDistMode == 'o' )
@ -322,9 +316,6 @@ void CalcVis( void ){
} }
} }
Sys_Printf( "\n--- BasePortalVis (%d) ---\n", numportals * 2 ); Sys_Printf( "\n--- BasePortalVis (%d) ---\n", numportals * 2 );
RunThreadsOnIndividual( numportals * 2, true, BasePortalVis ); RunThreadsOnIndividual( numportals * 2, true, BasePortalVis );

View File

@ -283,8 +283,7 @@ void SetModelNumbers( void ){
*/ */
void SetLightStyles( void ){ void SetLightStyles( void ){
int i, j, style, numStyles; int i, j, numStyles;
const char *t;
entity_t *e; entity_t *e;
epair_t *ep, *next; epair_t *ep, *next;
char value[ 10 ]; char value[ 10 ];
@ -297,10 +296,7 @@ void SetLightStyles( void ){
} }
/* ydnar: determine if we keep lights in the bsp */ /* ydnar: determine if we keep lights in the bsp */
if ( KeyExists( &entities[ 0 ], "_keepLights" ) ) { ENT_READKV( &entities[ 0 ], "_keepLights", &keepLights );
t = ValueForKey( &entities[ 0 ], "_keepLights" );
keepLights = ( t[ 0 ] == '1' );
}
/* 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;
@ -308,12 +304,11 @@ void SetLightStyles( void ){
{ {
e = &entities[ i ]; e = &entities[ i ];
t = ValueForKey( e, "classname" ); if ( !ent_class_prefixed( e, "light" ) ) {
if ( !striEqualPrefix( t, "light" ) ) {
continue; continue;
} }
t = ValueForKey( e, "targetname" ); const char *t;
if ( strEmpty( t ) ) { if ( !ENT_READKV( e, "targetname", &t ) ) {
/* ydnar: strip the light from the BSP file */ /* ydnar: strip the light from the BSP file */
if ( !keepLights ) { if ( !keepLights ) {
ep = e->epairs; ep = e->epairs;
@ -334,7 +329,7 @@ void SetLightStyles( void ){
} }
/* get existing style */ /* get existing style */
style = IntForKey( e, "style" ); const int style = IntForKey( e, "style" );
if ( style < LS_NORMAL || style > LS_NONE ) { if ( style < LS_NORMAL || style > LS_NONE ) {
Error( "Invalid lightstyle (%d) on entity %d", style, i ); Error( "Invalid lightstyle (%d) on entity %d", style, i );
} }