Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
2c4c1c47
Commit
2c4c1c47
authored
14 years ago
by
David Parks
Browse files
Options
Downloads
Patches
Plain Diff
Take advantage of automagical tcmalloc alignment.
parent
e18e26e8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indra/llmath/lloctree.h
+86
-41
86 additions, 41 deletions
indra/llmath/lloctree.h
with
86 additions
and
41 deletions
indra/llmath/lloctree.h
+
86
−
41
View file @
2c4c1c47
...
@@ -95,22 +95,30 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -95,22 +95,30 @@ class LLOctreeNode : public LLTreeNode<T>
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
(
m
D
[
CENTER
]
);
mOctant
=
((
oct_node
*
)
mParent
)
->
getOctant
(
m
Center
);
}
}
clearChildren
();
clearChildren
();
...
@@ -124,30 +132,27 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -124,30 +132,27 @@ class LLOctreeNode : public LLTreeNode<T>
{
{
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
m
D
[
CENTER
]
;
}
inline
const
LLVector4a
&
getCenter
()
const
{
return
m
Center
;
}
inline
const
LLVector4a
&
getSize
()
const
{
return
m
D
[
SIZE
]
;
}
inline
const
LLVector4a
&
getSize
()
const
{
return
m
Size
;
}
inline
void
setCenter
(
const
LLVector4a
&
center
)
{
m
D
[
CENTER
]
=
center
;
}
inline
void
setCenter
(
const
LLVector4a
&
center
)
{
m
Center
=
center
;
}
inline
void
setSize
(
const
LLVector4a
&
size
)
{
m
D
[
SIZE
]
=
size
;
}
inline
void
setSize
(
const
LLVector4a
&
size
)
{
m
Size
=
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
(
m
D
[
CENTER
]
).
getGatheredBits
()
&
0x7
;
return
(
U8
)
(
pos
.
greaterThan
(
m
Center
).
getGatheredBits
()
&
0x7
)
;
}
}
inline
bool
isInside
(
const
LLVector4a
&
pos
,
const
F32
&
rad
)
const
inline
bool
isInside
(
const
LLVector4a
&
pos
,
const
F32
&
rad
)
const
{
{
return
rad
<=
m
D
[
SIZE
]
[
0
]
*
2.
f
&&
isInside
(
pos
);
return
rad
<=
m
Size
[
0
]
*
2.
f
&&
isInside
(
pos
);
}
}
inline
bool
isInside
(
T
*
data
)
const
inline
bool
isInside
(
T
*
data
)
const
...
@@ -157,13 +162,13 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -157,13 +162,13 @@ class LLOctreeNode : public LLTreeNode<T>
bool
isInside
(
const
LLVector4a
&
pos
)
const
bool
isInside
(
const
LLVector4a
&
pos
)
const
{
{
S32
gt
=
pos
.
greaterThan
(
m
D
[
MAX
]
).
getGatheredBits
()
&
0x7
;
S32
gt
=
pos
.
greaterThan
(
m
Max
).
getGatheredBits
()
&
0x7
;
if
(
gt
)
if
(
gt
)
{
{
return
false
;
return
false
;
}
}
S32
lt
=
pos
.
lessEqual
(
m
D
[
MIN
]
).
getGatheredBits
()
&
0x7
;
S32
lt
=
pos
.
lessEqual
(
m
Min
).
getGatheredBits
()
&
0x7
;
if
(
lt
)
if
(
lt
)
{
{
return
false
;
return
false
;
...
@@ -174,8 +179,8 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -174,8 +179,8 @@ class LLOctreeNode : public LLTreeNode<T>
void
updateMinMax
()
void
updateMinMax
()
{
{
m
D
[
MAX
]
.
setAdd
(
m
D
[
CENTER
],
mD
[
SIZE
]
);
m
Max
.
setAdd
(
m
Center
,
mSize
);
m
D
[
MIN
]
.
setSub
(
m
D
[
CENTER
],
mD
[
SIZE
]
);
m
Min
.
setSub
(
m
Center
,
mSize
);
}
}
inline
oct_listener
*
getOctListener
(
U32
index
)
inline
oct_listener
*
getOctListener
(
U32
index
)
...
@@ -195,7 +200,7 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -195,7 +200,7 @@ class LLOctreeNode : public LLTreeNode<T>
return
false
;
return
false
;
}
}
F32
size
=
m
D
[
SIZE
]
[
0
];
F32
size
=
m
Size
[
0
];
F32
p_size
=
size
*
2.
f
;
F32
p_size
=
size
*
2.
f
;
return
(
radius
<=
0.001
f
&&
size
<=
0.001
f
)
||
return
(
radius
<=
0.001
f
&&
size
<=
0.001
f
)
||
...
@@ -234,6 +239,29 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -234,6 +239,29 @@ class LLOctreeNode : public LLTreeNode<T>
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 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -241,25 +269,19 @@ class LLOctreeNode : public LLTreeNode<T>
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 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -439,6 +461,9 @@ class LLOctreeNode : public LLTreeNode<T>
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 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -496,6 +521,8 @@ class LLOctreeNode : public LLTreeNode<T>
}
}
#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 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -517,6 +544,8 @@ class LLOctreeNode : public LLTreeNode<T>
listener
->
handleChildRemoval
(
this
,
getChild
(
index
));
listener
->
handleChildRemoval
(
this
,
getChild
(
index
));
}
}
if
(
destroy
)
if
(
destroy
)
{
{
mChild
[
index
]
->
destroy
();
mChild
[
index
]
->
destroy
();
...
@@ -524,6 +553,15 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -524,6 +553,15 @@ class LLOctreeNode : public LLTreeNode<T>
}
}
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 @@ class LLOctreeNode : public LLTreeNode<T>
...
@@ -562,15 +600,20 @@ class LLOctreeNode : public LLTreeNode<T>
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 @@ class LLOctreeRoot : public LLOctreeNode<T>
...
@@ -613,6 +656,8 @@ class LLOctreeRoot : public LLOctreeNode<T>
//destroy child
//destroy child
child
->
clearChildren
();
child
->
clearChildren
();
delete
child
;
delete
child
;
return
false
;
}
}
return
true
;
return
true
;
...
@@ -639,7 +684,7 @@ class LLOctreeRoot : public LLOctreeNode<T>
...
@@ -639,7 +684,7 @@ class LLOctreeRoot : public LLOctreeNode<T>
const
LLVector4a
&
v
=
data
->
getPositionGroup
();
const
LLVector4a
&
v
=
data
->
getPositionGroup
();
LLVector4a
val
;
LLVector4a
val
;
val
.
setSub
(
v
,
BaseType
::
m
D
[
BaseType
::
CENTER
]
);
val
.
setSub
(
v
,
BaseType
::
m
Center
);
val
.
setAbs
(
val
);
val
.
setAbs
(
val
);
S32
lt
=
val
.
lessThan
(
MAX_MAG
).
getGatheredBits
()
&
0x7
;
S32
lt
=
val
.
lessThan
(
MAX_MAG
).
getGatheredBits
()
&
0x7
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment