[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32386] trunk/blender/source/gameengine: patch [#23781] Dynamically Load Actions
Campbell Barton
ideasman42 at gmail.com
Sat Oct 9 12:45:25 CEST 2010
Revision: 32386
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32386
Author: campbellbarton
Date: 2010-10-09 12:45:25 +0200 (Sat, 09 Oct 2010)
Log Message:
-----------
patch [#23781] Dynamically Load Actions
from Mitchell Stokes (moguri)
Modified Paths:
--------------
trunk/blender/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h
trunk/blender/source/gameengine/PyDoc/bge.logic.rst
Modified: trunk/blender/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_BlenderSceneConverter.cpp 2010-10-09 01:31:20 UTC (rev 32385)
+++ trunk/blender/source/gameengine/Converter/KX_BlenderSceneConverter.cpp 2010-10-09 10:45:25 UTC (rev 32386)
@@ -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 @@
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 @@
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 @@
}
}
}
+
+ /* Now unregister actions */
+ {
+ GEN_Map<STR_HashedString,void*> &mapStringToActions = scene->GetLogicManager()->GetActionMap();
+
+ for(int i=0; i<mapStringToActions.size(); i++)
+ {
+ ID *action= (ID*) *mapStringToActions.at(i);
+
+ if(IS_TAGGED(action))
+ {
+ STR_HashedString an = action->name+2;
+ mapStringToActions.remove(an);
+ i--;
+ }
+ }
+ }
//scene->FreeTagged(); /* removed tagged objects and meshes*/
CListValue *obj_lists[] = {scene->GetObjectList(), scene->GetInactiveList(), NULL};
@@ -1128,6 +1156,17 @@
break;
}
}
+
+ /* make sure action actuators are not referencing tagged actions */
+ for (int act_idx=0; act_idx<gameobj->GetActuators().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);
+ }
+ }
}
}
}
Modified: trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h 2010-10-09 01:31:20 UTC (rev 32385)
+++ trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h 2010-10-09 10:45:25 UTC (rev 32386)
@@ -127,6 +127,7 @@
void RegisterMeshName(const STR_String& meshname,void* mesh);
void UnregisterMeshName(const STR_String& meshname,void* mesh);
GEN_Map<STR_HashedString,void*>& GetMeshMap() { return m_mapStringToMeshes; };
+ GEN_Map<STR_HashedString,void*>& GetActionMap() { return m_mapStringToActions; };
void RegisterActionName(const STR_String& actname,void* action);
Modified: trunk/blender/source/gameengine/PyDoc/bge.logic.rst
===================================================================
--- trunk/blender/source/gameengine/PyDoc/bge.logic.rst 2010-10-09 01:31:20 UTC (rev 32385)
+++ trunk/blender/source/gameengine/PyDoc/bge.logic.rst 2010-10-09 10:45:25 UTC (rev 32386)
@@ -179,7 +179,7 @@
: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
More information about the Bf-blender-cvs
mailing list