[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15778] trunk/blender/source/gameengine: BGE patch: support runtime duplication of groups.
Benoit Bolsee
benoit.bolsee at online.be
Sat Jul 26 13:00:21 CEST 2008
Revision: 15778
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15778
Author: ben2610
Date: 2008-07-26 13:00:21 +0200 (Sat, 26 Jul 2008)
Log Message:
-----------
BGE patch: support runtime duplication of groups. Adding an object with Dupligroup option set will cause the group to be instantiated. No special actuator is needed for this feature, just put dupligroup objects in inactive layers and add them dynamically
Modified Paths:
--------------
trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.cpp
trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h
trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp 2008-07-26 10:45:11 UTC (rev 15777)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp 2008-07-26 11:00:21 UTC (rev 15778)
@@ -2027,8 +2027,8 @@
// needed for python scripting
logicmgr->RegisterGameObjectName(gameobj->GetName(),gameobj);
- // needed for dynamic object morphing
- logicmgr->RegisterGameObj(gameobj, blenderobject);
+ // needed for group duplication
+ logicmgr->RegisterGameObj(blenderobject, gameobj);
for (int i = 0; i < gameobj->GetMeshCount(); i++)
logicmgr->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), blenderobject);
@@ -2050,8 +2050,6 @@
gameobj->NodeUpdateGS(0,true);
gameobj->Bucketize();
- if (gameobj->IsDupliGroup())
- grouplist.insert(blenderobject->dup_group);
}
else
{
@@ -2059,6 +2057,8 @@
//at the end of this function if it is not a root object
inactivelist->Add(gameobj->AddRef());
}
+ if (gameobj->IsDupliGroup())
+ grouplist.insert(blenderobject->dup_group);
if (converter->addInitFromFrame){
gameobj->NodeSetLocalPosition(posPrev);
gameobj->NodeSetLocalOrientation(angor);
@@ -2109,7 +2109,7 @@
blenderscene);
// this code is copied from above except that
- // object from groups are never is active layer
+ // object from groups are never in active layer
bool isInActiveLayer = false;
bool addobj=true;
@@ -2207,8 +2207,8 @@
// needed for python scripting
logicmgr->RegisterGameObjectName(gameobj->GetName(),gameobj);
- // needed for dynamic object morphing
- logicmgr->RegisterGameObj(gameobj, blenderobject);
+ // needed for group duplication
+ logicmgr->RegisterGameObj(blenderobject, gameobj);
for (int i = 0; i < gameobj->GetMeshCount(); i++)
logicmgr->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), blenderobject);
Modified: trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.cpp 2008-07-26 10:45:11 UTC (rev 15777)
+++ trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.cpp 2008-07-26 11:00:21 UTC (rev 15778)
@@ -127,13 +127,18 @@
-void SCA_LogicManager::RegisterGameObj(CValue* gameobj, void* blendobj)
+void SCA_LogicManager::RegisterGameObj(void* blendobj, CValue* gameobj)
{
- m_map_gameobj_to_blendobj.insert(CHashedPtr(gameobj), blendobj);
+ m_map_blendobj_to_gameobj.insert(CHashedPtr(blendobj), gameobj);
}
+void SCA_LogicManager::UnregisterGameObj(void* blendobj, CValue* gameobj)
+{
+ void **obp = m_map_blendobj_to_gameobj[CHashedPtr(blendobj)];
+ if (obp && (CValue*)(*obp) == gameobj)
+ m_map_blendobj_to_gameobj.remove(CHashedPtr(blendobj));
+}
-
CValue* SCA_LogicManager::GetGameObjectByName(const STR_String& gameobjname)
{
STR_HashedString mn = "OB"+gameobjname;
@@ -146,10 +151,10 @@
}
-void* SCA_LogicManager::FindBlendObjByGameObj(CValue* gameobject)
+CValue* SCA_LogicManager::FindGameObjByBlendObj(void* blendobj)
{
- void **obp= m_map_gameobj_to_blendobj[CHashedPtr(gameobject)];
- return obp?*obp:NULL;
+ void **obp= m_map_blendobj_to_gameobj[CHashedPtr(blendobj)];
+ return obp?(CValue*)(*obp):NULL;
}
Modified: trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h 2008-07-26 10:45:11 UTC (rev 15777)
+++ trunk/blender/source/gameengine/GameLogic/SCA_LogicManager.h 2008-07-26 11:00:21 UTC (rev 15778)
@@ -109,7 +109,7 @@
GEN_Map<STR_HashedString,void*> m_mapStringToActions;
GEN_Map<STR_HashedString,void*> m_map_gamemeshname_to_blendobj;
- GEN_Map<CHashedPtr,void*> m_map_gameobj_to_blendobj;
+ GEN_Map<CHashedPtr,void*> m_map_blendobj_to_gameobj;
vector<SmartActuatorPtr> m_removedActuators;
public:
@@ -152,8 +152,9 @@
void RegisterGameMeshName(const STR_String& gamemeshname, void* blendobj);
void* FindBlendObjByGameMeshName(const STR_String& gamemeshname);
- void RegisterGameObj(CValue* gameobj, void* blendobj);
- void* FindBlendObjByGameObj(CValue* gameobj);
+ void RegisterGameObj(void* blendobj, CValue* gameobj);
+ void UnregisterGameObj(void* blendobj, CValue* gameobj);
+ CValue* FindGameObjByBlendObj(void* blendobj);
};
#endif //__KX_LOGICMANAGER
Modified: trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp 2008-07-26 10:45:11 UTC (rev 15777)
+++ trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp 2008-07-26 11:00:21 UTC (rev 15778)
@@ -650,7 +650,7 @@
if (blgroupobj == blenderobj)
// this check is also in group_duplilist()
continue;
- gameobj = m_sceneConverter->FindGameObject(blenderobj);
+ gameobj = (KX_GameObject*)m_logicmgr->FindGameObjByBlendObj(blenderobj);
if (gameobj == NULL)
{
// this object has not been converted!!!
@@ -860,6 +860,20 @@
replica->GetSGNode()->UpdateWorldData(0);
replica->GetSGNode()->SetBBox(originalobj->GetSGNode()->BBox());
replica->GetSGNode()->SetRadius(originalobj->GetSGNode()->Radius());
+ // check if there are objects with dupligroup in the hierarchy
+ vector<KX_GameObject*> duplilist;
+ for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
+ {
+ if ((*git)->IsDupliGroup())
+ {
+ // separate list as m_logicHierarchicalGameObjects is also used by DupliGroupRecurse()
+ duplilist.push_back(*git);
+ }
+ }
+ for (git = duplilist.begin();!(git==duplilist.end());++git)
+ {
+ DupliGroupRecurse(*git, 0);
+ }
// don't release replica here because we are returning it, not done with it...
return replica;
}
@@ -906,6 +920,12 @@
int ret;
KX_GameObject* newobj = (KX_GameObject*) gameobj;
+ // keep the blender->game object association up to date
+ // note that all the replicas of an object will have the same
+ // blender object, that's why we need to check the game object
+ // as only the deletion of the original object must be recorded
+ m_logicmgr->UnregisterGameObj(newobj->GetBlenderObject(), gameobj);
+
//todo: look at this
//GetPhysicsEnvironment()->RemovePhysicsController(gameobj->getPhysicsController());
More information about the Bf-blender-cvs
mailing list