From bd00aa972727197daa4b891e7aee8146a706e68c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 9 Oct 2010 10:45:25 +0000 Subject: [PATCH] patch [#23781] Dynamically Load Actions from Mitchell Stokes (moguri) --- .../Converter/KX_BlenderSceneConverter.cpp | 41 ++++++++++++++++++- .../gameengine/GameLogic/SCA_LogicManager.h | 1 + source/gameengine/PyDoc/bge.logic.rst | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index f50fb6838e3..6f64f4e33af 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -40,6 +40,7 @@ #include "KX_KetsjiEngine.h" #include "KX_IPhysicsController.h" #include "BL_Material.h" +#include "BL_ActionActuator.h" #include "KX_BlenderMaterial.h" #include "KX_PolygonMaterial.h" @@ -960,7 +961,7 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha static char err_local[255]; /* only scene and mesh supported right now */ - if(idcode!=ID_SCE && idcode!=ID_ME) { + if(idcode!=ID_SCE && idcode!=ID_ME &&idcode!=ID_AC) { snprintf(err_local, sizeof(err_local), "invalid ID type given \"%s\"\n", group); return false; } @@ -1018,6 +1019,16 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha kx_scene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj); } } + else if(idcode==ID_AC) { + /* Convert all actions */ + ID *action; + KX_Scene *kx_scene= m_currentScene; + + for(action= (ID *)main_newlib->action.first; action; action= (ID *)action->next) { + printf("ActionName: %s\n", action->name); + kx_scene->GetLogicManager()->RegisterActionName(action->name+2, action); + } + } else if(idcode==ID_SCE) { /* Merge all new linked in scene into the existing one */ ID *scene; @@ -1092,6 +1103,23 @@ bool KX_BlenderSceneConverter::FreeBlendFile(struct Main *maggie) } } } + + /* Now unregister actions */ + { + GEN_Map &mapStringToActions = scene->GetLogicManager()->GetActionMap(); + + for(int i=0; iname+2; + mapStringToActions.remove(an); + i--; + } + } + } //scene->FreeTagged(); /* removed tagged objects and meshes*/ CListValue *obj_lists[] = {scene->GetObjectList(), scene->GetInactiveList(), NULL}; @@ -1128,6 +1156,17 @@ bool KX_BlenderSceneConverter::FreeBlendFile(struct Main *maggie) break; } } + + /* make sure action actuators are not referencing tagged actions */ + for (int act_idx=0; act_idxGetActuators().size(); act_idx++) + { + if (gameobj->GetActuators()[act_idx]->IsType(SCA_IActuator::KX_ACT_ACTION)) + { + BL_ActionActuator *act = (BL_ActionActuator*)gameobj->GetActuators()[act_idx]; + if(IS_TAGGED(act->GetAction())) + act->SetAction(NULL); + } + } } } } diff --git a/source/gameengine/GameLogic/SCA_LogicManager.h b/source/gameengine/GameLogic/SCA_LogicManager.h index 9ddb62df361..f92b27f641a 100644 --- a/source/gameengine/GameLogic/SCA_LogicManager.h +++ b/source/gameengine/GameLogic/SCA_LogicManager.h @@ -127,6 +127,7 @@ public: void RegisterMeshName(const STR_String& meshname,void* mesh); void UnregisterMeshName(const STR_String& meshname,void* mesh); GEN_Map& GetMeshMap() { return m_mapStringToMeshes; }; + GEN_Map& GetActionMap() { return m_mapStringToActions; }; void RegisterActionName(const STR_String& actname,void* action); diff --git a/source/gameengine/PyDoc/bge.logic.rst b/source/gameengine/PyDoc/bge.logic.rst index a7eb5635d0f..d3261f5747b 100644 --- a/source/gameengine/PyDoc/bge.logic.rst +++ b/source/gameengine/PyDoc/bge.logic.rst @@ -179,7 +179,7 @@ General functions :arg blend: The path to the blend file (or the name to use for the library if data is supplied) :type blend: string - :arg type: The datablock type (currently only "Scene" and "Mesh" are supported) + :arg type: The datablock type (currently only "Action", "Mesh" and "Scene" are supported) :type type: string :arg data: Binary data from a blend file (optional) :type data: bytes