mirror of
https://github.com/ptitSeb/Serious-Engine
synced 2024-11-22 10:20:26 +01:00
make all BSP-related tags size_t so they can store pointers
The tags are often initially assigned from pointers and then copied around, even from one tag type to the other. As BSPTree::MoveSubTreeToArray() uses them to get the original pointer, we need the pointers anyway, so just CRC-ing the pointers doesn't seem like a good option. As the tags are assigned from other tag-types sometimes, I probably would have needed to add Pointers for the same values in addition to the ULONG tags, that are also copied around along the tags, to keep the tags ULONG - that seemed like a worse alternative. However, when writing (via BSPTree::Write_t()) the bn_ulPlaneTag tag needs to be ULONG, so there I actually use CRC for 64bit pointers (via IntPtrToID()) - when restoring (in Read_t()), the pointers aren't valid anymore anyway, so that all should somehow be fine. I assume that Write_t() is only used by the Editor, anyway, so I fear I won't be able to test that part of the code on Linux anytime soon.
This commit is contained in:
parent
b437abf10d
commit
d228b6a7a7
|
@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <Engine/Templates/BSP_internal.h>
|
||||
|
||||
#include <Engine/Base/Stream.h>
|
||||
#include <Engine/Base/CRC.h>
|
||||
#include <Engine/Math/Vector.h>
|
||||
#include <Engine/Math/Plane.h>
|
||||
#include <Engine/Math/OBBox.h>
|
||||
|
@ -219,7 +220,7 @@ void BSPVertexContainer<Type, iDimensions>::ElliminatePairedVertices(void)
|
|||
* Create edges from vertices in one container -- must be sorted before.
|
||||
*/
|
||||
template<class Type, int iDimensions>
|
||||
void BSPVertexContainer<Type, iDimensions>::CreateEdges(CDynamicArray<BSPEdge<Type, iDimensions> > &abed, ULONG ulEdgeTag)
|
||||
void BSPVertexContainer<Type, iDimensions>::CreateEdges(CDynamicArray<BSPEdge<Type, iDimensions> > &abed, size_t ulEdgeTag)
|
||||
{
|
||||
// if there are no vertices, or the container is not line
|
||||
if (bvc_aVertices.Count()==0 || IsPlannar()) {
|
||||
|
@ -372,7 +373,7 @@ void BSPEdge<Type, iDimensions>::OptimizeBSPEdges(CDynamicArray<BSPEdge<Type, iD
|
|||
* Add an edge to the polygon.
|
||||
*/
|
||||
template<class Type, int iDimensions>
|
||||
inline void BSPPolygon<Type, iDimensions>::AddEdge(const Vector<Type, iDimensions> &vPoint0, const Vector<Type, iDimensions> &vPoint1, ULONG ulTag)
|
||||
inline void BSPPolygon<Type, iDimensions>::AddEdge(const Vector<Type, iDimensions> &vPoint0, const Vector<Type, iDimensions> &vPoint1, size_t ulTag)
|
||||
{
|
||||
*bpo_abedPolygonEdges.New() = BSPEdge<Type, iDimensions>(vPoint0, vPoint1, ulTag);
|
||||
}
|
||||
|
@ -412,7 +413,7 @@ BSPNode<Type, iDimensions>::BSPNode(enum BSPNodeLocation bnl)
|
|||
* Constructor for a branch node.
|
||||
*/
|
||||
template<class Type, int iDimensions>
|
||||
BSPNode<Type, iDimensions>::BSPNode(const Plane<Type, iDimensions> &plSplitPlane, ULONG ulPlaneTag,
|
||||
BSPNode<Type, iDimensions>::BSPNode(const Plane<Type, iDimensions> &plSplitPlane, size_t ulPlaneTag,
|
||||
BSPNode<Type, iDimensions> &bnFront, BSPNode<Type, iDimensions> &bnBack)
|
||||
: Plane<Type, iDimensions>(plSplitPlane)
|
||||
, bn_pbnFront(&bnFront)
|
||||
|
@ -731,7 +732,7 @@ void BSPCutter<Type, iDimensions>::CutPolygon(BSPPolygon<Type, iDimensions> &bpo
|
|||
* -- returns FALSE if polygon is laying on the plane
|
||||
*/
|
||||
template<class Type, int iDimensions>
|
||||
BOOL BSPCutter<Type, iDimensions>::SplitPolygon(BSPPolygon<Type, iDimensions> &bpoPolygon, const Plane<Type, iDimensions> &plSplitPlane, ULONG ulPlaneTag,
|
||||
BOOL BSPCutter<Type, iDimensions>::SplitPolygon(BSPPolygon<Type, iDimensions> &bpoPolygon, const Plane<Type, iDimensions> &plSplitPlane, size_t ulPlaneTag,
|
||||
BSPPolygon<Type, iDimensions> &bpoFront, BSPPolygon<Type, iDimensions> &bpoBack)
|
||||
{
|
||||
(Plane<Type, iDimensions> &)bpoFront = (Plane<Type, iDimensions> &)bpoPolygon;
|
||||
|
@ -802,7 +803,7 @@ BOOL BSPCutter<Type, iDimensions>::SplitPolygon(BSPPolygon<Type, iDimensions> &b
|
|||
* Split an edge with a plane.
|
||||
*/
|
||||
template<class Type, int iDimensions>
|
||||
void BSPCutter<Type, iDimensions>::SplitEdge(const Vector<Type, iDimensions> &vPoint0, const Vector<Type, iDimensions> &vPoint1, ULONG ulEdgeTag,
|
||||
void BSPCutter<Type, iDimensions>::SplitEdge(const Vector<Type, iDimensions> &vPoint0, const Vector<Type, iDimensions> &vPoint1, size_t ulEdgeTag,
|
||||
const Plane<Type, iDimensions> &plSplitPlane,
|
||||
BSPPolygon<Type, iDimensions> &bpoFront, BSPPolygon<Type, iDimensions> &bpoBack,
|
||||
BSPVertexContainer<Type, iDimensions> &bvcFront, BSPVertexContainer<Type, iDimensions> &bvcBack)
|
||||
|
@ -1132,20 +1133,17 @@ void BSPTree<Type, iDimensions>::MoveSubTreeToArray(BSPNode<Type, iDimensions> *
|
|||
bnInArray.bn_bnlLocation = pbnSubtree->bn_bnlLocation;
|
||||
bnInArray.bn_ulPlaneTag = pbnSubtree->bn_ulPlaneTag;
|
||||
// let plane tag hold pointer to node in array
|
||||
STUBBED("64-bit issue");
|
||||
pbnSubtree->bn_ulPlaneTag = (ULONG)(size_t)&bnInArray;
|
||||
pbnSubtree->bn_ulPlaneTag = (size_t)&bnInArray;
|
||||
|
||||
// remap pointers to subnodes
|
||||
if (pbnSubtree->bn_pbnFront==NULL) {
|
||||
bnInArray.bn_pbnFront = NULL;
|
||||
} else {
|
||||
STUBBED("64-bit issue"); // bn_ulPlaneTag is uint32!
|
||||
bnInArray.bn_pbnFront = (BSPNode<Type, iDimensions>*)pbnSubtree->bn_pbnFront->bn_ulPlaneTag;
|
||||
}
|
||||
if (pbnSubtree->bn_pbnBack==NULL) {
|
||||
bnInArray.bn_pbnBack = NULL;
|
||||
} else {
|
||||
STUBBED("64-bit issue"); // basically the same as above but for back!
|
||||
bnInArray.bn_pbnBack = (BSPNode<Type, iDimensions>*)pbnSubtree->bn_pbnBack->bn_ulPlaneTag;
|
||||
}
|
||||
}
|
||||
|
@ -1232,8 +1230,9 @@ void BSPTree<Type, iDimensions>::Read_t(CTStream &strm) // throw char *
|
|||
} else {
|
||||
bn.bn_pbnBack = &bt_abnNodes[iBack];
|
||||
}
|
||||
|
||||
strm>>bn.bn_ulPlaneTag;
|
||||
ULONG ul;
|
||||
strm>>ul;
|
||||
bn.bn_ulPlaneTag = ul;
|
||||
}
|
||||
|
||||
// check end id
|
||||
|
@ -1283,7 +1282,7 @@ void BSPTree<Type, iDimensions>::Write_t(CTStream &strm) // throw char *
|
|||
}
|
||||
strm<<iBack;
|
||||
|
||||
strm<<bn.bn_ulPlaneTag;
|
||||
strm<<IntPtrToID(bn.bn_ulPlaneTag);
|
||||
}
|
||||
// write end id for checking
|
||||
strm.WriteID_t("BSPE"); // bsp end
|
||||
|
|
|
@ -76,7 +76,7 @@ public:
|
|||
/* Elliminate paired vertices. */
|
||||
void ElliminatePairedVertices(void);
|
||||
/* Create edges from vertices in one container -- must be sorted before. */
|
||||
void CreateEdges(CDynamicArray<BSPEdge<Type, iDimensions> > &abedAll, ULONG ulEdgeTag);
|
||||
void CreateEdges(CDynamicArray<BSPEdge<Type, iDimensions> > &abedAll, size_t ulEdgeTag);
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -87,7 +87,7 @@ class BSPEdge {
|
|||
public:
|
||||
Vector<Type, iDimensions> bed_vVertex0; // edge vertices
|
||||
Vector<Type, iDimensions> bed_vVertex1;
|
||||
size_t bed_ulEdgeTag; // tags for BSPs with tagged edges/planes - FIXME DG: or uintprt_t?
|
||||
size_t bed_ulEdgeTag; // tags for BSPs with tagged edges/planes
|
||||
|
||||
/* Default constructor. */
|
||||
inline BSPEdge(void) {};
|
||||
|
@ -113,7 +113,7 @@ public:
|
|||
size_t bpo_ulPlaneTag; // tags for BSPs with tagged planes (-1 for no tag)
|
||||
|
||||
/* Add an edge to the polygon. */
|
||||
inline void AddEdge(const Vector<Type, iDimensions> &vPoint0, const Vector<Type, iDimensions> &vPoint1, ULONG ulTag);
|
||||
inline void AddEdge(const Vector<Type, iDimensions> &vPoint0, const Vector<Type, iDimensions> &vPoint1, size_t ulTag);
|
||||
|
||||
/* Default constructor. */
|
||||
inline BSPPolygon(void) : bpo_ulPlaneTag(-1) {};
|
||||
|
@ -146,7 +146,7 @@ public:
|
|||
|
||||
BSPNode<Type, iDimensions> *bn_pbnFront; // pointer to child node in front of split plane
|
||||
BSPNode<Type, iDimensions> *bn_pbnBack; // pointer to child node behind split plane
|
||||
ULONG bn_ulPlaneTag; // tags for BSPs with tagged planes (-1 for no tag)
|
||||
size_t bn_ulPlaneTag; // tags for BSPs with tagged planes (-1 for no tag)
|
||||
|
||||
public:
|
||||
/* Defualt constructor (for arrays only). */
|
||||
|
@ -154,7 +154,7 @@ public:
|
|||
/* Constructor for a leaf node. */
|
||||
inline BSPNode(enum BSPNodeLocation bnl);
|
||||
/* Constructor for a branch node. */
|
||||
inline BSPNode(const Plane<Type, iDimensions> &plSplitPlane, ULONG ulPlaneTag,
|
||||
inline BSPNode(const Plane<Type, iDimensions> &plSplitPlane, size_t ulPlaneTag,
|
||||
BSPNode<Type, iDimensions> &bnFront, BSPNode<Type, iDimensions> &bnBack);
|
||||
/* Constructor for cloning a bsp (sub)tree. */
|
||||
BSPNode(BSPNode<Type, iDimensions> &bnRoot);
|
||||
|
@ -180,7 +180,7 @@ template<class Type, int iDimensions>
|
|||
class BSPCutter {
|
||||
public:
|
||||
/* Split an edge with a plane. */
|
||||
static inline void SplitEdge(const Vector<Type, iDimensions> &vPoint0, const Vector<Type, iDimensions> &vPoint1, ULONG ulEdgeTag,
|
||||
static inline void SplitEdge(const Vector<Type, iDimensions> &vPoint0, const Vector<Type, iDimensions> &vPoint1, size_t ulEdgeTag,
|
||||
const Plane<Type, iDimensions> &plSplitPlane,
|
||||
BSPPolygon<Type, iDimensions> &abedFront, BSPPolygon<Type, iDimensions> &abedBack,
|
||||
BSPVertexContainer<Type, iDimensions> &bvcFront, BSPVertexContainer<Type, iDimensions> &bvcBack);
|
||||
|
@ -195,7 +195,7 @@ public:
|
|||
CDynamicArray<BSPEdge<Type, iDimensions> > bc_abedBorderOutside;// edges of border part of polygon facing outwards
|
||||
|
||||
/* Split a polygon with a plane. */
|
||||
static inline BOOL SplitPolygon(BSPPolygon<Type, iDimensions> &bpoPolygon, const Plane<Type, iDimensions> &plPlane, ULONG ulPlaneTag,
|
||||
static inline BOOL SplitPolygon(BSPPolygon<Type, iDimensions> &bpoPolygon, const Plane<Type, iDimensions> &plPlane, size_t ulPlaneTag,
|
||||
BSPPolygon<Type, iDimensions> &bpoFront, BSPPolygon<Type, iDimensions> &bpoBack);
|
||||
|
||||
/* Constructor for splitting a polygon with a BSP tree. */
|
||||
|
|
Loading…
Reference in New Issue
Block a user