diff --git a/tools/quake3/common/cmdlib.cpp b/tools/quake3/common/cmdlib.cpp index ab24a341..cd769f56 100644 --- a/tools/quake3/common/cmdlib.cpp +++ b/tools/quake3/common/cmdlib.cpp @@ -50,7 +50,7 @@ void_ptr safe_malloc( size_t size ){ void *p = malloc( size ); if ( !p ) { - Error( "safe_malloc failed on allocation of %lu bytes", (unsigned long)size ); + Error( "safe_malloc failed on allocation of %zu bytes", size ); } return p; } @@ -58,7 +58,7 @@ void_ptr safe_malloc( size_t size ){ void_ptr safe_malloc_info( size_t size, const char* info ){ void *p = malloc( size ); if ( !p ) { - Error( "%s: safe_malloc failed on allocation of %lu bytes", info, (unsigned long)size ); + Error( "%s: safe_malloc failed on allocation of %zu bytes", info, size ); } return p; } @@ -66,7 +66,7 @@ void_ptr safe_malloc_info( size_t size, const char* info ){ void_ptr safe_calloc( size_t size ){ void *p = calloc( 1, size ); if ( !p ) { - Error( "safe_calloc failed on allocation of %lu bytes", (unsigned long)size ); + Error( "safe_calloc failed on allocation of %zu bytes", size ); } return p; } @@ -74,7 +74,7 @@ void_ptr safe_calloc( size_t size ){ void_ptr safe_calloc_info( size_t size, const char* info ){ void *p = calloc( 1, size ); if ( !p ) { - Error( "%s: safe_calloc failed on allocation of %lu bytes", info, (unsigned long)size ); + Error( "%s: safe_calloc failed on allocation of %zu bytes", info, size ); } return p; } diff --git a/tools/quake3/q3map2/autopk3.cpp b/tools/quake3/q3map2/autopk3.cpp index fe95a482..3eca04d4 100644 --- a/tools/quake3/q3map2/autopk3.cpp +++ b/tools/quake3/q3map2/autopk3.cpp @@ -317,27 +317,27 @@ int pk3BSPMain( int argc, char **argv ){ res2list( pk3Sounds, str ); } - for ( i = 0; i < numBSPEntities && i < numEntities; ++i ) + for ( const auto& e : entities ) { - if ( ENT_READKV( &str, &entities[i], "noise" ) && str[0] != '*' ){ + if ( ENT_READKV( &str, &e, "noise" ) && str[0] != '*' ){ FixDOSName( str ); DefaultExtension( str, ".wav" ); res2list( pk3Sounds, str ); } - if ( ent_class_is( &entities[i], "func_plat" ) ){ + if ( ent_class_is( &e, "func_plat" ) ){ res2list( pk3Sounds, "sound/movers/plats/pt1_strt.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); } - if ( ent_class_is( &entities[i], "target_push" ) ){ - if ( !( IntForKey( &entities[i], "spawnflags") & 1 ) ){ + if ( ent_class_is( &e, "target_push" ) ){ + if ( !( IntForKey( &e, "spawnflags") & 1 ) ){ res2list( pk3Sounds, "sound/misc/windfly.wav" ); } } - res2list( pk3Shaders, ValueForKey( &entities[i], "targetShaderNewName" ) ); + res2list( pk3Shaders, ValueForKey( &e, "targetShaderNewName" ) ); - if ( ENT_READKV( &str, &entities[i], "model2" ) ){ - Sys_Warning( "unhandled model2 key of %s: %s\n", ent_classname( &entities[i] ), str ); + if ( ENT_READKV( &str, &e, "model2" ) ){ + Sys_Warning( "unhandled model2 key of %s: %s\n", ent_classname( &e ), str ); } } @@ -991,26 +991,26 @@ int repackBSPMain( int argc, char **argv ){ res2list( pk3Sounds, str ); } - for ( i = 0; i < numBSPEntities && i < numEntities; ++i ) + for ( const auto& e : entities ) { - if ( ENT_READKV( &str, &entities[i], "noise" ) && str[0] != '*' ){ + if ( ENT_READKV( &str, &e, "noise" ) && str[0] != '*' ){ FixDOSName( str ); DefaultExtension( str, ".wav" ); res2list( pk3Sounds, str ); } - if ( ent_class_is( &entities[i], "func_plat" ) ){ + if ( ent_class_is( &e, "func_plat" ) ){ res2list( pk3Sounds, "sound/movers/plats/pt1_strt.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); } - if ( ent_class_is( &entities[i], "target_push" ) ){ - if ( !( IntForKey( &entities[i], "spawnflags") & 1 ) ){ + if ( ent_class_is( &e, "target_push" ) ){ + if ( !( IntForKey( &e, "spawnflags") & 1 ) ){ res2list( pk3Sounds, "sound/misc/windfly.wav" ); } } - res2list( pk3Shaders, ValueForKey( &entities[i], "targetShaderNewName" ) ); + res2list( pk3Shaders, ValueForKey( &e, "targetShaderNewName" ) ); - if ( ENT_READKV( &str, &entities[i], "model2" ) ){ + if ( ENT_READKV( &str, &e, "model2" ) ){ Sys_Warning( "unhandled model2 key of %s: %s\n", ent_classname( &entities[i] ), str ); } } @@ -1073,21 +1073,18 @@ int repackBSPMain( int argc, char **argv ){ //numBSPBrushes = 0; //allocatedBSPBrushes = 0; } -*/ if ( entities != 0 ) { - for ( i = 0; i < numBSPEntities && i < numEntities; ++i ){ - ep = entities[i].epairs; +*/ { + for ( const auto& e : entities ){ + ep = e.epairs; while( ep != NULL){ epair_t *ep2free = ep; ep = ep->next; free( ep2free ); } } - free( entities ); - entities = NULL; + entities.clear(); //Sys_Printf( "freed entities\n" ); - numEntities = 0; numBSPEntities = 0; - allocatedEntities = 0; } /* if ( bspModels != 0 ) { free( bspModels ); diff --git a/tools/quake3/q3map2/bsp.cpp b/tools/quake3/q3map2/bsp.cpp index 3340b214..281733da 100644 --- a/tools/quake3/q3map2/bsp.cpp +++ b/tools/quake3/q3map2/bsp.cpp @@ -100,7 +100,6 @@ static void autocaulk_write(){ */ static void ProcessAdvertisements( void ) { - int i; const char* modelKey; int modelNum; bspModel_t* adModel; @@ -108,19 +107,19 @@ static void ProcessAdvertisements( void ) { Sys_FPrintf( SYS_VRB, "--- ProcessAdvertisements ---\n" ); - for ( i = 0; i < numEntities; i++ ) { + for ( const auto& e : entities ) { /* is an advertisement? */ - if ( ent_class_is( &entities[ i ], "advertisement" ) ) { + if ( ent_class_is( &e, "advertisement" ) ) { - modelKey = ValueForKey( &entities[ i ], "model" ); + modelKey = ValueForKey( &e, "model" ); if ( strlen( modelKey ) > MAX_QPATH - 1 ) { Error( "Model Key for entity exceeds ad struct string length." ); } else { if ( numBSPAds < MAX_MAP_ADVERTISEMENTS ) { - bspAds[numBSPAds].cellId = IntForKey( &entities[ i ], "cellId" ); + bspAds[numBSPAds].cellId = IntForKey( &e, "cellId" ); strncpy( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) ); modelKey++; @@ -171,7 +170,6 @@ static void ProcessAdvertisements( void ) { */ static void SetCloneModelNumbers( void ){ - int i, j; int models; char modelValue[ 16 ]; const char *value, *value2, *value3; @@ -179,7 +177,7 @@ static void SetCloneModelNumbers( void ){ /* start with 1 (worldspawn is model 0) */ models = 1; - for ( i = 1; i < numEntities; i++ ) + for ( std::size_t i = 1; i < entities.size(); ++i ) { /* only entities with brushes or patches get a model number */ if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) { @@ -199,7 +197,7 @@ static void SetCloneModelNumbers( void ){ } /* fix up clones */ - for ( i = 1; i < numEntities; i++ ) + for ( std::size_t i = 1; i < entities.size(); ++i ) { /* only entities with brushes or patches get a model number */ if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) { @@ -211,7 +209,7 @@ static void SetCloneModelNumbers( void ){ continue; /* find an entity with matching clone name */ - for ( j = 0; j < numEntities; j++ ) + for ( std::size_t j = 0; j < entities.size(); ++j ) { /* is this a clone parent? */ if ( !ENT_READKV( &value2, &entities[ j ], "_clonename" ) ) { @@ -453,45 +451,46 @@ void ProcessWorldModel( void ){ } /* ydnar: bug 645: do flares for lights */ - for ( int i = 0; i < numEntities && emitFlares; i++ ) - { - entity_t *light, *target; - vec3_t origin, targetOrigin, normal, color; + if( emitFlares ){ + for ( const auto& light : entities ) + { + entity_t *target; + vec3_t origin, targetOrigin, normal, color; - /* get light */ - light = &entities[ i ]; - if ( ent_class_is( light, "light" ) ) { - /* get flare shader */ - const char *flareShader = NULL; - if ( ENT_READKV( &flareShader, light, "_flareshader" ) || BoolForKey( light, "_flare" ) ) { - /* get specifics */ - GetVectorForKey( light, "origin", origin ); - GetVectorForKey( light, "_color", color ); - const int lightStyle = IntForKey( light, "_style", "style" ); + /* get light */ + if ( ent_class_is( &light, "light" ) ) { + /* get flare shader */ + const char *flareShader = NULL; + if ( ENT_READKV( &flareShader, &light, "_flareshader" ) || BoolForKey( &light, "_flare" ) ) { + /* get specifics */ + GetVectorForKey( &light, "origin", origin ); + GetVectorForKey( &light, "_color", color ); + const int lightStyle = IntForKey( &light, "_style", "style" ); - /* handle directional spotlights */ - if ( ENT_READKV( &value, light, "target" ) ) { - /* get target light */ - target = FindTargetEntity( value ); - if ( target != NULL ) { - GetVectorForKey( target, "origin", targetOrigin ); - VectorSubtract( targetOrigin, origin, normal ); - VectorNormalize( normal, normal ); + /* handle directional spotlights */ + if ( ENT_READKV( &value, &light, "target" ) ) { + /* get target light */ + target = FindTargetEntity( value ); + if ( target != NULL ) { + GetVectorForKey( target, "origin", targetOrigin ); + VectorSubtract( targetOrigin, origin, normal ); + VectorNormalize( normal, normal ); + } + } + else{ + //% VectorClear( normal ); + VectorSet( normal, 0, 0, -1 ); } - } - else{ - //% VectorClear( normal ); - VectorSet( normal, 0, 0, -1 ); - } - if ( colorsRGB ) { - color[0] = Image_LinearFloatFromsRGBFloat( color[0] ); - color[1] = Image_LinearFloatFromsRGBFloat( color[1] ); - color[2] = Image_LinearFloatFromsRGBFloat( color[2] ); - } + if ( colorsRGB ) { + color[0] = Image_LinearFloatFromsRGBFloat( color[0] ); + color[1] = Image_LinearFloatFromsRGBFloat( color[1] ); + color[2] = Image_LinearFloatFromsRGBFloat( color[2] ); + } - /* create the flare surface (note shader defaults automatically) */ - DrawSurfaceForFlare( mapEntityNum, origin, normal, color, flareShader, lightStyle ); + /* create the flare surface (note shader defaults automatically) */ + DrawSurfaceForFlare( mapEntityNum, origin, normal, color, flareShader, lightStyle ); + } } } } @@ -613,17 +612,17 @@ void ProcessModels( void ){ CreateMapFogs(); /* walk entity list */ - for ( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ ) + for ( std::size_t i = 0; i < entities.size(); ++i ) { /* get entity */ - entity = &entities[ mapEntityNum ]; + entity = &entities[ i ]; if ( entity->brushes == NULL && entity->patches == NULL ) { continue; } /* process the model */ Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels ); - if ( mapEntityNum == 0 ) { + if ( i == 0 ) { ProcessWorldModel(); } else{ @@ -669,7 +668,7 @@ void OnlyEnts( void ){ strcpyQ( save_version, ValueForKey( &entities[0], "_q3map2_version" ), sizeof( save_version ) ); strcpyQ( save_gridsize, ValueForKey( &entities[0], "gridsize" ), sizeof( save_gridsize ) ); - numEntities = 0; + entities.clear(); LoadShaderInfo(); LoadMapFile( name, false, false ); @@ -686,7 +685,7 @@ void OnlyEnts( void ){ SetKeyValue( &entities[0], "gridsize", save_gridsize ); } - numBSPEntities = numEntities; + numBSPEntities = entities.size(); UnparseEntities(); WriteBSPFile( out ); diff --git a/tools/quake3/q3map2/bspfile_abstract.cpp b/tools/quake3/q3map2/bspfile_abstract.cpp index 3c6fec0e..86e848cb 100644 --- a/tools/quake3/q3map2/bspfile_abstract.cpp +++ b/tools/quake3/q3map2/bspfile_abstract.cpp @@ -436,7 +436,7 @@ void WriteBSPFile( const char *filename ){ void PrintBSPFileSizes( void ){ /* parse entities first */ - if ( numEntities <= 0 ) { + if ( entities.empty() ) { ParseEntities(); } int patchCount = 0; @@ -461,8 +461,8 @@ void PrintBSPFileSizes( void ){ numBSPFogs, (int) ( numBSPFogs * sizeof( bspFog_t ) ) ); Sys_Printf( "%9d planes %9d\n", numBSPPlanes, (int) ( numBSPPlanes * sizeof( bspPlane_t ) ) ); - Sys_Printf( "%9d entdata %9d\n", - numEntities, bspEntDataSize ); + Sys_Printf( "%9zu entdata %9d\n", + entities.size(), bspEntDataSize ); Sys_Printf( "\n" ); Sys_Printf( "%9d nodes %9d\n", @@ -567,12 +567,10 @@ bool ParseEntity( void ){ if ( !strEqual( token, "{" ) ) { Error( "ParseEntity: { not found" ); } - AUTOEXPAND_BY_REALLOC( entities, numEntities, allocatedEntities, 32 ); /* create new entity */ - mapEnt = &entities[ numEntities ]; - numEntities++; - memset( mapEnt, 0, sizeof( *mapEnt ) ); + entities.emplace_back(); + mapEnt = &entities.back(); /* parse */ while ( 1 ) @@ -600,12 +598,12 @@ bool ParseEntity( void ){ */ void ParseEntities( void ){ - numEntities = 0; + entities.clear(); ParseFromMemory( bspEntData, bspEntDataSize ); while ( ParseEntity() ) ; /* ydnar: set number of bsp entities in case a map is loaded on top */ - numBSPEntities = numEntities; + numBSPEntities = entities.size(); } /* @@ -668,7 +666,7 @@ void UnparseEntities( void ){ end = buf = bspEntData; /* run through entity list */ - for ( int i = 0; i < numBSPEntities && i < numEntities; i++ ) + for ( std::size_t i = 0; i < numBSPEntities && i < entities.size(); i++ ) { { int sz = end - buf; @@ -986,10 +984,10 @@ bool ent_class_prefixed( const entity_t *entity, const char *prefix ){ entity_t *FindTargetEntity( const char *target ){ /* walk entity list */ - for ( int i = 0; i < numEntities; i++ ) + for ( auto& e : entities ) { - if ( strEqual( ValueForKey( &entities[ i ], "targetname" ), target ) ) { - return &entities[ i ]; + if ( strEqual( ValueForKey( &e, "targetname" ), target ) ) { + return &e; } } diff --git a/tools/quake3/q3map2/convert_ase.cpp b/tools/quake3/q3map2/convert_ase.cpp index a408ad09..0f5f63cc 100644 --- a/tools/quake3/q3map2/convert_ase.cpp +++ b/tools/quake3/q3map2/convert_ase.cpp @@ -337,7 +337,7 @@ static void ConvertLightmap( FILE *f, const char *base, int lightmapNum ){ */ int ConvertBSPToASE( char *bspName ){ - int i, modelNum; + int modelNum; FILE *f; bspShader_t *shader; bspModel_t *model; @@ -382,14 +382,14 @@ int ConvertBSPToASE( char *bspName ){ if ( lightmapsAsTexcoord ) { numLightmapsASE = Convert_CountLightmaps( dirname ); fprintf( f, "\t*MATERIAL_COUNT\t%d\r\n", numLightmapsASE ); - for ( i = 0; i < numLightmapsASE; i++ ) + for ( int i = 0; i < numLightmapsASE; i++ ) ConvertLightmap( f, base, i ); Convert_ReferenceLightmaps( base, lmIndices ); } else { fprintf( f, "\t*MATERIAL_COUNT\t%d\r\n", numBSPShaders ); - for ( i = 0; i < numBSPShaders; i++ ) + for ( int i = 0; i < numBSPShaders; i++ ) { shader = &bspShaders[ i ]; ConvertShader( f, shader, i ); @@ -398,7 +398,7 @@ int ConvertBSPToASE( char *bspName ){ fprintf( f, "}\r\n" ); /* walk entity list */ - for ( i = 0; i < numEntities; i++ ) + for ( std::size_t i = 0; i < entities.size(); ++i ) { /* get entity and model */ e = &entities[ i ]; diff --git a/tools/quake3/q3map2/convert_bsp.cpp b/tools/quake3/q3map2/convert_bsp.cpp index 1976cfa4..c18a6c40 100644 --- a/tools/quake3/q3map2/convert_bsp.cpp +++ b/tools/quake3/q3map2/convert_bsp.cpp @@ -461,13 +461,13 @@ int ScaleBSPMain( int argc, char **argv ){ /* note it */ Sys_Printf( "--- ScaleBSP ---\n" ); - Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities ); + Sys_FPrintf( SYS_VRB, "%9zu entities\n", entities.size() ); /* scale entity keys */ - for ( i = 0; i < numBSPEntities && i < numEntities; i++ ) + for ( auto& e : entities ) { /* scale origin */ - if ( ENT_READKV( &vec, &entities[ i ], "origin" ) ) { + if ( ENT_READKV( &vec, &e, "origin" ) ) { if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { vec[2] += spawn_ref; } @@ -478,10 +478,10 @@ int ScaleBSPMain( int argc, char **argv ){ vec[2] -= spawn_ref; } sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); - SetKeyValue( &entities[ i ], "origin", str ); + SetKeyValue( &e, "origin", str ); } - a = FloatForKey( &entities[ i ], "angle" ); + a = FloatForKey( &e, "angle" ); if ( a == -1 || a == -2 ) { // z scale axis = 2; } @@ -493,17 +493,17 @@ int ScaleBSPMain( int argc, char **argv ){ } /* scale door lip */ - if ( ENT_READKV( &f, &entities[ i ], "lip" ) ) { + if ( ENT_READKV( &f, &e, "lip" ) ) { f *= scale[axis]; sprintf( str, "%f", f ); - SetKeyValue( &entities[ i ], "lip", str ); + SetKeyValue( &e, "lip", str ); } /* scale plat height */ - if ( ENT_READKV( &f, &entities[ i ], "height" ) ) { + if ( ENT_READKV( &f, &e, "height" ) ) { f *= scale[2]; sprintf( str, "%f", f ); - SetKeyValue( &entities[ i ], "height", str ); + SetKeyValue( &e, "height", str ); } // TODO maybe allow a definition file for entities to specify which values are scaled how? @@ -697,24 +697,24 @@ int ShiftBSPMain( int argc, char **argv ){ /* note it */ Sys_Printf( "--- ShiftBSP ---\n" ); - Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities ); + Sys_FPrintf( SYS_VRB, "%9zu entities\n", entities.size() ); /* shift entity keys */ - for ( i = 0; i < numBSPEntities && i < numEntities; i++ ) + for ( auto& e : entities ) { /* shift origin */ - if ( ENT_READKV( &vec, &entities[ i ], "origin" ) ) { - if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { + if ( ENT_READKV( &vec, &e, "origin" ) ) { + if ( ent_class_prefixed( &e, "info_player_" ) ) { vec[2] += spawn_ref; } vec[0] += scale[0]; vec[1] += scale[1]; vec[2] += scale[2]; - if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { + if ( ent_class_prefixed( &e, "info_player_" ) ) { vec[2] -= spawn_ref; } sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); - SetKeyValue( &entities[ i ], "origin", str ); + SetKeyValue( &e, "origin", str ); } } @@ -821,7 +821,6 @@ void PseudoCompileBSP( bool need_tree ){ node_t *node; brush_t *brush; side_t *side; - int i; SetDrawSurfacesBuffer(); mapDrawSurfs = safe_calloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS ); @@ -829,15 +828,15 @@ void PseudoCompileBSP( bool need_tree ){ BeginBSPFile(); models = 1; - for ( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ ) + for ( std::size_t i = 0; i < entities.size(); ++i ) { /* get entity */ - entity = &entities[ mapEntityNum ]; + entity = &entities[ i ]; if ( entity->brushes == NULL && entity->patches == NULL ) { continue; } - if ( mapEntityNum != 0 ) { + if ( i != 0 ) { sprintf( modelValue, "*%d", models++ ); SetKeyValue( entity, "model", modelValue ); } @@ -851,7 +850,7 @@ void PseudoCompileBSP( bool need_tree ){ ClearMetaTriangles(); PatchMapDrawSurfs( entity ); - if ( mapEntityNum == 0 && need_tree ) { + if ( i == 0 && need_tree ) { faces = MakeStructuralBSPFaceList( entities[0].brushes ); tree = FaceBSP( faces ); node = tree->headnode; @@ -868,10 +867,10 @@ void PseudoCompileBSP( bool need_tree ){ for ( brush = entity->brushes; brush; brush = brush->next ) { /* walk the brush sides */ - for ( i = 0; i < brush->numsides; i++ ) + for ( int j = 0; j < brush->numsides; j++ ) { /* get side */ - side = &brush->sides[ i ]; + side = &brush->sides[ j ]; if ( side->winding == NULL ) { continue; } diff --git a/tools/quake3/q3map2/convert_map.cpp b/tools/quake3/q3map2/convert_map.cpp index 178b70d1..c5d8407b 100644 --- a/tools/quake3/q3map2/convert_map.cpp +++ b/tools/quake3/q3map2/convert_map.cpp @@ -1001,7 +1001,7 @@ static void ConvertEPairs( FILE *f, entity_t *e, bool skip_origin ){ */ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){ - int i, modelNum; + int modelNum; FILE *f; bspModel_t *model; entity_t *e; @@ -1027,13 +1027,13 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){ fprintf( f, "// Generated by Q3Map2 (ydnar) -convert -format map\n" ); /* walk entity list */ - for ( i = 0; i < numEntities; i++ ) + for ( std::size_t i = 0; i < entities.size(); ++i ) { /* get entity */ e = &entities[ i ]; /* start entity */ - fprintf( f, "// entity %d\n", i ); + fprintf( f, "// entity %zu\n", i ); fprintf( f, "{\n" ); /* get model num */ diff --git a/tools/quake3/q3map2/convert_obj.cpp b/tools/quake3/q3map2/convert_obj.cpp index 872ccb6d..756aa592 100644 --- a/tools/quake3/q3map2/convert_obj.cpp +++ b/tools/quake3/q3map2/convert_obj.cpp @@ -301,7 +301,7 @@ void Convert_ReferenceLightmaps( const char* base, int* lmIndices ){ */ int ConvertBSPToOBJ( char *bspName ){ - int i, modelNum; + int modelNum; FILE *f, *fmtl; bspShader_t *shader; bspModel_t *model; @@ -348,7 +348,7 @@ int ConvertBSPToOBJ( char *bspName ){ } else { - for ( i = 0; i < numBSPShaders; i++ ) + for ( int i = 0; i < numBSPShaders; i++ ) { shader = &bspShaders[ i ]; ConvertShaderToMTL( fmtl, shader, i ); @@ -356,7 +356,7 @@ int ConvertBSPToOBJ( char *bspName ){ } /* walk entity list */ - for ( i = 0; i < numEntities; i++ ) + for ( std::size_t i = 0; i < entities.size(); ++i ) { /* get entity and model */ e = &entities[ i ]; @@ -382,7 +382,7 @@ int ConvertBSPToOBJ( char *bspName ){ } if ( lightmapsAsTexcoord ) { - for ( i = firstLightmap; i <= lastLightmap; i++ ) + for ( int i = firstLightmap; i <= lastLightmap; i++ ) ConvertLightmapToMTL( fmtl, base, i ); } diff --git a/tools/quake3/q3map2/decals.cpp b/tools/quake3/q3map2/decals.cpp index bd6e526e..3b6323b1 100644 --- a/tools/quake3/q3map2/decals.cpp +++ b/tools/quake3/q3map2/decals.cpp @@ -405,11 +405,11 @@ static int MakeDecalProjector( shaderInfo_t *si, vec4_t projection, float distan #define PLANAR_EPSILON 0.5f void ProcessDecals( void ){ - int i, j, x, y, pw[ 5 ], r, iterations; + int j, x, y, pw[ 5 ], r, iterations; float distance; vec4_t projection, plane; vec3_t origin, target, delta; - entity_t *e, *e2; + entity_t *e2; parseMesh_t *p; mesh_t *mesh, *subdivided; bspDrawVert_t *dv[ 4 ]; @@ -419,23 +419,21 @@ void ProcessDecals( void ){ Sys_FPrintf( SYS_VRB, "--- ProcessDecals ---\n" ); /* walk entity list */ - for ( i = 0; i < numEntities; i++ ) + for ( auto& e : entities ) { - /* get entity */ - e = &entities[ i ]; - if ( !ent_class_is( e, "_decal" ) ) { + if ( !ent_class_is( &e, "_decal" ) ) { continue; } /* any patches? */ - if ( e->patches == NULL ) { + if ( e.patches == NULL ) { Sys_Warning( "Decal entity without any patch meshes, ignoring.\n" ); - e->epairs = NULL; /* fixme: leak! */ + e.epairs = NULL; /* fixme: leak! */ continue; } /* find target */ - e2 = FindTargetEntity( ValueForKey( e, "target" ) ); + e2 = FindTargetEntity( ValueForKey( &e, "target" ) ); /* no target? */ if ( e2 == NULL ) { @@ -444,15 +442,15 @@ void ProcessDecals( void ){ } /* walk entity patches */ - for ( p = e->patches; p != NULL; p = e->patches ) + for ( p = e.patches; p != NULL; p = e.patches ) { /* setup projector */ - if ( VectorCompare( e->origin, vec3_origin ) ) { + if ( VectorCompare( e.origin, vec3_origin ) ) { VectorAdd( p->eMins, p->eMaxs, origin ); VectorScale( origin, 0.5f, origin ); } else{ - VectorCopy( e->origin, origin ); + VectorCopy( e.origin, origin ); } VectorCopy( e2->origin, target ); @@ -475,7 +473,7 @@ void ProcessDecals( void ){ /* offset by projector origin */ for ( j = 0; j < ( mesh->width * mesh->height ); j++ ) - VectorAdd( mesh->verts[ j ].xyz, e->origin, mesh->verts[ j ].xyz ); + VectorAdd( mesh->verts[ j ].xyz, e.origin, mesh->verts[ j ].xyz ); /* iterate through the mesh quads */ for ( y = 0; y < ( mesh->height - 1 ); y++ ) @@ -523,7 +521,7 @@ void ProcessDecals( void ){ } /* remove patch from entity (fixme: leak!) */ - e->patches = p->next; + e.patches = p->next; /* push patch to worldspawn (enable this to debug projectors) */ #if 0 diff --git a/tools/quake3/q3map2/fog.cpp b/tools/quake3/q3map2/fog.cpp index e5fbff28..56639162 100644 --- a/tools/quake3/q3map2/fog.cpp +++ b/tools/quake3/q3map2/fog.cpp @@ -712,8 +712,7 @@ int FogForBounds( vec3_t mins, vec3_t maxs, float epsilon ){ */ void CreateMapFogs( void ){ - int i, j; - entity_t *entity; + int j; brush_t *brush; fog_t *fog; vec3_t invFogDir; @@ -728,13 +727,10 @@ void CreateMapFogs( void ){ Sys_FPrintf( SYS_VRB, "--- CreateMapFogs ---\n" ); /* walk entities */ - for ( i = 0; i < numEntities; i++ ) + for ( const auto& e : entities ) { - /* get entity */ - entity = &entities[ i ]; - /* walk entity brushes */ - for ( brush = entity->brushes; brush != NULL; brush = brush->next ) + for ( brush = e.brushes; brush != NULL; brush = brush->next ) { /* ignore non-fog brushes */ if ( !brush->contentShader->fogParms ) { diff --git a/tools/quake3/q3map2/light.cpp b/tools/quake3/q3map2/light.cpp index 315dfed3..68dd9e57 100644 --- a/tools/quake3/q3map2/light.cpp +++ b/tools/quake3/q3map2/light.cpp @@ -215,13 +215,13 @@ static void CreateSkyLights( vec3_t color, float value, int iterations, float fi */ void CreateEntityLights( void ){ - int i, j; + int j; light_t *light, *light2; - entity_t *e, *e2; + const entity_t *e, *e2; /* go throught entity list and find lights */ - for ( i = 0; i < numEntities; i++ ) + for ( std::size_t i = 0; i < entities.size(); ++i ) { /* get entity */ e = &entities[ i ]; @@ -337,7 +337,7 @@ void CreateEntityLights( void ){ GetVectorForKey( e, "origin", light->origin ); ENT_READKV( &light->style, e, "_style", "style" ); 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 %zu", light->style, i ); } /* set light intensity */ @@ -604,8 +604,7 @@ void CreateSurfaceLights( void ){ */ void SetEntityOrigins( void ){ - int i, j, k, f; - entity_t *e; + int j, k, f; const char *key; int modelnum; bspModel_t *dm; @@ -617,11 +616,10 @@ void SetEntityOrigins( void ){ memcpy( yDrawVerts, bspDrawVerts, numBSPDrawVerts * sizeof( bspDrawVert_t ) ); /* set the entity origins */ - for ( i = 0; i < numEntities; i++ ) + for ( const auto& e : entities ) { /* get entity and model */ - e = &entities[ i ]; - key = ValueForKey( e, "model" ); + key = ValueForKey( &e, "model" ); if ( key[ 0 ] != '*' ) { continue; } @@ -630,7 +628,7 @@ void SetEntityOrigins( void ){ /* get entity origin */ vec3_t origin = { 0.f, 0.f, 0.f }; - if ( !ENT_READKV( &origin, e, "origin" ) ) { + if ( !ENT_READKV( &origin, &e, "origin" ) ) { continue; } diff --git a/tools/quake3/q3map2/light_trace.cpp b/tools/quake3/q3map2/light_trace.cpp index de18d976..072ce158 100644 --- a/tools/quake3/q3map2/light_trace.cpp +++ b/tools/quake3/q3map2/light_trace.cpp @@ -1109,7 +1109,7 @@ static void PopulateWithPicoModel( int castShadows, picoModel_t *model, m4x4_t t */ static void PopulateTraceNodes( void ){ - int i, m; + int m; const char *value; picoModel_t *model; @@ -1120,7 +1120,7 @@ static void PopulateTraceNodes( void ){ PopulateWithBSPModel( &bspModels[ 0 ], transform ); /* walk each entity list */ - for ( i = 1; i < numEntities; i++ ) + for ( std::size_t i = 1; i < entities.size(); ++i ) { /* get entity */ entity_t *e = &entities[ i ]; diff --git a/tools/quake3/q3map2/map.cpp b/tools/quake3/q3map2/map.cpp index ca1448e2..85285a23 100644 --- a/tools/quake3/q3map2/map.cpp +++ b/tools/quake3/q3map2/map.cpp @@ -878,7 +878,7 @@ brush_t *FinishBrush( bool noCollapseGroups ){ Sys_Printf( "Entity %i (%s), Brush %i: origin brush detected\n", mapEnt->mapEntityNum, ent_classname( mapEnt ), entitySourceBrushes ); - if ( numEntities == 1 ) { + if ( entities.size() == 1 ) { Sys_FPrintf( SYS_WRN, "Entity %i, Brush %i: origin brushes not allowed in world\n", mapEnt->mapEntityNum, entitySourceBrushes ); return NULL; @@ -887,7 +887,7 @@ brush_t *FinishBrush( bool noCollapseGroups ){ VectorAdd( buildBrush->mins, buildBrush->maxs, origin ); VectorScale( origin, 0.5, origin ); - MergeOrigin( &entities[ numEntities - 1 ], origin ); + MergeOrigin( &entities.back(), origin ); /* don't keep this brush */ return NULL; @@ -895,8 +895,8 @@ brush_t *FinishBrush( bool noCollapseGroups ){ /* determine if the brush is an area portal */ if ( buildBrush->compileFlags & C_AREAPORTAL ) { - if ( numEntities != 1 ) { - Sys_FPrintf( SYS_WRN, "Entity %i (%s), Brush %i: areaportals only allowed in world\n", numEntities - 1, ent_classname( mapEnt ), entitySourceBrushes ); + if ( entities.size() != 1 ) { + Sys_FPrintf( SYS_WRN, "Entity %zu (%s), Brush %i: areaportals only allowed in world\n", entities.size() - 1, ent_classname( mapEnt ), entitySourceBrushes ); return NULL; } } @@ -1677,18 +1677,14 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ if ( !strEqual( token, "{" ) ) { Sys_Warning( "ParseEntity: { not found, found %s on line %d - last entity was at: <%4.2f, %4.2f, %4.2f>...\n" "Continuing to process map, but resulting BSP may be invalid.\n", - token, scriptline, entities[ numEntities ].origin[ 0 ], entities[ numEntities ].origin[ 1 ], entities[ numEntities ].origin[ 2 ] ); + token, scriptline, entities.back().origin[ 0 ], entities.back().origin[ 1 ], entities.back().origin[ 2 ] ); return false; } - /* range check */ - AUTOEXPAND_BY_REALLOC( entities, numEntities, allocatedEntities, 32 ); - /* setup */ entitySourceBrushes = 0; - mapEnt = &entities[ numEntities ]; - numEntities++; - memset( mapEnt, 0, sizeof( *mapEnt ) ); + entities.emplace_back(); + mapEnt = &entities.back(); /* ydnar: true entity numbering */ mapEnt->mapEntityNum = numMapEntities; @@ -1756,7 +1752,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ /* ydnar: only lights? */ if ( onlyLights && !striEqualPrefix( classname, "light" ) ) { - numEntities--; + entities.pop_back(); return true; } @@ -1849,14 +1845,14 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){ /* group_info entities are just for editor grouping (fixme: leak!) */ if ( !noCollapseGroups && striEqual( "group_info", classname ) ) { - numEntities--; + entities.pop_back(); return true; } /* group entities are just for editor convenience, toss all brushes into worldspawn */ if ( !noCollapseGroups && funcGroup ) { MoveBrushesToWorld( mapEnt ); - numEntities--; + entities.pop_back(); return true; } @@ -1890,10 +1886,10 @@ void LoadMapFile( char *filename, bool onlyLights, bool noCollapseGroups ){ /* setup */ if ( onlyLights ) { - oldNumEntities = numEntities; + oldNumEntities = entities.size(); } else{ - numEntities = 0; + entities.clear(); } /* initial setup */ @@ -1910,7 +1906,7 @@ void LoadMapFile( char *filename, bool onlyLights, bool noCollapseGroups ){ /* light loading */ if ( onlyLights ) { /* emit some statistics */ - Sys_FPrintf( SYS_VRB, "%9d light entities\n", numEntities - oldNumEntities ); + Sys_FPrintf( SYS_VRB, "%9zu light entities\n", entities.size() - oldNumEntities ); } else { @@ -1934,7 +1930,7 @@ void LoadMapFile( char *filename, bool onlyLights, bool noCollapseGroups ){ Sys_FPrintf( SYS_VRB, "%9d patches\n", numMapPatches ); Sys_FPrintf( SYS_VRB, "%9d boxbevels\n", c_boxbevels ); Sys_FPrintf( SYS_VRB, "%9d edgebevels\n", c_edgebevels ); - Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities ); + Sys_FPrintf( SYS_VRB, "%9zu entities\n", entities.size() ); Sys_FPrintf( SYS_VRB, "%9d planes\n", nummapplanes ); Sys_Printf( "%9d areaportals\n", c_areaportals ); Sys_Printf( "Size: %5.0f, %5.0f, %5.0f to %5.0f, %5.0f, %5.0f\n", diff --git a/tools/quake3/q3map2/model.cpp b/tools/quake3/q3map2/model.cpp index 1a394b91..fdf16305 100644 --- a/tools/quake3/q3map2/model.cpp +++ b/tools/quake3/q3map2/model.cpp @@ -1348,7 +1348,7 @@ void AddTriangleModels( entity_t *eparent ){ /* get current brush entity targetname */ const char *targetName; - if ( eparent == entities ) { + if ( eparent == &entities[0] ) { targetName = ""; } else{ /* misc_model entities target non-worldspawn brush model entities */ @@ -1358,10 +1358,10 @@ void AddTriangleModels( entity_t *eparent ){ } /* walk the entity list */ - for ( int num = 1; num < numEntities; num++ ) + for ( std::size_t i = 1; i < entities.size(); ++i ) { /* get entity */ - entity_t *e = &entities[ num ]; + entity_t *e = &entities[ i ]; /* convert misc_models into raw geometry */ if ( !ent_class_is( e, "misc_model" ) ) { @@ -1384,7 +1384,7 @@ void AddTriangleModels( entity_t *eparent ){ const int frame = IntForKey( e, "_frame", "frame" ); int castShadows, recvShadows; - if ( eparent == entities ) { /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */ + if ( eparent == &entities[0] ) { /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */ castShadows = WORLDSPAWN_CAST_SHADOWS; recvShadows = WORLDSPAWN_RECV_SHADOWS; } diff --git a/tools/quake3/q3map2/portals.cpp b/tools/quake3/q3map2/portals.cpp index 25d30221..5e6a2754 100644 --- a/tools/quake3/q3map2/portals.cpp +++ b/tools/quake3/q3map2/portals.cpp @@ -658,7 +658,7 @@ int FloodEntities( tree_t *tree ){ tripped = NULL; c_floodedleafs = 0; - for ( int i = 1; i < numEntities; i++ ) + for ( std::size_t i = 1; i < entities.size(); ++i ) { /* get entity */ e = &entities[ i ]; diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index bc434b02..2a54950a 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -2483,10 +2483,8 @@ Q_EXTERN vec3_t gridSize ------------------------------------------------------------------------------- */ -Q_EXTERN int numEntities Q_ASSIGN( 0 ); -Q_EXTERN int numBSPEntities Q_ASSIGN( 0 ); -Q_EXTERN int allocatedEntities Q_ASSIGN( 0 ); -Q_EXTERN entity_t* entities Q_ASSIGN( NULL ); +Q_EXTERN std::size_t numBSPEntities Q_ASSIGN( 0 ); +Q_EXTERN std::vector entities; Q_EXTERN int numBSPModels Q_ASSIGN( 0 ); Q_EXTERN int allocatedBSPModels Q_ASSIGN( 0 ); diff --git a/tools/quake3/q3map2/surface.cpp b/tools/quake3/q3map2/surface.cpp index cfc3b204..2168ddfc 100644 --- a/tools/quake3/q3map2/surface.cpp +++ b/tools/quake3/q3map2/surface.cpp @@ -3606,7 +3606,7 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree ){ BiasSurfaceTextures( ds ); /* ydnar: globalizing of fog volume handling (eek a hack) */ - if ( e != entities && !si->noFog ) { + if ( e != &entities[0] && !si->noFog ) { /* find surface origin and offset by entity origin */ VectorAdd( ds->mins, ds->maxs, origin ); VectorScale( origin, 0.5f, origin ); diff --git a/tools/quake3/q3map2/writebsp.cpp b/tools/quake3/q3map2/writebsp.cpp index 9fbd42d1..66cc1d69 100644 --- a/tools/quake3/q3map2/writebsp.cpp +++ b/tools/quake3/q3map2/writebsp.cpp @@ -259,12 +259,11 @@ int EmitDrawNode_r( node_t *node ){ ============ */ void SetModelNumbers( void ){ - int i; int models; char value[16]; models = 1; - for ( i = 1 ; i < numEntities ; i++ ) { + for ( std::size_t i = 1; i < entities.size(); ++i ) { if ( entities[i].brushes || entities[i].patches ) { sprintf( value, "*%i", models ); models++; @@ -283,7 +282,7 @@ void SetModelNumbers( void ){ */ void SetLightStyles( void ){ - int i, j, numStyles; + int j, numStyles; entity_t *e; epair_t *ep, *next; char value[ 10 ]; @@ -300,7 +299,7 @@ void SetLightStyles( void ){ /* any light that is controlled (has a targetname) must have a unique style number generated for it */ numStyles = 0; - for ( i = 1; i < numEntities; i++ ) + for ( std::size_t i = 1; i < entities.size(); ++i ) { e = &entities[ i ]; @@ -331,7 +330,7 @@ void SetLightStyles( void ){ /* get existing style */ const int style = IntForKey( e, "style" ); if ( style < LS_NORMAL || style > LS_NONE ) { - Error( "Invalid lightstyle (%d) on entity %d", style, i ); + Error( "Invalid lightstyle (%d) on entity %zu", style, i ); } /* find this targetname */ @@ -410,7 +409,7 @@ void EndBSPFile( bool do_write ){ EmitPlanes(); - numBSPEntities = numEntities; + numBSPEntities = entities.size(); UnparseEntities(); if ( do_write ) {