refactor foliage_t
This commit is contained in:
parent
762699287e
commit
8425ce3c3e
|
|
@ -572,8 +572,7 @@ struct surfaceModel_t
|
||||||
/* ydnar/sd: foliage stuff for wolf et (engine-supported optimization of the above) */
|
/* ydnar/sd: foliage stuff for wolf et (engine-supported optimization of the above) */
|
||||||
struct foliage_t
|
struct foliage_t
|
||||||
{
|
{
|
||||||
foliage_t *next;
|
CopiedString model;
|
||||||
char model[ MAX_QPATH ];
|
|
||||||
float scale, density, odds;
|
float scale, density, odds;
|
||||||
int inverseAlpha;
|
int inverseAlpha;
|
||||||
};
|
};
|
||||||
|
|
@ -643,7 +642,7 @@ struct shaderInfo_t
|
||||||
char *deprecateShader; /* vortex: shader is deprecated and replaced by this on use */
|
char *deprecateShader; /* vortex: shader is deprecated and replaced by this on use */
|
||||||
|
|
||||||
std::list<surfaceModel_t> surfaceModels; /* ydnar: for distribution of models */
|
std::list<surfaceModel_t> surfaceModels; /* ydnar: for distribution of models */
|
||||||
foliage_t *foliage; /* ydnar/splash damage: wolf et foliage */
|
std::list<foliage_t> foliage; /* ydnar/splash damage: wolf et foliage */
|
||||||
|
|
||||||
float subdivisions; /* from a "tesssize xxx" */
|
float subdivisions; /* from a "tesssize xxx" */
|
||||||
float backsplashFraction; /* floating point value, usually 0.05 */
|
float backsplashFraction; /* floating point value, usually 0.05 */
|
||||||
|
|
|
||||||
|
|
@ -1383,26 +1383,21 @@ static void ParseShaderFile( const char *filename ){
|
||||||
|
|
||||||
/* ydnar/sd: q3map_foliage <path to model> <scale> <density> <odds> <invert alpha (1 or 0)> */
|
/* ydnar/sd: q3map_foliage <path to model> <scale> <density> <odds> <invert alpha (1 or 0)> */
|
||||||
else if ( striEqual( token, "q3map_foliage" ) ) {
|
else if ( striEqual( token, "q3map_foliage" ) ) {
|
||||||
foliage_t *foliage;
|
|
||||||
|
|
||||||
|
|
||||||
/* allocate new foliage struct and attach it */
|
/* allocate new foliage struct and attach it */
|
||||||
foliage = safe_calloc( sizeof( *foliage ) );
|
foliage_t& foliage = si->foliage.emplace_back();
|
||||||
foliage->next = si->foliage;
|
|
||||||
si->foliage = foliage;
|
|
||||||
|
|
||||||
/* get parameters */
|
/* get parameters */
|
||||||
GetTokenAppend( shaderText, false );
|
GetTokenAppend( shaderText, false );
|
||||||
strcpy( foliage->model, token );
|
foliage.model = token;
|
||||||
|
|
||||||
GetTokenAppend( shaderText, false );
|
GetTokenAppend( shaderText, false );
|
||||||
foliage->scale = atof( token );
|
foliage.scale = atof( token );
|
||||||
GetTokenAppend( shaderText, false );
|
GetTokenAppend( shaderText, false );
|
||||||
foliage->density = atof( token );
|
foliage.density = atof( token );
|
||||||
GetTokenAppend( shaderText, false );
|
GetTokenAppend( shaderText, false );
|
||||||
foliage->odds = atof( token );
|
foliage.odds = atof( token );
|
||||||
GetTokenAppend( shaderText, false );
|
GetTokenAppend( shaderText, false );
|
||||||
foliage->inverseAlpha = atoi( token );
|
foliage.inverseAlpha = atoi( token );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ydnar: q3map_bounce <value> (fraction of light to re-emit during radiosity passes) */
|
/* ydnar: q3map_bounce <value> (fraction of light to re-emit during radiosity passes) */
|
||||||
|
|
|
||||||
|
|
@ -3571,7 +3571,7 @@ void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree ){
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ydnar/sd: make foliage surfaces */
|
/* ydnar/sd: make foliage surfaces */
|
||||||
if ( si->foliage != NULL ) {
|
if ( !si->foliage.empty() ) {
|
||||||
Foliage( ds );
|
Foliage( ds );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ static foliageInstance_t foliageInstances[ MAX_FOLIAGE_INSTANCES ];
|
||||||
the desired density, then pseudo-randomly sets a point
|
the desired density, then pseudo-randomly sets a point
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage, bspDrawVert_t **tri ){
|
static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, const foliage_t& foliage, bspDrawVert_t **tri ){
|
||||||
bspDrawVert_t mid, *tri2[ 3 ];
|
bspDrawVert_t mid, *tri2[ 3 ];
|
||||||
int max;
|
int max;
|
||||||
|
|
||||||
|
|
@ -110,18 +110,18 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage
|
||||||
}
|
}
|
||||||
|
|
||||||
/* is the triangle small enough? */
|
/* is the triangle small enough? */
|
||||||
if ( maxDist <= ( foliage->density * foliage->density ) ) {
|
if ( maxDist <= ( foliage.density * foliage.density ) ) {
|
||||||
float alpha, odds, r;
|
float alpha, odds, r;
|
||||||
|
|
||||||
|
|
||||||
/* get average alpha */
|
/* get average alpha */
|
||||||
if ( foliage->inverseAlpha == 2 ) {
|
if ( foliage.inverseAlpha == 2 ) {
|
||||||
alpha = 1.0f;
|
alpha = 1.0f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
alpha = ( (float) tri[ 0 ]->color[ 0 ][ 3 ] + (float) tri[ 1 ]->color[ 0 ][ 3 ] + (float) tri[ 2 ]->color[ 0 ][ 3 ] ) / 765.0f;
|
alpha = ( (float) tri[ 0 ]->color[ 0 ][ 3 ] + (float) tri[ 1 ]->color[ 0 ][ 3 ] + (float) tri[ 2 ]->color[ 0 ][ 3 ] ) / 765.0f;
|
||||||
if ( foliage->inverseAlpha == 1 ) {
|
if ( foliage.inverseAlpha == 1 ) {
|
||||||
alpha = 1.0f - alpha;
|
alpha = 1.0f - alpha;
|
||||||
}
|
}
|
||||||
if ( alpha < 0.75f ) {
|
if ( alpha < 0.75f ) {
|
||||||
|
|
@ -130,7 +130,7 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage
|
||||||
}
|
}
|
||||||
|
|
||||||
/* roll the dice */
|
/* roll the dice */
|
||||||
odds = foliage->odds * alpha;
|
odds = foliage.odds * alpha;
|
||||||
r = Random();
|
r = Random();
|
||||||
if ( r > odds ) {
|
if ( r > odds ) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -173,7 +173,6 @@ void Foliage( mapDrawSurface_t *src ){
|
||||||
int i, j, k, x, y, pw[ 5 ], r, oldNumMapDrawSurfs;
|
int i, j, k, x, y, pw[ 5 ], r, oldNumMapDrawSurfs;
|
||||||
mapDrawSurface_t *ds;
|
mapDrawSurface_t *ds;
|
||||||
shaderInfo_t *si;
|
shaderInfo_t *si;
|
||||||
foliage_t *foliage;
|
|
||||||
mesh_t srcMesh, *subdivided, *mesh;
|
mesh_t srcMesh, *subdivided, *mesh;
|
||||||
bspDrawVert_t *verts, *dv[ 3 ], *fi;
|
bspDrawVert_t *verts, *dv[ 3 ], *fi;
|
||||||
vec3_t scale;
|
vec3_t scale;
|
||||||
|
|
@ -182,12 +181,12 @@ void Foliage( mapDrawSurface_t *src ){
|
||||||
|
|
||||||
/* get shader */
|
/* get shader */
|
||||||
si = src->shaderInfo;
|
si = src->shaderInfo;
|
||||||
if ( si == NULL || si->foliage == NULL ) {
|
if ( si == NULL || si->foliage.empty() ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* do every foliage */
|
/* do every foliage */
|
||||||
for ( foliage = si->foliage; foliage != NULL; foliage = foliage->next )
|
for ( const auto& foliage : si->foliage )
|
||||||
{
|
{
|
||||||
/* zero out */
|
/* zero out */
|
||||||
numFoliageInstances = 0;
|
numFoliageInstances = 0;
|
||||||
|
|
@ -272,11 +271,11 @@ void Foliage( mapDrawSurface_t *src ){
|
||||||
oldNumMapDrawSurfs = numMapDrawSurfs;
|
oldNumMapDrawSurfs = numMapDrawSurfs;
|
||||||
|
|
||||||
/* set transform matrix */
|
/* set transform matrix */
|
||||||
VectorSet( scale, foliage->scale, foliage->scale, foliage->scale );
|
VectorSet( scale, foliage.scale, foliage.scale, foliage.scale );
|
||||||
m4x4_scale_for_vec3( transform, scale );
|
m4x4_scale_for_vec3( transform, scale );
|
||||||
|
|
||||||
/* add the model to the bsp */
|
/* add the model to the bsp */
|
||||||
InsertModel( foliage->model, 0, 0, transform, NULL, NULL, src->entityNum, src->castShadows, src->recvShadows, 0, src->lightmapScale, 0, 0, clipDepthGlobal );
|
InsertModel( foliage.model.c_str(), 0, 0, transform, NULL, NULL, src->entityNum, src->castShadows, src->recvShadows, 0, src->lightmapScale, 0, 0, clipDepthGlobal );
|
||||||
|
|
||||||
/* walk each new surface */
|
/* walk each new surface */
|
||||||
for ( i = oldNumMapDrawSurfs; i < numMapDrawSurfs; i++ )
|
for ( i = oldNumMapDrawSurfs; i < numMapDrawSurfs; i++ )
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user