remove global std::size_t mapEntityNum;

(not buildable)
This commit is contained in:
Garux 2021-11-06 17:27:11 +03:00
parent 25bb05b0d2
commit aa110638d4
8 changed files with 57 additions and 67 deletions

View File

@ -259,12 +259,11 @@ static void FixBrushSides( entity_t *e ){
creates a full bsp + surfaces for the worldspawn entity
*/
static void ProcessWorldModel(){
entity_t *e;
static void ProcessWorldModel( entity_t& e ){
const char *value;
/* sets integer blockSize from worldspawn "_blocksize" key if it exists */
if( entities[ 0 ].read_keyvalue( value, "_blocksize", "blocksize", "chopsize" ) ) { /* "chopsize" : sof2 */
if( e.read_keyvalue( value, "_blocksize", "blocksize", "chopsize" ) ) { /* "chopsize" : sof2 */
/* scan 3 numbers */
const int s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] );
@ -276,12 +275,11 @@ static void ProcessWorldModel(){
Sys_Printf( "block size = { %d %d %d }\n", blockSize[ 0 ], blockSize[ 1 ], blockSize[ 2 ] );
/* sof2: ignore leaks? */
const bool ignoreLeaks = entities[ 0 ].boolForKey( "_ignoreleaks", "ignoreleaks" );
const bool ignoreLeaks = e.boolForKey( "_ignoreleaks", "ignoreleaks" );
/* begin worldspawn model */
BeginModel();
e = &entities[ 0 ];
e->firstDrawSurf = 0;
BeginModel( e );
e.firstDrawSurf = 0;
/* ydnar: gs mods */
ClearMetaTriangles();
@ -294,7 +292,7 @@ static void ProcessWorldModel(){
}
/* build an initial bsp tree using all of the sides of all of the structural brushes */
facelist_t faces = MakeStructuralBSPFaceList( entities[ 0 ].brushes );
facelist_t faces = MakeStructuralBSPFaceList( e.brushes );
tree_t tree = FaceBSP( faces );
MakeTreePortals( tree );
FilterStructuralBrushesIntoTree( e, tree );
@ -322,7 +320,7 @@ static void ProcessWorldModel(){
ClipSidesIntoTree( e, tree );
/* build a visible face tree (same thing as the initial bsp tree but after reducing the faces) */
faces = MakeVisibleBSPFaceList( entities[ 0 ].brushes );
faces = MakeVisibleBSPFaceList( e.brushes );
FreeTree( tree );
tree = FaceBSP( faces );
MakeTreePortals( tree );
@ -394,7 +392,7 @@ static void ProcessWorldModel(){
}
/* ydnar: fog hull */
if ( entities[ 0 ].read_keyvalue( value, "_foghull" ) ) {
if ( e.read_keyvalue( value, "_foghull" ) ) {
const auto shader = String64()( "textures/", value );
MakeFogHullSurfs( e, shader );
}
@ -434,7 +432,7 @@ static void ProcessWorldModel(){
}
/* create the flare surface (note shader defaults automatically) */
DrawSurfaceForFlare( mapEntityNum, origin, normal, color, flareShader, lightStyle );
DrawSurfaceForFlare( e.mapEntityNum, origin, normal, color, flareShader, lightStyle );
}
}
}
@ -458,11 +456,10 @@ static void ProcessWorldModel(){
creates bsp + surfaces for other brush models
*/
static void ProcessSubModel(){
static void ProcessSubModel( entity_t& e ){
/* start a brush model */
BeginModel();
entity_t *e = &entities[ mapEntityNum ];
e->firstDrawSurf = numMapDrawSurfs;
BeginModel( e );
e.firstDrawSurf = numMapDrawSurfs;
/* ydnar: gs mods */
ClearMetaTriangles();
@ -541,21 +538,21 @@ static void ProcessModels(){
CreateMapFogs();
/* walk entity list */
for ( mapEntityNum = 0; mapEntityNum < entities.size(); mapEntityNum++ )
for ( size_t entityNum = 0; entityNum < entities.size(); ++entityNum )
{
/* get entity */
const entity_t& entity = entities[ mapEntityNum ];
entity_t& entity = entities[ entityNum ];
if ( entity.brushes.empty() && entity.patches == NULL ) {
continue;
}
/* process the model */
Sys_FPrintf( SYS_VRB, "############### model %zu ###############\n", bspModels.size() );
if ( mapEntityNum == 0 ) {
ProcessWorldModel();
if ( entityNum == 0 ) {
ProcessWorldModel( entity );
}
else{
ProcessSubModel();
ProcessSubModel( entity );
}
/* potentially turn off the deluge of text */

View File

@ -947,9 +947,8 @@ int MergeBSPMain( Args& args ){
a stripped down ProcessModels
*/
static void PseudoCompileBSP( bool need_tree ){
int models;
int models = 1;
char modelValue[16];
entity_t *entity;
facelist_t faces;
tree_t tree{};
@ -957,30 +956,29 @@ static void PseudoCompileBSP( bool need_tree ){
numMapDrawSurfs = 0;
BeginBSPFile();
models = 1;
for ( mapEntityNum = 0; mapEntityNum < entities.size(); mapEntityNum++ )
for ( size_t entityNum = 0; entityNum < entities.size(); ++entityNum )
{
/* get entity */
entity = &entities[ mapEntityNum ];
if ( entity->brushes.empty() && entity->patches == NULL ) {
entity_t& entity = entities[ entityNum ];
if ( entity.brushes.empty() && entity.patches == NULL ) {
continue;
}
if ( mapEntityNum != 0 ) {
if ( entityNum != 0 ) {
sprintf( modelValue, "*%d", models++ );
entity->setKeyValue( "model", modelValue );
entity.setKeyValue( "model", modelValue );
}
/* process the model */
Sys_FPrintf( SYS_VRB, "############### model %zu ###############\n", bspModels.size() );
BeginModel();
BeginModel( entity );
entity->firstDrawSurf = numMapDrawSurfs;
entity.firstDrawSurf = numMapDrawSurfs;
ClearMetaTriangles();
PatchMapDrawSurfs( entity );
if ( mapEntityNum == 0 && need_tree ) {
if ( entityNum == 0 && need_tree ) {
faces = MakeStructuralBSPFaceList( entities[0].brushes );
tree = FaceBSP( faces );
}
@ -991,7 +989,7 @@ static void PseudoCompileBSP( bool need_tree ){
}
/* a minimized ClipSidesIntoTree */
for ( const brush_t& brush : entity->brushes )
for ( const brush_t& brush : entity.brushes )
{
/* walk the brush sides */
for ( const side_t& side : brush.sides )
@ -1020,7 +1018,7 @@ static void PseudoCompileBSP( bool need_tree ){
FilterStructuralBrushesIntoTree( entity, tree );
FilterDetailBrushesIntoTree( entity, tree );
EmitBrushes( entity->brushes, &entity->firstBrush, &entity->numBrushes );
EmitBrushes( entity.brushes, &entity.firstBrush, &entity.numBrushes );
EndModel( entity, tree.headnode );
}
EndBSPFile( false );

View File

@ -1362,7 +1362,7 @@ static void LoadEntityIndexMap( entity_t& e ){
}
/* note it */
Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", e.mapEntityNum, e.classname(), indexMapFilename );
Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", e.mapEntityNum, e.classname(), indexMapFilename );
/* handle tga image */
if ( path_extension_is( indexMapFilename, "tga" ) ) {

View File

@ -415,7 +415,7 @@ static void make_brush_sides( const Plane3f plane, const Plane3f (&p)[3], const
buildBrush.sides[4].planenum = FindFloatPlane( reverse, 0, NULL );
}
static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t *si, const mapDrawSurface_t *ds, const char *modelName ){
static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t *si, const mapDrawSurface_t *ds, const char *modelName, entity_t& entity ){
const int spf = ( spawnFlags & ( eClipFlags & ~eClipModel ) );
/* ydnar: giant hack land: generate clipping brushes for model triangles */
@ -489,7 +489,7 @@ static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t *si, const
/* prepare a brush */
buildBrush.sides.reserve( MAX_BUILD_SIDES );
buildBrush.entityNum = mapEntityNum;
buildBrush.entityNum = entity.mapEntityNum;
buildBrush.contentShader = si;
buildBrush.compileFlags = si->compileFlags;
buildBrush.contentFlags = si->contentFlags;
@ -966,9 +966,9 @@ default_CLIPMODEL:
if ( CreateBrushWindings( buildBrush ) ) {
AddBrushBevels();
//% EmitBrushes( buildBrush, NULL, NULL );
brush_t& newBrush = entities[ mapEntityNum ].brushes.emplace_front( buildBrush );
brush_t& newBrush = entity.brushes.emplace_front( buildBrush );
newBrush.original = &newBrush;
entities[ mapEntityNum ].numBrushes++;
entity.numBrushes++;
}
else{
Sys_Warning( "triangle (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) (%6.0f %6.0f %6.0f) of %s was not autoclipped\n",
@ -988,7 +988,7 @@ default_CLIPMODEL:
adds a picomodel into the bsp
*/
void InsertModel( const char *name, int skin, int frame, const Matrix4& transform, const std::list<remap_t> *remaps, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle, float clipDepth ){
void InsertModel( const char *name, int skin, int frame, const Matrix4& transform, const std::list<remap_t> *remaps, shaderInfo_t *celShader, entity_t& entity, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle, float clipDepth ){
int i, j;
const Matrix4 nTransform( matrix4_for_normal_transform( transform ) );
const bool transform_lefthanded = MATRIX4_LEFTHANDED == matrix4_handedness( transform );
@ -1138,7 +1138,7 @@ void InsertModel( const char *name, int skin, int frame, const Matrix4& transfor
/* allocate a surface (ydnar: gs mods) */
ds = AllocDrawSurface( ESurfaceType::Triangles );
ds->entityNum = eNum;
ds->entityNum = entity.mapEntityNum;
ds->castShadows = castShadows;
ds->recvShadows = recvShadows;
@ -1249,7 +1249,7 @@ void InsertModel( const char *name, int skin, int frame, const Matrix4& transfor
/* set cel shader */
ds->celShader = celShader;
ClipModel( spawnFlags, clipDepth, si, ds, name );
ClipModel( spawnFlags, clipDepth, si, ds, name, entity );
}
}
@ -1410,7 +1410,6 @@ void AddTriangleModels( entity_t *eparent ){
/* insert the model */
InsertModel( model, skin, frame, transform, &remaps, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale, lightmapSampleSize, shadeAngle, clipDepth );
InsertModel( model, skin, frame, transform, &remaps, celShader, *eparent, castShadows, recvShadows, spawnFlags, lightmapScale, lightmapSampleSize, shadeAngle, clipDepth );
}
}

View File

@ -1489,7 +1489,7 @@ void EndBSPFile( bool do_write );
void EmitBrushes( brushlist_t& brushes, int *firstBrush, int *numBrushes );
void EmitFogs();
void BeginModel();
void BeginModel( const entity_t& e );
void EndModel( entity_t *e, node_t *headnode );
@ -1523,7 +1523,7 @@ tree_t FaceBSP( facelist_t& list );
/* model.c */
void assimp_init();
void InsertModel( const char *name, int skin, int frame, const Matrix4& transform, const std::list<remap_t> *remaps, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle, float clipDepth );
void InsertModel( const char *name, int skin, int frame, const Matrix4& transform, const std::list<remap_t> *remaps, shaderInfo_t *celShader, entity_t& entity, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle, float clipDepth );
void AddTriangleModels( entity_t *e );
@ -1538,7 +1538,6 @@ void TidyEntitySurfaces( entity_t *e );
mapDrawSurface_t *CloneSurface( mapDrawSurface_t *src, shaderInfo_t *si );
bool IsTriangleDegenerate( bspDrawVert_t *points, int a, int b, int c );
void ClearSurface( mapDrawSurface_t *ds );
void AddEntitySurfaceModels( entity_t *e );
mapDrawSurface_t *DrawSurfaceForSide( const entity_t *e, const brush_t& b, const side_t& s, const winding_t& w );
mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh );
mapDrawSurface_t *DrawSurfaceForFlare( int entNum, const Vector3& origin, const Vector3& normal, const Vector3& color, const char *flareShader, int lightStyle );
@ -1555,7 +1554,7 @@ void Fur( mapDrawSurface_t *src );
/* surface_foliage.c */
void Foliage( mapDrawSurface_t *src );
void Foliage( mapDrawSurface_t *src, entity_t& entity );
/* ydnar: surface_meta.c */
@ -1799,8 +1798,6 @@ inline int sampleSize = DEFAULT_LIGHTMAP_SAMPLE_SIZE; /* lightmap sampl
inline int minSampleSize = DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE; /* minimum sample size to use at all */
inline int sampleScale; /* vortex: lightmap sample scale (ie quality)*/
inline std::size_t mapEntityNum;
inline std::vector<plane_t> mapplanes; /* mapplanes[ num ^ 1 ] will always be the mirror or mapplanes[ num ] */ /* nummapplanes will always be even */
inline MinMax g_mapMinmax;

View File

@ -2719,7 +2719,7 @@ static void BiasSurfaceTextures( mapDrawSurface_t *ds ){
adds models to a specified triangle, returns the number of models added
*/
static int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, const surfaceModel_t& model, bspDrawVert_t **tri ){
static int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, const surfaceModel_t& model, bspDrawVert_t **tri, entity_t& entity ){
bspDrawVert_t mid, *tri2[ 3 ];
int max, n, localNumSurfaceModels;
@ -2811,7 +2811,7 @@ static int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, const surfaceMode
}
/* insert the model */
InsertModel( model.model.c_str(), 0, 0, transform, NULL, ds->celShader, ds->entityNum, ds->castShadows, ds->recvShadows, 0, ds->lightmapScale, 0, 0, clipDepthGlobal );
InsertModel( model.model.c_str(), 0, 0, transform, NULL, ds->celShader, entity, ds->castShadows, ds->recvShadows, 0, ds->lightmapScale, 0, 0, clipDepthGlobal );
/* return to sender */
return 1;
@ -2824,7 +2824,7 @@ static int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, const surfaceMode
/* recurse to first triangle */
VectorCopy( tri, tri2 );
tri2[ max ] = &mid;
n = AddSurfaceModelsToTriangle_r( ds, model, tri2 );
n = AddSurfaceModelsToTriangle_r( ds, model, tri2, entity );
if ( n < 0 ) {
return n;
}
@ -2833,7 +2833,7 @@ static int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, const surfaceMode
/* recurse to second triangle */
VectorCopy( tri, tri2 );
tri2[ ( max + 1 ) % 3 ] = &mid;
n = AddSurfaceModelsToTriangle_r( ds, model, tri2 );
n = AddSurfaceModelsToTriangle_r( ds, model, tri2, entity );
if ( n < 0 ) {
return n;
}
@ -2850,7 +2850,7 @@ static int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, const surfaceMode
adds a surface's shader models to the surface
*/
static int AddSurfaceModels( mapDrawSurface_t *ds ){
static int AddSurfaceModels( mapDrawSurface_t *ds, entity_t& entity ){
int i, x, y, n, pw[ 5 ], r, localNumSurfaceModels, iterations;
mesh_t src, *mesh, *subdivided;
bspDrawVert_t centroid, *tri[ 3 ];
@ -2906,7 +2906,7 @@ static int AddSurfaceModels( mapDrawSurface_t *ds ){
tri[ 2 ] = &ds->verts[ ( i + 1 ) % ds->numVerts ];
/* create models */
n = AddSurfaceModelsToTriangle_r( ds, model, tri );
n = AddSurfaceModelsToTriangle_r( ds, model, tri, entity );
if ( n < 0 ) {
return n;
}
@ -2948,7 +2948,7 @@ static int AddSurfaceModels( mapDrawSurface_t *ds ){
tri[ 0 ] = &mesh->verts[ pw[ r + 0 ] ];
tri[ 1 ] = &mesh->verts[ pw[ r + 1 ] ];
tri[ 2 ] = &mesh->verts[ pw[ r + 2 ] ];
n = AddSurfaceModelsToTriangle_r( ds, model, tri );
n = AddSurfaceModelsToTriangle_r( ds, model, tri, entity );
if ( n < 0 ) {
return n;
}
@ -2958,7 +2958,7 @@ static int AddSurfaceModels( mapDrawSurface_t *ds ){
tri[ 0 ] = &mesh->verts[ pw[ r + 0 ] ];
tri[ 1 ] = &mesh->verts[ pw[ r + 2 ] ];
tri[ 2 ] = &mesh->verts[ pw[ r + 3 ] ];
n = AddSurfaceModelsToTriangle_r( ds, model, tri );
n = AddSurfaceModelsToTriangle_r( ds, model, tri, entity );
if ( n < 0 ) {
return n;
}
@ -2980,7 +2980,7 @@ static int AddSurfaceModels( mapDrawSurface_t *ds ){
tri[ 0 ] = &ds->verts[ ds->indexes[ i ] ];
tri[ 1 ] = &ds->verts[ ds->indexes[ i + 1 ] ];
tri[ 2 ] = &ds->verts[ ds->indexes[ i + 2 ] ];
n = AddSurfaceModelsToTriangle_r( ds, model, tri );
n = AddSurfaceModelsToTriangle_r( ds, model, tri, entity );
if ( n < 0 ) {
return n;
}
@ -3014,7 +3014,7 @@ void AddEntitySurfaceModels( entity_t *e ){
/* walk the surface list */
for ( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
numSurfaceModels += AddSurfaceModels( &mapDrawSurfs[ i ] );
numSurfaceModels += AddSurfaceModels( &mapDrawSurfs[ i ], *e );
}
@ -3122,7 +3122,7 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t& tree ){
/* ydnar/sd: make foliage surfaces */
if ( !si->foliage.empty() ) {
Foliage( ds );
Foliage( ds, *e );
}
/* create a flare surface if necessary */

View File

@ -155,7 +155,7 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, const foliage_t& f
generates a foliage file for a bsp
*/
void Foliage( mapDrawSurface_t *src ){
void Foliage( mapDrawSurface_t *src, entity_t& entity ){
int i, j, x, y, pw[ 5 ], r, oldNumMapDrawSurfs;
mapDrawSurface_t *ds;
shaderInfo_t *si;
@ -255,7 +255,7 @@ void Foliage( mapDrawSurface_t *src ){
oldNumMapDrawSurfs = numMapDrawSurfs;
/* add the model to the bsp */
InsertModel( foliage.model.c_str(), 0, 0, matrix4_scale_for_vec3( Vector3( foliage.scale ) ), NULL, NULL, src->entityNum, src->castShadows, src->recvShadows, 0, src->lightmapScale, 0, 0, clipDepthGlobal );
InsertModel( foliage.model.c_str(), 0, 0, matrix4_scale_for_vec3( Vector3( foliage.scale ) ), NULL, NULL, entity, src->castShadows, src->recvShadows, 0, src->lightmapScale, 0, 0, clipDepthGlobal );
/* walk each new surface */
for ( i = oldNumMapDrawSurfs; i < numMapDrawSurfs; i++ )

View File

@ -476,14 +476,10 @@ void EmitFogs(){
sets up a new brush model
*/
void BeginModel(){
void BeginModel( const entity_t& e ){
MinMax minmax;
MinMax lgMinmax; /* ydnar: lightgrid mins/maxs */
/* get model and entity */
bspModel_t& mod = bspModels.emplace_back();
const entity_t& e = entities[ mapEntityNum ];
/* bound the brushes */
for ( const brush_t& b : e.brushes )
{
@ -506,6 +502,9 @@ void BeginModel(){
minmax.extend( vert.xyz );
}
/* get model */
bspModel_t& mod = bspModels.emplace_back();
/* ydnar: lightgrid mins/maxs */
if ( lgMinmax.valid() ) {
/* use lightgrid bounds */