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:
Benoit Bolsee
2009-05-03 22:29:00 +00:00
parent 2aa3c932d0
commit 3abb8e8e68
14 changed files with 649 additions and 420 deletions

View File

@@ -39,19 +39,20 @@ SG_IObject::
SG_IObject(
void* clientobj,
void* clientinfo,
SG_Callbacks callbacks
SG_Callbacks& callbacks
):
SG_QList(),
m_SGclientObject(clientobj),
m_SGclientInfo(clientinfo),
m_callbacks(callbacks)
m_SGclientInfo(clientinfo)
{
//nothing to do
m_callbacks = callbacks;
}
SG_IObject::
SG_IObject(
const SG_IObject &other
) :
SG_QList(),
m_SGclientObject(other.m_SGclientObject),
m_SGclientInfo(other.m_SGclientInfo),
m_callbacks(other.m_callbacks)
@@ -74,92 +75,17 @@ RemoveAllControllers(
m_SGcontrollers.clear();
}
/// Needed for replication
SGControllerList&
SG_IObject::
GetSGControllerList(
){
return m_SGcontrollers;
}
void*
SG_IObject::
GetSGClientObject(
){
return m_SGclientObject;
}
const
void*
SG_IObject::
GetSGClientObject(
) const {
return m_SGclientObject;
}
void
SG_IObject::
SetSGClientObject(
void* clientObject
){
m_SGclientObject = clientObject;
}
bool
SG_IObject::
ActivateReplicationCallback(
SG_IObject *replica
){
if (m_callbacks.m_replicafunc)
{
// Call client provided replication func
if (m_callbacks.m_replicafunc(replica,m_SGclientObject,m_SGclientInfo) == NULL)
return false;
}
return true;
};
void
SG_IObject::
ActivateDestructionCallback(
){
if (m_callbacks.m_destructionfunc)
{
// Call client provided destruction function on this!
m_callbacks.m_destructionfunc(this,m_SGclientObject,m_SGclientInfo);
}
else
{
// no callback but must still destroy the node to avoid memory leak
delete this;
}
}
void
SG_IObject::
ActivateUpdateTransformCallback(
){
if (m_callbacks.m_updatefunc)
{
// Call client provided update func.
m_callbacks.m_updatefunc(this, m_SGclientObject, m_SGclientInfo);
}
}
void
SG_IObject::
SetControllerTime(
double time
){
void SG_IObject::SetControllerTime(double time)
{
SGControllerList::iterator contit;
for (contit = m_SGcontrollers.begin();contit!=m_SGcontrollers.end();++contit)
{
(*contit)->SetSimulatedTime(time);
}
}
/// Needed for replication
SG_IObject::
~SG_IObject()