Skip to content
Snippets Groups Projects
Commit 2c4c1c47 authored by David Parks's avatar David Parks
Browse files

Take advantage of automagical tcmalloc alignment.

parent e18e26e8
No related branches found
No related tags found
No related merge requests found
...@@ -95,22 +95,30 @@ public: ...@@ -95,22 +95,30 @@ public:
typedef LLOctreeNode<T> oct_node; typedef LLOctreeNode<T> oct_node;
typedef LLOctreeListener<T> oct_listener; typedef LLOctreeListener<T> oct_listener;
/*void* operator new(size_t size)
{
return ll_aligned_malloc_16(size);
}
void operator delete(void* ptr)
{
ll_aligned_free_16(ptr);
}*/
LLOctreeNode( const LLVector4a& center, LLOctreeNode( const LLVector4a& center,
const LLVector4a& size, const LLVector4a& size,
BaseType* parent, BaseType* parent,
S32 octant = -1) U8 octant = 255)
: mParent((oct_node*)parent), : mParent((oct_node*)parent),
mOctant(octant) mOctant(octant)
{ {
mD = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*4); mCenter = center;
mSize = size;
mD[CENTER] = center;
mD[SIZE] = size;
updateMinMax(); updateMinMax();
if ((mOctant == -1) && mParent) if ((mOctant == 255) && mParent)
{ {
mOctant = ((oct_node*) mParent)->getOctant(mD[CENTER]); mOctant = ((oct_node*) mParent)->getOctant(mCenter);
} }
clearChildren(); clearChildren();
...@@ -124,30 +132,27 @@ public: ...@@ -124,30 +132,27 @@ public:
{ {
delete getChild(i); delete getChild(i);
} }
ll_aligned_free_16(mD);
} }
inline const BaseType* getParent() const { return mParent; } inline const BaseType* getParent() const { return mParent; }
inline void setParent(BaseType* parent) { mParent = (oct_node*) parent; } inline void setParent(BaseType* parent) { mParent = (oct_node*) parent; }
inline const LLVector4a& getCenter() const { return mD[CENTER]; } inline const LLVector4a& getCenter() const { return mCenter; }
inline const LLVector4a& getSize() const { return mD[SIZE]; } inline const LLVector4a& getSize() const { return mSize; }
inline void setCenter(const LLVector4a& center) { mD[CENTER] = center; } inline void setCenter(const LLVector4a& center) { mCenter = center; }
inline void setSize(const LLVector4a& size) { mD[SIZE] = size; } inline void setSize(const LLVector4a& size) { mSize = size; }
inline oct_node* getNodeAt(T* data) { return getNodeAt(data->getPositionGroup(), data->getBinRadius()); } inline oct_node* getNodeAt(T* data) { return getNodeAt(data->getPositionGroup(), data->getBinRadius()); }
inline S32 getOctant() const { return mOctant; } inline U8 getOctant() const { return mOctant; }
inline void setOctant(S32 octant) { mOctant = octant; }
inline const oct_node* getOctParent() const { return (const oct_node*) getParent(); } inline const oct_node* getOctParent() const { return (const oct_node*) getParent(); }
inline oct_node* getOctParent() { return (oct_node*) getParent(); } inline oct_node* getOctParent() { return (oct_node*) getParent(); }
S32 getOctant(const LLVector4a& pos) const //get the octant pos is in U8 getOctant(const LLVector4a& pos) const //get the octant pos is in
{ {
return pos.greaterThan(mD[CENTER]).getGatheredBits() & 0x7; return (U8) (pos.greaterThan(mCenter).getGatheredBits() & 0x7);
} }
inline bool isInside(const LLVector4a& pos, const F32& rad) const inline bool isInside(const LLVector4a& pos, const F32& rad) const
{ {
return rad <= mD[SIZE][0]*2.f && isInside(pos); return rad <= mSize[0]*2.f && isInside(pos);
} }
inline bool isInside(T* data) const inline bool isInside(T* data) const
...@@ -157,13 +162,13 @@ public: ...@@ -157,13 +162,13 @@ public:
bool isInside(const LLVector4a& pos) const bool isInside(const LLVector4a& pos) const
{ {
S32 gt = pos.greaterThan(mD[MAX]).getGatheredBits() & 0x7; S32 gt = pos.greaterThan(mMax).getGatheredBits() & 0x7;
if (gt) if (gt)
{ {
return false; return false;
} }
S32 lt = pos.lessEqual(mD[MIN]).getGatheredBits() & 0x7; S32 lt = pos.lessEqual(mMin).getGatheredBits() & 0x7;
if (lt) if (lt)
{ {
return false; return false;
...@@ -174,8 +179,8 @@ public: ...@@ -174,8 +179,8 @@ public:
void updateMinMax() void updateMinMax()
{ {
mD[MAX].setAdd(mD[CENTER], mD[SIZE]); mMax.setAdd(mCenter, mSize);
mD[MIN].setSub(mD[CENTER], mD[SIZE]); mMin.setSub(mCenter, mSize);
} }
inline oct_listener* getOctListener(U32 index) inline oct_listener* getOctListener(U32 index)
...@@ -195,7 +200,7 @@ public: ...@@ -195,7 +200,7 @@ public:
return false; return false;
} }
F32 size = mD[SIZE][0]; F32 size = mSize[0];
F32 p_size = size * 2.f; F32 p_size = size * 2.f;
return (radius <= 0.001f && size <= 0.001f) || return (radius <= 0.001f && size <= 0.001f) ||
...@@ -234,6 +239,29 @@ public: ...@@ -234,6 +239,29 @@ public:
void accept(tree_traveler* visitor) const { visitor->visit(this); } void accept(tree_traveler* visitor) const { visitor->visit(this); }
void accept(oct_traveler* visitor) const { visitor->visit(this); } void accept(oct_traveler* visitor) const { visitor->visit(this); }
void validateChildMap()
{
for (U32 i = 0; i < 8; i++)
{
U8 idx = mChildMap[i];
if (idx != 255)
{
LLOctreeNode<T>* child = mChild[idx];
if (child->getOctant() != i)
{
llerrs << "Invalid child map, bad octant data." << llendl;
}
if (getOctant(child->getCenter()) != child->getOctant())
{
llerrs << "Invalid child octant compared to position data." << llendl;
}
}
}
}
oct_node* getNodeAt(const LLVector4a& pos, const F32& rad) oct_node* getNodeAt(const LLVector4a& pos, const F32& rad)
{ {
LLOctreeNode<T>* node = this; LLOctreeNode<T>* node = this;
...@@ -241,25 +269,19 @@ public: ...@@ -241,25 +269,19 @@ public:
if (node->isInside(pos, rad)) if (node->isInside(pos, rad))
{ {
//do a quick search by octant //do a quick search by octant
S32 octant = node->getOctant(pos); U8 octant = node->getOctant(pos);
BOOL keep_going = TRUE;
//traverse the tree until we find a node that has no node //traverse the tree until we find a node that has no node
//at the appropriate octant or is smaller than the object. //at the appropriate octant or is smaller than the object.
//by definition, that node is the smallest node that contains //by definition, that node is the smallest node that contains
// the data // the data
while (keep_going && node->getSize()[0] >= rad) U8 next_node = node->mChildMap[octant];
while (next_node != 255 && node->getSize()[0] >= rad)
{ {
keep_going = FALSE; node = node->getChild(next_node);
for (U32 i = 0; i < node->getChildCount() && !keep_going; i++) octant = node->getOctant(pos);
{ next_node = node->mChildMap[octant];
if (node->getChild(i)->getOctant() == octant)
{
node = node->getChild(i);
octant = node->getOctant(pos);
keep_going = TRUE;
}
}
} }
} }
else if (!node->contains(rad) && node->getParent()) else if (!node->contains(rad) && node->getParent())
...@@ -439,6 +461,9 @@ public: ...@@ -439,6 +461,9 @@ public:
void clearChildren() void clearChildren()
{ {
mChild.clear(); mChild.clear();
U32* foo = (U32*) mChildMap;
foo[0] = foo[1] = 0xFFFFFFFF;
} }
void validate() void validate()
...@@ -496,6 +521,8 @@ public: ...@@ -496,6 +521,8 @@ public:
} }
#endif #endif
mChildMap[child->getOctant()] = (U8) mChild.size();
mChild.push_back(child); mChild.push_back(child);
child->setParent(this); child->setParent(this);
...@@ -517,6 +544,8 @@ public: ...@@ -517,6 +544,8 @@ public:
listener->handleChildRemoval(this, getChild(index)); listener->handleChildRemoval(this, getChild(index));
} }
if (destroy) if (destroy)
{ {
mChild[index]->destroy(); mChild[index]->destroy();
...@@ -524,6 +553,15 @@ public: ...@@ -524,6 +553,15 @@ public:
} }
mChild.erase(mChild.begin() + index); mChild.erase(mChild.begin() + index);
//rebuild child map
U32* foo = (U32*) mChildMap;
foo[0] = foo[1] = 0xFFFFFFFF;
for (U32 i = 0; i < mChild.size(); ++i)
{
mChildMap[mChild[i]->getOctant()] = i;
}
checkAlive(); checkAlive();
} }
...@@ -562,15 +600,20 @@ protected: ...@@ -562,15 +600,20 @@ protected:
MIN = 3 MIN = 3
} eDName; } eDName;
LLVector4a* mD; LLVector4a mCenter;
LLVector4a mSize;
LLVector4a mMax;
LLVector4a mMin;
oct_node* mParent; oct_node* mParent;
S32 mOctant; U8 mOctant;
child_list mChild; child_list mChild;
U8 mChildMap[8];
element_list mData; element_list mData;
}; };
//just like a regular node, except it might expand on insert and compress on balance //just like a regular node, except it might expand on insert and compress on balance
template <class T> template <class T>
...@@ -613,6 +656,8 @@ public: ...@@ -613,6 +656,8 @@ public:
//destroy child //destroy child
child->clearChildren(); child->clearChildren();
delete child; delete child;
return false;
} }
return true; return true;
...@@ -639,7 +684,7 @@ public: ...@@ -639,7 +684,7 @@ public:
const LLVector4a& v = data->getPositionGroup(); const LLVector4a& v = data->getPositionGroup();
LLVector4a val; LLVector4a val;
val.setSub(v, BaseType::mD[BaseType::CENTER]); val.setSub(v, BaseType::mCenter);
val.setAbs(val); val.setAbs(val);
S32 lt = val.lessThan(MAX_MAG).getGatheredBits() & 0x7; S32 lt = val.lessThan(MAX_MAG).getGatheredBits() & 0x7;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment