BGE animations: Adding a separate list to KX_Scene for animated objects. This makes scenes with a lot of non-animated objects faster. In my test scene with 8000 static, non-animated cubes my time spent on animations went from 1.5~1.7ms to 0.001ms.

This commit is contained in:
Mitchell Stokes 2011-09-03 20:48:47 +00:00
parent 8295480bbe
commit 1f8291f78d
3 changed files with 23 additions and 3 deletions

@ -159,6 +159,7 @@ KX_GameObject::~KX_GameObject()
} }
if (m_actionManager) if (m_actionManager)
{ {
KX_GetActiveScene()->RemoveAnimatedObject(this);
delete m_actionManager; delete m_actionManager;
} }
#ifdef WITH_PYTHON #ifdef WITH_PYTHON
@ -355,8 +356,8 @@ BL_ActionManager* KX_GameObject::GetActionManager()
{ {
// We only want to create an action manager if we need it // We only want to create an action manager if we need it
if (!m_actionManager) if (!m_actionManager)
m_actionManager = new BL_ActionManager(this); { KX_GetActiveScene()->AddAnimatedObject(this); m_actionManager = new BL_ActionManager(this);
}
return m_actionManager; return m_actionManager;
} }

@ -168,6 +168,7 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice,
m_lightlist= new CListValue(); m_lightlist= new CListValue();
m_inactivelist = new CListValue(); m_inactivelist = new CListValue();
m_euthanasyobjects = new CListValue(); m_euthanasyobjects = new CListValue();
m_animatedlist = new CListValue();
m_logicmgr = new SCA_LogicManager(); m_logicmgr = new SCA_LogicManager();
@ -253,6 +254,9 @@ KX_Scene::~KX_Scene()
if (m_euthanasyobjects) if (m_euthanasyobjects)
m_euthanasyobjects->Release(); m_euthanasyobjects->Release();
if (m_animatedlist)
m_animatedlist->Release();
if (m_logicmgr) if (m_logicmgr)
delete m_logicmgr; delete m_logicmgr;
@ -1502,10 +1506,20 @@ void KX_Scene::LogicBeginFrame(double curtime)
m_logicmgr->BeginFrame(curtime, 1.0/KX_KetsjiEngine::GetTicRate()); m_logicmgr->BeginFrame(curtime, 1.0/KX_KetsjiEngine::GetTicRate());
} }
void KX_Scene::AddAnimatedObject(CValue* gameobj)
{
m_animatedlist->Add(gameobj);
}
void KX_Scene::RemoveAnimatedObject(CValue* gameobj)
{
m_animatedlist->RemoveValue(gameobj);
}
void KX_Scene::UpdateAnimations(double curtime) void KX_Scene::UpdateAnimations(double curtime)
{ {
// Update any animations // Update any animations
for (int i=0; i<GetObjectList()->GetCount(); ++i) for (int i=0; i<m_animatedlist->GetCount(); ++i)
((KX_GameObject*)GetObjectList()->GetValue(i))->UpdateActionManager(curtime); ((KX_GameObject*)GetObjectList()->GetValue(i))->UpdateActionManager(curtime);
} }

@ -130,6 +130,7 @@ protected:
CListValue* m_parentlist; // all 'root' parents CListValue* m_parentlist; // all 'root' parents
CListValue* m_lightlist; CListValue* m_lightlist;
CListValue* m_inactivelist; // all objects that are not in the active layer CListValue* m_inactivelist; // all objects that are not in the active layer
CListValue* m_animatedlist; // all animated objects
SG_QList m_sghead; // list of nodes that needs scenegraph update SG_QList m_sghead; // list of nodes that needs scenegraph update
// the Dlist is not object that must be updated // the Dlist is not object that must be updated
@ -334,6 +335,10 @@ public:
int NewRemoveObject(CValue* gameobj); int NewRemoveObject(CValue* gameobj);
void ReplaceMesh(CValue* gameobj, void ReplaceMesh(CValue* gameobj,
void* meshob, bool use_gfx, bool use_phys); void* meshob, bool use_gfx, bool use_phys);
void AddAnimatedObject(CValue* gameobj);
void RemoveAnimatedObject(CValue* gameobj);
/** /**
* @section Logic stuff * @section Logic stuff
* Initiate an update of the logic system. * Initiate an update of the logic system.