consistency

This commit is contained in:
Irlan 2018-07-17 21:31:07 -03:00
parent 99117d30b7
commit c3a69b6026

View File

@ -24,24 +24,16 @@
// Used to map pointers to indices // Used to map pointers to indices
// If more performance is required then a use hash-map // If more performance is required then a use hash-map
template<class T, u32 N> template<class T, u32 N>
struct b3UniqueArray struct b3UniqueStackArray
{ {
b3UniqueArray() b3UniqueStackArray()
{ {
count = 0; count = 0;
} }
// Add the value
void Add(const T& value)
{
B3_ASSERT(count < N);
values[count++] = value;
}
// Add the value if not found
// Return value index if added // Return value index if added
// Return N if the array is full // Return N if the array is full
u32 Find(const T& value) u32 PushBack(const T& value)
{ {
for (u32 i = 0; i < count; ++i) for (u32 i = 0; i < count; ++i)
{ {
@ -308,15 +300,14 @@ void b3QHull::Set(const b3Vec3* points, u32 count, bool simplify)
} }
// Convert the constructed hull into a run-time hull. // Convert the constructed hull into a run-time hull.
b3UniqueArray<qhVertex*, B3_MAX_HULL_VERTICES> vs; b3UniqueStackArray<qhVertex*, B3_MAX_HULL_VERTICES> vs;
b3UniqueArray<qhHalfEdge*, B3_MAX_HULL_EDGES> es; b3UniqueStackArray<qhHalfEdge*, B3_MAX_HULL_EDGES> es;
u32 fs_count = 0; u32 fs_count = 0;
// Add vertices to the map // Add vertices to the map
for (qhVertex* vertex = hull.GetVertexList().head; vertex != NULL; vertex = vertex->next) for (qhVertex* vertex = hull.GetVertexList().head; vertex != NULL; vertex = vertex->next)
{ {
// Add vertex vs.PushBack(vertex);
vs.Add(vertex);
} }
// Add faces and half-edges to the map // Add faces and half-edges to the map
@ -332,7 +323,7 @@ void b3QHull::Set(const b3Vec3* points, u32 count, bool simplify)
do do
{ {
// Add half-edge // Add half-edge
u32 iedge = es.Find(edge); u32 iedge = es.PushBack(edge);
if (iedge == B3_MAX_HULL_EDGES) if (iedge == B3_MAX_HULL_EDGES)
{ {
// Half-edge excess // Half-edge excess
@ -340,7 +331,7 @@ void b3QHull::Set(const b3Vec3* points, u32 count, bool simplify)
} }
// Add half-edge just after its twin // Add half-edge just after its twin
u32 itwin = es.Find(edge->twin); u32 itwin = es.PushBack(edge->twin);
if (itwin == B3_MAX_HULL_EDGES) if (itwin == B3_MAX_HULL_EDGES)
{ {
// Half-edge excess // Half-edge excess
@ -361,29 +352,29 @@ void b3QHull::Set(const b3Vec3* points, u32 count, bool simplify)
planes[iface] = face->plane; planes[iface] = face->plane;
qhHalfEdge* begin = face->edge; qhHalfEdge* begin = face->edge;
hface->edge = (u8)es.Find(begin); hface->edge = (u8)es.PushBack(begin);
qhHalfEdge* edge = begin; qhHalfEdge* edge = begin;
do do
{ {
qhVertex* v = edge->tail; qhVertex* v = edge->tail;
u8 iv = (u8)vs.Find(v); u8 iv = (u8)vs.PushBack(v);
vertices[iv] = v->position; vertices[iv] = v->position;
u8 iedge = (u8)es.Find(edge); u8 iedge = (u8)es.PushBack(edge);
b3HalfEdge* hedge = edges + iedge; b3HalfEdge* hedge = edges + iedge;
hedge->face = u8(iface); hedge->face = u8(iface);
hedge->origin = iv; hedge->origin = iv;
qhHalfEdge* twin = edge->twin; qhHalfEdge* twin = edge->twin;
u8 itwin = (u8)es.Find(twin); u8 itwin = (u8)es.PushBack(twin);
b3HalfEdge* htwin = edges + itwin; b3HalfEdge* htwin = edges + itwin;
htwin->twin = iedge; htwin->twin = iedge;
hedge->twin = itwin; hedge->twin = itwin;
qhHalfEdge* next = edge->next; qhHalfEdge* next = edge->next;
u8 inext = (u8)es.Find(next); u8 inext = (u8)es.PushBack(next);
edges[iedge].next = inext; edges[iedge].next = inext;