remove global entity_t *mapEnt;

This commit is contained in:
Garux 2021-11-06 13:50:30 +03:00
parent 0aa61b7dfa
commit 16dddad640
4 changed files with 109 additions and 115 deletions

View File

@ -360,7 +360,7 @@ void ParseEPair( std::list<epair_t>& epairs ){
ep.value = StripTrailing( token ); ep.value = StripTrailing( token );
if( !ep.key.empty() && !ep.value.empty() ) if( !ep.key.empty() && !ep.value.empty() )
epairs.emplace_back( ep ); epairs.push_back( std::move( ep ) );
} }
@ -380,7 +380,7 @@ static bool ParseEntity(){
} }
/* create new entity */ /* create new entity */
mapEnt = &entities.emplace_back(); entity_t& e = entities.emplace_back();
/* parse */ /* parse */
while ( 1 ) while ( 1 )
@ -391,7 +391,7 @@ static bool ParseEntity(){
if ( strEqual( token, "}" ) ) { if ( strEqual( token, "}" ) ) {
break; break;
} }
ParseEPair( mapEnt->epairs ); ParseEPair( e.epairs );
} }
/* return to sender */ /* return to sender */

View File

@ -516,7 +516,7 @@ static void SetBrushContents( brush_t& b ){
/* check for detail & structural */ /* check for detail & structural */
if ( ( compileFlags & C_DETAIL ) && ( compileFlags & C_STRUCTURAL ) ) { if ( ( compileFlags & C_DETAIL ) && ( compileFlags & C_STRUCTURAL ) ) {
xml_Select( "Mixed detail and structural (defaulting to structural)", mapEnt->mapEntityNum, entitySourceBrushes, false ); xml_Select( "Mixed detail and structural (defaulting to structural)", b.entityNum, b.brushNum, false );
compileFlags &= ~C_DETAIL; compileFlags &= ~C_DETAIL;
} }
@ -777,7 +777,7 @@ static void MergeOrigin( entity_t& ent, const Vector3& origin ){
and links it to the current entity and links it to the current entity
*/ */
static void FinishBrush( bool noCollapseGroups ){ static void FinishBrush( bool noCollapseGroups, entity_t& mapEnt ){
/* create windings for sides and bounds for brush */ /* create windings for sides and bounds for brush */
if ( !CreateBrushWindings( buildBrush ) ) { if ( !CreateBrushWindings( buildBrush ) ) {
return; return;
@ -787,15 +787,15 @@ static void FinishBrush( bool noCollapseGroups ){
after the entire entity is parsed, the planenums and texinfos will be adjusted for the origin brush */ after the entire entity is parsed, the planenums and texinfos will be adjusted for the origin brush */
if ( buildBrush.compileFlags & C_ORIGIN ) { if ( buildBrush.compileFlags & C_ORIGIN ) {
Sys_Printf( "Entity %i (%s), Brush %i: origin brush detected\n", Sys_Printf( "Entity %i (%s), Brush %i: origin brush detected\n",
mapEnt->mapEntityNum, mapEnt->classname(), entitySourceBrushes ); mapEnt.mapEntityNum, mapEnt.classname(), entitySourceBrushes );
if ( entities.size() == 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; return;
} }
MergeOrigin( entities.back(), buildBrush.minmax.origin() ); MergeOrigin( mapEnt, buildBrush.minmax.origin() );
/* don't keep this brush */ /* don't keep this brush */
return; return;
@ -804,7 +804,7 @@ static void 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 ( entities.size() != 1 ) { if ( entities.size() != 1 ) {
Sys_FPrintf( SYS_WRN, "Entity %zu (%s), Brush %i: areaportals only allowed in world\n", entities.size() - 1, mapEnt->classname(), entitySourceBrushes ); Sys_FPrintf( SYS_WRN, "Entity %i (%s), Brush %i: areaportals only allowed in world\n", mapEnt.mapEntityNum, mapEnt.classname(), entitySourceBrushes );
return; return;
} }
} }
@ -816,12 +816,8 @@ static void FinishBrush( bool noCollapseGroups ){
/* keep it */ /* keep it */
/* link opaque brushes to head of list, translucent brushes to end */ /* link opaque brushes to head of list, translucent brushes to end */
brush_t& b = ( buildBrush.opaque )? mapEnt->brushes.emplace_front( buildBrush ) brush_t& b = ( buildBrush.opaque )? mapEnt.brushes.emplace_front( buildBrush )
: mapEnt->brushes.emplace_back( buildBrush ); : mapEnt.brushes.emplace_back( buildBrush );
/* set map entity and brush numbering */
b.entityNum = mapEnt->mapEntityNum;
b.brushNum = entitySourceBrushes;
/* set original */ /* set original */
b.original = &b; b.original = &b;
@ -830,7 +826,7 @@ static void FinishBrush( bool noCollapseGroups ){
if ( b.contentShader != NULL && if ( b.contentShader != NULL &&
b.contentShader->colorMod != NULL && b.contentShader->colorMod != NULL &&
b.contentShader->colorMod->type == EColorMod::Volume ) { b.contentShader->colorMod->type == EColorMod::Volume ) {
mapEnt->colorModBrushes.push_back( &b ); mapEnt.colorModBrushes.push_back( &b );
} }
} }
@ -1163,7 +1159,7 @@ static bool RemoveDuplicateBrushPlanes( brush_t& b ){
parses a brush out of a map file and sets it up parses a brush out of a map file and sets it up
*/ */
static void ParseBrush( bool onlyLights, bool noCollapseGroups ){ static void ParseBrush( bool onlyLights, bool noCollapseGroups, entity_t& mapEnt ){
/* parse the brush out of the map */ /* parse the brush out of the map */
ParseRawBrush( onlyLights ); ParseRawBrush( onlyLights );
@ -1175,7 +1171,8 @@ static void ParseBrush( bool onlyLights, bool noCollapseGroups ){
/* set some defaults */ /* set some defaults */
buildBrush.portalareas[ 0 ] = -1; buildBrush.portalareas[ 0 ] = -1;
buildBrush.portalareas[ 1 ] = -1; buildBrush.portalareas[ 1 ] = -1;
buildBrush.entityNum = numMapEntities - 1; /* set map entity and brush numbering */
buildBrush.entityNum = mapEnt.mapEntityNum;
buildBrush.brushNum = entitySourceBrushes; buildBrush.brushNum = entitySourceBrushes;
/* if there are mirrored planes, the entire brush is invalid */ /* if there are mirrored planes, the entire brush is invalid */
@ -1202,7 +1199,40 @@ static void ParseBrush( bool onlyLights, bool noCollapseGroups ){
} }
/* finish the brush */ /* finish the brush */
FinishBrush( noCollapseGroups ); FinishBrush( noCollapseGroups, mapEnt );
}
/*
AdjustBrushesForOrigin()
*/
static void AdjustBrushesForOrigin( entity_t& ent ){
/* walk brush list */
for ( brush_t& b : ent.brushes )
{
/* offset brush planes */
for ( side_t& side : b.sides )
{
/* offset side plane */
const float newdist = -plane3_distance_to_point( mapplanes[ side.planenum ].plane, ent.originbrush_origin );
/* find a new plane */
side.planenum = FindFloatPlane( mapplanes[ side.planenum ].normal(), newdist, 0, NULL );
side.plane.dist() = -plane3_distance_to_point( side.plane, ent.originbrush_origin );
}
/* rebuild brush windings (ydnar: just offsetting the winding above should be fine) */
CreateBrushWindings( b );
}
/* walk patch list */
for ( parseMesh_t *p = ent.patches; p != NULL; p = p->next )
{
for ( bspDrawVert_t& vert : Span( p->mesh.verts, p->mesh.width * p->mesh.height ) )
vert.xyz -= ent.originbrush_origin;
}
} }
@ -1214,78 +1244,43 @@ static void ParseBrush( bool onlyLights, bool noCollapseGroups ){
(used by func_group) (used by func_group)
*/ */
static void AdjustBrushesForOrigin( entity_t *ent ); static void MoveBrushesToWorld( entity_t& ent ){
void MoveBrushesToWorld( entity_t *ent ){
/* we need to undo the common/origin adjustment, and instead shift them by the entity key origin */ /* we need to undo the common/origin adjustment, and instead shift them by the entity key origin */
ent->originbrush_origin = -ent->origin; ent.originbrush_origin = -ent.origin;
AdjustBrushesForOrigin( ent ); AdjustBrushesForOrigin( ent );
ent->originbrush_origin.set( 0 ); ent.originbrush_origin.set( 0 );
/* move brushes */ /* move brushes */
for ( brushlist_t::const_iterator next, b = ent->brushes.begin(); b != ent->brushes.end(); b = next ) for ( brushlist_t::const_iterator next, b = ent.brushes.begin(); b != ent.brushes.end(); b = next )
{ {
/* get next brush */ /* get next brush */
next = std::next( b ); next = std::next( b );
/* link opaque brushes to head of list, translucent brushes to end */ /* link opaque brushes to head of list, translucent brushes to end */
if ( b->opaque ) { if ( b->opaque ) {
entities[ 0 ].brushes.splice( entities[ 0 ].brushes.begin(), ent->brushes, b ); entities[ 0 ].brushes.splice( entities[ 0 ].brushes.begin(), ent.brushes, b );
} }
else else
{ {
entities[ 0 ].brushes.splice( entities[ 0 ].brushes.end(), ent->brushes, b ); entities[ 0 ].brushes.splice( entities[ 0 ].brushes.end(), ent.brushes, b );
} }
} }
/* ydnar: move colormod brushes */ /* ydnar: move colormod brushes */
if ( !ent->colorModBrushes.empty() ) { if ( !ent.colorModBrushes.empty() ) {
entities[ 0 ].colorModBrushes.insert( entities[ 0 ].colorModBrushes.end(), ent->colorModBrushes.begin(), ent->colorModBrushes.end() ); entities[ 0 ].colorModBrushes.insert( entities[ 0 ].colorModBrushes.end(), ent.colorModBrushes.begin(), ent.colorModBrushes.end() );
ent->colorModBrushes.clear(); ent.colorModBrushes.clear();
} }
/* move patches */ /* move patches */
if ( ent->patches != NULL ) { if ( ent.patches != NULL ) {
parseMesh_t *pm; parseMesh_t *pm;
for ( pm = ent->patches; pm->next != NULL; pm = pm->next ){}; for ( pm = ent.patches; pm->next != NULL; pm = pm->next ){};
pm->next = entities[ 0 ].patches; pm->next = entities[ 0 ].patches;
entities[ 0 ].patches = ent->patches; entities[ 0 ].patches = ent.patches;
ent->patches = NULL; ent.patches = NULL;
}
}
/*
AdjustBrushesForOrigin()
*/
static void AdjustBrushesForOrigin( entity_t *ent ){
/* walk brush list */
for ( brush_t& b : ent->brushes )
{
/* offset brush planes */
for ( side_t& side : b.sides )
{
/* offset side plane */
const float newdist = -plane3_distance_to_point( mapplanes[ side.planenum ].plane, ent->originbrush_origin );
/* find a new plane */
side.planenum = FindFloatPlane( mapplanes[ side.planenum ].normal(), newdist, 0, NULL );
side.plane.dist() = -plane3_distance_to_point( side.plane, ent->originbrush_origin );
}
/* rebuild brush windings (ydnar: just offsetting the winding above should be fine) */
CreateBrushWindings( b );
}
/* walk patch list */
for ( parseMesh_t *p = ent->patches; p != NULL; p = p->next )
{
for ( bspDrawVert_t& vert : Span( p->mesh.verts, p->mesh.width * p->mesh.height ) )
vert.xyz -= ent->originbrush_origin;
} }
} }
@ -1296,30 +1291,30 @@ static void AdjustBrushesForOrigin( entity_t *ent ){
finds the bounds of an entity's brushes (necessary for terrain-style generic metashaders) finds the bounds of an entity's brushes (necessary for terrain-style generic metashaders)
*/ */
static void SetEntityBounds( entity_t *e ){ static void SetEntityBounds( entity_t& e ){
MinMax minmax; MinMax minmax;
/* walk the entity's brushes/patches and determine bounds */ /* walk the entity's brushes/patches and determine bounds */
for ( const brush_t& b : e->brushes ) for ( const brush_t& b : e.brushes )
{ {
minmax.extend( b.minmax ); minmax.extend( b.minmax );
} }
for ( parseMesh_t *p = e->patches; p; p = p->next ) for ( const parseMesh_t *p = e.patches; p; p = p->next )
{ {
for ( const bspDrawVert_t& vert : Span( p->mesh.verts, p->mesh.width * p->mesh.height ) ) for ( const bspDrawVert_t& vert : Span( p->mesh.verts, p->mesh.width * p->mesh.height ) )
minmax.extend( vert.xyz ); minmax.extend( vert.xyz );
} }
/* try to find explicit min/max key */ /* try to find explicit min/max key */
e->read_keyvalue( minmax.mins, "min" ); e.read_keyvalue( minmax.mins, "min" );
e->read_keyvalue( minmax.maxs, "max" ); e.read_keyvalue( minmax.maxs, "max" );
/* store the bounds */ /* store the bounds */
for ( brush_t& b : e->brushes ) for ( brush_t& b : e.brushes )
{ {
b.eMinmax = minmax; b.eMinmax = minmax;
} }
for ( parseMesh_t *p = e->patches; p; p = p->next ) for ( parseMesh_t *p = e.patches; p; p = p->next )
{ {
p->eMinmax = minmax; p->eMinmax = minmax;
} }
@ -1332,23 +1327,23 @@ static void SetEntityBounds( entity_t *e ){
based on LoadAlphaMap() from terrain.c, a little more generic based on LoadAlphaMap() from terrain.c, a little more generic
*/ */
static void LoadEntityIndexMap( entity_t *e ){ static void LoadEntityIndexMap( entity_t& e ){
int numLayers, w, h; int numLayers, w, h;
const char *indexMapFilename, *shader; const char *indexMapFilename, *shader;
byte *pixels; byte *pixels;
/* this only works with bmodel ents */ /* this only works with bmodel ents */
if ( e->brushes.empty() && e->patches == NULL ) { if ( e.brushes.empty() && e.patches == NULL ) {
return; return;
} }
/* determine if there is an index map (support legacy "alphamap" key as well) */ /* determine if there is an index map (support legacy "alphamap" key as well) */
if( !e->read_keyvalue( indexMapFilename, "_indexmap", "alphamap" ) ) if( !e.read_keyvalue( indexMapFilename, "_indexmap", "alphamap" ) )
return; return;
/* get number of layers (support legacy "layers" key as well) */ /* get number of layers (support legacy "layers" key as well) */
if( !e->read_keyvalue( numLayers, "_layers", "layers" ) ){ if( !e.read_keyvalue( numLayers, "_layers", "layers" ) ){
Sys_Warning( "Entity with index/alpha map \"%s\" has missing \"_layers\" or \"layers\" key\n", indexMapFilename ); Sys_Warning( "Entity with index/alpha map \"%s\" has missing \"_layers\" or \"layers\" key\n", indexMapFilename );
Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" ); Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
return; return;
@ -1360,14 +1355,14 @@ static void LoadEntityIndexMap( entity_t *e ){
} }
/* get base shader name (support legacy "shader" key as well) */ /* get base shader name (support legacy "shader" key as well) */
if( !mapEnt->read_keyvalue( shader, "_shader", "shader" ) ){ if( !e.read_keyvalue( shader, "_shader", "shader" ) ){
Sys_Warning( "Entity with index/alpha map \"%s\" has missing \"_shader\" or \"shader\" key\n", indexMapFilename ); Sys_Warning( "Entity with index/alpha map \"%s\" has missing \"_shader\" or \"shader\" key\n", indexMapFilename );
Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" ); Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
return; return;
} }
/* note it */ /* note it */
Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->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 */ /* handle tga image */
if ( path_extension_is( indexMapFilename, "tga" ) ) { if ( path_extension_is( indexMapFilename, "tga" ) ) {
@ -1436,7 +1431,7 @@ static void LoadEntityIndexMap( entity_t *e ){
/* get height offsets */ /* get height offsets */
const char *offset; const char *offset;
if( mapEnt->read_keyvalue( offset, "_offsets", "offsets" ) ){ if( e.read_keyvalue( offset, "_offsets", "offsets" ) ){
/* value is a space-separated set of numbers */ /* value is a space-separated set of numbers */
/* get each value */ /* get each value */
for ( int i = 0; i < 256 && !strEmpty( offset ); ++i ) for ( int i = 0; i < 256 && !strEmpty( offset ); ++i )
@ -1454,9 +1449,9 @@ static void LoadEntityIndexMap( entity_t *e ){
} }
/* store the index map in every brush/patch in the entity */ /* store the index map in every brush/patch in the entity */
for ( brush_t& b : e->brushes ) for ( brush_t& b : e.brushes )
b.im = im; b.im = im;
for ( parseMesh_t *p = e->patches; p != NULL; p = p->next ) for ( parseMesh_t *p = e.patches; p != NULL; p = p->next )
p->im = im; p->im = im;
} }
@ -1487,10 +1482,10 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
/* setup */ /* setup */
entitySourceBrushes = 0; entitySourceBrushes = 0;
mapEnt = &entities.emplace_back(); entity_t& mapEnt = entities.emplace_back();
/* ydnar: true entity numbering */ /* ydnar: true entity numbering */
mapEnt->mapEntityNum = numMapEntities++; mapEnt.mapEntityNum = numMapEntities++;
/* loop */ /* loop */
while ( 1 ) while ( 1 )
@ -1515,7 +1510,7 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
/* check */ /* check */
if ( strEqual( token, "patchDef2" ) ) { if ( strEqual( token, "patchDef2" ) ) {
++c_patches; ++c_patches;
ParsePatch( onlyLights ); ParsePatch( onlyLights, mapEnt );
} }
else if ( strEqual( token, "terrainDef" ) ) { else if ( strEqual( token, "terrainDef" ) ) {
//% ParseTerrain(); //% ParseTerrain();
@ -1526,25 +1521,25 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
Sys_FPrintf( SYS_VRB, "detected brushType = BRUSH PRIMITIVES\n" ); Sys_FPrintf( SYS_VRB, "detected brushType = BRUSH PRIMITIVES\n" );
g_brushType = EBrushType::Bp; g_brushType = EBrushType::Bp;
} }
ParseBrush( onlyLights, noCollapseGroups ); ParseBrush( onlyLights, noCollapseGroups, mapEnt );
} }
else else
{ {
/* AP or 220 */ /* AP or 220 */
UnGetToken(); // ( UnGetToken(); // (
ParseBrush( onlyLights, noCollapseGroups ); ParseBrush( onlyLights, noCollapseGroups, mapEnt );
} }
entitySourceBrushes++; entitySourceBrushes++;
} }
else else
{ {
/* parse a key / value pair */ /* parse a key / value pair */
ParseEPair( mapEnt->epairs ); ParseEPair( mapEnt.epairs );
} }
} }
/* ydnar: get classname */ /* ydnar: get classname */
const char *classname = mapEnt->classname(); const char *classname = mapEnt.classname();
/* ydnar: only lights? */ /* ydnar: only lights? */
if ( onlyLights && !striEqualPrefix( classname, "light" ) ) { if ( onlyLights && !striEqualPrefix( classname, "light" ) ) {
@ -1557,52 +1552,52 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
/* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */ /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
int castShadows, recvShadows; int castShadows, recvShadows;
if ( funcGroup || mapEnt->mapEntityNum == 0 ) { if ( funcGroup || mapEnt.mapEntityNum == 0 ) {
//% Sys_Printf( "World: %d\n", mapEnt->mapEntityNum ); //% Sys_Printf( "World: %d\n", mapEnt.mapEntityNum );
castShadows = WORLDSPAWN_CAST_SHADOWS; castShadows = WORLDSPAWN_CAST_SHADOWS;
recvShadows = WORLDSPAWN_RECV_SHADOWS; recvShadows = WORLDSPAWN_RECV_SHADOWS;
} }
else{ /* other entities don't cast any shadows, but recv worldspawn shadows */ else{ /* other entities don't cast any shadows, but recv worldspawn shadows */
//% Sys_Printf( "Entity: %d\n", mapEnt->mapEntityNum ); //% Sys_Printf( "Entity: %d\n", mapEnt.mapEntityNum );
castShadows = ENTITY_CAST_SHADOWS; castShadows = ENTITY_CAST_SHADOWS;
recvShadows = ENTITY_RECV_SHADOWS; recvShadows = ENTITY_RECV_SHADOWS;
} }
/* get explicit shadow flags */ /* get explicit shadow flags */
GetEntityShadowFlags( mapEnt, NULL, &castShadows, &recvShadows ); GetEntityShadowFlags( &mapEnt, NULL, &castShadows, &recvShadows );
/* ydnar: get lightmap scaling value for this entity */ /* ydnar: get lightmap scaling value for this entity */
const float lightmapScale = std::max( 0.f, mapEnt->floatForKey( "lightmapscale", "_lightmapscale", "_ls" ) ); const float lightmapScale = std::max( 0.f, mapEnt.floatForKey( "lightmapscale", "_lightmapscale", "_ls" ) );
if ( lightmapScale != 0 ) if ( lightmapScale != 0 )
Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale ); Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt.mapEntityNum, classname, lightmapScale );
/* ydnar: get cel shader :) for this entity */ /* ydnar: get cel shader :) for this entity */
shaderInfo_t *celShader; shaderInfo_t *celShader;
const char *value; const char *value;
if( mapEnt->read_keyvalue( value, "_celshader" ) || if( mapEnt.read_keyvalue( value, "_celshader" ) ||
entities[ 0 ].read_keyvalue( value, "_celshader" ) ){ entities[ 0 ].read_keyvalue( value, "_celshader" ) ){
celShader = ShaderInfoForShader( String64()( "textures/", value ) ); celShader = ShaderInfoForShader( String64()( "textures/", value ) );
Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader.c_str() ); Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt.mapEntityNum, classname, celShader->shader.c_str() );
} }
else{ else{
celShader = globalCelShader.empty() ? NULL : ShaderInfoForShader( globalCelShader ); celShader = globalCelShader.empty() ? NULL : ShaderInfoForShader( globalCelShader );
} }
/* jal : entity based _shadeangle */ /* jal : entity based _shadeangle */
const float shadeAngle = std::max( 0.f, mapEnt->floatForKey( "_shadeangle", const float shadeAngle = std::max( 0.f, mapEnt.floatForKey( "_shadeangle",
"_smoothnormals", "_sn", "_sa", "_smooth" ) ); /* vortex' aliases */ "_smoothnormals", "_sn", "_sa", "_smooth" ) ); /* vortex' aliases */
if ( shadeAngle != 0 ) if ( shadeAngle != 0 )
Sys_Printf( "Entity %d (%s) has shading angle of %.4f\n", mapEnt->mapEntityNum, classname, shadeAngle ); Sys_Printf( "Entity %d (%s) has shading angle of %.4f\n", mapEnt.mapEntityNum, classname, shadeAngle );
/* jal : entity based _samplesize */ /* jal : entity based _samplesize */
const int lightmapSampleSize = std::max( 0, mapEnt->intForKey( "_lightmapsamplesize", "_samplesize", "_ss" ) ); const int lightmapSampleSize = std::max( 0, mapEnt.intForKey( "_lightmapsamplesize", "_samplesize", "_ss" ) );
if ( lightmapSampleSize != 0 ) if ( lightmapSampleSize != 0 )
Sys_Printf( "Entity %d (%s) has lightmap sample size of %d\n", mapEnt->mapEntityNum, classname, lightmapSampleSize ); Sys_Printf( "Entity %d (%s) has lightmap sample size of %d\n", mapEnt.mapEntityNum, classname, lightmapSampleSize );
/* attach stuff to everything in the entity */ /* attach stuff to everything in the entity */
for ( brush_t& brush : mapEnt->brushes ) for ( brush_t& brush : mapEnt.brushes )
{ {
brush.entityNum = mapEnt->mapEntityNum; brush.entityNum = mapEnt.mapEntityNum;
brush.castShadows = castShadows; brush.castShadows = castShadows;
brush.recvShadows = recvShadows; brush.recvShadows = recvShadows;
brush.lightmapSampleSize = lightmapSampleSize; brush.lightmapSampleSize = lightmapSampleSize;
@ -1611,9 +1606,9 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
brush.shadeAngleDegrees = shadeAngle; brush.shadeAngleDegrees = shadeAngle;
} }
for ( parseMesh_t *patch = mapEnt->patches; patch != NULL; patch = patch->next ) for ( parseMesh_t *patch = mapEnt.patches; patch != NULL; patch = patch->next )
{ {
patch->entityNum = mapEnt->mapEntityNum; patch->entityNum = mapEnt.mapEntityNum;
patch->castShadows = castShadows; patch->castShadows = castShadows;
patch->recvShadows = recvShadows; patch->recvShadows = recvShadows;
patch->lightmapSampleSize = lightmapSampleSize; patch->lightmapSampleSize = lightmapSampleSize;
@ -1628,8 +1623,8 @@ static bool ParseMapEntity( bool onlyLights, bool noCollapseGroups ){
LoadEntityIndexMap( mapEnt ); LoadEntityIndexMap( mapEnt );
/* get entity origin and adjust brushes */ /* get entity origin and adjust brushes */
mapEnt->origin = mapEnt->vectorForKey( "origin" ); mapEnt.origin = mapEnt.vectorForKey( "origin" );
if ( mapEnt->originbrush_origin != g_vector3_identity ) { if ( mapEnt.originbrush_origin != g_vector3_identity ) {
AdjustBrushesForOrigin( mapEnt ); AdjustBrushesForOrigin( mapEnt );
} }

View File

@ -194,7 +194,7 @@ static void ExpandMaxIterations( int *maxIterations, int maxError, const Vector3
creates a mapDrawSurface_t from the patch text creates a mapDrawSurface_t from the patch text
*/ */
void ParsePatch( bool onlyLights ){ void ParsePatch( bool onlyLights, entity_t& mapEnt ){
float info[ 5 ]; float info[ 5 ];
mesh_t m; mesh_t m;
bspDrawVert_t *verts; bspDrawVert_t *verts;
@ -292,7 +292,7 @@ void ParsePatch( bool onlyLights ){
/* warn and select degenerate patch */ /* warn and select degenerate patch */
if ( degenerate ) { if ( degenerate ) {
xml_Select( "degenerate patch", mapEnt->mapEntityNum, entitySourceBrushes, false ); xml_Select( "degenerate patch", mapEnt.mapEntityNum, entitySourceBrushes, false );
free( m.verts ); free( m.verts );
return; return;
} }
@ -315,7 +315,7 @@ void ParsePatch( bool onlyLights ){
parseMesh_t *pm = safe_calloc( sizeof( *pm ) ); parseMesh_t *pm = safe_calloc( sizeof( *pm ) );
/* ydnar: add entity/brush numbering */ /* ydnar: add entity/brush numbering */
pm->entityNum = mapEnt->mapEntityNum; pm->entityNum = mapEnt.mapEntityNum;
pm->brushNum = entitySourceBrushes; pm->brushNum = entitySourceBrushes;
/* set shader */ /* set shader */
@ -329,8 +329,8 @@ void ParsePatch( bool onlyLights ){
pm->maxIterations = maxIterations; pm->maxIterations = maxIterations;
/* link to the entity */ /* link to the entity */
pm->next = mapEnt->patches; pm->next = mapEnt.patches;
mapEnt->patches = pm; mapEnt.patches = pm;
} }

View File

@ -1498,7 +1498,7 @@ inline node_t *AllocNode(){ return new node_t(); }
/* patch.c */ /* patch.c */
void ParsePatch( bool onlyLights ); void ParsePatch( bool onlyLights, entity_t& mapEnt );
void PatchMapDrawSurfs( entity_t *e ); void PatchMapDrawSurfs( entity_t *e );
@ -1812,7 +1812,6 @@ inline const MinMax c_worldMinmax( Vector3( MIN_WORLD_COORD ), Vector3( MAX_WORL
inline int defaultFogNum = -1; /* ydnar: cleaner fog handling */ inline int defaultFogNum = -1; /* ydnar: cleaner fog handling */
inline std::vector<fog_t> mapFogs; inline std::vector<fog_t> mapFogs;
inline entity_t *mapEnt;
inline brush_t buildBrush; inline brush_t buildBrush;
inline EBrushType g_brushType = EBrushType::Undefined; inline EBrushType g_brushType = EBrushType::Undefined;