From 7d03ed4dc76a9fa71f5ab63a1b48b6e7a30ded0b Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 30 Apr 2016 22:37:02 -0500 Subject: [PATCH] Use floating point node bounding boxes --- src/nodebuild.cpp | 12 ++++++------ src/nodebuild_extract.cpp | 14 ++++++++++++++ src/p_glnodes.cpp | 6 +++--- src/p_setup.cpp | 4 ++-- src/po_man.cpp | 14 +++++++------- src/r_bsp.cpp | 18 +++++++++--------- src/r_defs.h | 6 +++++- 7 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/nodebuild.cpp b/src/nodebuild.cpp index d1a8737ec..2d81d2ab2 100644 --- a/src/nodebuild.cpp +++ b/src/nodebuild.cpp @@ -156,12 +156,12 @@ int FNodeBuilder::CreateNode (DWORD set, unsigned int count, fixed_t bbox[4]) D(PrintSet (1, set1)); D(Printf (PRINT_LOG, "(%d,%d) delta (%d,%d) from seg %d\n", node.x>>16, node.y>>16, node.dx>>16, node.dy>>16, splitseg)); D(PrintSet (2, set2)); - node.intchildren[0] = CreateNode (set1, count1, node.bbox[0]); - node.intchildren[1] = CreateNode (set2, count2, node.bbox[1]); - bbox[BOXTOP] = MAX (node.bbox[0][BOXTOP], node.bbox[1][BOXTOP]); - bbox[BOXBOTTOM] = MIN (node.bbox[0][BOXBOTTOM], node.bbox[1][BOXBOTTOM]); - bbox[BOXLEFT] = MIN (node.bbox[0][BOXLEFT], node.bbox[1][BOXLEFT]); - bbox[BOXRIGHT] = MAX (node.bbox[0][BOXRIGHT], node.bbox[1][BOXRIGHT]); + node.intchildren[0] = CreateNode (set1, count1, node.nb_bbox[0]); + node.intchildren[1] = CreateNode (set2, count2, node.nb_bbox[1]); + bbox[BOXTOP] = MAX (node.nb_bbox[0][BOXTOP], node.nb_bbox[1][BOXTOP]); + bbox[BOXBOTTOM] = MIN (node.nb_bbox[0][BOXBOTTOM], node.nb_bbox[1][BOXBOTTOM]); + bbox[BOXLEFT] = MIN (node.nb_bbox[0][BOXLEFT], node.nb_bbox[1][BOXLEFT]); + bbox[BOXRIGHT] = MAX (node.nb_bbox[0][BOXRIGHT], node.nb_bbox[1][BOXRIGHT]); return (int)Nodes.Push (node); } else diff --git a/src/nodebuild_extract.cpp b/src/nodebuild_extract.cpp index 425c656e3..c3f63c820 100644 --- a/src/nodebuild_extract.cpp +++ b/src/nodebuild_extract.cpp @@ -94,6 +94,13 @@ void FNodeBuilder::Extract (node_t *&outNodes, int &nodeCount, outNodes[i].children[j] = outNodes + outNodes[i].intchildren[j]; } } + for (int j = 0; j < 2; ++j) + { + for (int k = 0; k < 4; ++k) + { + outNodes[i].bbox[j][k] = FIXED2FLOAT(outNodes[i].nb_bbox[j][k]); + } + } } if (GLNodes) @@ -194,6 +201,13 @@ void FNodeBuilder::ExtractMini (FMiniBSP *bsp) bsp->Nodes[i].children[j] = &bsp->Nodes[bsp->Nodes[i].intchildren[j]]; } } + for (int j = 0; j < 2; ++j) + { + for (int k = 0; k < 4; ++k) + { + bsp->Nodes[i].bbox[j][k] = FIXED2FLOAT(bsp->Nodes[i].nb_bbox[j][k]); + } + } } if (GLNodes) diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index 739990692..0fe4cd9c0 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -589,7 +589,7 @@ static bool LoadNodes (FileReader * lump) } for (k = 0; k < 4; k++) { - no->bbox[j][k] = LittleShort(mn->bbox[j][k])<bbox[j][k] = (float)LittleShort(mn->bbox[j][k]); } } } @@ -649,7 +649,7 @@ static bool LoadNodes (FileReader * lump) } for (k = 0; k < 4; k++) { - no->bbox[j][k] = LittleShort(mn->bbox[j][k])<bbox[j][k] = (float)LittleShort(mn->bbox[j][k]); } } } @@ -1135,7 +1135,7 @@ static void CreateCachedNodes(MapData *map) { for (int k = 0; k < 4; ++k) { - WriteWord(ZNodes, nodes[i].bbox[j][k] >> FRACBITS); + WriteWord(ZNodes, (short)nodes[i].bbox[j][k]); } } diff --git a/src/p_setup.cpp b/src/p_setup.cpp index ebd38ba9a..762f4b794 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -1096,7 +1096,7 @@ void LoadZNodes(FileReaderBase &data, int glnodes) { SWORD coord; data >> coord; - nodes[i].bbox[j][k] = coord << FRACBITS; + nodes[i].bbox[j][k] = coord; } } for (int m = 0; m < 2; ++m) @@ -1640,7 +1640,7 @@ void P_LoadNodes (MapData * map) } for (k = 0; k < 4; k++) { - no->bbox[j][k] = LittleShort(mn->bbox[j][k])<bbox[j][k] = (float)LittleShort(mn->bbox[j][k]); } } } diff --git a/src/po_man.cpp b/src/po_man.cpp index 1f9c6dbfd..7b5e187a8 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -1919,7 +1919,7 @@ static double PartitionDistance(FPolyVertex *vt, node_t *node) // //========================================================================== -static void AddToBBox(fixed_t child[4], fixed_t parent[4]) +static void AddToBBox(float child[4], float parent[4]) { if (child[BOXTOP] > parent[BOXTOP]) { @@ -1945,10 +1945,10 @@ static void AddToBBox(fixed_t child[4], fixed_t parent[4]) // //========================================================================== -static void AddToBBox(FPolyVertex *v, fixed_t bbox[4]) +static void AddToBBox(FPolyVertex *v, float bbox[4]) { - fixed_t x = FLOAT2FIXED(v->pos.X); - fixed_t y = FLOAT2FIXED(v->pos.Y); + float x = float(v->pos.X); + float y = float(v->pos.Y); if (x < bbox[BOXLEFT]) { bbox[BOXLEFT] = x; @@ -1973,7 +1973,7 @@ static void AddToBBox(FPolyVertex *v, fixed_t bbox[4]) // //========================================================================== -static void SplitPoly(FPolyNode *pnode, void *node, fixed_t bbox[4]) +static void SplitPoly(FPolyNode *pnode, void *node, float bbox[4]) { static TArray lists[2]; static const double POLY_EPSILON = 0.3125; @@ -2110,7 +2110,7 @@ static void SplitPoly(FPolyNode *pnode, void *node, fixed_t bbox[4]) // calculate bounding box for this polynode assert(pnode->segs.Size() != 0); - fixed_t subbbox[4] = { FIXED_MIN, FIXED_MAX, FIXED_MAX, FIXED_MIN }; + float subbbox[4] = { FLT_MIN, FLT_MAX, FLT_MAX, FLT_MIN }; for (unsigned i = 0; i < pnode->segs.Size(); ++i) { @@ -2134,7 +2134,7 @@ void FPolyObj::CreateSubsectorLinks() // Even though we don't care about it, we need to initialize this // bounding box to something so that Valgrind won't complain about it // when SplitPoly modifies it. - fixed_t dummybbox[4] = { 0 }; + float dummybbox[4] = { 0 }; node->poly = this; node->segs.Resize(Sidedefs.Size()); diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 2660fce6e..f41e99a74 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -877,7 +877,7 @@ extern "C" const int checkcoord[12][4] = }; -static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static +static bool R_CheckBBox (float *bspcoord) // killough 1/28/98: static { int boxx; int boxy; @@ -891,16 +891,16 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static // Find the corners of the box // that define the edges from current viewpoint. - if (ViewPos.X <= FIXED2DBL(bspcoord[BOXLEFT])) + if (ViewPos.X <= bspcoord[BOXLEFT]) boxx = 0; - else if (ViewPos.X < FIXED2DBL(bspcoord[BOXRIGHT])) + else if (ViewPos.X < bspcoord[BOXRIGHT]) boxx = 1; else boxx = 2; - if (ViewPos.Y >= FIXED2DBL(bspcoord[BOXTOP])) + if (ViewPos.Y >= bspcoord[BOXTOP]) boxy = 0; - else if (ViewPos.Y > FIXED2DBL(bspcoord[BOXBOTTOM])) + else if (ViewPos.Y > bspcoord[BOXBOTTOM]) boxy = 1; else boxy = 2; @@ -909,10 +909,10 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static if (boxpos == 5) return true; - x1 = FIXED2DBL(bspcoord[checkcoord[boxpos][0]]) - ViewPos.X; - y1 = FIXED2DBL(bspcoord[checkcoord[boxpos][1]]) - ViewPos.Y; - x2 = FIXED2DBL(bspcoord[checkcoord[boxpos][2]]) - ViewPos.X; - y2 = FIXED2DBL(bspcoord[checkcoord[boxpos][3]]) - ViewPos.Y; + x1 = bspcoord[checkcoord[boxpos][0]] - ViewPos.X; + y1 = bspcoord[checkcoord[boxpos][1]] - ViewPos.Y; + x2 = bspcoord[checkcoord[boxpos][2]] - ViewPos.X; + y2 = bspcoord[checkcoord[boxpos][3]] - ViewPos.Y; // check clip list for an open space diff --git a/src/r_defs.h b/src/r_defs.h index 371b9918e..f27ac2716 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -1364,7 +1364,11 @@ struct node_t fixed_t y; fixed_t dx; fixed_t dy; - fixed_t bbox[2][4]; // Bounding box for each child. + union + { + float bbox[2][4]; // Bounding box for each child. + fixed_t nb_bbox[2][4]; // Used by nodebuilder. + }; float len; union {