BGE animations: Adding a separate list to KX_Scene for animated objects. This makes...
authorMitchell Stokes <mogurijin@gmail.com>
Sat, 3 Sep 2011 20:48:47 +0000 (20:48 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Sat, 3 Sep 2011 20:48:47 +0000 (20:48 +0000)
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_Scene.h

index 3f6f4bb90994b5d76868ac3456d8c7649313be8b..6adaea2d6ad824948959f2b1b3a6f57638457f50 100644 (file)
@@ -159,6 +159,7 @@ KX_GameObject::~KX_GameObject()
        }
        if (m_actionManager)
        {
+               KX_GetActiveScene()->RemoveAnimatedObject(this);
                delete m_actionManager;
        }
 #ifdef WITH_PYTHON
@@ -355,8 +356,8 @@ BL_ActionManager* KX_GameObject::GetActionManager()
 {
        // We only want to create an action manager if we need it
        if (!m_actionManager)
-               m_actionManager = new BL_ActionManager(this);
-
+       {               KX_GetActiveScene()->AddAnimatedObject(this);           m_actionManager = new BL_ActionManager(this);
+       }
        return m_actionManager;
 }
 
index a49c1bf4b4cbd48f918ae500277b73d55d786cff..06e343cedb235ea5f2496161de00d97a1e40842d 100644 (file)
@@ -168,6 +168,7 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice,
        m_lightlist= new CListValue();
        m_inactivelist = new CListValue();
        m_euthanasyobjects = new CListValue();
+       m_animatedlist = new CListValue();
 
        m_logicmgr = new SCA_LogicManager();
        
@@ -253,6 +254,9 @@ KX_Scene::~KX_Scene()
        if (m_euthanasyobjects)
                m_euthanasyobjects->Release();
 
+       if (m_animatedlist)
+               m_animatedlist->Release();
+
        if (m_logicmgr)
                delete m_logicmgr;
 
@@ -1502,10 +1506,20 @@ void KX_Scene::LogicBeginFrame(double curtime)
        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)
 {
        // 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);
 }
 
index da9cc12c76aee84019d3fd5d3abf1a679c079f0e..499861bce5046bab5dc8a7f46130bad53158a712 100644 (file)
@@ -130,6 +130,7 @@ protected:
        CListValue*                     m_parentlist; // all 'root' parents
        CListValue*                     m_lightlist;
        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
                                                                                // the Dlist is not object that must be updated
@@ -334,6 +335,10 @@ public:
        int NewRemoveObject(CValue* gameobj);
        void ReplaceMesh(CValue* gameobj,
                                         void* meshob, bool use_gfx, bool use_phys);
+
+       void AddAnimatedObject(CValue* gameobj);
+       void RemoveAnimatedObject(CValue* gameobj);
+
        /**
         * @section Logic stuff
         * Initiate an update of the logic system.