turn entities array to std::vector<entity_t>

This commit is contained in:
Garux 2021-01-23 15:39:42 +03:00
parent b949f70077
commit 36b63e1d2c
18 changed files with 165 additions and 187 deletions

View File

@ -50,7 +50,7 @@
void_ptr safe_malloc( size_t size ){ void_ptr safe_malloc( size_t size ){
void *p = malloc( size ); void *p = malloc( size );
if ( !p ) { 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; 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_ptr safe_malloc_info( size_t size, const char* info ){
void *p = malloc( size ); void *p = malloc( size );
if ( !p ) { 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; 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_ptr safe_calloc( size_t size ){
void *p = calloc( 1, size ); void *p = calloc( 1, size );
if ( !p ) { 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; 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_ptr safe_calloc_info( size_t size, const char* info ){
void *p = calloc( 1, size ); void *p = calloc( 1, size );
if ( !p ) { 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; return p;
} }

View File

@ -317,27 +317,27 @@ int pk3BSPMain( int argc, char **argv ){
res2list( pk3Sounds, str ); 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 ); FixDOSName( str );
DefaultExtension( str, ".wav" ); DefaultExtension( str, ".wav" );
res2list( pk3Sounds, str ); 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_strt.wav" );
res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" );
} }
if ( ent_class_is( &entities[i], "target_push" ) ){ if ( ent_class_is( &e, "target_push" ) ){
if ( !( IntForKey( &entities[i], "spawnflags") & 1 ) ){ if ( !( IntForKey( &e, "spawnflags") & 1 ) ){
res2list( pk3Sounds, "sound/misc/windfly.wav" ); 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 ); 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 ); 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 ); FixDOSName( str );
DefaultExtension( str, ".wav" ); DefaultExtension( str, ".wav" );
res2list( pk3Sounds, str ); 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_strt.wav" );
res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" ); res2list( pk3Sounds, "sound/movers/plats/pt1_end.wav" );
} }
if ( ent_class_is( &entities[i], "target_push" ) ){ if ( ent_class_is( &e, "target_push" ) ){
if ( !( IntForKey( &entities[i], "spawnflags") & 1 ) ){ if ( !( IntForKey( &e, "spawnflags") & 1 ) ){
res2list( pk3Sounds, "sound/misc/windfly.wav" ); 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 ); 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; //numBSPBrushes = 0;
//allocatedBSPBrushes = 0; //allocatedBSPBrushes = 0;
} }
*/ if ( entities != 0 ) { */ {
for ( i = 0; i < numBSPEntities && i < numEntities; ++i ){ for ( const auto& e : entities ){
ep = entities[i].epairs; ep = e.epairs;
while( ep != NULL){ while( ep != NULL){
epair_t *ep2free = ep; epair_t *ep2free = ep;
ep = ep->next; ep = ep->next;
free( ep2free ); free( ep2free );
} }
} }
free( entities ); entities.clear();
entities = NULL;
//Sys_Printf( "freed entities\n" ); //Sys_Printf( "freed entities\n" );
numEntities = 0;
numBSPEntities = 0; numBSPEntities = 0;
allocatedEntities = 0;
} }
/* if ( bspModels != 0 ) { /* if ( bspModels != 0 ) {
free( bspModels ); free( bspModels );

View File

@ -100,7 +100,6 @@ static void autocaulk_write(){
*/ */
static void ProcessAdvertisements( void ) { static void ProcessAdvertisements( void ) {
int i;
const char* modelKey; const char* modelKey;
int modelNum; int modelNum;
bspModel_t* adModel; bspModel_t* adModel;
@ -108,19 +107,19 @@ static void ProcessAdvertisements( void ) {
Sys_FPrintf( SYS_VRB, "--- ProcessAdvertisements ---\n" ); Sys_FPrintf( SYS_VRB, "--- ProcessAdvertisements ---\n" );
for ( i = 0; i < numEntities; i++ ) { for ( const auto& e : entities ) {
/* is an advertisement? */ /* 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 ) { if ( strlen( modelKey ) > MAX_QPATH - 1 ) {
Error( "Model Key for entity exceeds ad struct string length." ); Error( "Model Key for entity exceeds ad struct string length." );
} }
else { else {
if ( numBSPAds < MAX_MAP_ADVERTISEMENTS ) { 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 ) ); strncpy( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) );
modelKey++; modelKey++;
@ -171,7 +170,6 @@ static void ProcessAdvertisements( void ) {
*/ */
static void SetCloneModelNumbers( void ){ static void SetCloneModelNumbers( void ){
int i, j;
int models; int models;
char modelValue[ 16 ]; char modelValue[ 16 ];
const char *value, *value2, *value3; const char *value, *value2, *value3;
@ -179,7 +177,7 @@ static void SetCloneModelNumbers( void ){
/* start with 1 (worldspawn is model 0) */ /* start with 1 (worldspawn is model 0) */
models = 1; 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 */ /* only entities with brushes or patches get a model number */
if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) { if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) {
@ -199,7 +197,7 @@ static void SetCloneModelNumbers( void ){
} }
/* fix up clones */ /* 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 */ /* only entities with brushes or patches get a model number */
if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) { if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) {
@ -211,7 +209,7 @@ static void SetCloneModelNumbers( void ){
continue; continue;
/* find an entity with matching clone name */ /* 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? */ /* is this a clone parent? */
if ( !ENT_READKV( &value2, &entities[ j ], "_clonename" ) ) { if ( !ENT_READKV( &value2, &entities[ j ], "_clonename" ) ) {
@ -453,45 +451,46 @@ void ProcessWorldModel( void ){
} }
/* ydnar: bug 645: do flares for lights */ /* ydnar: bug 645: do flares for lights */
for ( int i = 0; i < numEntities && emitFlares; i++ ) if( emitFlares ){
{ for ( const auto& light : entities )
entity_t *light, *target; {
vec3_t origin, targetOrigin, normal, color; entity_t *target;
vec3_t origin, targetOrigin, normal, color;
/* get light */ /* get light */
light = &entities[ i ]; if ( ent_class_is( &light, "light" ) ) {
if ( ent_class_is( light, "light" ) ) { /* get flare shader */
/* get flare shader */ const char *flareShader = NULL;
const char *flareShader = NULL; if ( ENT_READKV( &flareShader, &light, "_flareshader" ) || BoolForKey( &light, "_flare" ) ) {
if ( ENT_READKV( &flareShader, light, "_flareshader" ) || BoolForKey( light, "_flare" ) ) { /* get specifics */
/* get specifics */ GetVectorForKey( &light, "origin", origin );
GetVectorForKey( light, "origin", origin ); GetVectorForKey( &light, "_color", color );
GetVectorForKey( light, "_color", color ); const int lightStyle = IntForKey( &light, "_style", "style" );
const int lightStyle = IntForKey( light, "_style", "style" );
/* handle directional spotlights */ /* handle directional spotlights */
if ( ENT_READKV( &value, light, "target" ) ) { if ( ENT_READKV( &value, &light, "target" ) ) {
/* get target light */ /* get target light */
target = FindTargetEntity( value ); target = FindTargetEntity( value );
if ( target != NULL ) { if ( target != NULL ) {
GetVectorForKey( target, "origin", targetOrigin ); GetVectorForKey( target, "origin", targetOrigin );
VectorSubtract( targetOrigin, origin, normal ); VectorSubtract( targetOrigin, origin, normal );
VectorNormalize( normal, normal ); VectorNormalize( normal, normal );
}
}
else{
//% VectorClear( normal );
VectorSet( normal, 0, 0, -1 );
} }
}
else{
//% VectorClear( normal );
VectorSet( normal, 0, 0, -1 );
}
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] );
color[2] = Image_LinearFloatFromsRGBFloat( color[2] ); color[2] = Image_LinearFloatFromsRGBFloat( color[2] );
} }
/* create the flare surface (note shader defaults automatically) */ /* create the flare surface (note shader defaults automatically) */
DrawSurfaceForFlare( mapEntityNum, origin, normal, color, flareShader, lightStyle ); DrawSurfaceForFlare( mapEntityNum, origin, normal, color, flareShader, lightStyle );
}
} }
} }
} }
@ -613,17 +612,17 @@ void ProcessModels( void ){
CreateMapFogs(); CreateMapFogs();
/* walk entity list */ /* walk entity list */
for ( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ ) for ( std::size_t i = 0; i < entities.size(); ++i )
{ {
/* get entity */ /* get entity */
entity = &entities[ mapEntityNum ]; entity = &entities[ i ];
if ( entity->brushes == NULL && entity->patches == NULL ) { if ( entity->brushes == NULL && entity->patches == NULL ) {
continue; continue;
} }
/* process the model */ /* process the model */
Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels ); Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
if ( mapEntityNum == 0 ) { if ( i == 0 ) {
ProcessWorldModel(); ProcessWorldModel();
} }
else{ else{
@ -669,7 +668,7 @@ void OnlyEnts( void ){
strcpyQ( save_version, ValueForKey( &entities[0], "_q3map2_version" ), sizeof( save_version ) ); strcpyQ( save_version, ValueForKey( &entities[0], "_q3map2_version" ), sizeof( save_version ) );
strcpyQ( save_gridsize, ValueForKey( &entities[0], "gridsize" ), sizeof( save_gridsize ) ); strcpyQ( save_gridsize, ValueForKey( &entities[0], "gridsize" ), sizeof( save_gridsize ) );
numEntities = 0; entities.clear();
LoadShaderInfo(); LoadShaderInfo();
LoadMapFile( name, false, false ); LoadMapFile( name, false, false );
@ -686,7 +685,7 @@ void OnlyEnts( void ){
SetKeyValue( &entities[0], "gridsize", save_gridsize ); SetKeyValue( &entities[0], "gridsize", save_gridsize );
} }
numBSPEntities = numEntities; numBSPEntities = entities.size();
UnparseEntities(); UnparseEntities();
WriteBSPFile( out ); WriteBSPFile( out );

View File

@ -436,7 +436,7 @@ void WriteBSPFile( const char *filename ){
void PrintBSPFileSizes( void ){ void PrintBSPFileSizes( void ){
/* parse entities first */ /* parse entities first */
if ( numEntities <= 0 ) { if ( entities.empty() ) {
ParseEntities(); ParseEntities();
} }
int patchCount = 0; int patchCount = 0;
@ -461,8 +461,8 @@ void PrintBSPFileSizes( void ){
numBSPFogs, (int) ( numBSPFogs * sizeof( bspFog_t ) ) ); numBSPFogs, (int) ( numBSPFogs * sizeof( bspFog_t ) ) );
Sys_Printf( "%9d planes %9d\n", Sys_Printf( "%9d planes %9d\n",
numBSPPlanes, (int) ( numBSPPlanes * sizeof( bspPlane_t ) ) ); numBSPPlanes, (int) ( numBSPPlanes * sizeof( bspPlane_t ) ) );
Sys_Printf( "%9d entdata %9d\n", Sys_Printf( "%9zu entdata %9d\n",
numEntities, bspEntDataSize ); entities.size(), bspEntDataSize );
Sys_Printf( "\n" ); Sys_Printf( "\n" );
Sys_Printf( "%9d nodes %9d\n", Sys_Printf( "%9d nodes %9d\n",
@ -567,12 +567,10 @@ bool ParseEntity( void ){
if ( !strEqual( token, "{" ) ) { if ( !strEqual( token, "{" ) ) {
Error( "ParseEntity: { not found" ); Error( "ParseEntity: { not found" );
} }
AUTOEXPAND_BY_REALLOC( entities, numEntities, allocatedEntities, 32 );
/* create new entity */ /* create new entity */
mapEnt = &entities[ numEntities ]; entities.emplace_back();
numEntities++; mapEnt = &entities.back();
memset( mapEnt, 0, sizeof( *mapEnt ) );
/* parse */ /* parse */
while ( 1 ) while ( 1 )
@ -600,12 +598,12 @@ bool ParseEntity( void ){
*/ */
void ParseEntities( void ){ void ParseEntities( void ){
numEntities = 0; entities.clear();
ParseFromMemory( bspEntData, bspEntDataSize ); ParseFromMemory( bspEntData, bspEntDataSize );
while ( ParseEntity() ) ; while ( ParseEntity() ) ;
/* ydnar: set number of bsp entities in case a map is loaded on top */ /* 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; end = buf = bspEntData;
/* run through entity list */ /* 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; 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 ){ entity_t *FindTargetEntity( const char *target ){
/* walk entity list */ /* walk entity list */
for ( int i = 0; i < numEntities; i++ ) for ( auto& e : entities )
{ {
if ( strEqual( ValueForKey( &entities[ i ], "targetname" ), target ) ) { if ( strEqual( ValueForKey( &e, "targetname" ), target ) ) {
return &entities[ i ]; return &e;
} }
} }

View File

@ -337,7 +337,7 @@ static void ConvertLightmap( FILE *f, const char *base, int lightmapNum ){
*/ */
int ConvertBSPToASE( char *bspName ){ int ConvertBSPToASE( char *bspName ){
int i, modelNum; int modelNum;
FILE *f; FILE *f;
bspShader_t *shader; bspShader_t *shader;
bspModel_t *model; bspModel_t *model;
@ -382,14 +382,14 @@ int ConvertBSPToASE( char *bspName ){
if ( lightmapsAsTexcoord ) { if ( lightmapsAsTexcoord ) {
numLightmapsASE = Convert_CountLightmaps( dirname ); numLightmapsASE = Convert_CountLightmaps( dirname );
fprintf( f, "\t*MATERIAL_COUNT\t%d\r\n", numLightmapsASE ); 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 ); ConvertLightmap( f, base, i );
Convert_ReferenceLightmaps( base, lmIndices ); Convert_ReferenceLightmaps( base, lmIndices );
} }
else else
{ {
fprintf( f, "\t*MATERIAL_COUNT\t%d\r\n", numBSPShaders ); 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 ]; shader = &bspShaders[ i ];
ConvertShader( f, shader, i ); ConvertShader( f, shader, i );
@ -398,7 +398,7 @@ int ConvertBSPToASE( char *bspName ){
fprintf( f, "}\r\n" ); fprintf( f, "}\r\n" );
/* walk entity list */ /* walk entity list */
for ( i = 0; i < numEntities; i++ ) for ( std::size_t i = 0; i < entities.size(); ++i )
{ {
/* get entity and model */ /* get entity and model */
e = &entities[ i ]; e = &entities[ i ];

View File

@ -461,13 +461,13 @@ int ScaleBSPMain( int argc, char **argv ){
/* note it */ /* note it */
Sys_Printf( "--- ScaleBSP ---\n" ); Sys_Printf( "--- ScaleBSP ---\n" );
Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities ); Sys_FPrintf( SYS_VRB, "%9zu entities\n", entities.size() );
/* scale entity keys */ /* scale entity keys */
for ( i = 0; i < numBSPEntities && i < numEntities; i++ ) for ( auto& e : entities )
{ {
/* scale origin */ /* scale origin */
if ( ENT_READKV( &vec, &entities[ i ], "origin" ) ) { if ( ENT_READKV( &vec, &e, "origin" ) ) {
if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { if ( ent_class_prefixed( &entities[i], "info_player_" ) ) {
vec[2] += spawn_ref; vec[2] += spawn_ref;
} }
@ -478,10 +478,10 @@ int ScaleBSPMain( int argc, char **argv ){
vec[2] -= spawn_ref; vec[2] -= spawn_ref;
} }
sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); 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 if ( a == -1 || a == -2 ) { // z scale
axis = 2; axis = 2;
} }
@ -493,17 +493,17 @@ int ScaleBSPMain( int argc, char **argv ){
} }
/* scale door lip */ /* scale door lip */
if ( ENT_READKV( &f, &entities[ i ], "lip" ) ) { if ( ENT_READKV( &f, &e, "lip" ) ) {
f *= scale[axis]; f *= scale[axis];
sprintf( str, "%f", f ); sprintf( str, "%f", f );
SetKeyValue( &entities[ i ], "lip", str ); SetKeyValue( &e, "lip", str );
} }
/* scale plat height */ /* scale plat height */
if ( ENT_READKV( &f, &entities[ i ], "height" ) ) { if ( ENT_READKV( &f, &e, "height" ) ) {
f *= scale[2]; f *= scale[2];
sprintf( str, "%f", f ); 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? // 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 */ /* note it */
Sys_Printf( "--- ShiftBSP ---\n" ); Sys_Printf( "--- ShiftBSP ---\n" );
Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities ); Sys_FPrintf( SYS_VRB, "%9zu entities\n", entities.size() );
/* shift entity keys */ /* shift entity keys */
for ( i = 0; i < numBSPEntities && i < numEntities; i++ ) for ( auto& e : entities )
{ {
/* shift origin */ /* shift origin */
if ( ENT_READKV( &vec, &entities[ i ], "origin" ) ) { if ( ENT_READKV( &vec, &e, "origin" ) ) {
if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { if ( ent_class_prefixed( &e, "info_player_" ) ) {
vec[2] += spawn_ref; vec[2] += spawn_ref;
} }
vec[0] += scale[0]; vec[0] += scale[0];
vec[1] += scale[1]; vec[1] += scale[1];
vec[2] += scale[2]; vec[2] += scale[2];
if ( ent_class_prefixed( &entities[i], "info_player_" ) ) { if ( ent_class_prefixed( &e, "info_player_" ) ) {
vec[2] -= spawn_ref; vec[2] -= spawn_ref;
} }
sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] ); 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; node_t *node;
brush_t *brush; brush_t *brush;
side_t *side; side_t *side;
int i;
SetDrawSurfacesBuffer(); SetDrawSurfacesBuffer();
mapDrawSurfs = safe_calloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS ); mapDrawSurfs = safe_calloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
@ -829,15 +828,15 @@ void PseudoCompileBSP( bool need_tree ){
BeginBSPFile(); BeginBSPFile();
models = 1; models = 1;
for ( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ ) for ( std::size_t i = 0; i < entities.size(); ++i )
{ {
/* get entity */ /* get entity */
entity = &entities[ mapEntityNum ]; entity = &entities[ i ];
if ( entity->brushes == NULL && entity->patches == NULL ) { if ( entity->brushes == NULL && entity->patches == NULL ) {
continue; continue;
} }
if ( mapEntityNum != 0 ) { if ( i != 0 ) {
sprintf( modelValue, "*%d", models++ ); sprintf( modelValue, "*%d", models++ );
SetKeyValue( entity, "model", modelValue ); SetKeyValue( entity, "model", modelValue );
} }
@ -851,7 +850,7 @@ void PseudoCompileBSP( bool need_tree ){
ClearMetaTriangles(); ClearMetaTriangles();
PatchMapDrawSurfs( entity ); PatchMapDrawSurfs( entity );
if ( mapEntityNum == 0 && need_tree ) { if ( i == 0 && need_tree ) {
faces = MakeStructuralBSPFaceList( entities[0].brushes ); faces = MakeStructuralBSPFaceList( entities[0].brushes );
tree = FaceBSP( faces ); tree = FaceBSP( faces );
node = tree->headnode; node = tree->headnode;
@ -868,10 +867,10 @@ void PseudoCompileBSP( bool need_tree ){
for ( brush = entity->brushes; brush; brush = brush->next ) for ( brush = entity->brushes; brush; brush = brush->next )
{ {
/* walk the brush sides */ /* walk the brush sides */
for ( i = 0; i < brush->numsides; i++ ) for ( int j = 0; j < brush->numsides; j++ )
{ {
/* get side */ /* get side */
side = &brush->sides[ i ]; side = &brush->sides[ j ];
if ( side->winding == NULL ) { if ( side->winding == NULL ) {
continue; continue;
} }

View File

@ -1001,7 +1001,7 @@ static void ConvertEPairs( FILE *f, entity_t *e, bool skip_origin ){
*/ */
int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){
int i, modelNum; int modelNum;
FILE *f; FILE *f;
bspModel_t *model; bspModel_t *model;
entity_t *e; entity_t *e;
@ -1027,13 +1027,13 @@ int ConvertBSPToMap_Ext( char *bspName, bool brushPrimitives ){
fprintf( f, "// Generated by Q3Map2 (ydnar) -convert -format map\n" ); fprintf( f, "// Generated by Q3Map2 (ydnar) -convert -format map\n" );
/* walk entity list */ /* walk entity list */
for ( i = 0; i < numEntities; i++ ) for ( std::size_t i = 0; i < entities.size(); ++i )
{ {
/* get entity */ /* get entity */
e = &entities[ i ]; e = &entities[ i ];
/* start entity */ /* start entity */
fprintf( f, "// entity %d\n", i ); fprintf( f, "// entity %zu\n", i );
fprintf( f, "{\n" ); fprintf( f, "{\n" );
/* get model num */ /* get model num */

View File

@ -301,7 +301,7 @@ void Convert_ReferenceLightmaps( const char* base, int* lmIndices ){
*/ */
int ConvertBSPToOBJ( char *bspName ){ int ConvertBSPToOBJ( char *bspName ){
int i, modelNum; int modelNum;
FILE *f, *fmtl; FILE *f, *fmtl;
bspShader_t *shader; bspShader_t *shader;
bspModel_t *model; bspModel_t *model;
@ -348,7 +348,7 @@ int ConvertBSPToOBJ( char *bspName ){
} }
else else
{ {
for ( i = 0; i < numBSPShaders; i++ ) for ( int i = 0; i < numBSPShaders; i++ )
{ {
shader = &bspShaders[ i ]; shader = &bspShaders[ i ];
ConvertShaderToMTL( fmtl, shader, i ); ConvertShaderToMTL( fmtl, shader, i );
@ -356,7 +356,7 @@ int ConvertBSPToOBJ( char *bspName ){
} }
/* walk entity list */ /* walk entity list */
for ( i = 0; i < numEntities; i++ ) for ( std::size_t i = 0; i < entities.size(); ++i )
{ {
/* get entity and model */ /* get entity and model */
e = &entities[ i ]; e = &entities[ i ];
@ -382,7 +382,7 @@ int ConvertBSPToOBJ( char *bspName ){
} }
if ( lightmapsAsTexcoord ) { if ( lightmapsAsTexcoord ) {
for ( i = firstLightmap; i <= lastLightmap; i++ ) for ( int i = firstLightmap; i <= lastLightmap; i++ )
ConvertLightmapToMTL( fmtl, base, i ); ConvertLightmapToMTL( fmtl, base, i );
} }

View File

@ -405,11 +405,11 @@ static int MakeDecalProjector( shaderInfo_t *si, vec4_t projection, float distan
#define PLANAR_EPSILON 0.5f #define PLANAR_EPSILON 0.5f
void ProcessDecals( void ){ void ProcessDecals( void ){
int i, j, x, y, pw[ 5 ], r, iterations; int j, x, y, pw[ 5 ], r, iterations;
float distance; float distance;
vec4_t projection, plane; vec4_t projection, plane;
vec3_t origin, target, delta; vec3_t origin, target, delta;
entity_t *e, *e2; entity_t *e2;
parseMesh_t *p; parseMesh_t *p;
mesh_t *mesh, *subdivided; mesh_t *mesh, *subdivided;
bspDrawVert_t *dv[ 4 ]; bspDrawVert_t *dv[ 4 ];
@ -419,23 +419,21 @@ void ProcessDecals( void ){
Sys_FPrintf( SYS_VRB, "--- ProcessDecals ---\n" ); Sys_FPrintf( SYS_VRB, "--- ProcessDecals ---\n" );
/* walk entity list */ /* walk entity list */
for ( i = 0; i < numEntities; i++ ) for ( auto& e : entities )
{ {
/* get entity */ if ( !ent_class_is( &e, "_decal" ) ) {
e = &entities[ i ];
if ( !ent_class_is( e, "_decal" ) ) {
continue; continue;
} }
/* any patches? */ /* any patches? */
if ( e->patches == NULL ) { if ( e.patches == NULL ) {
Sys_Warning( "Decal entity without any patch meshes, ignoring.\n" ); Sys_Warning( "Decal entity without any patch meshes, ignoring.\n" );
e->epairs = NULL; /* fixme: leak! */ e.epairs = NULL; /* fixme: leak! */
continue; continue;
} }
/* find target */ /* find target */
e2 = FindTargetEntity( ValueForKey( e, "target" ) ); e2 = FindTargetEntity( ValueForKey( &e, "target" ) );
/* no target? */ /* no target? */
if ( e2 == NULL ) { if ( e2 == NULL ) {
@ -444,15 +442,15 @@ void ProcessDecals( void ){
} }
/* walk entity patches */ /* walk entity patches */
for ( p = e->patches; p != NULL; p = e->patches ) for ( p = e.patches; p != NULL; p = e.patches )
{ {
/* setup projector */ /* setup projector */
if ( VectorCompare( e->origin, vec3_origin ) ) { if ( VectorCompare( e.origin, vec3_origin ) ) {
VectorAdd( p->eMins, p->eMaxs, origin ); VectorAdd( p->eMins, p->eMaxs, origin );
VectorScale( origin, 0.5f, origin ); VectorScale( origin, 0.5f, origin );
} }
else{ else{
VectorCopy( e->origin, origin ); VectorCopy( e.origin, origin );
} }
VectorCopy( e2->origin, target ); VectorCopy( e2->origin, target );
@ -475,7 +473,7 @@ void ProcessDecals( void ){
/* offset by projector origin */ /* offset by projector origin */
for ( j = 0; j < ( mesh->width * mesh->height ); j++ ) 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 */ /* iterate through the mesh quads */
for ( y = 0; y < ( mesh->height - 1 ); y++ ) for ( y = 0; y < ( mesh->height - 1 ); y++ )
@ -523,7 +521,7 @@ void ProcessDecals( void ){
} }
/* remove patch from entity (fixme: leak!) */ /* remove patch from entity (fixme: leak!) */
e->patches = p->next; e.patches = p->next;
/* push patch to worldspawn (enable this to debug projectors) */ /* push patch to worldspawn (enable this to debug projectors) */
#if 0 #if 0

View File

@ -712,8 +712,7 @@ int FogForBounds( vec3_t mins, vec3_t maxs, float epsilon ){
*/ */
void CreateMapFogs( void ){ void CreateMapFogs( void ){
int i, j; int j;
entity_t *entity;
brush_t *brush; brush_t *brush;
fog_t *fog; fog_t *fog;
vec3_t invFogDir; vec3_t invFogDir;
@ -728,13 +727,10 @@ void CreateMapFogs( void ){
Sys_FPrintf( SYS_VRB, "--- CreateMapFogs ---\n" ); Sys_FPrintf( SYS_VRB, "--- CreateMapFogs ---\n" );
/* walk entities */ /* walk entities */
for ( i = 0; i < numEntities; i++ ) for ( const auto& e : entities )
{ {
/* get entity */
entity = &entities[ i ];
/* walk entity brushes */ /* 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 */ /* ignore non-fog brushes */
if ( !brush->contentShader->fogParms ) { if ( !brush->contentShader->fogParms ) {

View File

@ -215,13 +215,13 @@ static void CreateSkyLights( vec3_t color, float value, int iterations, float fi
*/ */
void CreateEntityLights( void ){ void CreateEntityLights( void ){
int i, j; int j;
light_t *light, *light2; light_t *light, *light2;
entity_t *e, *e2; const entity_t *e, *e2;
/* go throught entity list and find lights */ /* 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 */ /* get entity */
e = &entities[ i ]; e = &entities[ i ];
@ -337,7 +337,7 @@ void CreateEntityLights( void ){
GetVectorForKey( e, "origin", light->origin ); GetVectorForKey( e, "origin", light->origin );
ENT_READKV( &light->style, e, "_style", "style" ); ENT_READKV( &light->style, e, "_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 %d", light->style, i ); Error( "Invalid lightstyle (%d) on entity %zu", light->style, i );
} }
/* set light intensity */ /* set light intensity */
@ -604,8 +604,7 @@ void CreateSurfaceLights( void ){
*/ */
void SetEntityOrigins( void ){ void SetEntityOrigins( void ){
int i, j, k, f; int j, k, f;
entity_t *e;
const char *key; const char *key;
int modelnum; int modelnum;
bspModel_t *dm; bspModel_t *dm;
@ -617,11 +616,10 @@ void SetEntityOrigins( void ){
memcpy( yDrawVerts, bspDrawVerts, numBSPDrawVerts * sizeof( bspDrawVert_t ) ); memcpy( yDrawVerts, bspDrawVerts, numBSPDrawVerts * sizeof( bspDrawVert_t ) );
/* set the entity origins */ /* set the entity origins */
for ( i = 0; i < numEntities; i++ ) for ( const auto& e : entities )
{ {
/* get entity and model */ /* get entity and model */
e = &entities[ i ]; key = ValueForKey( &e, "model" );
key = ValueForKey( e, "model" );
if ( key[ 0 ] != '*' ) { if ( key[ 0 ] != '*' ) {
continue; continue;
} }
@ -630,7 +628,7 @@ void SetEntityOrigins( void ){
/* get entity origin */ /* get entity origin */
vec3_t origin = { 0.f, 0.f, 0.f }; vec3_t origin = { 0.f, 0.f, 0.f };
if ( !ENT_READKV( &origin, e, "origin" ) ) { if ( !ENT_READKV( &origin, &e, "origin" ) ) {
continue; continue;
} }

View File

@ -1109,7 +1109,7 @@ static void PopulateWithPicoModel( int castShadows, picoModel_t *model, m4x4_t t
*/ */
static void PopulateTraceNodes( void ){ static void PopulateTraceNodes( void ){
int i, m; int m;
const char *value; const char *value;
picoModel_t *model; picoModel_t *model;
@ -1120,7 +1120,7 @@ static void PopulateTraceNodes( void ){
PopulateWithBSPModel( &bspModels[ 0 ], transform ); PopulateWithBSPModel( &bspModels[ 0 ], transform );
/* walk each entity list */ /* walk each entity list */
for ( i = 1; i < numEntities; i++ ) for ( std::size_t i = 1; i < entities.size(); ++i )
{ {
/* get entity */ /* get entity */
entity_t *e = &entities[ i ]; entity_t *e = &entities[ i ];

View File

@ -878,7 +878,7 @@ brush_t *FinishBrush( bool noCollapseGroups ){
Sys_Printf( "Entity %i (%s), Brush %i: origin brush detected\n", Sys_Printf( "Entity %i (%s), Brush %i: origin brush detected\n",
mapEnt->mapEntityNum, ent_classname( mapEnt ), entitySourceBrushes ); 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", Sys_FPrintf( SYS_WRN, "Entity %i, Brush %i: origin brushes not allowed in world\n",
mapEnt->mapEntityNum, entitySourceBrushes ); mapEnt->mapEntityNum, entitySourceBrushes );
return NULL; return NULL;
@ -887,7 +887,7 @@ brush_t *FinishBrush( bool noCollapseGroups ){
VectorAdd( buildBrush->mins, buildBrush->maxs, origin ); VectorAdd( buildBrush->mins, buildBrush->maxs, origin );
VectorScale( origin, 0.5, origin ); VectorScale( origin, 0.5, origin );
MergeOrigin( &entities[ numEntities - 1 ], origin ); MergeOrigin( &entities.back(), origin );
/* don't keep this brush */ /* don't keep this brush */
return NULL; return NULL;
@ -895,8 +895,8 @@ brush_t *FinishBrush( bool noCollapseGroups ){
/* determine if the brush is an area portal */ /* determine if the brush is an area portal */
if ( buildBrush->compileFlags & C_AREAPORTAL ) { if ( buildBrush->compileFlags & C_AREAPORTAL ) {
if ( numEntities != 1 ) { if ( entities.size() != 1 ) {
Sys_FPrintf( SYS_WRN, "Entity %i (%s), Brush %i: areaportals only allowed in world\n", numEntities - 1, ent_classname( mapEnt ), entitySourceBrushes ); Sys_FPrintf( SYS_WRN, "Entity %zu (%s), Brush %i: areaportals only allowed in world\n", entities.size() - 1, ent_classname( mapEnt ), entitySourceBrushes );
return NULL; return NULL;
} }
} }
@ -1677,18 +1677,14 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
if ( !strEqual( token, "{" ) ) { if ( !strEqual( token, "{" ) ) {
Sys_Warning( "ParseEntity: { not found, found %s on line %d - last entity was at: <%4.2f, %4.2f, %4.2f>...\n" 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", "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; return false;
} }
/* range check */
AUTOEXPAND_BY_REALLOC( entities, numEntities, allocatedEntities, 32 );
/* setup */ /* setup */
entitySourceBrushes = 0; entitySourceBrushes = 0;
mapEnt = &entities[ numEntities ]; entities.emplace_back();
numEntities++; mapEnt = &entities.back();
memset( mapEnt, 0, sizeof( *mapEnt ) );
/* ydnar: true entity numbering */ /* ydnar: true entity numbering */
mapEnt->mapEntityNum = numMapEntities; mapEnt->mapEntityNum = numMapEntities;
@ -1756,7 +1752,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
/* ydnar: only lights? */ /* ydnar: only lights? */
if ( onlyLights && !striEqualPrefix( classname, "light" ) ) { if ( onlyLights && !striEqualPrefix( classname, "light" ) ) {
numEntities--; entities.pop_back();
return true; return true;
} }
@ -1849,14 +1845,14 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
/* group_info entities are just for editor grouping (fixme: leak!) */ /* group_info entities are just for editor grouping (fixme: leak!) */
if ( !noCollapseGroups && striEqual( "group_info", classname ) ) { if ( !noCollapseGroups && striEqual( "group_info", classname ) ) {
numEntities--; entities.pop_back();
return true; return true;
} }
/* group entities are just for editor convenience, toss all brushes into worldspawn */ /* group entities are just for editor convenience, toss all brushes into worldspawn */
if ( !noCollapseGroups && funcGroup ) { if ( !noCollapseGroups && funcGroup ) {
MoveBrushesToWorld( mapEnt ); MoveBrushesToWorld( mapEnt );
numEntities--; entities.pop_back();
return true; return true;
} }
@ -1890,10 +1886,10 @@ void LoadMapFile( char *filename, bool onlyLights, bool noCollapseGroups ){
/* setup */ /* setup */
if ( onlyLights ) { if ( onlyLights ) {
oldNumEntities = numEntities; oldNumEntities = entities.size();
} }
else{ else{
numEntities = 0; entities.clear();
} }
/* initial setup */ /* initial setup */
@ -1910,7 +1906,7 @@ void LoadMapFile( char *filename, bool onlyLights, bool noCollapseGroups ){
/* light loading */ /* light loading */
if ( onlyLights ) { if ( onlyLights ) {
/* emit some statistics */ /* 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 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 patches\n", numMapPatches );
Sys_FPrintf( SYS_VRB, "%9d boxbevels\n", c_boxbevels ); Sys_FPrintf( SYS_VRB, "%9d boxbevels\n", c_boxbevels );
Sys_FPrintf( SYS_VRB, "%9d edgebevels\n", c_edgebevels ); 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_FPrintf( SYS_VRB, "%9d planes\n", nummapplanes );
Sys_Printf( "%9d areaportals\n", c_areaportals ); Sys_Printf( "%9d areaportals\n", c_areaportals );
Sys_Printf( "Size: %5.0f, %5.0f, %5.0f to %5.0f, %5.0f, %5.0f\n", Sys_Printf( "Size: %5.0f, %5.0f, %5.0f to %5.0f, %5.0f, %5.0f\n",

View File

@ -1348,7 +1348,7 @@ void AddTriangleModels( entity_t *eparent ){
/* get current brush entity targetname */ /* get current brush entity targetname */
const char *targetName; const char *targetName;
if ( eparent == entities ) { if ( eparent == &entities[0] ) {
targetName = ""; targetName = "";
} }
else{ /* misc_model entities target non-worldspawn brush model entities */ else{ /* misc_model entities target non-worldspawn brush model entities */
@ -1358,10 +1358,10 @@ void AddTriangleModels( entity_t *eparent ){
} }
/* walk the entity list */ /* walk the entity list */
for ( int num = 1; num < numEntities; num++ ) for ( std::size_t i = 1; i < entities.size(); ++i )
{ {
/* get entity */ /* get entity */
entity_t *e = &entities[ num ]; entity_t *e = &entities[ i ];
/* convert misc_models into raw geometry */ /* convert misc_models into raw geometry */
if ( !ent_class_is( e, "misc_model" ) ) { if ( !ent_class_is( e, "misc_model" ) ) {
@ -1384,7 +1384,7 @@ void AddTriangleModels( entity_t *eparent ){
const int frame = IntForKey( e, "_frame", "frame" ); const int frame = IntForKey( e, "_frame", "frame" );
int castShadows, recvShadows; 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; castShadows = WORLDSPAWN_CAST_SHADOWS;
recvShadows = WORLDSPAWN_RECV_SHADOWS; recvShadows = WORLDSPAWN_RECV_SHADOWS;
} }

View File

@ -658,7 +658,7 @@ int FloodEntities( tree_t *tree ){
tripped = NULL; tripped = NULL;
c_floodedleafs = 0; c_floodedleafs = 0;
for ( int i = 1; i < numEntities; i++ ) for ( std::size_t i = 1; i < entities.size(); ++i )
{ {
/* get entity */ /* get entity */
e = &entities[ i ]; e = &entities[ i ];

View File

@ -2483,10 +2483,8 @@ Q_EXTERN vec3_t gridSize
------------------------------------------------------------------------------- */ ------------------------------------------------------------------------------- */
Q_EXTERN int numEntities Q_ASSIGN( 0 ); Q_EXTERN std::size_t numBSPEntities Q_ASSIGN( 0 );
Q_EXTERN int numBSPEntities Q_ASSIGN( 0 ); Q_EXTERN std::vector<entity_t> entities;
Q_EXTERN int allocatedEntities Q_ASSIGN( 0 );
Q_EXTERN entity_t* entities Q_ASSIGN( NULL );
Q_EXTERN int numBSPModels Q_ASSIGN( 0 ); Q_EXTERN int numBSPModels Q_ASSIGN( 0 );
Q_EXTERN int allocatedBSPModels Q_ASSIGN( 0 ); Q_EXTERN int allocatedBSPModels Q_ASSIGN( 0 );

View File

@ -3606,7 +3606,7 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree ){
BiasSurfaceTextures( ds ); BiasSurfaceTextures( ds );
/* ydnar: globalizing of fog volume handling (eek a hack) */ /* 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 */ /* find surface origin and offset by entity origin */
VectorAdd( ds->mins, ds->maxs, origin ); VectorAdd( ds->mins, ds->maxs, origin );
VectorScale( origin, 0.5f, origin ); VectorScale( origin, 0.5f, origin );

View File

@ -259,12 +259,11 @@ int EmitDrawNode_r( node_t *node ){
============ ============
*/ */
void SetModelNumbers( void ){ void SetModelNumbers( void ){
int i;
int models; int models;
char value[16]; char value[16];
models = 1; 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 ) { if ( entities[i].brushes || entities[i].patches ) {
sprintf( value, "*%i", models ); sprintf( value, "*%i", models );
models++; models++;
@ -283,7 +282,7 @@ void SetModelNumbers( void ){
*/ */
void SetLightStyles( void ){ void SetLightStyles( void ){
int i, j, numStyles; int j, numStyles;
entity_t *e; entity_t *e;
epair_t *ep, *next; epair_t *ep, *next;
char value[ 10 ]; 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 */ /* any light that is controlled (has a targetname) must have a unique style number generated for it */
numStyles = 0; numStyles = 0;
for ( i = 1; i < numEntities; i++ ) for ( std::size_t i = 1; i < entities.size(); ++i )
{ {
e = &entities[ i ]; e = &entities[ i ];
@ -331,7 +330,7 @@ void SetLightStyles( void ){
/* get existing style */ /* get existing style */
const int style = IntForKey( e, "style" ); const int style = IntForKey( e, "style" );
if ( style < LS_NORMAL || style > LS_NONE ) { 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 */ /* find this targetname */
@ -410,7 +409,7 @@ void EndBSPFile( bool do_write ){
EmitPlanes(); EmitPlanes();
numBSPEntities = numEntities; numBSPEntities = entities.size();
UnparseEntities(); UnparseEntities();
if ( do_write ) { if ( do_write ) {