refactor surfaceModel_t
This commit is contained in:
parent
276d1f5875
commit
762699287e
|
|
@ -561,8 +561,7 @@ struct sun_t
|
|||
|
||||
struct surfaceModel_t
|
||||
{
|
||||
surfaceModel_t *next;
|
||||
char model[ MAX_QPATH ];
|
||||
CopiedString model;
|
||||
float density, odds;
|
||||
float minScale, maxScale;
|
||||
float minAngle, maxAngle;
|
||||
|
|
@ -643,7 +642,7 @@ struct shaderInfo_t
|
|||
char *remapShader; /* ydnar: remap a shader in final stage */
|
||||
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 */
|
||||
|
||||
float subdivisions; /* from a "tesssize xxx" */
|
||||
|
|
|
|||
|
|
@ -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)> */
|
||||
else if ( striEqual( token, "q3map_surfacemodel" ) ) {
|
||||
surfaceModel_t *model;
|
||||
|
||||
/* allocate new model and attach it */
|
||||
model = safe_calloc( sizeof( *model ) );
|
||||
model->next = si->surfaceModel;
|
||||
si->surfaceModel = model;
|
||||
surfaceModel_t& model = si->surfaceModels.emplace_back();
|
||||
|
||||
/* get parameters */
|
||||
GetTokenAppend( shaderText, false );
|
||||
strcpy( model->model, token );
|
||||
model.model = token;
|
||||
|
||||
GetTokenAppend( shaderText, false );
|
||||
model->density = atof( token );
|
||||
model.density = atof( token );
|
||||
GetTokenAppend( shaderText, false );
|
||||
model->odds = atof( token );
|
||||
model.odds = atof( token );
|
||||
|
||||
GetTokenAppend( shaderText, false );
|
||||
model->minScale = atof( token );
|
||||
model.minScale = atof( token );
|
||||
GetTokenAppend( shaderText, false );
|
||||
model->maxScale = atof( token );
|
||||
model.maxScale = atof( token );
|
||||
|
||||
GetTokenAppend( shaderText, false );
|
||||
model->minAngle = atof( token );
|
||||
model.minAngle = atof( token );
|
||||
GetTokenAppend( shaderText, false );
|
||||
model->maxAngle = atof( token );
|
||||
model.maxAngle = atof( token );
|
||||
|
||||
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)> */
|
||||
|
|
|
|||
|
|
@ -3123,7 +3123,7 @@ void BiasSurfaceTextures( mapDrawSurface_t *ds ){
|
|||
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 ];
|
||||
int max, n, localNumSurfaceModels;
|
||||
|
||||
|
|
@ -3160,25 +3160,25 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
|
|||
}
|
||||
|
||||
/* 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;
|
||||
vec3_t origin, normal, scale, axis[ 3 ], angles;
|
||||
m4x4_t transform, temp;
|
||||
|
||||
|
||||
/* 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();
|
||||
if ( r > odds ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* calculate scale */
|
||||
r = model->minScale + Random() * ( model->maxScale - model->minScale );
|
||||
r = model.minScale + Random() * ( model.maxScale - model.minScale );
|
||||
VectorSet( scale, r, r, r );
|
||||
|
||||
/* calculate angle */
|
||||
angle = model->minAngle + Random() * ( model->maxAngle - model->minAngle );
|
||||
angle = model.minAngle + Random() * ( model.maxAngle - model.minAngle );
|
||||
|
||||
/* calculate average origin */
|
||||
VectorCopy( tri[ 0 ]->xyz, origin );
|
||||
|
|
@ -3190,7 +3190,7 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
|
|||
m4x4_identity( transform );
|
||||
|
||||
/* handle oriented models */
|
||||
if ( model->oriented ) {
|
||||
if ( model.oriented ) {
|
||||
/* set angles */
|
||||
VectorSet( angles, 0.0f, 0.0f, angle );
|
||||
|
||||
|
|
@ -3235,7 +3235,7 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
|
|||
}
|
||||
|
||||
/* 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 1;
|
||||
|
|
@ -3275,7 +3275,6 @@ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, b
|
|||
*/
|
||||
|
||||
int AddSurfaceModels( mapDrawSurface_t *ds ){
|
||||
surfaceModel_t *model;
|
||||
int i, x, y, n, pw[ 5 ], r, localNumSurfaceModels, iterations;
|
||||
mesh_t src, *mesh, *subdivided;
|
||||
bspDrawVert_t centroid, *tri[ 3 ];
|
||||
|
|
@ -3283,7 +3282,7 @@ int AddSurfaceModels( mapDrawSurface_t *ds ){
|
|||
|
||||
|
||||
/* dummy check */
|
||||
if ( ds == NULL || ds->shaderInfo == NULL || ds->shaderInfo->surfaceModel == NULL ) {
|
||||
if ( ds == NULL || ds->shaderInfo == NULL || ds->shaderInfo->surfaceModels.empty() ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -3291,7 +3290,7 @@ int AddSurfaceModels( mapDrawSurface_t *ds ){
|
|||
localNumSurfaceModels = 0;
|
||||
|
||||
/* 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 ( ds->type )
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user