make whitespace match master better

This commit is contained in:
Rudolf Polzer
2012-05-14 20:57:25 +02:00
parent 9557abbf57
commit cdf98d81c7
5 changed files with 2825 additions and 2825 deletions
+329 -329
View File
File diff suppressed because it is too large Load Diff
+154 -154
View File
@@ -38,7 +38,7 @@
/*
/*
PicoPrintFunc()
callback for picomodel.lib
*/
@@ -49,31 +49,31 @@ void PicoPrintFunc( int level, const char *str ){
}
switch ( level )
{
case PICO_NORMAL:
Sys_Printf( "%s\n", str );
break;
case PICO_VERBOSE:
Sys_FPrintf( SYS_VRB, "%s\n", str );
break;
case PICO_WARNING:
Sys_Printf( "WARNING: %s\n", str );
break;
case PICO_ERROR:
Sys_Printf( "ERROR: %s\n", str );
break;
case PICO_FATAL:
Error( "ERROR: %s\n", str );
break;
case PICO_NORMAL:
Sys_Printf( "%s\n", str );
break;
case PICO_VERBOSE:
Sys_FPrintf( SYS_VRB, "%s\n", str );
break;
case PICO_WARNING:
Sys_Printf( "WARNING: %s\n", str );
break;
case PICO_ERROR:
Sys_Printf( "ERROR: %s\n", str );
break;
case PICO_FATAL:
Error( "ERROR: %s\n", str );
break;
}
}
/*
/*
PicoLoadFileFunc()
callback for picomodel.lib
*/
@@ -90,29 +90,29 @@ void PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize ){
*/
picoModel_t *FindModel( const char *name, int frame ){
int i;
int i;
/* init */
if ( numPicoModels <= 0 ) {
memset( picoModels, 0, sizeof( picoModels ) );
}
/* dummy check */
if ( name == NULL || name[ 0 ] == '\0' ) {
return NULL;
}
/* search list */
for ( i = 0; i < MAX_MODELS; i++ )
{
if ( picoModels[ i ] != NULL &&
!strcmp( PicoGetModelName( picoModels[ i ] ), name ) &&
!strcmp( PicoGetModelName( picoModels[ i ] ), name ) &&
PicoGetModelFrameNum( picoModels[ i ] ) == frame ) {
return picoModels[ i ];
}
}
}
/* no matching picoModel found */
return NULL;
}
@@ -125,44 +125,44 @@ picoModel_t *FindModel( const char *name, int frame ){
*/
picoModel_t *LoadModel( const char *name, int frame ){
int i;
picoModel_t *model, **pm;
int i;
picoModel_t *model, **pm;
/* init */
if ( numPicoModels <= 0 ) {
memset( picoModels, 0, sizeof( picoModels ) );
}
/* dummy check */
if ( name == NULL || name[ 0 ] == '\0' ) {
return NULL;
}
/* try to find existing picoModel */
model = FindModel( name, frame );
if ( model != NULL ) {
return model;
}
/* none found, so find first non-null picoModel */
pm = NULL;
for ( i = 0; i < MAX_MODELS; i++ )
{
{
if ( picoModels[ i ] == NULL ) {
pm = &picoModels[ i ];
break;
}
}
/* too many picoModels? */
if ( pm == NULL ) {
Error( "MAX_MODELS (%d) exceeded, there are too many model files referenced by the map.", MAX_MODELS );
}
/* attempt to parse model */
*pm = PicoLoadModel( name, frame );
/* if loading failed, make a bogus model to silence the rest of the warnings */
if ( *pm == NULL ) {
/* allocate a new model */
@@ -170,19 +170,19 @@ picoModel_t *LoadModel( const char *name, int frame ){
if ( *pm == NULL ) {
return NULL;
}
/* set data */
PicoSetModelName( *pm, name );
PicoSetModelFrameNum( *pm, frame );
}
/* debug code */
#if 0
{
int numSurfaces, numVertexes;
picoSurface_t *ps;
int numSurfaces, numVertexes;
picoSurface_t *ps;
Sys_Printf( "Model %s\n", name );
numSurfaces = PicoGetModelNumSurfaces( *pm );
for ( i = 0; i < numSurfaces; i++ )
@@ -193,12 +193,12 @@ picoModel_t *LoadModel( const char *name, int frame ){
}
}
#endif
/* set count */
if ( *pm != NULL ) {
numPicoModels++;
}
/* return the picoModel */
return *pm;
}
@@ -211,29 +211,29 @@ picoModel_t *LoadModel( const char *name, int frame ){
*/
void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle, vec3_t colormod ){
int i, j, s, numSurfaces;
m4x4_t identity, nTransform;
picoModel_t *model;
picoShader_t *shader;
picoSurface_t *surface;
shaderInfo_t *si;
mapDrawSurface_t *ds;
bspDrawVert_t *dv;
char *picoShaderName;
char shaderName[ MAX_QPATH ];
picoVec_t *xyz, *normal, *st;
byte *color;
picoIndex_t *indexes;
remap_t *rm, *glob;
skinfile_t *sf, *sf2;
double normalEpsilon_save;
double distanceEpsilon_save;
char skinfilename[ MAX_QPATH ];
char *skinfilecontent;
int skinfilesize;
char *skinfileptr, *skinfilenextptr;
int i, j, s, numSurfaces;
m4x4_t identity, nTransform;
picoModel_t *model;
picoShader_t *shader;
picoSurface_t *surface;
shaderInfo_t *si;
mapDrawSurface_t *ds;
bspDrawVert_t *dv;
char *picoShaderName;
char shaderName[ MAX_QPATH ];
picoVec_t *xyz, *normal, *st;
byte *color;
picoIndex_t *indexes;
remap_t *rm, *glob;
skinfile_t *sf, *sf2;
double normalEpsilon_save;
double distanceEpsilon_save;
char skinfilename[ MAX_QPATH ];
char *skinfilecontent;
int skinfilesize;
char *skinfileptr, *skinfilenextptr;
/* get model */
model = LoadModel( name, frame );
if ( model == NULL ) {
@@ -251,7 +251,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
skinfilesize = vfsLoadFile( skinfilename, (void**) &skinfilecontent, 0 );
if ( skinfilesize >= 0 ) {
Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name );
}
}
}
sf = NULL;
if ( skinfilesize >= 0 ) {
@@ -298,25 +298,25 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
}
free( skinfilecontent );
}
/* handle null matrix */
if ( transform == NULL ) {
m4x4_identity( identity );
transform = identity;
}
/* hack: Stable-1_2 and trunk have differing row/column major matrix order
this transpose is necessary with Stable-1_2
uncomment the following line with old m4x4_t (non 1.3/spog_branch) code */
//% m4x4_transpose( transform );
/* create transform matrix for normals */
memcpy( nTransform, transform, sizeof( m4x4_t ) );
if ( m4x4_invert( nTransform ) ) {
Sys_FPrintf( SYS_VRB, "WARNING: Can't invert model transform matrix, using transpose instead\n" );
}
m4x4_transpose( nTransform );
/* fix bogus lightmap scale */
if ( lightmapScale <= 0.0f ) {
lightmapScale = 1.0f;
@@ -326,7 +326,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
if ( shadeAngle <= 0.0f ) {
shadeAngle = 0.0f;
}
/* each surface on the model will become a new map drawsurface */
numSurfaces = PicoGetModelNumSurfaces( model );
//% Sys_FPrintf( SYS_VRB, "Model %s has %d surfaces\n", name, numSurfaces );
@@ -337,14 +337,14 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
if ( surface == NULL ) {
continue;
}
/* only handle triangle surfaces initially (fixme: support patches) */
if ( PicoGetSurfaceType( surface ) != PICO_TRIANGLES ) {
continue;
}
/* get shader name */
shader = PicoGetSurfaceShader( surface );
shader = PicoGetSurfaceShader( surface );
if ( shader == NULL ) {
picoShaderName = "";
}
@@ -356,7 +356,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
if ( sf ) {
picoShaderName = NULL;
for ( sf2 = sf; sf2 != NULL; sf2 = sf2->next )
{
{
if ( !Q_stricmp( surface->name, sf2->name ) ) {
Sys_FPrintf( SYS_VRB, "Skin file: mapping %s to %s\n", surface->name, sf2->to );
picoShaderName = sf2->to;
@@ -383,12 +383,12 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
break;
}
}
if ( glob != NULL ) {
Sys_FPrintf( SYS_VRB, "Globbing %s to %s\n", picoShaderName, glob->to );
picoShaderName = glob->to;
}
/* shader renaming for sof2 */
if ( renameModelShaders ) {
strcpy( shaderName, picoShaderName );
@@ -404,7 +404,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
else{
si = ShaderInfoForShader( picoShaderName );
}
/* allocate a surface (ydnar: gs mods) */
ds = AllocDrawSurface( SURFACE_TRIANGLES );
ds->entityNum = eNum;
@@ -428,7 +428,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
if ( lightmapSampleSize > 0.0f ) {
ds->sampleSize = lightmapSampleSize;
}
/* set lightmap scale */
if ( lightmapScale > 0.0f ) {
ds->lightmapScale = lightmapScale;
@@ -441,27 +441,27 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
if ( shadeAngle > 0.0f ) {
ds->shadeAngleDegrees = shadeAngle;
}
/* set particulars */
ds->numVerts = PicoGetSurfaceNumVertexes( surface );
ds->verts = safe_malloc( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
memset( ds->verts, 0, ds->numVerts * sizeof( ds->verts[ 0 ] ) );
ds->numIndexes = PicoGetSurfaceNumIndexes( surface );
ds->indexes = safe_malloc( ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
memset( ds->indexes, 0, ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
/* copy vertexes */
for ( i = 0; i < ds->numVerts; i++ )
{
/* get vertex */
dv = &ds->verts[ i ];
/* xyz and normal */
xyz = PicoGetSurfaceXYZ( surface, i );
VectorCopy( xyz, dv->xyz );
m4x4_transform_point( transform, dv->xyz );
normal = PicoGetSurfaceNormal( surface, i );
VectorCopy( normal, dv->normal );
m4x4_transform_normal( nTransform, dv->normal );
@@ -472,14 +472,14 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
dv->st[ 0 ] = si->stFlat[ 0 ];
dv->st[ 1 ] = si->stFlat[ 1 ];
}
/* ydnar: gs mods: added support for explicit shader texcoord generation */
else if ( si->tcGen ) {
/* project the texture */
dv->st[ 0 ] = DotProduct( si->vecs[ 0 ], dv->xyz );
dv->st[ 1 ] = DotProduct( si->vecs[ 1 ], dv->xyz );
}
/* normal texture coordinates */
else
{
@@ -487,7 +487,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
dv->st[ 0 ] = st[ 0 ];
dv->st[ 1 ] = st[ 1 ];
}
/* set lightmap/color bits */
color = PicoGetSurfaceColor( surface, 0, i );
for ( j = 0; j < MAX_LIGHTMAPS; j++ )
@@ -509,44 +509,44 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
}
}
}
/* copy indexes */
indexes = PicoGetSurfaceIndexes( surface, 0 );
for ( i = 0; i < ds->numIndexes; i++ )
ds->indexes[ i ] = indexes[ i ];
/* set cel shader */
ds->celShader = celShader;
/* ydnar: giant hack land: generate clipping brushes for model triangles */
if ( si->clipModel || ( spawnFlags & 2 ) ) { /* 2nd bit */
vec3_t points[ 4 ], backs[ 3 ];
vec4_t plane, reverse, pa, pb, pc;
vec3_t points[ 4 ], backs[ 3 ];
vec4_t plane, reverse, pa, pb, pc;
/* temp hack */
if ( !si->clipModel && !( si->compileFlags & C_SOLID ) ) {
continue;
}
/* walk triangle list */
for ( i = 0; i < ds->numIndexes; i += 3 )
{
/* overflow hack */
AUTOEXPAND_BY_REALLOC( mapplanes, ( nummapplanes + 64 ) << 1, allocatedmapplanes, 1024 );
/* make points and back points */
for ( j = 0; j < 3; j++ )
{
/* get vertex */
dv = &ds->verts[ ds->indexes[ i + j ] ];
/* copy xyz */
VectorCopy( dv->xyz, points[ j ] );
}
VectorCopy( points[0], points[3] ); // for cyclic usage
/* make plane for triangle */
// div0: add some extra spawnflags:
// 0: snap normals to axial planes for extrusion
@@ -617,7 +617,7 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
}
if ( distanceEpsilon > 0 ) {
distanceEpsilon = 0;
}
}
}
else{
buildBrush->detail = qtrue;
@@ -642,13 +642,13 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
// that's at least sqrt(1/3) backPlaneDistance, unless in DOWN mode; in DOWN mode, we are screwed anyway if we encounter a plane that's perpendicular to the xy plane)
if ( PlaneFromPoints( pa, points[ 2 ], points[ 1 ], backs[ 1 ] ) &&
PlaneFromPoints( pb, points[ 1 ], points[ 0 ], backs[ 0 ] ) &&
PlaneFromPoints( pb, points[ 1 ], points[ 0 ], backs[ 0 ] ) &&
PlaneFromPoints( pc, points[ 0 ], points[ 2 ], backs[ 2 ] ) ) {
/* set up brush sides */
buildBrush->numsides = 5;
buildBrush->sides[ 0 ].shaderInfo = si;
for ( j = 1; j < buildBrush->numsides; j++ )
buildBrush->sides[ j ].shaderInfo = NULL; // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works
buildBrush->sides[ j ].shaderInfo = NULL; // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works
buildBrush->sides[ 0 ].planenum = FindFloatPlane( plane, plane[ 3 ], 3, points );
buildBrush->sides[ 1 ].planenum = FindFloatPlane( pa, pa[ 3 ], 2, &points[ 1 ] ); // pa contains points[1] and points[2]
@@ -675,11 +675,11 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
}
else{
free( buildBrush );
}
}
}
}
}
}
}
@@ -690,25 +690,25 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
*/
void AddTriangleModels( entity_t *e ){
int num, frame, skin, castShadows, recvShadows, spawnFlags;
entity_t *e2;
const char *targetName;
const char *target, *model, *value;
char shader[ MAX_QPATH ];
shaderInfo_t *celShader;
float temp, baseLightmapScale, lightmapScale;
float shadeAngle;
int lightmapSampleSize;
vec3_t origin, scale, angles;
m4x4_t transform;
epair_t *ep;
remap_t *remap, *remap2;
char *split;
int num, frame, skin, castShadows, recvShadows, spawnFlags;
entity_t *e2;
const char *targetName;
const char *target, *model, *value;
char shader[ MAX_QPATH ];
shaderInfo_t *celShader;
float temp, baseLightmapScale, lightmapScale;
float shadeAngle;
int lightmapSampleSize;
vec3_t origin, scale, angles;
m4x4_t transform;
epair_t *ep;
remap_t *remap, *remap2;
char *split;
/* note it */
Sys_FPrintf( SYS_VRB, "--- AddTriangleModels ---\n" );
/* get current brush entity targetname */
if ( e == entities ) {
targetName = "";
@@ -716,18 +716,18 @@ void AddTriangleModels( entity_t *e ){
else
{
targetName = ValueForKey( e, "targetname" );
/* misc_model entities target non-worldspawn brush model entities */
if ( targetName[ 0 ] == '\0' ) {
return;
}
}
}
/* get lightmap scale */
/* vortex: added _ls key (short name of lightmapscale) */
baseLightmapScale = 0.0f;
if ( strcmp( "", ValueForKey( e, "lightmapscale" ) ) ||
strcmp( "", ValueForKey( e, "_lightmapscale" ) ) ||
strcmp( "", ValueForKey( e, "_lightmapscale" ) ) ||
strcmp( "", ValueForKey( e, "_ls" ) ) ) {
baseLightmapScale = FloatForKey( e, "lightmapscale" );
if ( baseLightmapScale <= 0.0f ) {
@@ -741,16 +741,16 @@ void AddTriangleModels( entity_t *e ){
}
if ( baseLightmapScale > 0.0f ) {
Sys_Printf( "World Entity has lightmap scale of %.4f\n", baseLightmapScale );
}
}
}
/* walk the entity list */
for ( num = 1; num < numEntities; num++ )
{
/* get e2 */
e2 = &entities[ num ];
/* convert misc_models into raw geometry */
if ( Q_stricmp( "misc_model", ValueForKey( e2, "classname" ) ) ) {
continue;
@@ -761,15 +761,15 @@ void AddTriangleModels( entity_t *e ){
if ( strcmp( target, targetName ) ) {
continue;
}
/* get model name */
model = ValueForKey( e2, "model" );
if ( model[ 0 ] == '\0' ) {
Sys_Printf( "WARNING: misc_model at %i %i %i without a model key\n",
(int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] );
(int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] );
continue;
}
/* get model frame */
frame = 0;
if ( strcmp( "", ValueForKey( e2, "_frame" ) ) ) {
@@ -778,30 +778,30 @@ void AddTriangleModels( entity_t *e ){
else if ( strcmp( "", ValueForKey( e2, "frame" ) ) ) {
frame = IntForKey( e2, "frame" );
}
/* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
if ( e == entities ) {
castShadows = WORLDSPAWN_CAST_SHADOWS;
recvShadows = WORLDSPAWN_RECV_SHADOWS;
}
/* other entities don't cast any shadows, but recv worldspawn shadows */
else
{
castShadows = ENTITY_CAST_SHADOWS;
recvShadows = ENTITY_RECV_SHADOWS;
}
/* get explicit shadow flags */
GetEntityShadowFlags( e2, e, &castShadows, &recvShadows );
/* get spawnflags */
spawnFlags = IntForKey( e2, "spawnflags" );
/* get origin */
GetVectorForKey( e2, "origin", origin );
VectorSubtract( origin, e->origin, origin ); /* offset by parent */
VectorSubtract( origin, e->origin, origin ); /* offset by parent */
/* get scale */
scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = 1.0f;
temp = FloatForKey( e2, "modelscale" );
@@ -812,7 +812,7 @@ void AddTriangleModels( entity_t *e ){
if ( value[ 0 ] != '\0' ) {
sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] );
}
/* get "angle" (yaw) or "angles" (pitch yaw roll) */
angles[ 0 ] = angles[ 1 ] = angles[ 2 ] = 0.0f;
angles[ 2 ] = FloatForKey( e2, "angle" );
@@ -820,25 +820,25 @@ void AddTriangleModels( entity_t *e ){
if ( value[ 0 ] != '\0' ) {
sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] );
}
/* set transform matrix (thanks spog) */
m4x4_identity( transform );
m4x4_pivoted_transform_by_vec3( transform, origin, angles, eXYZ, scale, vec3_origin );
/* get shader remappings */
remap = NULL;
for ( ep = e2->epairs; ep != NULL; ep = ep->next )
{
/* look for keys prefixed with "_remap" */
if ( ep->key != NULL && ep->value != NULL &&
ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' &&
ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' &&
!Q_strncasecmp( ep->key, "_remap", 6 ) ) {
/* create new remapping */
remap2 = remap;
remap = safe_malloc( sizeof( *remap ) );
remap->next = remap2;
strcpy( remap->from, ep->value );
/* split the string */
split = strchr( remap->from, ';' );
if ( split == NULL ) {
@@ -847,16 +847,16 @@ void AddTriangleModels( entity_t *e ){
remap = remap2;
continue;
}
/* store the split */
*split = '\0';
strcpy( remap->to, ( split + 1 ) );
/* note it */
//% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", remap->from, remap->to );
}
}
/* ydnar: cel shader support */
value = ValueForKey( e2, "_celshader" );
if ( value[ 0 ] == '\0' ) {
@@ -891,7 +891,7 @@ void AddTriangleModels( entity_t *e ){
/* vortex: added _ls key (short name of lightmapscale) */
lightmapScale = 0.0f;
if ( strcmp( "", ValueForKey( e2, "lightmapscale" ) ) ||
strcmp( "", ValueForKey( e2, "_lightmapscale" ) ) ||
strcmp( "", ValueForKey( e2, "_lightmapscale" ) ) ||
strcmp( "", ValueForKey( e2, "_ls" ) ) ) {
lightmapScale = FloatForKey( e2, "lightmapscale" );
if ( lightmapScale <= 0.0f ) {
@@ -905,7 +905,7 @@ void AddTriangleModels( entity_t *e ){
}
if ( lightmapScale > 0.0f ) {
Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale );
}
}
}
/* jal : entity based _shadeangle */
@@ -942,7 +942,7 @@ void AddTriangleModels( entity_t *e ){
/* insert the model */
InsertModel( model, skin, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale, lightmapSampleSize, shadeAngle, colormod );
/* free shader remappings */
while ( remap != NULL )
{
+1355 -1355
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+113 -113
View File
@@ -37,10 +37,10 @@
#define MAX_FOLIAGE_INSTANCES 8192
#define MAX_FOLIAGE_INSTANCES 8192
static int numFoliageInstances;
static foliageInstance_t foliageInstances[ MAX_FOLIAGE_INSTANCES ];
static int numFoliageInstances;
static foliageInstance_t foliageInstances[ MAX_FOLIAGE_INSTANCES ];
@@ -51,41 +51,41 @@ static foliageInstance_t foliageInstances[ MAX_FOLIAGE_INSTANCES ];
*/
static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage, bspDrawVert_t **tri ){
bspDrawVert_t mid, *tri2[ 3 ];
int max;
bspDrawVert_t mid, *tri2[ 3 ];
int max;
/* limit test */
if ( numFoliageInstances >= MAX_FOLIAGE_INSTANCES ) {
return;
}
/* plane test */
{
vec4_t plane;
vec4_t plane;
/* make a plane */
if ( !PlaneFromPoints( plane, tri[ 0 ]->xyz, tri[ 1 ]->xyz, tri[ 2 ]->xyz ) ) {
return;
}
/* if normal is too far off vertical, then don't place an instance */
if ( plane[ 2 ] < 0.5f ) {
return;
}
}
}
/* subdivide calc */
{
int i;
float *a, *b, dx, dy, dz, dist, maxDist;
foliageInstance_t *fi;
int i;
float *a, *b, dx, dy, dz, dist, maxDist;
foliageInstance_t *fi;
/* get instance */
fi = &foliageInstances[ numFoliageInstances ];
/* find the longest edge and split it */
max = -1;
maxDist = 0.0f;
@@ -96,29 +96,29 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage
/* get verts */
a = tri[ i ]->xyz;
b = tri[ ( i + 1 ) % 3 ]->xyz;
/* get dists */
dx = a[ 0 ] - b[ 0 ];
dy = a[ 1 ] - b[ 1 ];
dz = a[ 2 ] - b[ 2 ];
dist = ( dx * dx ) + ( dy * dy ) + ( dz * dz );
/* longer? */
if ( dist > maxDist ) {
maxDist = dist;
max = i;
}
/* add to centroid */
VectorAdd( fi->xyz, tri[ i ]->xyz, fi->xyz );
VectorAdd( fi->normal, tri[ i ]->normal, fi->normal );
}
/* is the triangle small enough? */
if ( maxDist <= ( foliage->density * foliage->density ) ) {
float alpha, odds, r;
float alpha, odds, r;
/* get average alpha */
if ( foliage->inverseAlpha == 2 ) {
alpha = 1.0f;
@@ -131,36 +131,36 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage
}
if ( alpha < 0.75f ) {
return;
}
}
}
/* roll the dice */
odds = foliage->odds * alpha;
r = Random();
if ( r > odds ) {
return;
}
/* scale centroid */
VectorScale( fi->xyz, 0.33333333f, fi->xyz );
if ( VectorNormalize( fi->normal, fi->normal ) == 0.0f ) {
return;
}
/* add to count and return */
numFoliageInstances++;
return;
}
}
/* split the longest edge and map it */
LerpDrawVert( tri[ max ], tri[ ( max + 1 ) % 3 ], &mid );
/* recurse to first triangle */
VectorCopy( tri, tri2 );
tri2[ max ] = &mid;
SubdivideFoliageTriangle_r( ds, foliage, tri2 );
/* recurse to second triangle */
VectorCopy( tri, tri2 );
tri2[ ( max + 1 ) % 3 ] = &mid;
@@ -175,138 +175,138 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage
*/
void Foliage( mapDrawSurface_t *src ){
int i, j, k, x, y, pw[ 5 ], r, oldNumMapDrawSurfs;
mapDrawSurface_t *ds;
shaderInfo_t *si;
foliage_t *foliage;
mesh_t srcMesh, *subdivided, *mesh;
bspDrawVert_t *verts, *dv[ 3 ], *fi;
vec3_t scale;
m4x4_t transform;
int i, j, k, x, y, pw[ 5 ], r, oldNumMapDrawSurfs;
mapDrawSurface_t *ds;
shaderInfo_t *si;
foliage_t *foliage;
mesh_t srcMesh, *subdivided, *mesh;
bspDrawVert_t *verts, *dv[ 3 ], *fi;
vec3_t scale;
m4x4_t transform;
/* get shader */
si = src->shaderInfo;
if ( si == NULL || si->foliage == NULL ) {
return;
}
/* do every foliage */
for ( foliage = si->foliage; foliage != NULL; foliage = foliage->next )
{
/* zero out */
numFoliageInstances = 0;
/* map the surface onto the lightmap origin/cluster/normal buffers */
switch ( src->type )
{
case SURFACE_META:
case SURFACE_FORCED_META:
case SURFACE_TRIANGLES:
/* get verts */
verts = src->verts;
/* map the triangles */
case SURFACE_META:
case SURFACE_FORCED_META:
case SURFACE_TRIANGLES:
/* get verts */
verts = src->verts;
/* map the triangles */
for ( i = 0; i < src->numIndexes; i += 3 )
{
dv[ 0 ] = &verts[ src->indexes[ i ] ];
dv[ 1 ] = &verts[ src->indexes[ i + 1 ] ];
dv[ 2 ] = &verts[ src->indexes[ i + 2 ] ];
SubdivideFoliageTriangle_r( src, foliage, dv );
}
break;
case SURFACE_PATCH:
/* make a mesh from the drawsurf */
srcMesh.width = src->patchWidth;
srcMesh.height = src->patchHeight;
srcMesh.verts = src->verts;
subdivided = SubdivideMesh( srcMesh, 8, 512 );
/* fit it to the curve and remove colinear verts on rows/columns */
PutMeshOnCurve( *subdivided );
mesh = RemoveLinearMeshColumnsRows( subdivided );
FreeMesh( subdivided );
/* get verts */
verts = mesh->verts;
/* map the mesh quads */
{
dv[ 0 ] = &verts[ src->indexes[ i ] ];
dv[ 1 ] = &verts[ src->indexes[ i + 1 ] ];
dv[ 2 ] = &verts[ src->indexes[ i + 2 ] ];
SubdivideFoliageTriangle_r( src, foliage, dv );
}
break;
case SURFACE_PATCH:
/* make a mesh from the drawsurf */
srcMesh.width = src->patchWidth;
srcMesh.height = src->patchHeight;
srcMesh.verts = src->verts;
subdivided = SubdivideMesh( srcMesh, 8, 512 );
/* fit it to the curve and remove colinear verts on rows/columns */
PutMeshOnCurve( *subdivided );
mesh = RemoveLinearMeshColumnsRows( subdivided );
FreeMesh( subdivided );
/* get verts */
verts = mesh->verts;
/* map the mesh quads */
for ( y = 0; y < ( mesh->height - 1 ); y++ )
{
{
for ( x = 0; x < ( mesh->width - 1 ); x++ )
{
/* set indexes */
{
/* set indexes */
pw[ 0 ] = x + ( y * mesh->width );
pw[ 1 ] = x + ( ( y + 1 ) * mesh->width );
pw[ 2 ] = x + 1 + ( ( y + 1 ) * mesh->width );
pw[ 3 ] = x + 1 + ( y * mesh->width );
pw[ 4 ] = x + ( y * mesh->width ); /* same as pw[ 0 ] */
/* set radix */
/* set radix */
r = ( x + y ) & 1;
/* get drawverts and map first triangle */
dv[ 0 ] = &verts[ pw[ r + 0 ] ];
dv[ 1 ] = &verts[ pw[ r + 1 ] ];
dv[ 2 ] = &verts[ pw[ r + 2 ] ];
SubdivideFoliageTriangle_r( src, foliage, dv );
/* get drawverts and map second triangle */
dv[ 0 ] = &verts[ pw[ r + 0 ] ];
dv[ 1 ] = &verts[ pw[ r + 2 ] ];
dv[ 2 ] = &verts[ pw[ r + 3 ] ];
SubdivideFoliageTriangle_r( src, foliage, dv );
}
/* get drawverts and map first triangle */
dv[ 0 ] = &verts[ pw[ r + 0 ] ];
dv[ 1 ] = &verts[ pw[ r + 1 ] ];
dv[ 2 ] = &verts[ pw[ r + 2 ] ];
SubdivideFoliageTriangle_r( src, foliage, dv );
/* get drawverts and map second triangle */
dv[ 0 ] = &verts[ pw[ r + 0 ] ];
dv[ 1 ] = &verts[ pw[ r + 2 ] ];
dv[ 2 ] = &verts[ pw[ r + 3 ] ];
SubdivideFoliageTriangle_r( src, foliage, dv );
}
/* free the mesh */
FreeMesh( mesh );
break;
default:
break;
}
/* free the mesh */
FreeMesh( mesh );
break;
default:
break;
}
/* any origins? */
if ( numFoliageInstances < 1 ) {
continue;
}
/* remember surface count */
oldNumMapDrawSurfs = numMapDrawSurfs;
/* set transform matrix */
VectorSet( scale, foliage->scale, foliage->scale, foliage->scale );
m4x4_scale_for_vec3( transform, scale );
/* 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, src->colormod );
/* walk each new surface */
for ( i = oldNumMapDrawSurfs; i < numMapDrawSurfs; i++ )
{
/* get surface */
ds = &mapDrawSurfs[ i ];
/* set up */
ds->type = SURFACE_FOLIAGE;
ds->numFoliageInstances = numFoliageInstances;
/* a wee hack */
ds->patchWidth = ds->numFoliageInstances;
ds->patchHeight = ds->numVerts;
/* set fog to be same as source surface */
ds->fogNum = src->fogNum;
/* add a drawvert for every instance */
verts = safe_malloc( ( ds->numVerts + ds->numFoliageInstances ) * sizeof( *verts ) );
memset( verts, 0, ( ds->numVerts + ds->numFoliageInstances ) * sizeof( *verts ) );
memcpy( verts, ds->verts, ds->numVerts * sizeof( *verts ) );
free( ds->verts );
ds->verts = verts;
/* copy the verts */
for ( j = 0; j < ds->numFoliageInstances; j++ )
{
@@ -326,7 +326,7 @@ void Foliage( mapDrawSurface_t *src ){
fi->color[ k ][ 3 ] = 255;
}
}
/* increment */
ds->numVerts += ds->numFoliageInstances;
}