refactor surfaceModel_t

This commit is contained in:
Garux 2021-01-29 21:11:56 +03:00
parent 276d1f5875
commit 762699287e
3 changed files with 20 additions and 26 deletions

View File

@ -561,8 +561,7 @@ struct sun_t
struct surfaceModel_t struct surfaceModel_t
{ {
surfaceModel_t *next; CopiedString model;
char model[ MAX_QPATH ];
float density, odds; float density, odds;
float minScale, maxScale; float minScale, maxScale;
float minAngle, maxAngle; float minAngle, maxAngle;
@ -643,7 +642,7 @@ struct shaderInfo_t
char *remapShader; /* ydnar: remap a shader in final stage */ char *remapShader; /* ydnar: remap a shader in final stage */
char *deprecateShader; /* vortex: shader is deprecated and replaced by this on use */ char *deprecateShader; /* vortex: shader is deprecated and replaced by this on use */
surfaceModel_t *surfaceModel; /* ydnar: for distribution of models */ std::list<surfaceModel_t> surfaceModels; /* ydnar: for distribution of models */
foliage_t *foliage; /* ydnar/splash damage: wolf et foliage */ foliage_t *foliage; /* ydnar/splash damage: wolf et foliage */
float subdivisions; /* from a "tesssize xxx" */ float subdivisions; /* from a "tesssize xxx" */

View File

@ -1355,34 +1355,30 @@ static void ParseShaderFile( const char *filename ){
/* ydnar: q3map_surfacemodel <path to model> <density> <min scale> <max scale> <min angle> <max angle> <oriented (0 or 1)> */ /* ydnar: q3map_surfacemodel <path to model> <density> <min scale> <max scale> <min angle> <max angle> <oriented (0 or 1)> */
else if ( striEqual( token, "q3map_surfacemodel" ) ) { else if ( striEqual( token, "q3map_surfacemodel" ) ) {
surfaceModel_t *model;
/* allocate new model and attach it */ /* allocate new model and attach it */
model = safe_calloc( sizeof( *model ) ); surfaceModel_t& model = si->surfaceModels.emplace_back();
model->next = si->surfaceModel;
si->surfaceModel = model;
/* get parameters */ /* get parameters */
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
strcpy( model->model, token ); model.model = token;
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
model->density = atof( token ); model.density = atof( token );
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
model->odds = atof( token ); model.odds = atof( token );
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
model->minScale = atof( token ); model.minScale = atof( token );
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
model->maxScale = atof( token ); model.maxScale = atof( token );
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
model->minAngle = atof( token ); model.minAngle = atof( token );
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
model->maxAngle = atof( token ); model.maxAngle = atof( token );
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
model->oriented = ( token[ 0 ] == '1' ); model.oriented = ( token[ 0 ] == '1' );
} }
/* 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)> */

View File

@ -3123,7 +3123,7 @@ void BiasSurfaceTextures( mapDrawSurface_t *ds ){
adds models to a specified triangle, returns the number of models added adds models to a specified triangle, returns the number of models added
*/ */
int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, bspDrawVert_t **tri ){ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, const surfaceModel_t& model, bspDrawVert_t **tri ){
bspDrawVert_t mid, *tri2[ 3 ]; bspDrawVert_t mid, *tri2[ 3 ];
int max, n, localNumSurfaceModels; int max, n, localNumSurfaceModels;
@ -3160,25 +3160,25 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
} }
/* is the triangle small enough? */ /* is the triangle small enough? */
if ( max < 0 || maxDist <= ( model->density * model->density ) ) { if ( max < 0 || maxDist <= ( model.density * model.density ) ) {
float odds, r, angle; float odds, r, angle;
vec3_t origin, normal, scale, axis[ 3 ], angles; vec3_t origin, normal, scale, axis[ 3 ], angles;
m4x4_t transform, temp; m4x4_t transform, temp;
/* roll the dice (model's odds scaled by vertex alpha) */ /* roll the dice (model's odds scaled by vertex alpha) */
odds = model->odds * ( tri[ 0 ]->color[ 0 ][ 3 ] + tri[ 0 ]->color[ 0 ][ 3 ] + tri[ 0 ]->color[ 0 ][ 3 ] ) / 765.0f; odds = model.odds * ( tri[ 0 ]->color[ 0 ][ 3 ] + tri[ 0 ]->color[ 0 ][ 3 ] + tri[ 0 ]->color[ 0 ][ 3 ] ) / 765.0f;
r = Random(); r = Random();
if ( r > odds ) { if ( r > odds ) {
return 0; return 0;
} }
/* calculate scale */ /* calculate scale */
r = model->minScale + Random() * ( model->maxScale - model->minScale ); r = model.minScale + Random() * ( model.maxScale - model.minScale );
VectorSet( scale, r, r, r ); VectorSet( scale, r, r, r );
/* calculate angle */ /* calculate angle */
angle = model->minAngle + Random() * ( model->maxAngle - model->minAngle ); angle = model.minAngle + Random() * ( model.maxAngle - model.minAngle );
/* calculate average origin */ /* calculate average origin */
VectorCopy( tri[ 0 ]->xyz, origin ); VectorCopy( tri[ 0 ]->xyz, origin );
@ -3190,7 +3190,7 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
m4x4_identity( transform ); m4x4_identity( transform );
/* handle oriented models */ /* handle oriented models */
if ( model->oriented ) { if ( model.oriented ) {
/* set angles */ /* set angles */
VectorSet( angles, 0.0f, 0.0f, angle ); VectorSet( angles, 0.0f, 0.0f, angle );
@ -3235,7 +3235,7 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
} }
/* insert the model */ /* insert the model */
InsertModel( model->model, 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, ds->entityNum, ds->castShadows, ds->recvShadows, 0, ds->lightmapScale, 0, 0, clipDepthGlobal );
/* return to sender */ /* return to sender */
return 1; return 1;
@ -3275,7 +3275,6 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
*/ */
int AddSurfaceModels( mapDrawSurface_t *ds ){ int AddSurfaceModels( mapDrawSurface_t *ds ){
surfaceModel_t *model;
int i, x, y, n, pw[ 5 ], r, localNumSurfaceModels, iterations; int i, x, y, n, pw[ 5 ], r, localNumSurfaceModels, iterations;
mesh_t src, *mesh, *subdivided; mesh_t src, *mesh, *subdivided;
bspDrawVert_t centroid, *tri[ 3 ]; bspDrawVert_t centroid, *tri[ 3 ];
@ -3283,7 +3282,7 @@ int AddSurfaceModels( mapDrawSurface_t *ds ){
/* dummy check */ /* dummy check */
if ( ds == NULL || ds->shaderInfo == NULL || ds->shaderInfo->surfaceModel == NULL ) { if ( ds == NULL || ds->shaderInfo == NULL || ds->shaderInfo->surfaceModels.empty() ) {
return 0; return 0;
} }
@ -3291,7 +3290,7 @@ int AddSurfaceModels( mapDrawSurface_t *ds ){
localNumSurfaceModels = 0; localNumSurfaceModels = 0;
/* walk the model list */ /* walk the model list */
for ( model = ds->shaderInfo->surfaceModel; model != NULL; model = model->next ) for ( const auto& model : ds->shaderInfo->surfaceModels )
{ {
/* switch on type */ /* switch on type */
switch ( ds->type ) switch ( ds->type )