From 4242e2adcda518c075e4987bd587c8f9ddde6137 Mon Sep 17 00:00:00 2001 From: g-cont Date: Sat, 13 Sep 2008 00:00:00 +0400 Subject: [PATCH] 13 Sep 2008 --- common/bsplib/bspfile.c | 2 +- common/bsplib/bsplib.h | 5 +- common/bsplib/light_trace.c | 539 +++++++++++++++++++----------------- common/bsplib/map.c | 6 +- common/bsplib/qbsp3.c | 2 - common/bsplib/qrad3.c | 10 +- common/bsplib/shaders.c | 2 +- common/common.dsp | 4 + common/common.plg | 125 --------- physic/cm_model.c | 18 -- public/ref_dfiles.h | 1 - 11 files changed, 310 insertions(+), 404 deletions(-) delete mode 100644 common/common.plg diff --git a/common/bsplib/bspfile.c b/common/bsplib/bspfile.c index f192f29b..782606d5 100644 --- a/common/bsplib/bspfile.c +++ b/common/bsplib/bspfile.c @@ -240,7 +240,7 @@ bool LoadBSPFile( void ) { byte *buffer; - buffer = (byte *)FS_LoadFile( va("maps/%.bsp", gs_filename ), NULL ); + buffer = (byte *)FS_LoadFile( va("maps/%s.bsp", gs_filename ), NULL ); if( !buffer ) return false; header = (dheader_t *)buffer; // load the file header diff --git a/common/bsplib/bsplib.h b/common/bsplib/bsplib.h index 858eeca6..8dd37023 100644 --- a/common/bsplib/bsplib.h +++ b/common/bsplib/bsplib.h @@ -419,7 +419,6 @@ bool LoadBSPFile ( void ); void WriteBSPFile ( void ); //============================================================================= - // // terrain.c // @@ -665,8 +664,6 @@ typedef struct vec3_t origin; float radius; - bool patch; - int numFacets; cFacet_t *facets; bsp_shader_t *shader; // for translucency @@ -710,4 +707,6 @@ typedef struct } lightmap_t; +bool PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c ); + #endif//BSPLIB_H \ No newline at end of file diff --git a/common/bsplib/light_trace.c b/common/bsplib/light_trace.c index d71fe208..e636110e 100644 --- a/common/bsplib/light_trace.c +++ b/common/bsplib/light_trace.c @@ -4,6 +4,7 @@ //======================================================================= #include "bsplib.h" +#include "const.h" #define CURVE_FACET_ERROR 8 @@ -13,6 +14,31 @@ int c_testFacets; surfaceTest_t *surfaceTest[MAX_MAP_SURFACES]; + +/* +===================== +PlaneFromPoints + +Returns false if the triangle is degenrate. +The normal will point out of the clock for clockwise ordered points +===================== +*/ +bool PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c ) +{ + vec3_t d1, d2; + + VectorSubtract( b, a, d1 ); + VectorSubtract( c, a, d2 ); + CrossProduct( d2, d1, plane ); + if( VectorNormalizeLength( plane ) == 0 ) + { + return false; + } + + plane[3] = DotProduct( a, plane ); + return true; +} + /* ===================== CM_GenerateBoundaryForPoints @@ -59,14 +85,19 @@ void TextureMatrixFromPoints( cFacet_t *f, dvertex_t *a, dvertex_t *b, dvertex_t m[2][2] = c->point[2]; m[2][3] = c->st[i]; - if ( fabs(m[1][0]) > fabs(m[0][0]) && fabs(m[1][0]) > fabs(m[2][0]) ) { - for ( j = 0 ; j < 4 ; j ++ ) { + if( fabs(m[1][0]) > fabs(m[0][0]) && fabs(m[1][0]) > fabs(m[2][0])) + { + for( j = 0; j < 4; j++ ) + { t = m[0][j]; m[0][j] = m[1][j]; m[1][j] = t; } - } else if ( fabs(m[2][0]) > fabs(m[0][0]) && fabs(m[2][0]) > fabs(m[1][0]) ) { - for ( j = 0 ; j < 4 ; j ++ ) { + } + else if( fabs(m[2][0]) > fabs(m[0][0]) && fabs(m[2][0]) > fabs(m[1][0])) + { + for( j = 0; j < 4; j++ ) + { t = m[0][j]; m[0][j] = m[2][j]; m[2][j] = t; @@ -91,8 +122,10 @@ void TextureMatrixFromPoints( cFacet_t *f, dvertex_t *a, dvertex_t *b, dvertex_t m[2][2] -= m[0][2] * s; m[2][3] -= m[0][3] * s; - if ( fabs(m[2][1]) > fabs(m[1][1]) ) { - for ( j = 0 ; j < 4 ; j ++ ) { + if( fabs(m[2][1]) > fabs(m[1][1])) + { + for( j = 0; j < 4; j++ ) + { t = m[1][j]; m[1][j] = m[2][j]; m[2][j] = t; @@ -124,16 +157,19 @@ void TextureMatrixFromPoints( cFacet_t *f, dvertex_t *a, dvertex_t *b, dvertex_t f->textureMatrix[i][3] = 0; /* s = fabs( DotProduct( a->point, f->textureMatrix[i] ) - a->st[i] ); - if ( s > 0.01 ) { - Error( "Bad textureMatrix" ); + if( s > 0.01 ) + { + Sys_Error( "Bad textureMatrix\n" ); } s = fabs( DotProduct( b->point, f->textureMatrix[i] ) - b->st[i] ); - if ( s > 0.01 ) { - Error( "Bad textureMatrix" ); + if( s > 0.01 ) + { + Sys_Error( "Bad textureMatrix\n" ); } s = fabs( DotProduct( c->point, f->textureMatrix[i] ) - c->st[i] ); - if ( s > 0.01 ) { - Error( "Bad textureMatrix" ); + if ( s > 0.01 ) + { + Sys_Error( "Bad textureMatrix\n" ); } */ } @@ -144,11 +180,13 @@ void TextureMatrixFromPoints( cFacet_t *f, dvertex_t *a, dvertex_t *b, dvertex_t CM_GenerateFacetFor3Points ===================== */ -bool CM_GenerateFacetFor3Points( cFacet_t *f, drawVert_t *a, drawVert_t *b, drawVert_t *c ) { +bool CM_GenerateFacetFor3Points( cFacet_t *f, dvertex_t *a, dvertex_t *b, dvertex_t *c ) +{ // if we can't generate a valid plane for the points, ignore the facet - if ( !PlaneFromPoints( f->surface, a->point, b->point, c->point ) ) { + if( !PlaneFromPoints( f->surface, a->point, b->point, c->point )) + { f->numBoundaries = 0; - return qfalse; + return false; } // make boundaries @@ -164,7 +202,7 @@ bool CM_GenerateFacetFor3Points( cFacet_t *f, drawVert_t *a, drawVert_t *b, draw TextureMatrixFromPoints( f, a, b, c ); - return qtrue; + return true; } /* @@ -174,23 +212,25 @@ CM_GenerateFacetFor4Points Attempts to use four points as a planar quad ===================== */ -#define PLANAR_EPSILON 0.1 -qboolean CM_GenerateFacetFor4Points( cFacet_t *f, drawVert_t *a, drawVert_t *b, drawVert_t *c, drawVert_t *d ) { +bool CM_GenerateFacetFor4Points( cFacet_t *f, dvertex_t *a, dvertex_t *b, dvertex_t *c, dvertex_t *d ) +{ float dist; - int i; + int i; vec4_t plane; // if we can't generate a valid plane for the points, ignore the facet - if ( !PlaneFromPoints( f->surface, a->point, b->point, c->point ) ) { + if( !PlaneFromPoints( f->surface, a->point, b->point, c->point )) + { f->numBoundaries = 0; - return qfalse; + return false; } // if the fourth point is also on the plane, we can make a quad facet dist = DotProduct( d->point, f->surface ) - f->surface[3]; - if ( fabs( dist ) > PLANAR_EPSILON ) { + if( fabs( dist ) > ON_EPSILON ) + { f->numBoundaries = 0; - return qfalse; + return false; } // make boundaries @@ -206,22 +246,24 @@ qboolean CM_GenerateFacetFor4Points( cFacet_t *f, drawVert_t *a, drawVert_t *b, VectorCopy( c->point, f->points[2] ); VectorCopy( d->point, f->points[3] ); - for (i = 1; i < 4; i++) + for( i = 1; i < 4; i++ ) { - if ( !PlaneFromPoints( plane, f->points[i], f->points[(i+1) % 4], f->points[(i+2) % 4]) ) { + if( !PlaneFromPoints( plane, f->points[i], f->points[(i+1) % 4], f->points[(i+2) % 4])) + { f->numBoundaries = 0; - return qfalse; + return false; } - if (DotProduct(f->surface, plane) < 0.9) { + if( DotProduct( f->surface, plane ) < 0.9 ) + { f->numBoundaries = 0; - return qfalse; + return false; } } TextureMatrixFromPoints( f, a, b, c ); - return qtrue; + return true; } @@ -232,7 +274,8 @@ qboolean CM_GenerateFacetFor4Points( cFacet_t *f, drawVert_t *a, drawVert_t *b, SphereFromBounds =============== */ -void SphereFromBounds( vec3_t mins, vec3_t maxs, vec3_t origin, float *radius ) { +void SphereFromBounds( vec3_t mins, vec3_t maxs, vec3_t origin, float *radius ) +{ vec3_t temp; VectorAdd( mins, maxs, origin ); @@ -247,35 +290,39 @@ void SphereFromBounds( vec3_t mins, vec3_t maxs, vec3_t origin, float *radius ) FacetsForTriangleSurface ==================== */ -void FacetsForTriangleSurface( dsurface_t *dsurf, shaderInfo_t *si, surfaceTest_t *test ) { - int i; - drawVert_t *v1, *v2, *v3, *v4; - int count; - int i1, i2, i3, i4, i5, i6; +void FacetsForTriangleSurface( dsurface_t *dsurf, bsp_shader_t *si, surfaceTest_t *test ) +{ + int i; + dvertex_t *v1, *v2, *v3, *v4; + int count; + int i1, i2, i3, i4, i5, i6; - test->patch = qfalse; - test->numFacets = dsurf->numIndexes / 3; - test->facets = malloc( sizeof( test->facets[0] ) * test->numFacets ); + test->numFacets = dsurf->numindices / 3; + test->facets = BSP_Malloc( sizeof( test->facets[0] ) * test->numFacets ); test->shader = si; count = 0; - for ( i = 0 ; i < test->numFacets ; i++ ) { - i1 = drawIndexes[ dsurf->firstIndex + i*3 ]; - i2 = drawIndexes[ dsurf->firstIndex + i*3 + 1 ]; - i3 = drawIndexes[ dsurf->firstIndex + i*3 + 2 ]; + for( i = 0; i < test->numFacets; i++ ) + { + i1 = dindexes[dsurf->firstindex+i*3+0]; + i2 = dindexes[dsurf->firstindex+i*3+1]; + i3 = dindexes[dsurf->firstindex+i*3+2]; - v1 = &drawVerts[ dsurf->firstVert + i1 ]; - v2 = &drawVerts[ dsurf->firstVert + i2 ]; - v3 = &drawVerts[ dsurf->firstVert + i3 ]; + v1 = &dvertexes[dsurf->firstvertex+i1]; + v2 = &dvertexes[dsurf->firstvertex+i2]; + v3 = &dvertexes[dsurf->firstvertex+i3]; // try and make a quad out of two triangles - if ( i != test->numFacets - 1 ) { - i4 = drawIndexes[ dsurf->firstIndex + i*3 + 3 ]; - i5 = drawIndexes[ dsurf->firstIndex + i*3 + 4 ]; - i6 = drawIndexes[ dsurf->firstIndex + i*3 + 5 ]; - if ( i4 == i3 && i5 == i2 ) { - v4 = &drawVerts[ dsurf->firstVert + i6 ]; - if ( CM_GenerateFacetFor4Points( &test->facets[count], v1, v2, v4, v3 ) ) { + if( i != test->numFacets - 1 ) + { + i4 = dindexes[dsurf->firstindex+i*3+3]; + i5 = dindexes[dsurf->firstindex+i*3+4]; + i6 = dindexes[dsurf->firstindex+i*3+5]; + if( i4 == i3 && i5 == i2 ) + { + v4 = &dvertexes[ dsurf->firstvertex + i6 ]; + if( CM_GenerateFacetFor4Points( &test->facets[count], v1, v2, v4, v3 )) + { count++; i++; // skip next tri continue; @@ -283,7 +330,7 @@ void FacetsForTriangleSurface( dsurface_t *dsurf, shaderInfo_t *si, surfaceTest_ } } - if (CM_GenerateFacetFor3Points( &test->facets[count], v1, v2, v3 )) + if( CM_GenerateFacetFor3Points( &test->facets[count], v1, v2, v3 )) count++; } @@ -291,58 +338,6 @@ void FacetsForTriangleSurface( dsurface_t *dsurf, shaderInfo_t *si, surfaceTest_ test->numFacets = count; } -/* -==================== -FacetsForPatch -==================== -*/ -void FacetsForPatch( dsurface_t *dsurf, shaderInfo_t *si, surfaceTest_t *test ) { - int i, j; - drawVert_t *v1, *v2, *v3, *v4; - int count; - mesh_t srcMesh, *subdivided, *mesh; - - srcMesh.width = dsurf->patchWidth; - srcMesh.height = dsurf->patchHeight; - srcMesh.verts = &drawVerts[ dsurf->firstVert ]; - - //subdivided = SubdivideMesh( mesh, CURVE_FACET_ERROR, 9999 ); - mesh = SubdivideMesh( srcMesh, 8, 999 ); - PutMeshOnCurve( *mesh ); - MakeMeshNormals( *mesh ); - - subdivided = RemoveLinearMeshColumnsRows( mesh ); - FreeMesh(mesh); - - test->patch = qtrue; - test->numFacets = ( subdivided->width - 1 ) * ( subdivided->height - 1 ) * 2; - test->facets = malloc( sizeof( test->facets[0] ) * test->numFacets ); - test->shader = si; - - count = 0; - for ( i = 0 ; i < subdivided->width - 1 ; i++ ) { - for ( j = 0 ; j < subdivided->height - 1 ; j++ ) { - - v1 = subdivided->verts + j * subdivided->width + i; - v2 = v1 + 1; - v3 = v1 + subdivided->width + 1; - v4 = v1 + subdivided->width; - - if ( CM_GenerateFacetFor4Points( &test->facets[count], v1, v4, v3, v2 ) ) { - count++; - } else { - if (CM_GenerateFacetFor3Points( &test->facets[count], v1, v4, v3 )) - count++; - if (CM_GenerateFacetFor3Points( &test->facets[count], v1, v3, v2 )) - count++; - } - } - } - test->numFacets = count; - FreeMesh(subdivided); -} - - /* ===================== InitSurfacesForTesting @@ -350,43 +345,43 @@ InitSurfacesForTesting Builds structures to speed the ray tracing against surfaces ===================== */ -void InitSurfacesForTesting( void ) { - - int i, j; - dsurface_t *dsurf; +void InitSurfacesForTesting( void ) +{ + int i, j; + dsurface_t *dsurf; surfaceTest_t *test; - drawVert_t *dvert; - shaderInfo_t *si; + dvertex_t *dvert; + bsp_shader_t *si; - for ( i = 0 ; i < numDrawSurfaces ; i++ ) { - dsurf = &drawSurfaces[ i ]; - if ( !dsurf->numIndexes && !dsurf->patchWidth ) { + for( i = 0; i < numsurfaces; i++ ) + { + dsurf = &dsurfaces[i]; + if( !dsurf->numindices ) + { continue; } // don't make surfaces for transparent objects // because we want light to pass through them - si = ShaderInfoForShader( dshaders[ dsurf->shaderNum].shader ); - if ( (si->contents & CONTENTS_TRANSLUCENT) && !(si->surfaceFlags & SURF_ALPHASHADOW) ) { + si = FindShader( dshaders[dsurf->shadernum].name ); + if(( si->contents & CONTENTS_TRANSLUCENT) && !(si->surfaceFlags & SURF_ALPHASHADOW)) + { continue; } - test = malloc( sizeof( *test ) ); + test = BSP_Malloc( sizeof( *test )); surfaceTest[i] = test; ClearBounds( test->mins, test->maxs ); - dvert = &drawVerts[ dsurf->firstVert ]; - for ( j = 0 ; j < dsurf->numVerts ; j++, dvert++ ) { + dvert = &dvertexes[ dsurf->firstvertex ]; + for( j = 0; j < dsurf->numvertices; j++, dvert++ ) + { AddPointToBounds( dvert->point, test->mins, test->maxs ); } SphereFromBounds( test->mins, test->maxs, test->origin, &test->radius ); - if ( dsurf->surfaceType == MST_TRIANGLE_SOUP || dsurf->surfaceType == MST_PLANAR ) { - FacetsForTriangleSurface( dsurf, si, test ); - } else if ( dsurf->surfaceType == MST_PATCH ) { - FacetsForPatch( dsurf, si, test ); - } + FacetsForTriangleSurface( dsurf, si, test ); } } @@ -396,13 +391,14 @@ void InitSurfacesForTesting( void ) { GenerateBoundaryForPoints ===================== */ -void GenerateBoundaryForPoints( float boundary[4], float plane[4], vec3_t a, vec3_t b ) { +void GenerateBoundaryForPoints( float boundary[4], float plane[4], vec3_t a, vec3_t b ) +{ vec3_t d1; // amke a perpendicular vector to the edge and the surface VectorSubtract( b, a, d1 ); CrossProduct( plane, d1, boundary ); - VectorNormalize( boundary, boundary ); + VectorNormalize( boundary ); boundary[3] = DotProduct( a, boundary ); } @@ -415,14 +411,16 @@ Given a point on a facet, determine the color filter for light passing through ================= */ -void SetFacetFilter( traceWork_t *tr, shaderInfo_t *shader, cFacet_t *facet, vec3_t point ) { +void SetFacetFilter( traceWork_t *tr, bsp_shader_t *shader, cFacet_t *facet, vec3_t point ) +{ float s, t; - int is, it; + int is, it; byte *image; - int b; + int b; // most surfaces are completely opaque - if ( !(shader->surfaceFlags & SURF_ALPHASHADOW) ) { + if( !(shader->surfaceFlags & SURF_ALPHASHADOW )) + { VectorClear( tr->trace->filter ); return; } @@ -430,7 +428,8 @@ void SetFacetFilter( traceWork_t *tr, shaderInfo_t *shader, cFacet_t *facet, vec s = DotProduct( point, facet->textureMatrix[0] ) + facet->textureMatrix[0][3]; t = DotProduct( point, facet->textureMatrix[1] ) + facet->textureMatrix[1][3]; - if ( !shader->pixels ) { + if( !shader->pixels ) + { // assume completely solid VectorClear( point ); return; @@ -463,14 +462,16 @@ TraceAgainstFacet Shader is needed for translucent surfaces ==================== */ -void TraceAgainstFacet( traceWork_t *tr, shaderInfo_t *shader, cFacet_t *facet ) { - int j; +void TraceAgainstFacet( traceWork_t *tr, bsp_shader_t *shader, cFacet_t *facet ) +{ + int j; float d1, d2, d, f; vec3_t point; float dist; // ignore degenerate facets - if ( facet->numBoundaries < 3 ) { + if( facet->numBoundaries < 3 ) + { return; } @@ -478,49 +479,60 @@ void TraceAgainstFacet( traceWork_t *tr, shaderInfo_t *shader, cFacet_t *facet ) // compare the trace endpoints against the facet plane d1 = DotProduct( tr->start, facet->surface ) - dist; - if ( d1 > -1 && d1 < 1 ) { + if( d1 > -1 && d1 < 1 ) + { return; // don't self intersect } d2 = DotProduct( tr->end, facet->surface ) - dist; - if ( d2 > -1 && d2 < 1 ) { + if( d2 > -1 && d2 < 1 ) + { return; // don't self intersect } // calculate the intersection fraction f = ( d1 - ON_EPSILON ) / ( d1 - d2 ); - if ( f <= 0 ) { + if( f <= 0 ) + { return; } - if ( f >= tr->trace->hitFraction ) { - return; // we have hit something earlier + if( f >= tr->trace->hitFraction ) + { + return; // we have hit something earlier } // calculate the intersection point - for ( j = 0 ; j < 3 ; j++ ) { + for( j = 0; j < 3; j++ ) + { point[j] = tr->start[j] + f * ( tr->end[j] - tr->start[j] ); } // check the point against the facet boundaries - for ( j = 0 ; j < facet->numBoundaries ; j++ ) { + for( j = 0; j < facet->numBoundaries; j++ ) + { // adjust the plane distance apropriately for mins/maxs dist = facet->boundaries[j][3]; d = DotProduct( point, facet->boundaries[j] ); - if ( d > dist + ON_EPSILON ) { + if( d > dist + ON_EPSILON ) + { break; // outside the bounds } } - if ( j != facet->numBoundaries ) { + if( j != facet->numBoundaries ) + { return; // we are outside the bounds of the facet } // we hit this facet // if this is a transparent surface, calculate filter value - if ( shader->surfaceFlags & SURF_ALPHASHADOW ) { + if( shader->surfaceFlags & SURF_ALPHASHADOW ) + { SetFacetFilter( tr, shader, facet, point ); - } else { + } + else + { // completely opaque VectorClear( tr->trace->filter ); tr->trace->hitFraction = f; @@ -538,21 +550,17 @@ void TraceAgainstFacet( traceWork_t *tr, shaderInfo_t *shader, cFacet_t *facet ) =============================================================== */ - - -#define TRACE_ON_EPSILON 0.1 - typedef struct tnode_s { int type; - vec3_t normal; - float dist; + vec3_t normal; + float dist; int children[2]; int planeNum; } tnode_t; -#define MAX_TNODES (MAX_MAP_NODES*4) -tnode_t *tnodes, *tnode_p; +#define MAX_TNODES (MAX_MAP_NODES*4) +tnode_t *tnodes, *tnode_p; /* ============== @@ -561,35 +569,41 @@ MakeTnode Converts the disk node structure into the efficient tracing structure ============== */ -void MakeTnode (int nodenum) +void MakeTnode( int nodenum ) { - tnode_t *t; + tnode_t *t; dplane_t *plane; - int i; + int i; dnode_t *node; - int leafNum; + int leafNum; t = tnode_p++; node = dnodes + nodenum; - plane = dplanes + node->planeNum; + plane = dplanes + node->planenum; - t->planeNum = node->planeNum; + t->planeNum = node->planenum; t->type = PlaneTypeForNormal( plane->normal ); VectorCopy (plane->normal, t->normal); t->dist = plane->dist; - for (i=0 ; i<2 ; i++) + for( i = 0; i < 2; i++ ) { - if (node->children[i] < 0) { + if( node->children[i] < 0 ) + { leafNum = -node->children[i] - 1; - if ( dleafs[leafNum].cluster == -1 ) { + if( dleafs[leafNum].cluster == -1 ) + { // solid t->children[i] = leafNum | ( 1 << 31 ) | ( 1 << 30 ); - } else { + } + else + { t->children[i] = leafNum | ( 1 << 31 ); } - } else { + } + else + { t->children[i] = tnode_p - tnodes; MakeTnode (node->children[i]); } @@ -604,13 +618,14 @@ InitTrace Loads the node structure out of a .bsp file to be used for light occlusion ============= */ -void InitTrace( void ) { +void InitTrace( void ) +{ // 32 byte align the structs - tnodes = malloc( (MAX_TNODES+1) * sizeof(tnode_t)); + tnodes = BSP_Malloc((MAX_TNODES+1) * sizeof(tnode_t)); tnodes = (tnode_t *)(((int)tnodes + 31)&~31); tnode_p = tnodes; - MakeTnode (0); + MakeTnode( 0 ); InitSurfacesForTesting(); } @@ -621,13 +636,16 @@ void InitTrace( void ) { PointInSolid =================== */ -qboolean PointInSolid_r( vec3_t start, int node ) { +bool PointInSolid_r( vec3_t start, int node ) +{ tnode_t *tnode; float front; - while ( !(node & (1<<31) ) ) { + while(!(node & ( 1<<31 ))) + { tnode = &tnodes[node]; - switch (tnode->type) { + switch( tnode->type ) + { case PLANE_X: front = start[0] - tnode->dist; break; @@ -638,27 +656,31 @@ qboolean PointInSolid_r( vec3_t start, int node ) { front = start[2] - tnode->dist; break; default: - front = (start[0]*tnode->normal[0] + start[1]*tnode->normal[1] + start[2]*tnode->normal[2]) - tnode->dist; + front = (start[0]*tnode->normal[0]+start[1]*tnode->normal[1]+start[2]*tnode->normal[2]) - tnode->dist; break; } - if ( front == 0 ) { + if( front == 0 ) + { // exactly on node, must check both sides - return (qboolean) ( PointInSolid_r( start, tnode->children[0] ) - | PointInSolid_r( start, tnode->children[1] ) ); + return (bool)(PointInSolid_r( start, tnode->children[0] )|PointInSolid_r( start, tnode->children[1])); } - if ( front > 0 ) { + if( front > 0 ) + { node = tnode->children[0]; - } else { + } + else + { node = tnode->children[1]; } } - if ( node & ( 1 << 30 ) ) { - return qtrue; + if( node & ( 1 << 30 )) + { + return true; } - return qfalse; + return false; } /* @@ -667,7 +689,8 @@ PointInSolid ============= */ -qboolean PointInSolid( vec3_t start ) { +bool PointInSolid( vec3_t start ) +{ return PointInSolid_r( start, 0 ); } @@ -679,32 +702,39 @@ TraceLine_r Returns qtrue if something is hit and tracing can stop ============= */ -int TraceLine_r( int node, const vec3_t start, const vec3_t stop, traceWork_t *tw ) { +int TraceLine_r( int node, const vec3_t start, const vec3_t stop, traceWork_t *tw ) +{ tnode_t *tnode; float front, back; vec3_t mid; float frac; - int side; - int r; + int side; + int r; - if (node & (1<<31)) { - if (node & ( 1 << 30 ) ) { + if( node & (1<<31)) + { + if( node & ( 1 << 30 )) + { VectorCopy (start, tw->trace->hit); - tw->trace->passSolid = qtrue; - return qtrue; - } else { + tw->trace->passSolid = true; + return true; + } + else + { // save the node off for more exact testing - if ( tw->numOpenLeafs == MAX_MAP_LEAFS ) { - return qfalse; + if( tw->numOpenLeafs == MAX_MAP_LEAFS ) + { + return false; } tw->openLeafNumbers[ tw->numOpenLeafs ] = node & ~(3 << 30); tw->numOpenLeafs++; - return qfalse; + return false; } } tnode = &tnodes[node]; - switch (tnode->type) { + switch( tnode->type ) + { case PLANE_X: front = start[0] - tnode->dist; back = stop[0] - tnode->dist; @@ -723,12 +753,14 @@ int TraceLine_r( int node, const vec3_t start, const vec3_t stop, traceWork_t *t break; } - if (front >= -TRACE_ON_EPSILON && back >= -TRACE_ON_EPSILON) { - return TraceLine_r (tnode->children[0], start, stop, tw); + if( front >= -ON_EPSILON && back >= -ON_EPSILON ) + { + return TraceLine_r( tnode->children[0], start, stop, tw ); } - if (front < TRACE_ON_EPSILON && back < TRACE_ON_EPSILON) { - return TraceLine_r (tnode->children[1], start, stop, tw); + if( front < ON_EPSILON && back < ON_EPSILON ) + { + return TraceLine_r( tnode->children[1], start, stop, tw ); } side = front < 0; @@ -739,14 +771,15 @@ int TraceLine_r( int node, const vec3_t start, const vec3_t stop, traceWork_t *t mid[1] = start[1] + (stop[1] - start[1])*frac; mid[2] = start[2] + (stop[2] - start[2])*frac; - r = TraceLine_r (tnode->children[side], start, mid, tw); + r = TraceLine_r( tnode->children[side], start, mid, tw ); - if (r) { + if( r ) + { return r; } // trace->planeNum = tnode->planeNum; - return TraceLine_r (tnode->children[!side], mid, stop, tw); + return TraceLine_r( tnode->children[!side], mid, stop, tw ); } //========================================================================================== @@ -757,7 +790,8 @@ int TraceLine_r( int node, const vec3_t start, const vec3_t stop, traceWork_t *t SphereCull ================ */ -qboolean SphereCull( vec3_t start, vec3_t stop, vec3_t origin, float radius ) { +bool SphereCull( vec3_t start, vec3_t stop, vec3_t origin, float radius ) +{ vec3_t v; float d; vec3_t dir; @@ -765,15 +799,17 @@ qboolean SphereCull( vec3_t start, vec3_t stop, vec3_t origin, float radius ) { vec3_t on; VectorSubtract( stop, start, dir ); - len = VectorNormalize( dir, dir ); + len = VectorNormalizeLength( dir ); VectorSubtract( origin, start, v ); d = DotProduct( v, dir ); - if ( d > len + radius ) { - return qtrue; // too far ahead + if( d > len + radius ) + { + return true; // too far ahead } - if ( d < -radius ) { - return qtrue; // too far behind + if( d < -radius ) + { + return true; // too far behind } VectorMA( start, d, dir, on ); @@ -781,11 +817,11 @@ qboolean SphereCull( vec3_t start, vec3_t stop, vec3_t origin, float radius ) { len = VectorLength( v ); - if ( len > radius ) { - return qtrue; // too far to the side + if( len > radius ) + { + return true; // too far to the side } - - return qfalse; // must be traced against + return false; // must be traced against } /* @@ -793,30 +829,36 @@ qboolean SphereCull( vec3_t start, vec3_t stop, vec3_t origin, float radius ) { TraceAgainstSurface ================ */ -void TraceAgainstSurface( traceWork_t *tw, surfaceTest_t *surf ) { +void TraceAgainstSurface( traceWork_t *tw, surfaceTest_t *surf ) +{ int i; // if surfaces are trans - if ( SphereCull( tw->start, tw->end, surf->origin, surf->radius ) ) { - if ( numthreads == 1 ) { + if( SphereCull( tw->start, tw->end, surf->origin, surf->radius )) + { + if( GetNumThreads() == 1 ) + { c_cullTrace++; } return; } - if ( numthreads == 1 ) { + if( GetNumThreads() == 1 ) + { c_testTrace++; c_testFacets += surf->numFacets; } /* // MrE: backface culling - if (!surf->patch && surf->numFacets) { + if( surf->numFacets ) + { // if the surface does not cast an alpha shadow - if ( !(surf->shader->surfaceFlags & SURF_ALPHASHADOW) ) { + if(!(surf->shader->surfaceFlags & SURF_ALPHASHADOW )) + { vec3_t vec; - VectorSubtract(tw->end, tw->start, vec); - if (DotProduct(vec, surf->facets->surface) > 0) + VectorSubtract( tw->end, tw->start, vec ); + if( DotProduct(vec, surf->facets->surface) > 0 ) return; } } @@ -845,19 +887,18 @@ if you need to know the exact first point of impact (for a sun trace), set testAll to true ============= */ -extern qboolean patchshadows; - -void TraceLine( const vec3_t start, const vec3_t stop, trace_t *trace, qboolean testAll, traceWork_t *tw ) { - int r; - int i, j; - dleaf_t *leaf; - float oldHitFrac; +void TraceLine( const vec3_t start, const vec3_t stop, lighttrace_t *trace, bool testAll, traceWork_t *tw ) +{ + int r; + int i, j; + dleaf_t *leaf; + float oldHitFrac; surfaceTest_t *test; - int surfaceNum; - byte surfaceTested[MAX_MAP_DRAW_SURFS/8]; - ; + int surfaceNum; + byte surfaceTested[MAX_MAP_SURFACES/8]; - if ( numthreads == 1 ) { + if( GetNumThreads() == 1 ) + { c_totalTrace++; } @@ -873,7 +914,7 @@ void TraceLine( const vec3_t start, const vec3_t stop, trace_t *trace, qboolean tw->numOpenLeafs = 0; - trace->passSolid = qfalse; + trace->passSolid = false; trace->hitFraction = 1.0; r = TraceLine_r( 0, start, stop, tw ); @@ -881,47 +922,51 @@ void TraceLine( const vec3_t start, const vec3_t stop, trace_t *trace, qboolean // if we hit a solid leaf, stop without testing the leaf // surfaces. Note that the plane and endpoint might not // be the first solid intersection along the ray. - if ( r && !testAll ) { + if( r && !testAll ) + { return; } - if ( noSurfaces ) { + if( noSurfaces ) + { return; } - memset( surfaceTested, 0, (numDrawSurfaces+7)/8 ); + memset( surfaceTested, 0, (numsurfaces + 7)/8 ); oldHitFrac = trace->hitFraction; - for ( i = 0 ; i < tw->numOpenLeafs ; i++ ) { - leaf = &dleafs[ tw->openLeafNumbers[ i ] ]; - for ( j = 0 ; j < leaf->numLeafSurfaces ; j++ ) { - surfaceNum = dleafsurfaces[ leaf->firstLeafSurface + j ]; + for( i = 0; i < tw->numOpenLeafs; i++ ) + { + leaf = &dleafs[tw->openLeafNumbers[i]]; + for( j = 0 ; j < leaf->numleaffaces; j++ ) + { + surfaceNum = dleaffaces[leaf->firstleafface+j]; // make sure we don't test the same ray against a surface more than once - if ( surfaceTested[ surfaceNum>>3 ] & ( 1 << ( surfaceNum & 7) ) ) { + if( surfaceTested[surfaceNum>>3] & ( 1 << ( surfaceNum & 7) )) + { continue; } - surfaceTested[ surfaceNum>>3 ] |= ( 1 << ( surfaceNum & 7 ) ); + surfaceTested[surfaceNum>>3] |= ( 1 << ( surfaceNum & 7 )); - test = surfaceTest[ surfaceNum ]; - if ( !test ) { - continue; - } - // - if ( !tw->patchshadows && test->patch ) { + test = surfaceTest[surfaceNum]; + if( !test ) + { continue; } TraceAgainstSurface( tw, test ); } // if the trace is now solid, we can't possibly hit anything closer - if ( trace->hitFraction < oldHitFrac ) { - trace->passSolid = qtrue; + if( trace->hitFraction < oldHitFrac ) + { + trace->passSolid = true; break; } } - for ( i = 0 ; i < 3 ; i++ ) { + for( i = 0; i < 3; i++ ) + { trace->hit[i] = start[i] + ( stop[i] - start[i] ) * trace->hitFraction; } } diff --git a/common/bsplib/map.c b/common/bsplib/map.c index 81e891db..653fb028 100644 --- a/common/bsplib/map.c +++ b/common/bsplib/map.c @@ -209,10 +209,10 @@ int FindFloatPlane( vec3_t normal, vec_t dist ) /* ================ -PlaneFromPoints +MapPlaneFromPoints ================ */ -int PlaneFromPoints (vec_t *p0, vec_t *p1, vec_t *p2) +int MapPlaneFromPoints (vec_t *p0, vec_t *p1, vec_t *p2) { vec3_t t1, t2, normal; vec_t dist; @@ -632,7 +632,7 @@ void ParseRawBrush( void ) } // find the plane number - planenum = PlaneFromPoints( planepts[0], planepts[1], planepts[2] ); + planenum = MapPlaneFromPoints( planepts[0], planepts[1], planepts[2] ); side->planenum = planenum; if( g_brushtype == BRUSH_QUARK ) diff --git a/common/bsplib/qbsp3.c b/common/bsplib/qbsp3.c index b703aa6e..25be525c 100644 --- a/common/bsplib/qbsp3.c +++ b/common/bsplib/qbsp3.c @@ -85,7 +85,6 @@ void EmitLeaf( node_t *node ) leaf_p = &dleafs[numleafs]; numleafs++; - leaf_p->contents = node->contents; leaf_p->cluster = node->cluster; leaf_p->area = node->area; @@ -314,7 +313,6 @@ void BeginBSPFile( void ) numleafbrushes = 0; numleafs = 1; // leave leaf 0 as an error - dleafs[0].contents = CONTENTS_SOLID; // assume error } diff --git a/common/bsplib/qrad3.c b/common/bsplib/qrad3.c index cc48a7e0..9754b77c 100644 --- a/common/bsplib/qrad3.c +++ b/common/bsplib/qrad3.c @@ -60,6 +60,10 @@ int entitySurface[MAX_MAP_SURFACES]; vec3_t sunDirection = { 0.45, 0.3, 0.9 }; vec3_t sunLight = { 100, 100, 50 }; +// g-cont. moved it here to avoid stack overflow problems +byte occluded[LIGHTMAP_WIDTH*EXTRASCALE][LIGHTMAP_HEIGHT*EXTRASCALE]; +vec3_t color[LIGHTMAP_WIDTH*EXTRASCALE][LIGHTMAP_HEIGHT*EXTRASCALE]; + typedef struct { dbrush_t *b; @@ -1107,8 +1111,6 @@ void TraceLtm( int num ) int x, y; int position, numPositions; vec3_t base, origin, normal; - byte occluded[LIGHTMAP_WIDTH*EXTRASCALE][LIGHTMAP_HEIGHT*EXTRASCALE]; - vec3_t color[LIGHTMAP_WIDTH*EXTRASCALE][LIGHTMAP_HEIGHT*EXTRASCALE]; traceWork_t tw; vec3_t average; int count; @@ -1121,6 +1123,9 @@ void TraceLtm( int num ) int sampleWidth, sampleHeight, ssize; vec3_t lightmapOrigin, lightmapVecs[2]; + memset( occluded, 0, LIGHTMAP_WIDTH*EXTRASCALE*LIGHTMAP_HEIGHT*EXTRASCALE ); + memset( color, 0, LIGHTMAP_WIDTH*EXTRASCALE*LIGHTMAP_HEIGHT*EXTRASCALE ); + ds = &dsurfaces[num]; si = FindShader( dshaders[ds->shadernum].name ); @@ -1742,7 +1747,6 @@ void WradMain ( bool option ) pointScale *= com.atof( cmdparm ); if( FS_CheckParm( "-notrace" )) notrace = true; if( FS_CheckParm( "-patchshadows" )) patchshadows = true; - if( FS_CheckParm( "-notrace" )) notrace = true; if( FS_CheckParm( "-extrawide" )) extra = extraWide = true; samplesize = bsp_lightmap_size->integer; diff --git a/common/bsplib/shaders.c b/common/bsplib/shaders.c index bf240fd5..3aff0752 100644 --- a/common/bsplib/shaders.c +++ b/common/bsplib/shaders.c @@ -140,7 +140,7 @@ static void ParseShaderFile( char *filename ) MsgDev(D_INFO, "Adding shader: %s.txt\n", name ); } - while ( load ) + while( load ) { if ( !Com_GetToken( true )) break; diff --git a/common/common.dsp b/common/common.dsp index f5b08a43..12df2960 100644 --- a/common/common.dsp +++ b/common/common.dsp @@ -133,6 +133,10 @@ SOURCE=.\bsplib\leakfile.c # End Source File # Begin Source File +SOURCE=.\bsplib\light_trace.c +# End Source File +# Begin Source File + SOURCE=.\bsplib\lightmaps.c # End Source File # Begin Source File diff --git a/common/common.plg b/common/common.plg deleted file mode 100644 index 1dc1e140..00000000 --- a/common/common.plg +++ /dev/null @@ -1,125 +0,0 @@ - - -
-

Build Log

-

---------------------Configuration: common - Win32 Debug-------------------- -

-

Command Lines

-Creating temporary file "C:\DOCUME~1\ÀÄÌÈÍÈ~1.9CC\LOCALS~1\Temp\RSP245F.tmp" with contents -[ -/nologo /MDd /W3 /Gm /Gi /GX /ZI /I "./" /I "../public" /I "./bsplib/" /I "./ripper" /I "./common" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FR"..\temp\common\!debug/" /Fo"..\temp\common\!debug/" /Fd"..\temp\common\!debug/" /FD /GZ /c -"D:\Xash3D\src_main\common\bsplib\brush.c" -"D:\Xash3D\src_main\common\bsplib\bspfile.c" -"D:\Xash3D\src_main\common\bsplib\bsplib.c" -"D:\Xash3D\src_main\common\bsplib\facebsp.c" -"D:\Xash3D\src_main\common\bsplib\leakfile.c" -"D:\Xash3D\src_main\common\bsplib\lightmap.c" -"D:\Xash3D\src_main\common\bsplib\lightmaps.c" -"D:\Xash3D\src_main\common\bsplib\map.c" -"D:\Xash3D\src_main\common\bsplib\patches.c" -"D:\Xash3D\src_main\common\platform.c" -"D:\Xash3D\src_main\common\bsplib\portals.c" -"D:\Xash3D\src_main\common\bsplib\prtfile.c" -"D:\Xash3D\src_main\common\bsplib\qbsp3.c" -"D:\Xash3D\src_main\common\bsplib\qrad3.c" -"D:\Xash3D\src_main\common\bsplib\qvis3.c" -"D:\Xash3D\src_main\common\bsplib\shaders.c" -"D:\Xash3D\src_main\common\spritegen.c" -"D:\Xash3D\src_main\common\studio.c" -"D:\Xash3D\src_main\common\studio_utils.c" -"D:\Xash3D\src_main\common\bsplib\surface.c" -"D:\Xash3D\src_main\common\bsplib\terrain.c" -"D:\Xash3D\src_main\common\bsplib\tjunc.c" -"D:\Xash3D\src_main\common\bsplib\trace.c" -"D:\Xash3D\src_main\common\bsplib\tree.c" -"D:\Xash3D\src_main\common\utils.c" -"D:\Xash3D\src_main\common\bsplib\visflow.c" -"D:\Xash3D\src_main\common\wadlib.c" -"D:\Xash3D\src_main\common\bsplib\winding.c" -] -Creating command line "cl.exe @"C:\DOCUME~1\ÀÄÌÈÍÈ~1.9CC\LOCALS~1\Temp\RSP245F.tmp"" -Creating temporary file "C:\DOCUME~1\ÀÄÌÈÍÈ~1.9CC\LOCALS~1\Temp\RSP2460.tmp" with contents -[ -msvcrt.lib user32.lib /nologo /dll /incremental:yes /pdb:"..\temp\common\!debug/common.pdb" /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"..\temp\common\!debug/common.dll" /implib:"..\temp\common\!debug/common.lib" /pdbtype:sept -"\Xash3D\src_main\temp\common\!debug\brush.obj" -"\Xash3D\src_main\temp\common\!debug\bspfile.obj" -"\Xash3D\src_main\temp\common\!debug\bsplib.obj" -"\Xash3D\src_main\temp\common\!debug\facebsp.obj" -"\Xash3D\src_main\temp\common\!debug\leakfile.obj" -"\Xash3D\src_main\temp\common\!debug\lightmap.obj" -"\Xash3D\src_main\temp\common\!debug\lightmaps.obj" -"\Xash3D\src_main\temp\common\!debug\map.obj" -"\Xash3D\src_main\temp\common\!debug\patches.obj" -"\Xash3D\src_main\temp\common\!debug\platform.obj" -"\Xash3D\src_main\temp\common\!debug\portals.obj" -"\Xash3D\src_main\temp\common\!debug\prtfile.obj" -"\Xash3D\src_main\temp\common\!debug\qbsp3.obj" -"\Xash3D\src_main\temp\common\!debug\qrad3.obj" -"\Xash3D\src_main\temp\common\!debug\qvis3.obj" -"\Xash3D\src_main\temp\common\!debug\shaders.obj" -"\Xash3D\src_main\temp\common\!debug\spritegen.obj" -"\Xash3D\src_main\temp\common\!debug\studio.obj" -"\Xash3D\src_main\temp\common\!debug\studio_utils.obj" -"\Xash3D\src_main\temp\common\!debug\surface.obj" -"\Xash3D\src_main\temp\common\!debug\terrain.obj" -"\Xash3D\src_main\temp\common\!debug\tjunc.obj" -"\Xash3D\src_main\temp\common\!debug\trace.obj" -"\Xash3D\src_main\temp\common\!debug\tree.obj" -"\Xash3D\src_main\temp\common\!debug\utils.obj" -"\Xash3D\src_main\temp\common\!debug\visflow.obj" -"\Xash3D\src_main\temp\common\!debug\wadlib.obj" -"\Xash3D\src_main\temp\common\!debug\winding.obj" -] -Creating command line "link.exe @"C:\DOCUME~1\ÀÄÌÈÍÈ~1.9CC\LOCALS~1\Temp\RSP2460.tmp"" -Creating temporary file "C:\DOCUME~1\ÀÄÌÈÍÈ~1.9CC\LOCALS~1\Temp\RSP2461.bat" with contents -[ -@echo off -copy \Xash3D\src_main\temp\common\!debug\common.dll "D:\Xash3D\bin\common.dll" -] -Creating command line ""C:\DOCUME~1\ÀÄÌÈÍÈ~1.9CC\LOCALS~1\Temp\RSP2461.bat"" -Compiling... -brush.c -bspfile.c -bsplib.c -facebsp.c -leakfile.c -lightmap.c -lightmaps.c -map.c -patches.c -platform.c -portals.c -prtfile.c -qbsp3.c -qrad3.c -qvis3.c -shaders.c -spritegen.c -studio.c -studio_utils.c -surface.c -Generating Code... -Compiling... -terrain.c -tjunc.c -trace.c -tree.c -utils.c -visflow.c -wadlib.c -winding.c -Generating Code... -Linking... - Creating library ..\temp\common\!debug/common.lib and object ..\temp\common\!debug/common.exp -

Output Window

-Performing Custom Build Step on \Xash3D\src_main\temp\common\!debug\common.dll -‘ª®¯¨à®¢ ­® ä ©«®¢: 1. - - - -

Results

-common.dll - 0 error(s), 0 warning(s) -
- - diff --git a/physic/cm_model.c b/physic/cm_model.c index 3c24f966..a5ffa47b 100644 --- a/physic/cm_model.c +++ b/physic/cm_model.c @@ -356,7 +356,6 @@ void BSP_LoadLeafs( lump_t *l ) dleaf_t *in; cleaf_t *out; int i, j, n, c, count; - int emptyleaf = -1; in = (void *)(cm.mod_base + l->fileofs); if (l->filelen % sizeof(*in)) Host_Error("BSP_LoadLeafs: funny lump size\n"); @@ -370,7 +369,6 @@ void BSP_LoadLeafs( lump_t *l ) { out->parent = NULL; out->plane = NULL; - out->contents = LittleLong( in->contents ); out->cluster = LittleLong( in->cluster ); out->area = LittleLong( in->area ); @@ -401,22 +399,6 @@ void BSP_LoadLeafs( lump_t *l ) cm.areaportals_size = cm.numareas * cm.numareas * sizeof( *cm.areaportals ); cm.areas = Mem_Alloc( cmappool, cm.numareas * sizeof( *cm.areas )); cm.areaportals = Mem_Alloc( cmappool, cm.areaportals_size ); - - // probably any wall it's liquid ? - if( cm.leafs[0].contents != CONTENTS_SOLID ) - Host_Error("Map %s with leaf 0 is not CONTENTS_SOLID\n", cm.name ); - - for( i = 1; i < count; i++ ) - { - if(!cm.leafs[i].contents) - { - emptyleaf = i; - break; - } - } - - // stuck into brushes - if( emptyleaf == -1 ) Host_Error("Map %s does not have an empty leaf\n", cm.name ); } /* diff --git a/public/ref_dfiles.h b/public/ref_dfiles.h index 75eaf92f..bf3e5864 100644 --- a/public/ref_dfiles.h +++ b/public/ref_dfiles.h @@ -249,7 +249,6 @@ typedef struct int cluster; int mins[3]; // for frustum culling int maxs[3]; - int contents; int firstleafface; int numleaffaces; int firstleafbrush;