return Vector3 from vectorForKey()

This commit is contained in:
Garux 2021-03-11 20:16:52 +03:00
parent 1144be0881
commit 09c78ec0dc
11 changed files with 22 additions and 43 deletions

View File

@ -440,26 +440,23 @@ void ProcessWorldModel( void ){
if( emitFlares ){
for ( const auto& light : entities )
{
entity_t *target;
Vector3 origin, targetOrigin, normal, color;
/* get light */
if ( light.classname_is( "light" ) ) {
/* get flare shader */
const char *flareShader = NULL;
if ( light.read_keyvalue( flareShader, "_flareshader" ) || light.boolForKey( "_flare" ) ) {
/* get specifics */
light.vectorForKey( "origin", origin );
light.vectorForKey( "_color", color );
const Vector3 origin( light.vectorForKey( "origin" ) );
Vector3 color( light.vectorForKey( "_color" ) );
const int lightStyle = light.intForKey( "_style", "style" );
Vector3 normal;
/* handle directional spotlights */
if ( light.read_keyvalue( value, "target" ) ) {
/* get target light */
target = FindTargetEntity( value );
const entity_t *target = FindTargetEntity( value );
if ( target != NULL ) {
target->vectorForKey( "origin", targetOrigin );
normal = VectorNormalized( targetOrigin - origin );
normal = VectorNormalized( target->vectorForKey( "origin" ) - origin );
}
}
else{

View File

@ -400,12 +400,8 @@ int ConvertBSPToASE( char *bspName ){
}
model = &bspModels[ modelNum ];
/* get entity origin */
Vector3 origin;
e->vectorForKey( "origin", origin );
/* convert model */
ConvertModel( f, model, modelNum, origin, lmIndices );
ConvertModel( f, model, modelNum, e->vectorForKey( "origin" ), lmIndices );
}
/* close the file and return */

View File

@ -1012,12 +1012,8 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){
/* get model */
model = &bspModels[ modelNum ];
/* get entity origin */
Vector3 origin;
e->vectorForKey( "origin", origin );
/* convert model */
ConvertModel( f, model, modelNum, origin, brushPrimitives );
ConvertModel( f, model, modelNum, e->vectorForKey( "origin" ), brushPrimitives );
}
/* end entity */

View File

@ -357,12 +357,8 @@ int ConvertBSPToOBJ( char *bspName ){
}
model = &bspModels[ modelNum ];
/* get entity origin */
Vector3 origin;
e->vectorForKey( "origin", origin );
/* convert model */
ConvertModelToOBJ( f, model, modelNum, origin, lmIndices );
ConvertModelToOBJ( f, model, modelNum, e->vectorForKey( "origin" ), lmIndices );
}
if ( lightmapsAsTexcoord ) {

View File

@ -104,7 +104,7 @@ xmlNodePtr LeakFile( tree_t *tree ){
count++;
}
// add the occupant center
node->occupant->vectorForKey( "origin", mid );
mid = node->occupant->vectorForKey( "origin" );
fprintf( linefile, "%f %f %f\n", mid[0], mid[1], mid[2] );
point = xml_NodeForVec( mid );

View File

@ -322,7 +322,7 @@ void CreateEntityLights( void ){
}
/* set origin */
e->vectorForKey( "origin", light->origin );
light->origin = e->vectorForKey( "origin" );
e->read_keyvalue( light->style, "_style", "style" );
if ( light->style < LS_NORMAL || light->style >= LS_NONE ) {
Error( "Invalid lightstyle (%d) on entity %zu", light->style, i );
@ -394,9 +394,7 @@ void CreateEntityLights( void ){
numSpotLights++;
/* make a spotlight */
Vector3 dest;
e2->vectorForKey( "origin", dest );
light->normal = dest - light->origin;
light->normal = e2->vectorForKey( "origin" ) - light->origin;
float dist = VectorNormalize( light->normal );
float radius = e->floatForKey( "radius" );
if ( !radius ) {
@ -1753,7 +1751,7 @@ void LightWorld( bool fastAllocate ){
}
/* find the optional minimum lighting values */
entities[ 0 ].vectorForKey( "_color", color );
color = entities[ 0 ].vectorForKey( "_color" );
if ( colorsRGB ) {
color[0] = Image_LinearFloatFromsRGBFloat( color[0] );
color[1] = Image_LinearFloatFromsRGBFloat( color[1] );

View File

@ -1108,8 +1108,7 @@ static void PopulateTraceNodes( void ){
}
/* get entity origin */
Vector3 origin;
e->vectorForKey( "origin", origin );
const Vector3 origin( e->vectorForKey( "origin" ) );
/* get scale */
Vector3 scale( 1 );

View File

@ -797,9 +797,8 @@ static void MergeOrigin( entity_t *ent, const Vector3& origin ){
char string[128];
/* we have not parsed the brush completely yet... */
ent->vectorForKey( "origin", ent->origin );
ent->origin = ent->vectorForKey( "origin" ) + origin - ent->originbrush_origin;
ent->origin += origin - ent->originbrush_origin;
ent->originbrush_origin = origin;
sprintf( string, "%f %f %f", ent->origin[0], ent->origin[1], ent->origin[2] );
@ -1748,8 +1747,8 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
LoadEntityIndexMap( mapEnt );
/* get entity origin and adjust brushes */
mapEnt->vectorForKey( "origin", mapEnt->origin );
if ( mapEnt->originbrush_origin[ 0 ] || mapEnt->originbrush_origin[ 1 ] || mapEnt->originbrush_origin[ 2 ] ) {
mapEnt->origin = mapEnt->vectorForKey( "origin" );
if ( mapEnt->originbrush_origin != g_vector3_identity ) {
AdjustBrushesForOrigin( mapEnt );
}

View File

@ -1313,9 +1313,7 @@ void AddTriangleModels( entity_t *eparent ){
const int spawnFlags = e->intForKey( "spawnflags" );
/* get origin */
Vector3 origin;
e->vectorForKey( "origin", origin );
origin -= eparent->origin; /* offset by parent */
const Vector3 origin = e->vectorForKey( "origin" ) - eparent->origin; /* offset by parent */
/* get scale */
Vector3 scale( 1 );

View File

@ -614,8 +614,7 @@ EFloodEntities FloodEntities( tree_t *tree ){
const entity_t& e = entities[ i ];
/* get origin */
Vector3 origin;
e.vectorForKey( "origin", origin );
Vector3 origin( e.vectorForKey( "origin" ) );
#if 0 // 0 = allow maps with only point entity@( 0, 0, 0 ); assuming that entities, containing no primitives are point ones
/* as a special case, allow origin-less entities */
if ( VectorCompare( origin, g_vector3_identity ) ) {

View File

@ -1025,9 +1025,10 @@ struct entity_t
read_keyvalue_( float_value, { keys ... } );
return float_value;
}
void vectorForKey( const char *key, Vector3& vec ) const {
if( !read_keyvalue_( vec, { key } ) )
vec.set( 0 );
Vector3 vectorForKey( const char *key ) const {
Vector3 vec( 0 );
read_keyvalue_( vec, { key } );
return vec;
}
const char *classname() const {