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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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