BGE performance: second round of scenegraph improvement.

Use dynamic linked list to handle scenegraph rather than dumb scan
of the whole tree. The performance improvement depends on the fraction
of moving objects. If most objects are static, the speed up is 
considerable. The following table compares the time spent on 
scenegraph before and after this commit on a scene with 10000 objects
in various configuratons:

Scenegraph time (ms)              Before         After
(includes culling)

All objects static,               8.8            1.7  
all visible but small fraction          
in the view frustrum

All objects static,               7,5            0.01
all invisible.

All objects moving,               14.1           8.4
all visible but small fraction
in the view frustrum

This tables shows that static and invisible objects take no CPU at all
for scenegraph and culling. In the general case, this commit will 
speed up the scenegraph between 2x and 5x. Compared to 2.48a, it should
be between 4x and 10x faster. Further speed up is possible by making
the scenegraph cache-friendly.

Next round of performance improvement will be on the rasterizer: use
the same dynamic linked list technique for the mesh slots.
This commit is contained in:
2009-05-03 22:29:00 +00:00
parent 2aa3c932d0
commit 3abb8e8e68
14 changed files with 649 additions and 420 deletions

View File

@@ -40,7 +40,7 @@ SG_Spatial::
SG_Spatial(
void* clientobj,
void* clientinfo,
SG_Callbacks callbacks
SG_Callbacks& callbacks
):
SG_IObject(clientobj,clientinfo,callbacks),
@@ -56,8 +56,9 @@ SG_Spatial(
m_bbox(MT_Point3(-1.0, -1.0, -1.0), MT_Point3(1.0, 1.0, 1.0)),
m_radius(1.0),
m_modified(true)
m_modified(false)
{
SetModified();
}
SG_Spatial::
@@ -88,13 +89,6 @@ SG_Spatial::
delete (m_parent_relation);
}
SG_ParentRelation *
SG_Spatial::
GetParentRelation(
){
return m_parent_relation;
}
void
SG_Spatial::
SetParentRelation(
@@ -102,7 +96,7 @@ SetParentRelation(
){
delete (m_parent_relation);
m_parent_relation = relation;
m_modified = true;
SetModified();
}
@@ -143,11 +137,6 @@ UpdateSpatialData(
return bComputesWorldTransform;
}
bool SG_Spatial::ComputeWorldTransforms(const SG_Spatial *parent, bool& parentUpdated)
{
return m_parent_relation->UpdateChildCoordinates(this,parent,parentUpdated);
}
/**
* Position and translation methods
*/
@@ -169,56 +158,14 @@ RelativeTranslate(
m_localPosition += trans;
}
}
m_modified = true;
SetModified();
}
void
SG_Spatial::
SetLocalPosition(
const MT_Point3& trans
){
m_localPosition = trans;
m_modified = true;
}
void
SG_Spatial::
SetWorldPosition(
const MT_Point3& trans
) {
m_worldPosition = trans;
}
/**
* Scaling methods.
*/
void
SG_Spatial::
RelativeScale(
const MT_Vector3& scale
){
m_localScaling = m_localScaling * scale;
m_modified = true;
}
void
SG_Spatial::
SetLocalScale(
const MT_Vector3& scale
){
m_localScaling = scale;
m_modified = true;
}
void
SG_Spatial::
SetWorldScale(
const MT_Vector3& scale
){
m_worldScaling = scale;
}
/**
* Orientation and rotation methods.
@@ -236,93 +183,11 @@ RelativeRotate(
rot
:
(GetWorldOrientation().inverse() * rot * GetWorldOrientation()));
m_modified = true;
}
void
SG_Spatial::
SetLocalOrientation(const MT_Matrix3x3& rot)
{
m_localRotation = rot;
m_modified = true;
SetModified();
}
void
SG_Spatial::
SetWorldOrientation(
const MT_Matrix3x3& rot
) {
m_worldRotation = rot;
}
const
MT_Point3&
SG_Spatial::
GetLocalPosition(
) const {
return m_localPosition;
}
const
MT_Matrix3x3&
SG_Spatial::
GetLocalOrientation(
) const {
return m_localRotation;
}
const
MT_Vector3&
SG_Spatial::
GetLocalScale(
) const{
return m_localScaling;
}
const
MT_Point3&
SG_Spatial::
GetWorldPosition(
) const {
return m_worldPosition;
}
const
MT_Matrix3x3&
SG_Spatial::
GetWorldOrientation(
) const {
return m_worldRotation;
}
const
MT_Vector3&
SG_Spatial::
GetWorldScaling(
) const {
return m_worldScaling;
}
void SG_Spatial::SetWorldFromLocalTransform()
{
m_worldPosition= m_localPosition;
m_worldScaling= m_localScaling;
m_worldRotation= m_localRotation;
}
SG_BBox& SG_Spatial::BBox()
{
return m_bbox;
}
void SG_Spatial::SetBBox(SG_BBox& bbox)
{
m_bbox = bbox;
}
MT_Transform SG_Spatial::GetWorldTransform() const
{
return MT_Transform(m_worldPosition,