gameObject -> blenderObject mapping was being created but wasnt needed.
authorCampbell Barton <ideasman42@gmail.com>
Fri, 7 Aug 2009 03:51:28 +0000 (03:51 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 7 Aug 2009 03:51:28 +0000 (03:51 +0000)
Added utility func tag_main for (un)tagging every ID in a Main database with LIB_DOIT.

source/blender/blenkernel/BKE_library.h
source/blender/blenkernel/intern/library.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/KX_BlenderSceneConverter.cpp
source/gameengine/Converter/KX_BlenderSceneConverter.h
source/gameengine/Ketsji/KX_Scene.cpp

index d840401d4fa9732bb864b5ebf1e61b0e87e251c5..095db4860ceae387f1befdfa45f45a924d3c1625 100644 (file)
@@ -55,6 +55,7 @@ int set_listbasepointers(struct Main *main, struct ListBase **lb);
 void free_libblock(struct ListBase *lb, void *idv);
 void free_libblock_us(struct ListBase *lb, void *idv);
 void free_main(struct Main *mainvar);
+void tag_main(struct Main *mainvar, int tag);
 
 void splitIDname(char *name, char *left, int *nr);
 void rename_id(struct ID *id, char *name);
index 33c1a4da4c786b5e2db7b677cacd0b8b2192752b..2994c981b17a19115d756db38776e46b68b7a3ba 100644 (file)
@@ -1020,6 +1020,20 @@ static void lib_indirect_test_id(ID *id)
        }
 }
 
+void tag_main(struct Main *mainvar, int tag)
+{
+       ListBase *lbarray[MAX_LIBARRAY];
+       ID *id;
+       int a;
+
+       a= set_listbasepointers(mainvar, lbarray);
+       while(a--) {
+               for(id= lbarray[a]->first; id; id= id->next) {
+                       if(tag) id->flag |= LIB_DOIT;
+                       else    id->flag &= ~LIB_DOIT;
+               }
+       }
+}
 
 /* if lib!=NULL, only all from lib local */
 void all_local(Library *lib, int untagged_only)
index d27c544ccb4f071d267584d52c972140c8a9b964..5b03bbbbc4ec1ff210d3e672bf4d6c29c8bc90a6 100644 (file)
@@ -2520,7 +2520,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        for (i=0;i<sumolist->GetCount();i++)
        {
                KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
-               struct Object* blenderobject = converter->FindBlenderObject(gameobj);
+               struct Object* blenderobject = gameobj->GetBlenderObject();
                int nummeshes = gameobj->GetMeshCount();
                RAS_MeshObject* meshobj = 0;
                if (nummeshes > 0)
@@ -2536,7 +2536,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        for (i=0;i<sumolist->GetCount();i++)
        {
                KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
-               struct Object* blenderobject = converter->FindBlenderObject(gameobj);
+               struct Object* blenderobject = gameobj->GetBlenderObject();
                int nummeshes = gameobj->GetMeshCount();
                RAS_MeshObject* meshobj = 0;
                if (nummeshes > 0)
@@ -2564,7 +2564,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        for (i=0;i<sumolist->GetCount();i++)
        {
                KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
-               struct Object* blenderobject = converter->FindBlenderObject(gameobj);
+               struct Object* blenderobject = gameobj->GetBlenderObject();
                ListBase *conlist;
                bConstraint *curcon;
                conlist = get_active_constraints2(blenderobject);
@@ -2661,7 +2661,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        for (i=0;i<logicbrick_conversionlist->GetCount();i++)
        {
                KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
-               struct Object* blenderobj = converter->FindBlenderObject(gameobj);
+               struct Object* blenderobj = gameobj->GetBlenderObject();
                int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0;
                bool isInActiveLayer = (blenderobj->lay & layerMask)!=0;
                BL_ConvertActuators(maggie->name, blenderobj,gameobj,logicmgr,kxscene,ketsjiEngine,layerMask,isInActiveLayer,rendertools,converter);
@@ -2669,7 +2669,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        for ( i=0;i<logicbrick_conversionlist->GetCount();i++)
        {
                KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
-               struct Object* blenderobj = converter->FindBlenderObject(gameobj);
+               struct Object* blenderobj = gameobj->GetBlenderObject();
                int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0;
                bool isInActiveLayer = (blenderobj->lay & layerMask)!=0;
                BL_ConvertControllers(blenderobj,gameobj,logicmgr,pythondictionary,layerMask,isInActiveLayer,converter);
@@ -2677,7 +2677,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        for ( i=0;i<logicbrick_conversionlist->GetCount();i++)
        {
                KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
-               struct Object* blenderobj = converter->FindBlenderObject(gameobj);
+               struct Object* blenderobj = gameobj->GetBlenderObject();
                int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0;
                bool isInActiveLayer = (blenderobj->lay & layerMask)!=0;
                BL_ConvertSensors(blenderobj,gameobj,logicmgr,kxscene,ketsjiEngine,layerMask,isInActiveLayer,canvas,converter);
index d817999393c5faa40cb52ea110c8b396fb50d024..59c073c2b1f38f1749461b5c2652ea9472d89a97 100644 (file)
@@ -375,10 +375,6 @@ void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
        //This cache mecanism is buggy so I leave it disable and the memory leak
        //that would result from this is fixed in RemoveScene()
        m_map_mesh_to_gamemesh.clear();
-       //Don't clear this lookup, it is needed for the baking physics into ipo animation
-       //To avoid it's infinite grows, object will be unregister when they are deleted 
-       //see KX_Scene::NewRemoveObject
-       //m_map_gameobject_to_blender.clear();
 }
 
 // This function removes all entities stored in the converter for that scene
@@ -492,27 +488,28 @@ void KX_BlenderSceneConverter::RegisterGameObject(
                                                                        KX_GameObject *gameobject, 
                                                                        struct Object *for_blenderobject) 
 {
-       m_map_gameobject_to_blender.insert(CHashedPtr(gameobject),for_blenderobject);
+       /* only maintained while converting, freed during game runtime */
        m_map_blender_to_gameobject.insert(CHashedPtr(for_blenderobject),gameobject);
 }
 
 void KX_BlenderSceneConverter::UnregisterGameObject(
                                                                        KX_GameObject *gameobject) 
 {
-       CHashedPtr gptr(gameobject);
-       struct Object **bobp= m_map_gameobject_to_blender[gptr];
+#if 0
+       struct Object *bobp= gameobject->GetBlenderObject();
        if (bobp) {
-               CHashedPtr bptr(*bobp);
+               CHashedPtr bptr(bobp);
                KX_GameObject **gobp= m_map_blender_to_gameobject[bptr];
                if (gobp && *gobp == gameobject)
+               {
                        // also maintain m_map_blender_to_gameobject if the gameobject
                        // being removed is matching the blender object
                        m_map_blender_to_gameobject.remove(bptr);
-               m_map_gameobject_to_blender.remove(gptr);
+               }
        }
+#endif
 }
 
-
 KX_GameObject *KX_BlenderSceneConverter::FindGameObject(
                                                                        struct Object *for_blenderobject) 
 {
@@ -521,18 +518,6 @@ KX_GameObject *KX_BlenderSceneConverter::FindGameObject(
        return obp?*obp:NULL;
 }
 
-
-
-struct Object *KX_BlenderSceneConverter::FindBlenderObject(
-                                                                       KX_GameObject *for_gameobject) 
-{
-       struct Object **obp= m_map_gameobject_to_blender[CHashedPtr(for_gameobject)];
-       
-       return obp?*obp:NULL;
-}
-
-       
-
 void KX_BlenderSceneConverter::RegisterGameMesh(
                                                                        RAS_MeshObject *gamemesh,
                                                                        struct Mesh *for_blendermesh)
@@ -717,7 +702,7 @@ void        KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
                        {
                                //KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController();
                                
-                               Object* blenderObject = FindBlenderObject(gameObj);
+                               Object* blenderObject = gameObj->GetBlenderObject();
                                if (blenderObject)
                                {
                                        //erase existing ipo's
@@ -781,7 +766,7 @@ void        KX_BlenderSceneConverter::resetNoneDynamicObjectToIpo(){
                        for (int ix=0;ix<parentList->GetCount();ix++){
                                KX_GameObject* gameobj = (KX_GameObject*)parentList->GetValue(ix);
                                if (!gameobj->IsDynamic()){
-                                       Object* blenderobject = FindBlenderObject(gameobj);
+                                       Object* blenderobject = gameobj->GetBlenderObject();
                                        if (!blenderobject)
                                                continue;
                                        if (blenderobject->type==OB_ARMATURE)
@@ -835,7 +820,7 @@ void        KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber)
                        {
                                //KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController();
                                
-                               Object* blenderObject = FindBlenderObject(gameObj);
+                               Object* blenderObject = gameObj->GetBlenderObject();
                                if (blenderObject && blenderObject->ipo)
                                {
                                        const MT_Point3& position = gameObj->NodeGetWorldPosition();
@@ -933,7 +918,7 @@ void        KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo()
                        {
                                //KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController();
                                
-                               Object* blenderObject = FindBlenderObject(gameObj);
+                               Object* blenderObject = gameObj->GetBlenderObject();
                                if (blenderObject && blenderObject->ipo)
                                {
                                        Ipo* ipo = blenderObject->ipo;
index cc93a953533e7e0084b25ba297992251ff22aed3..e8a958a310ace82fbb78b5ae8cd4a5b9c7568646 100644 (file)
@@ -56,16 +56,12 @@ class KX_BlenderSceneConverter : public KX_ISceneConverter
        // Should also have a list of collision shapes. 
        // For the time being this is held in KX_Scene::m_shapes
 
-       GEN_Map<CHashedPtr,struct Object*> m_map_gameobject_to_blender;
-       GEN_Map<CHashedPtr,KX_GameObject*> m_map_blender_to_gameobject;
-
-       GEN_Map<CHashedPtr,RAS_MeshObject*> m_map_mesh_to_gamemesh;
-//     GEN_Map<CHashedPtr,DT_ShapeHandle> m_map_gamemesh_to_sumoshape;
-       
-       GEN_Map<CHashedPtr,SCA_IActuator*> m_map_blender_to_gameactuator;
-       GEN_Map<CHashedPtr,SCA_IController*> m_map_blender_to_gamecontroller;
+       GEN_Map<CHashedPtr,KX_GameObject*>      m_map_blender_to_gameobject;            /* cleared after conversion */
+       GEN_Map<CHashedPtr,RAS_MeshObject*>     m_map_mesh_to_gamemesh;                         /* cleared after conversion */
+       GEN_Map<CHashedPtr,SCA_IActuator*>      m_map_blender_to_gameactuator;          /* cleared after conversion */
+       GEN_Map<CHashedPtr,SCA_IController*>m_map_blender_to_gamecontroller;    /* cleared after conversion */
        
-       GEN_Map<CHashedPtr,BL_InterpolatorList*> m_map_blender_to_gameipolist;
+       GEN_Map<CHashedPtr,BL_InterpolatorList*> m_map_blender_to_gameipolist;  /* kept, should be freed, TODO */
        
        Main*                                   m_maggie;
 
@@ -107,14 +103,10 @@ public:
        void RegisterGameObject(KX_GameObject *gameobject, struct Object *for_blenderobject);
        void UnregisterGameObject(KX_GameObject *gameobject);
        KX_GameObject *FindGameObject(struct Object *for_blenderobject);
-       struct Object *FindBlenderObject(KX_GameObject *for_gameobject);
 
        void RegisterGameMesh(RAS_MeshObject *gamemesh, struct Mesh *for_blendermesh);
        RAS_MeshObject *FindGameMesh(struct Mesh *for_blendermesh/*, unsigned int onlayer*/);
 
-//     void RegisterSumoShape(DT_ShapeHandle shape, RAS_MeshObject *for_gamemesh);
-//     DT_ShapeHandle FindSumoShape(RAS_MeshObject *for_gamemesh);
-
        void RegisterPolyMaterial(RAS_IPolyMaterial *polymat);
 
        void RegisterBlenderMaterial(BL_Material *mat);
index 0aeccbcaaad74dbb775a6339f8d61359e8fbc586..dce2f2d8930c057bf6bfb6a797694db38e91d5cf 100644 (file)
@@ -1008,8 +1008,12 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj)
        // in case this is a camera
        m_cameras.remove((KX_Camera*)newobj);
 
+       /* currently does nothing, keep incase we need to Unregister something */
+#if 0
        if (m_sceneConverter)
                m_sceneConverter->UnregisterGameObject(newobj);
+#endif
+       
        // return value will be 0 if the object is actually deleted (all reference gone)
        
        return ret;