From 99f4a4a76769d1e3817f3ff3ffb63b34a5897fd3 Mon Sep 17 00:00:00 2001 From: Garux Date: Tue, 3 Aug 2021 20:54:21 +0300 Subject: [PATCH] minor tweaks --- tools/quake3/q3map2/bsp.cpp | 5 ++- tools/quake3/q3map2/bspfile_abstract.cpp | 3 +- tools/quake3/q3map2/map.cpp | 15 +++++---- tools/quake3/q3map2/model.cpp | 40 ++++++++++++------------ tools/quake3/q3map2/q3map2.h | 4 +-- tools/quake3/q3map2/writebsp.cpp | 15 +++++---- 6 files changed, 39 insertions(+), 43 deletions(-) diff --git a/tools/quake3/q3map2/bsp.cpp b/tools/quake3/q3map2/bsp.cpp index 481d4153..dfccfc37 100644 --- a/tools/quake3/q3map2/bsp.cpp +++ b/tools/quake3/q3map2/bsp.cpp @@ -581,7 +581,6 @@ void ProcessSubModel( void ){ void ProcessModels( void ){ bool oldVerbose; - entity_t *entity; /* preserve -v setting */ @@ -597,8 +596,8 @@ void ProcessModels( void ){ for ( mapEntityNum = 0; mapEntityNum < entities.size(); mapEntityNum++ ) { /* get entity */ - entity = &entities[ mapEntityNum ]; - if ( entity->brushes == NULL && entity->patches == NULL ) { + const entity_t& entity = entities[ mapEntityNum ]; + if ( entity.brushes == NULL && entity.patches == NULL ) { continue; } diff --git a/tools/quake3/q3map2/bspfile_abstract.cpp b/tools/quake3/q3map2/bspfile_abstract.cpp index 63bab33a..2f0b63c4 100644 --- a/tools/quake3/q3map2/bspfile_abstract.cpp +++ b/tools/quake3/q3map2/bspfile_abstract.cpp @@ -557,8 +557,7 @@ bool ParseEntity( void ){ } /* create new entity */ - entities.emplace_back(); - mapEnt = &entities.back(); + mapEnt = &entities.emplace_back(); /* parse */ while ( 1 ) diff --git a/tools/quake3/q3map2/map.cpp b/tools/quake3/q3map2/map.cpp index c91f5c5e..29d683f5 100644 --- a/tools/quake3/q3map2/map.cpp +++ b/tools/quake3/q3map2/map.cpp @@ -789,16 +789,16 @@ void AddBrushBevels( void ){ and links it to the current entity */ -static void MergeOrigin( entity_t *ent, const Vector3& origin ){ +static void MergeOrigin( entity_t& ent, const Vector3& origin ){ char string[128]; /* we have not parsed the brush completely yet... */ - ent->origin = ent->vectorForKey( "origin" ) + origin - ent->originbrush_origin; + ent.origin = ent.vectorForKey( "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] ); - ent->setKeyValue( "origin", string ); + sprintf( string, "%f %f %f", ent.origin[0], ent.origin[1], ent.origin[2] ); + ent.setKeyValue( "origin", string ); } brush_t *FinishBrush( bool noCollapseGroups ){ @@ -822,7 +822,7 @@ brush_t *FinishBrush( bool noCollapseGroups ){ return NULL; } - MergeOrigin( &entities.back(), buildBrush->minmax.origin() ); + MergeOrigin( entities.back(), buildBrush->minmax.origin() ); /* don't keep this brush */ return NULL; @@ -1602,8 +1602,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ /* setup */ entitySourceBrushes = 0; - entities.emplace_back(); - mapEnt = &entities.back(); + mapEnt = &entities.emplace_back(); /* ydnar: true entity numbering */ mapEnt->mapEntityNum = numMapEntities; diff --git a/tools/quake3/q3map2/model.cpp b/tools/quake3/q3map2/model.cpp index 763e1feb..ea89b8fc 100644 --- a/tools/quake3/q3map2/model.cpp +++ b/tools/quake3/q3map2/model.cpp @@ -1430,27 +1430,27 @@ void AddTriangleModels( entity_t *eparent ){ for ( std::size_t i = 1; i < entities.size(); ++i ) { /* get entity */ - entity_t *e = &entities[ i ]; + const entity_t& e = entities[ i ]; /* convert misc_models into raw geometry */ - if ( !e->classname_is( "misc_model" ) ) { + if ( !e.classname_is( "misc_model" ) ) { continue; } /* ydnar: added support for md3 models on non-worldspawn models */ - if ( !strEqual( e->valueForKey( "target" ), targetName ) ) { + if ( !strEqual( e.valueForKey( "target" ), targetName ) ) { continue; } /* get model name */ const char *model; - if ( !e->read_keyvalue( model, "model" ) ) { - Sys_Warning( "entity#%d misc_model without a model key\n", e->mapEntityNum ); + if ( !e.read_keyvalue( model, "model" ) ) { + Sys_Warning( "entity#%d misc_model without a model key\n", e.mapEntityNum ); continue; } /* get model frame */ - const int frame = e->intForKey( "_frame", "frame" ); + const int frame = e.intForKey( "_frame", "frame" ); int castShadows, recvShadows; if ( eparent == &entities[0] ) { /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */ @@ -1463,26 +1463,26 @@ void AddTriangleModels( entity_t *eparent ){ } /* get explicit shadow flags */ - GetEntityShadowFlags( e, eparent, &castShadows, &recvShadows ); + GetEntityShadowFlags( &e, eparent, &castShadows, &recvShadows ); /* get spawnflags */ - const int spawnFlags = e->intForKey( "spawnflags" ); + const int spawnFlags = e.intForKey( "spawnflags" ); /* get origin */ - const Vector3 origin = e->vectorForKey( "origin" ) - eparent->origin; /* offset by parent */ + const Vector3 origin = e.vectorForKey( "origin" ) - eparent->origin; /* offset by parent */ /* get scale */ Vector3 scale( 1 ); - if( !e->read_keyvalue( scale, "modelscale_vec" ) ) - if( e->read_keyvalue( scale[0], "modelscale" ) ) + if( !e.read_keyvalue( scale, "modelscale_vec" ) ) + if( e.read_keyvalue( scale[0], "modelscale" ) ) scale[1] = scale[2] = scale[0]; /* get "angle" (yaw) or "angles" (pitch yaw roll), store as (roll pitch yaw) */ const char *value; Vector3 angles( 0 ); - if ( !e->read_keyvalue( value, "angles" ) || + if ( !e.read_keyvalue( value, "angles" ) || 3 != sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] ) ) - e->read_keyvalue( angles[ 2 ], "angle" ); + e.read_keyvalue( angles[ 2 ], "angle" ); /* set transform matrix (thanks spog) */ Matrix4 transform( g_matrix4_identity ); @@ -1490,7 +1490,7 @@ void AddTriangleModels( entity_t *eparent ){ /* get shader remappings */ std::list remaps; - for ( const auto& ep : e->epairs ) + for ( const auto& ep : e.epairs ) { /* look for keys prefixed with "_remap" */ if ( striEqualPrefix( ep.key.c_str(), "_remap" ) ) { @@ -1529,7 +1529,7 @@ void AddTriangleModels( entity_t *eparent ){ /* ydnar: cel shader support */ shaderInfo_t *celShader; - if( e->read_keyvalue( value, "_celshader" ) || + if( e.read_keyvalue( value, "_celshader" ) || entities[ 0 ].read_keyvalue( value, "_celshader" ) ){ celShader = ShaderInfoForShader( String64()( "textures/", value ) ); } @@ -1538,25 +1538,25 @@ void AddTriangleModels( entity_t *eparent ){ } /* jal : entity based _samplesize */ - const int lightmapSampleSize = std::max( 0, e->intForKey( "_lightmapsamplesize", "_samplesize", "_ss" ) ); + const int lightmapSampleSize = std::max( 0, e.intForKey( "_lightmapsamplesize", "_samplesize", "_ss" ) ); if ( lightmapSampleSize != 0 ) Sys_Printf( "misc_model has lightmap sample size of %.d\n", lightmapSampleSize ); /* get lightmap scale */ - const float lightmapScale = std::max( 0.f, e->floatForKey( "lightmapscale", "_lightmapscale", "_ls" ) ); + const float lightmapScale = std::max( 0.f, e.floatForKey( "lightmapscale", "_lightmapscale", "_ls" ) ); if ( lightmapScale != 0 ) Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale ); /* jal : entity based _shadeangle */ - const float shadeAngle = std::max( 0.f, e->floatForKey( "_shadeangle", + const float shadeAngle = std::max( 0.f, e.floatForKey( "_shadeangle", "_smoothnormals", "_sn", "_sa", "_smooth" ) ); /* vortex' aliases */ if ( shadeAngle != 0 ) Sys_Printf( "misc_model has shading angle of %.4f\n", shadeAngle ); - const int skin = e->intForKey( "_skin", "skin" ); + const int skin = e.intForKey( "_skin", "skin" ); float clipDepth = clipDepthGlobal; - if ( e->read_keyvalue( clipDepth, "_clipdepth" ) ) + if ( e.read_keyvalue( clipDepth, "_clipdepth" ) ) Sys_Printf( "misc_model %s has autoclip depth of %.3f\n", model, clipDepth ); diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index ae3d18d8..fa2479d6 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -991,13 +991,13 @@ struct epair_t struct entity_t { - Vector3 origin; + Vector3 origin{ 0 }; brush_t *brushes, *lastBrush, *colorModBrushes; parseMesh_t *patches; int mapEntityNum, firstDrawSurf; int firstBrush, numBrushes; /* only valid during BSP compile */ std::list epairs; - Vector3 originbrush_origin; + Vector3 originbrush_origin{ 0 }; void setKeyValue( const char *key, const char *value ); const char *valueForKey( const char *key ) const; diff --git a/tools/quake3/q3map2/writebsp.cpp b/tools/quake3/q3map2/writebsp.cpp index 1967403c..0552b29f 100644 --- a/tools/quake3/q3map2/writebsp.cpp +++ b/tools/quake3/q3map2/writebsp.cpp @@ -271,7 +271,6 @@ void SetModelNumbers( void ){ void SetLightStyles( void ){ int j, numStyles; - entity_t *e; char value[ 10 ]; char lightTargets[ MAX_SWITCHED_LIGHTS ][ 64 ]; int lightStyles[ MAX_SWITCHED_LIGHTS ]; @@ -288,16 +287,16 @@ void SetLightStyles( void ){ numStyles = 0; for ( std::size_t i = 1; i < entities.size(); ++i ) { - e = &entities[ i ]; + entity_t& e = entities[ i ]; - if ( !e->classname_prefixed( "light" ) ) { + if ( !e.classname_prefixed( "light" ) ) { continue; } const char *t; - if ( !e->read_keyvalue( t, "targetname" ) ) { + if ( !e.read_keyvalue( t, "targetname" ) ) { /* ydnar: strip the light from the BSP file */ if ( !keepLights ) { - e->epairs.clear(); + e.epairs.clear(); numStrippedLights++; } @@ -306,7 +305,7 @@ void SetLightStyles( void ){ } /* get existing style */ - const int style = e->intForKey( "style" ); + const int style = e.intForKey( "style" ); if ( style < LS_NORMAL || style > LS_NONE ) { Error( "Invalid lightstyle (%d) on entity %zu", style, i ); } @@ -329,12 +328,12 @@ void SetLightStyles( void ){ /* set explicit style */ sprintf( value, "%d", 32 + j ); - e->setKeyValue( "style", value ); + e.setKeyValue( "style", value ); /* set old style */ if ( style != LS_NORMAL ) { sprintf( value, "%d", style ); - e->setKeyValue( "switch_style", value ); + e.setKeyValue( "switch_style", value ); } }