diff --git a/tools/quake3/q3map2/bsp.cpp b/tools/quake3/q3map2/bsp.cpp index 3d7b4f2a..706dc653 100644 --- a/tools/quake3/q3map2/bsp.cpp +++ b/tools/quake3/q3map2/bsp.cpp @@ -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{ diff --git a/tools/quake3/q3map2/convert_ase.cpp b/tools/quake3/q3map2/convert_ase.cpp index 3a805598..4f82af78 100644 --- a/tools/quake3/q3map2/convert_ase.cpp +++ b/tools/quake3/q3map2/convert_ase.cpp @@ -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 */ diff --git a/tools/quake3/q3map2/convert_map.cpp b/tools/quake3/q3map2/convert_map.cpp index 2c55c9ab..de50c281 100644 --- a/tools/quake3/q3map2/convert_map.cpp +++ b/tools/quake3/q3map2/convert_map.cpp @@ -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 */ diff --git a/tools/quake3/q3map2/convert_obj.cpp b/tools/quake3/q3map2/convert_obj.cpp index d14d6c01..430b0490 100644 --- a/tools/quake3/q3map2/convert_obj.cpp +++ b/tools/quake3/q3map2/convert_obj.cpp @@ -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 ) { diff --git a/tools/quake3/q3map2/leakfile.cpp b/tools/quake3/q3map2/leakfile.cpp index 63719255..a2a72496 100644 --- a/tools/quake3/q3map2/leakfile.cpp +++ b/tools/quake3/q3map2/leakfile.cpp @@ -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 ); diff --git a/tools/quake3/q3map2/light.cpp b/tools/quake3/q3map2/light.cpp index c950182c..bac0f46b 100644 --- a/tools/quake3/q3map2/light.cpp +++ b/tools/quake3/q3map2/light.cpp @@ -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] ); diff --git a/tools/quake3/q3map2/light_trace.cpp b/tools/quake3/q3map2/light_trace.cpp index c83e1480..37bd0a58 100644 --- a/tools/quake3/q3map2/light_trace.cpp +++ b/tools/quake3/q3map2/light_trace.cpp @@ -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 ); diff --git a/tools/quake3/q3map2/map.cpp b/tools/quake3/q3map2/map.cpp index e18f2720..cc942b06 100644 --- a/tools/quake3/q3map2/map.cpp +++ b/tools/quake3/q3map2/map.cpp @@ -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 ); } diff --git a/tools/quake3/q3map2/model.cpp b/tools/quake3/q3map2/model.cpp index 5f3d9315..815ca0b7 100644 --- a/tools/quake3/q3map2/model.cpp +++ b/tools/quake3/q3map2/model.cpp @@ -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 ); diff --git a/tools/quake3/q3map2/portals.cpp b/tools/quake3/q3map2/portals.cpp index 1a1cbc41..90a3cbc4 100644 --- a/tools/quake3/q3map2/portals.cpp +++ b/tools/quake3/q3map2/portals.cpp @@ -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 ) ) { diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 4fd7174e..77d11165 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -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 {