From: havoc Date: Thu, 18 Feb 2010 06:25:26 +0000 (+0000) Subject: moved BIH_LEAF from bih_nodetype_t to bih_leaftype_t X-Git-Tag: xonotic-v0.1.0preview~230^2~485 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c47771198ec4b5144616f28a9774038a0767b3da;p=xonotic%2Fdarkplaces.git moved BIH_LEAF from bih_nodetype_t to bih_leaftype_t renamed BIH_LEAF to BIH_BRUSH renamed BIH_LEAF + 1 to BIH_COLLISIONTRIANGLE renamed BIH_LEAF + 2 to BIH_RENDERTRIANGLE git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9984 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/bih.c b/bih.c index 8797d20d..fdda1d6d 100644 --- a/bih.c +++ b/bih.c @@ -2,7 +2,7 @@ // This code written in 2010 by Forest Hale (lordhavoc ghdigital com), and placed into public domain. #include -#include +#include #include "bih.h" static int BIH_BuildNode(bih_t *bih, int numchildren, int *leaflist, float *totalmins, float *totalmaxs) @@ -10,10 +10,10 @@ static int BIH_BuildNode(bih_t *bih, int numchildren, int *leaflist, float *tota int i; int j; int longestaxis; - int axis; + int axis = 0; int nodenum; - int front; - int back; + int front = 0; + int back = 0; bih_node_t *node; bih_leaf_t *child; float splitdist; @@ -112,7 +112,7 @@ static int BIH_BuildNode(bih_t *bih, int numchildren, int *leaflist, float *tota } // we now have front and back children divided in leaflist... - node->type = BIH_SPLITX + axis; + node->type = (bih_nodetype_t)((int)BIH_SPLITX + axis); node->front = BIH_BuildNode(bih, front, leaflist, frontmins, frontmaxs); node->frontmin = frontmins[axis]; node->back = BIH_BuildNode(bih, back, leaflist + front, backmins, backmaxs); diff --git a/bih.h b/bih.h index 56632b36..48a33d11 100644 --- a/bih.h +++ b/bih.h @@ -18,10 +18,17 @@ typedef enum bih_nodetype_e BIH_SPLITX = 0, BIH_SPLITY = 1, BIH_SPLITZ = 2, - BIH_LEAF = 3, } bih_nodetype_t; +typedef enum bih_leaftype_e +{ + BIH_BRUSH = 3, + BIH_COLLISIONTRIANGLE = 4, + BIH_RENDERTRIANGLE = 5, +} +bih_leaftype_t; + typedef struct bih_node_s { bih_nodetype_t type; // = BIH_SPLITX and similar values @@ -40,7 +47,7 @@ bih_node_t; typedef struct bih_leaf_s { - bih_nodetype_t type; // = BIH_LEAF + bih_leaftype_t type; // = BIH_BRUSH And similar values float mins[3]; float maxs[3]; // data past this point is generic and entirely up to the caller... diff --git a/gl_rmain.c b/gl_rmain.c index 3635f19f..be299bf2 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -12145,8 +12145,7 @@ void R_DrawDebugModel(void) continue; switch (bihleaf->type) { - case BIH_LEAF: - // brush + case BIH_BRUSH: brush = model->brush.data_brushes + bihleaf->itemindex; if (brush->colbrushf && brush->colbrushf->numtriangles) { @@ -12155,8 +12154,7 @@ void R_DrawDebugModel(void) R_Mesh_Draw(0, brush->colbrushf->numpoints, 0, brush->colbrushf->numtriangles, brush->colbrushf->elements, NULL, 0, 0); } break; - case BIH_LEAF + 1: - // triangle + case BIH_COLLISIONTRIANGLE: triangleindex = bihleaf->itemindex; VectorCopy(model->brush.data_collisionvertex3f + 3*model->brush.data_collisionelement3i[triangleindex*3+0], vertex3f[0]); VectorCopy(model->brush.data_collisionvertex3f + 3*model->brush.data_collisionelement3i[triangleindex*3+1], vertex3f[1]); @@ -12165,7 +12163,14 @@ void R_DrawDebugModel(void) GL_Color((bihleafindex & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 5) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 10) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, r_showcollisionbrushes.value); R_Mesh_Draw(0, 3, 0, 1, polygonelement3i, polygonelement3s, 0, 0); break; - default: + case BIH_RENDERTRIANGLE: + triangleindex = bihleaf->itemindex; + VectorCopy(model->surfmesh.data_vertex3f + 3*model->surfmesh.data_element3i[triangleindex*3+0], vertex3f[0]); + VectorCopy(model->surfmesh.data_vertex3f + 3*model->surfmesh.data_element3i[triangleindex*3+1], vertex3f[1]); + VectorCopy(model->surfmesh.data_vertex3f + 3*model->surfmesh.data_element3i[triangleindex*3+2], vertex3f[2]); + R_Mesh_VertexPointer(vertex3f[0], 0, 0); + GL_Color((bihleafindex & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 5) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 10) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, r_showcollisionbrushes.value); + R_Mesh_Draw(0, 3, 0, 1, polygonelement3i, polygonelement3s, 0, 0); break; } } diff --git a/model_brush.c b/model_brush.c index 06db2edd..ea5a2391 100644 --- a/model_brush.c +++ b/model_brush.c @@ -5717,19 +5717,16 @@ static void Mod_CollisionBIH_TracePoint_RecursiveBIHNode(trace_t *trace, dp_mode leaf = model->collision_bih.leafs + (-1-nodenum); switch(leaf->type) { - case BIH_LEAF: - // brush + case BIH_BRUSH: brush = model->brush.data_brushes[leaf->itemindex].colbrushf; Collision_TracePointBrushFloat(trace, point, brush); break; - case BIH_LEAF + 1: + case BIH_COLLISIONTRIANGLE: // collision triangle - skipped because they have no volume break; - case BIH_LEAF + 2: + case BIH_RENDERTRIANGLE: // render triangle - skipped because they have no volume break; - default: - break; } } @@ -5980,27 +5977,22 @@ static void Mod_CollisionBIH_TraceLine_RecursiveBIHNode(trace_t *trace, dp_model #endif switch(leaf->type) { - case BIH_LEAF: - // brush + case BIH_BRUSH: brush = model->brush.data_brushes[leaf->itemindex].colbrushf; Collision_TraceLineBrushFloat(trace, linestart, lineend, brush, brush); break; - case BIH_LEAF + 1: - // collision triangle + case BIH_COLLISIONTRIANGLE: if (!mod_q3bsp_curves_collisions.integer) return; e = model->brush.data_collisionelement3i + 3*leaf->itemindex; texture = model->data_textures + leaf->textureindex; Collision_TraceLineTriangleFloat(trace, linestart, lineend, model->brush.data_collisionvertex3f + e[0] * 3, model->brush.data_collisionvertex3f + e[1] * 3, model->brush.data_collisionvertex3f + e[2] * 3, texture->supercontents, texture->surfaceflags, texture); break; - case BIH_LEAF + 2: - // render triangle + case BIH_RENDERTRIANGLE: e = model->surfmesh.data_element3i + 3*leaf->itemindex; texture = model->data_textures + leaf->textureindex; Collision_TraceLineTriangleFloat(trace, linestart, lineend, model->surfmesh.data_vertex3f + e[0] * 3, model->surfmesh.data_vertex3f + e[1] * 3, model->surfmesh.data_vertex3f + e[2] * 3, texture->supercontents, texture->surfaceflags, texture); break; - default: - break; } } @@ -6045,27 +6037,22 @@ static void Mod_CollisionBIH_TraceBrush_RecursiveBIHNode(trace_t *trace, dp_mode #endif switch(leaf->type) { - case BIH_LEAF: - // brush + case BIH_BRUSH: brush = model->brush.data_brushes[leaf->itemindex].colbrushf; Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, brush, brush); break; - case BIH_LEAF + 1: - // collision triangle + case BIH_COLLISIONTRIANGLE: if (!mod_q3bsp_curves_collisions.integer) return; e = model->brush.data_collisionelement3i + 3*leaf->itemindex; texture = model->data_textures + leaf->textureindex; Collision_TraceBrushTriangleFloat(trace, thisbrush_start, thisbrush_end, model->brush.data_collisionvertex3f + e[0] * 3, model->brush.data_collisionvertex3f + e[1] * 3, model->brush.data_collisionvertex3f + e[2] * 3, texture->supercontents, texture->surfaceflags, texture); break; - case BIH_LEAF + 2: - // render triangle + case BIH_RENDERTRIANGLE: e = model->surfmesh.data_element3i + 3*leaf->itemindex; texture = model->data_textures + leaf->textureindex; Collision_TraceBrushTriangleFloat(trace, thisbrush_start, thisbrush_end, model->surfmesh.data_vertex3f + e[0] * 3, model->surfmesh.data_vertex3f + e[1] * 3, model->surfmesh.data_vertex3f + e[2] * 3, texture->supercontents, texture->surfaceflags, texture); break; - default: - break; } } @@ -6606,7 +6593,7 @@ void Mod_MakeCollisionBIH(dp_model_t *model, qboolean userendersurfaces) { for (triangleindex = 0, e = renderelement3i + 3*surface->num_firsttriangle;triangleindex < surface->num_triangles;triangleindex++, e += 3) { - bihleafs[bihleafindex].type = BIH_LEAF + 2; + bihleafs[bihleafindex].type = BIH_RENDERTRIANGLE; bihleafs[bihleafindex].textureindex = surface->texture - model->data_textures; bihleafs[bihleafindex].itemindex = triangleindex+surface->num_firsttriangle; bihleafs[bihleafindex].mins[0] = min(rendervertex3f[3*e[0]+0], min(rendervertex3f[3*e[1]+0], rendervertex3f[3*e[2]+0])) - 1; @@ -6626,7 +6613,7 @@ void Mod_MakeCollisionBIH(dp_model_t *model, qboolean userendersurfaces) { if (!brush->colbrushf) continue; - bihleafs[bihleafindex].type = BIH_LEAF; + bihleafs[bihleafindex].type = BIH_BRUSH; bihleafs[bihleafindex].textureindex = brush->texture - model->data_textures; bihleafs[bihleafindex].itemindex = brushindex+model->firstmodelbrush; VectorCopy(brush->colbrushf->mins, bihleafs[bihleafindex].mins); @@ -6641,7 +6628,7 @@ void Mod_MakeCollisionBIH(dp_model_t *model, qboolean userendersurfaces) { for (triangleindex = 0, e = collisionelement3i + 3*surface->num_firstcollisiontriangle;triangleindex < surface->num_collisiontriangles;triangleindex++, e += 3) { - bihleafs[bihleafindex].type = BIH_LEAF + 1; + bihleafs[bihleafindex].type = BIH_COLLISIONTRIANGLE; bihleafs[bihleafindex].textureindex = surface->texture - model->data_textures; bihleafs[bihleafindex].itemindex = triangleindex+surface->num_firstcollisiontriangle; bihleafs[bihleafindex].mins[0] = min(collisionvertex3f[3*e[0]+0], min(collisionvertex3f[3*e[1]+0], collisionvertex3f[3*e[2]+0])) - 1;