std::vector<plane_t> mapplanes
This commit is contained in:
parent
ee92bdd801
commit
ffa1a4340c
|
|
@ -55,7 +55,7 @@ void GetBestSurfaceTriangleMatchForBrushside( side_t *buildSide, bspDrawVert_t *
|
||||||
float thisarea;
|
float thisarea;
|
||||||
bspDrawVert_t *vert[3];
|
bspDrawVert_t *vert[3];
|
||||||
winding_t *polygon;
|
winding_t *polygon;
|
||||||
plane_t *buildPlane = &mapplanes[buildSide->planenum];
|
const plane_t& buildPlane = mapplanes[buildSide->planenum];
|
||||||
int matches = 0;
|
int matches = 0;
|
||||||
|
|
||||||
// first, start out with NULLs
|
// first, start out with NULLs
|
||||||
|
|
@ -76,9 +76,9 @@ void GetBestSurfaceTriangleMatchForBrushside( side_t *buildSide, bspDrawVert_t *
|
||||||
vert[1] = &bspDrawVerts[s->firstVert + bspDrawIndexes[s->firstIndex + t + 1]];
|
vert[1] = &bspDrawVerts[s->firstVert + bspDrawIndexes[s->firstIndex + t + 1]];
|
||||||
vert[2] = &bspDrawVerts[s->firstVert + bspDrawIndexes[s->firstIndex + t + 2]];
|
vert[2] = &bspDrawVerts[s->firstVert + bspDrawIndexes[s->firstIndex + t + 2]];
|
||||||
if ( s->surfaceType == MST_PLANAR && VectorCompare( vert[0]->normal, vert[1]->normal ) && VectorCompare( vert[1]->normal, vert[2]->normal ) ) {
|
if ( s->surfaceType == MST_PLANAR && VectorCompare( vert[0]->normal, vert[1]->normal ) && VectorCompare( vert[1]->normal, vert[2]->normal ) ) {
|
||||||
if ( vector3_length( vert[0]->normal - buildPlane->normal() ) >= normalEpsilon
|
if ( vector3_length( vert[0]->normal - buildPlane.normal() ) >= normalEpsilon
|
||||||
|| vector3_length( vert[1]->normal - buildPlane->normal() ) >= normalEpsilon
|
|| vector3_length( vert[1]->normal - buildPlane.normal() ) >= normalEpsilon
|
||||||
|| vector3_length( vert[2]->normal - buildPlane->normal() ) >= normalEpsilon ) {
|
|| vector3_length( vert[2]->normal - buildPlane.normal() ) >= normalEpsilon ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,14 +88,14 @@ void GetBestSurfaceTriangleMatchForBrushside( side_t *buildSide, bspDrawVert_t *
|
||||||
// models, there is no better way
|
// models, there is no better way
|
||||||
Plane3f plane;
|
Plane3f plane;
|
||||||
PlaneFromPoints( plane, vert[0]->xyz, vert[1]->xyz, vert[2]->xyz );
|
PlaneFromPoints( plane, vert[0]->xyz, vert[1]->xyz, vert[2]->xyz );
|
||||||
if ( vector3_length( plane.normal() - buildPlane->normal() ) >= normalEpsilon ) {
|
if ( vector3_length( plane.normal() - buildPlane.normal() ) >= normalEpsilon ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fixme? better distance epsilon
|
// fixme? better distance epsilon
|
||||||
if ( abs( plane3_distance_to_point( buildPlane->plane, vert[0]->xyz ) ) > 1
|
if ( abs( plane3_distance_to_point( buildPlane.plane, vert[0]->xyz ) ) > 1
|
||||||
|| abs( plane3_distance_to_point( buildPlane->plane, vert[1]->xyz ) ) > 1
|
|| abs( plane3_distance_to_point( buildPlane.plane, vert[1]->xyz ) ) > 1
|
||||||
|| abs( plane3_distance_to_point( buildPlane->plane, vert[2]->xyz ) ) > 1 ) {
|
|| abs( plane3_distance_to_point( buildPlane.plane, vert[2]->xyz ) ) > 1 ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Okay. Correct surface type, correct shader, correct plane. Let's start with the business...
|
// Okay. Correct surface type, correct shader, correct plane. Let's start with the business...
|
||||||
|
|
@ -108,7 +108,7 @@ void GetBestSurfaceTriangleMatchForBrushside( side_t *buildSide, bspDrawVert_t *
|
||||||
const Vector3& v1 = vert[( i + 1 ) % 3]->xyz;
|
const Vector3& v1 = vert[( i + 1 ) % 3]->xyz;
|
||||||
const Vector3& v2 = vert[( i + 2 ) % 3]->xyz;
|
const Vector3& v2 = vert[( i + 2 ) % 3]->xyz;
|
||||||
// we now need to generate the plane spanned by normal and (v2 - v1).
|
// we now need to generate the plane spanned by normal and (v2 - v1).
|
||||||
Plane3f plane( vector3_cross( v2 - v1, buildPlane->normal() ), 0 );
|
Plane3f plane( vector3_cross( v2 - v1, buildPlane.normal() ), 0 );
|
||||||
plane.dist() = vector3_dot( v1, plane.normal() );
|
plane.dist() = vector3_dot( v1, plane.normal() );
|
||||||
ChopWindingInPlace( &polygon, plane, distanceEpsilon );
|
ChopWindingInPlace( &polygon, plane, distanceEpsilon );
|
||||||
if ( !polygon ) {
|
if ( !polygon ) {
|
||||||
|
|
@ -876,13 +876,13 @@ static void ConvertModel( FILE *f, bspModel_t *model, int modelNum, const Vector
|
||||||
|
|
||||||
|
|
||||||
/* convert bsp planes to map planes */
|
/* convert bsp planes to map planes */
|
||||||
nummapplanes = numBSPPlanes;
|
mapplanes.resize( numBSPPlanes );
|
||||||
AUTOEXPAND_BY_REALLOC( mapplanes, nummapplanes, allocatedmapplanes, 1024 );
|
|
||||||
for ( i = 0; i < numBSPPlanes; i++ )
|
for ( i = 0; i < numBSPPlanes; i++ )
|
||||||
{
|
{
|
||||||
mapplanes[ i ].plane = bspPlanes[ i ];
|
plane_t& plane = mapplanes[i];
|
||||||
mapplanes[ i ].type = PlaneTypeForNormal( mapplanes[ i ].normal() );
|
plane.plane = bspPlanes[ i ];
|
||||||
mapplanes[ i ].hash_chain = 0;
|
plane.type = PlaneTypeForNormal( plane.normal() );
|
||||||
|
plane.hash_chain = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate a build brush */
|
/* allocate a build brush */
|
||||||
|
|
|
||||||
|
|
@ -363,24 +363,21 @@ void BuildFaceTree_r( node_t *node, face_t *list ){
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
tree_t *FaceBSP( face_t *list ) {
|
tree_t *FaceBSP( face_t *list ) {
|
||||||
tree_t *tree;
|
|
||||||
face_t *face;
|
|
||||||
|
|
||||||
Sys_FPrintf( SYS_VRB, "--- FaceBSP ---\n" );
|
Sys_FPrintf( SYS_VRB, "--- FaceBSP ---\n" );
|
||||||
|
|
||||||
tree = AllocTree();
|
tree_t *tree = AllocTree();
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for ( face = list; face != NULL; face = face->next )
|
for ( const face_t *face = list; face != NULL; face = face->next )
|
||||||
{
|
{
|
||||||
WindingExtendBounds( face->w, tree->minmax );
|
WindingExtendBounds( face->w, tree->minmax );
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
Sys_FPrintf( SYS_VRB, "%9d faces\n", count );
|
Sys_FPrintf( SYS_VRB, "%9d faces\n", count );
|
||||||
|
|
||||||
for ( int i = 0; i < nummapplanes; i++ )
|
for ( plane_t& plane : mapplanes )
|
||||||
{
|
{
|
||||||
mapplanes[ i ].counter = 0;
|
plane.counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
tree->headnode = AllocNode();
|
tree->headnode = AllocNode();
|
||||||
|
|
|
||||||
|
|
@ -81,14 +81,11 @@ bool PlaneEqual( const plane_t& p, const Plane3f& plane ){
|
||||||
AddPlaneToHash()
|
AddPlaneToHash()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void AddPlaneToHash( plane_t *p ){
|
void AddPlaneToHash( plane_t& p ){
|
||||||
int hash;
|
const int hash = ( PLANE_HASHES - 1 ) & (int) fabs( p.dist() );
|
||||||
|
|
||||||
|
p.hash_chain = planehash[hash];
|
||||||
hash = ( PLANE_HASHES - 1 ) & (int) fabs( p->dist() );
|
planehash[hash] = &p - mapplanes.data() + 1;
|
||||||
|
|
||||||
p->hash_chain = planehash[hash];
|
|
||||||
planehash[hash] = p - mapplanes + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -104,30 +101,28 @@ int CreateNewFloatPlane( const Plane3f& plane ){
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a new plane
|
// create a new plane
|
||||||
AUTOEXPAND_BY_REALLOC( mapplanes, nummapplanes + 1, allocatedmapplanes, 1024 );
|
mapplanes.resize( mapplanes.size() + 2 );
|
||||||
|
plane_t& p = *( mapplanes.end() - 2 );
|
||||||
plane_t *p = &mapplanes[nummapplanes];
|
plane_t& p2 = *( mapplanes.end() - 1 );
|
||||||
p->plane = plane;
|
p.plane = plane;
|
||||||
( p + 1 )->plane = plane3_flipped( plane );
|
p2.plane = plane3_flipped( plane );
|
||||||
p->type = ( p + 1 )->type = PlaneTypeForNormal( p->normal() );
|
p.type = p2.type = PlaneTypeForNormal( p.normal() );
|
||||||
|
|
||||||
nummapplanes += 2;
|
|
||||||
|
|
||||||
// always put axial planes facing positive first
|
// always put axial planes facing positive first
|
||||||
if ( p->type < ePlaneNonAxial ) {
|
if ( p.type < ePlaneNonAxial ) {
|
||||||
if ( p->normal()[0] < 0 || p->normal()[1] < 0 || p->normal()[2] < 0 ) {
|
if ( p.normal()[0] < 0 || p.normal()[1] < 0 || p.normal()[2] < 0 ) {
|
||||||
// flip order
|
// flip order
|
||||||
std::swap( *p, *( p + 1 ) );
|
std::swap( p, p2 );
|
||||||
|
|
||||||
AddPlaneToHash( p );
|
AddPlaneToHash( p );
|
||||||
AddPlaneToHash( p + 1 );
|
AddPlaneToHash( p2 );
|
||||||
return nummapplanes - 1;
|
return mapplanes.size() - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AddPlaneToHash( p );
|
AddPlaneToHash( p );
|
||||||
AddPlaneToHash( p + 1 );
|
AddPlaneToHash( p2 );
|
||||||
return nummapplanes - 2;
|
return mapplanes.size() - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -338,28 +333,25 @@ int FindFloatPlane( const Plane3f& inplane, int numPoints, const Vector3 *points
|
||||||
#ifdef USE_HASHING
|
#ifdef USE_HASHING
|
||||||
|
|
||||||
{
|
{
|
||||||
int i, j, hash, h;
|
|
||||||
int pidx;
|
|
||||||
Plane3f plane( inplane );
|
Plane3f plane( inplane );
|
||||||
|
|
||||||
#if Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX
|
#if Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX
|
||||||
SnapPlaneImproved( plane, numPoints, points );
|
SnapPlaneImproved( plane, numPoints, points );
|
||||||
#else
|
#else
|
||||||
SnapPlane( plane );
|
SnapPlane( plane );
|
||||||
#endif
|
#endif
|
||||||
/* hash the plane */
|
/* hash the plane */
|
||||||
hash = ( PLANE_HASHES - 1 ) & (int) fabs( plane.dist() );
|
const int hash = ( PLANE_HASHES - 1 ) & (int) fabs( plane.dist() );
|
||||||
|
|
||||||
/* search the border bins as well */
|
/* search the border bins as well */
|
||||||
for ( i = -1; i <= 1; i++ )
|
for ( int i = -1; i <= 1; i++ )
|
||||||
{
|
{
|
||||||
h = ( hash + i ) & ( PLANE_HASHES - 1 );
|
const int h = ( hash + i ) & ( PLANE_HASHES - 1 );
|
||||||
for ( pidx = planehash[ h ] - 1; pidx != -1; pidx = mapplanes[pidx].hash_chain - 1 )
|
for ( int pidx = planehash[ h ] - 1; pidx != -1; pidx = mapplanes[pidx].hash_chain - 1 )
|
||||||
{
|
{
|
||||||
plane_t *p = &mapplanes[pidx];
|
const plane_t& p = mapplanes[pidx];
|
||||||
|
|
||||||
/* do standard plane compare */
|
/* do standard plane compare */
|
||||||
if ( !PlaneEqual( *p, plane ) ) {
|
if ( !PlaneEqual( p, plane ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -367,6 +359,7 @@ int FindFloatPlane( const Plane3f& inplane, int numPoints, const Vector3 *points
|
||||||
//% return p - mapplanes;
|
//% return p - mapplanes;
|
||||||
|
|
||||||
/* ydnar: test supplied points against this plane */
|
/* ydnar: test supplied points against this plane */
|
||||||
|
int j;
|
||||||
for ( j = 0; j < numPoints; j++ )
|
for ( j = 0; j < numPoints; j++ )
|
||||||
{
|
{
|
||||||
// NOTE: When dist approaches 2^16, the resolution of 32 bit floating
|
// NOTE: When dist approaches 2^16, the resolution of 32 bit floating
|
||||||
|
|
@ -374,7 +367,7 @@ int FindFloatPlane( const Plane3f& inplane, int numPoints, const Vector3 *points
|
||||||
// very small when world coordinates extend to 2^16. Making the
|
// very small when world coordinates extend to 2^16. Making the
|
||||||
// dot product here in 64 bit land will not really help the situation
|
// dot product here in 64 bit land will not really help the situation
|
||||||
// because the error will already be carried in dist.
|
// because the error will already be carried in dist.
|
||||||
const double d = fabs( plane3_distance_to_point( p->plane, points[ j ] ) );
|
const double d = fabs( plane3_distance_to_point( p.plane, points[ j ] ) );
|
||||||
if ( d != 0.0 && d >= distanceEpsilon ) {
|
if ( d != 0.0 && d >= distanceEpsilon ) {
|
||||||
break; // Point is too far from plane.
|
break; // Point is too far from plane.
|
||||||
}
|
}
|
||||||
|
|
@ -382,7 +375,7 @@ int FindFloatPlane( const Plane3f& inplane, int numPoints, const Vector3 *points
|
||||||
|
|
||||||
/* found a matching plane */
|
/* found a matching plane */
|
||||||
if ( j >= numPoints ) {
|
if ( j >= numPoints ) {
|
||||||
return p - mapplanes;
|
return pidx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1842,7 +1835,7 @@ void LoadMapFile( char *filename, bool onlyLights, bool noCollapseGroups ){
|
||||||
Sys_FPrintf( SYS_VRB, "%9d boxbevels\n", c_boxbevels );
|
Sys_FPrintf( SYS_VRB, "%9d boxbevels\n", c_boxbevels );
|
||||||
Sys_FPrintf( SYS_VRB, "%9d edgebevels\n", c_edgebevels );
|
Sys_FPrintf( SYS_VRB, "%9d edgebevels\n", c_edgebevels );
|
||||||
Sys_FPrintf( SYS_VRB, "%9zu entities\n", entities.size() );
|
Sys_FPrintf( SYS_VRB, "%9zu entities\n", entities.size() );
|
||||||
Sys_FPrintf( SYS_VRB, "%9d planes\n", nummapplanes );
|
Sys_FPrintf( SYS_VRB, "%9zu planes\n", mapplanes.size() );
|
||||||
Sys_Printf( "%9d areaportals\n", c_areaportals );
|
Sys_Printf( "%9d areaportals\n", c_areaportals );
|
||||||
Sys_Printf( "Size: %5.0f, %5.0f, %5.0f to %5.0f, %5.0f, %5.0f\n",
|
Sys_Printf( "Size: %5.0f, %5.0f, %5.0f to %5.0f, %5.0f, %5.0f\n",
|
||||||
g_mapMinmax.mins[0], g_mapMinmax.mins[1], g_mapMinmax.mins[2],
|
g_mapMinmax.mins[0], g_mapMinmax.mins[1], g_mapMinmax.mins[2],
|
||||||
|
|
|
||||||
|
|
@ -707,9 +707,6 @@ void InsertModel( const char *name, int skin, int frame, const Matrix4& transfor
|
||||||
/* walk triangle list */
|
/* walk triangle list */
|
||||||
for ( i = 0; i < ds->numIndexes; i += 3 )
|
for ( i = 0; i < ds->numIndexes; i += 3 )
|
||||||
{
|
{
|
||||||
/* overflow hack */
|
|
||||||
AUTOEXPAND_BY_REALLOC( mapplanes, ( nummapplanes + 64 ) << 1, allocatedmapplanes, 1024 );
|
|
||||||
|
|
||||||
/* make points */
|
/* make points */
|
||||||
for ( j = 0; j < 3; j++ )
|
for ( j = 0; j < 3; j++ )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2104,9 +2104,7 @@ Q_EXTERN std::size_t mapEntityNum Q_ASSIGN( 0 );
|
||||||
|
|
||||||
Q_EXTERN int entitySourceBrushes;
|
Q_EXTERN int entitySourceBrushes;
|
||||||
|
|
||||||
Q_EXTERN plane_t *mapplanes Q_ASSIGN( NULL ); /* mapplanes[ num ^ 1 ] will always be the mirror or mapplanes[ num ] */
|
Q_EXTERN std::vector<plane_t> mapplanes; /* mapplanes[ num ^ 1 ] will always be the mirror or mapplanes[ num ] */ /* nummapplanes will always be even */
|
||||||
Q_EXTERN int nummapplanes Q_ASSIGN( 0 ); /* nummapplanes will always be even */
|
|
||||||
Q_EXTERN int allocatedmapplanes Q_ASSIGN( 0 );
|
|
||||||
Q_EXTERN int numMapPatches;
|
Q_EXTERN int numMapPatches;
|
||||||
Q_EXTERN MinMax g_mapMinmax;
|
Q_EXTERN MinMax g_mapMinmax;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,11 +117,7 @@ void FreeTree( tree_t *tree ){
|
||||||
//===============================================================
|
//===============================================================
|
||||||
|
|
||||||
void PrintTree_r( node_t *node, int depth ){
|
void PrintTree_r( node_t *node, int depth ){
|
||||||
int i;
|
for ( int i = 0; i < depth; i++ )
|
||||||
plane_t *plane;
|
|
||||||
brush_t *bb;
|
|
||||||
|
|
||||||
for ( i = 0 ; i < depth ; i++ )
|
|
||||||
Sys_Printf( " " );
|
Sys_Printf( " " );
|
||||||
if ( node->planenum == PLANENUM_LEAF ) {
|
if ( node->planenum == PLANENUM_LEAF ) {
|
||||||
if ( !node->brushlist ) {
|
if ( !node->brushlist ) {
|
||||||
|
|
@ -129,17 +125,17 @@ void PrintTree_r( node_t *node, int depth ){
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for ( bb = node->brushlist ; bb ; bb = bb->next )
|
for ( const brush_t *bb = node->brushlist; bb; bb = bb->next )
|
||||||
Sys_Printf( "%d ", bb->original->brushNum );
|
Sys_Printf( "%d ", bb->original->brushNum );
|
||||||
Sys_Printf( "\n" );
|
Sys_Printf( "\n" );
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plane = &mapplanes[node->planenum];
|
const plane_t& plane = mapplanes[node->planenum];
|
||||||
Sys_Printf( "#%d (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum,
|
Sys_Printf( "#%d (%5.2f %5.2f %5.2f):%5.2f\n", node->planenum,
|
||||||
plane->normal()[0], plane->normal()[1], plane->normal()[2],
|
plane.normal()[0], plane.normal()[1], plane.normal()[2],
|
||||||
plane->dist() );
|
plane.dist() );
|
||||||
PrintTree_r( node->children[0], depth + 1 );
|
PrintTree_r( node->children[0], depth + 1 );
|
||||||
PrintTree_r( node->children[1], depth + 1 );
|
PrintTree_r( node->children[1], depth + 1 );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,11 +112,10 @@ int EmitShader( const char *shader, int *contentFlags, int *surfaceFlags ){
|
||||||
|
|
||||||
void EmitPlanes( void ){
|
void EmitPlanes( void ){
|
||||||
/* walk plane list */
|
/* walk plane list */
|
||||||
plane_t *mp = mapplanes;
|
for ( size_t i = 0; i < mapplanes.size(); ++i )
|
||||||
for ( int i = 0; i < nummapplanes; i++, mp++ )
|
|
||||||
{
|
{
|
||||||
AUTOEXPAND_BY_REALLOC_BSP( Planes, 1024 );
|
AUTOEXPAND_BY_REALLOC_BSP( Planes, 1024 );
|
||||||
bspPlanes[ numBSPPlanes ] = mp->plane;
|
bspPlanes[ numBSPPlanes ] = mapplanes[i].plane;
|
||||||
numBSPPlanes++;
|
numBSPPlanes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user