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

This commit is contained in:
Benoit Bolsee 2008-07-26 11:00:21 +00:00
parent 9f803439c7
commit c4116a7f8d
4 changed files with 43 additions and 17 deletions

@ -2027,8 +2027,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
// 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 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
gameobj->NodeUpdateGS(0,true);
gameobj->Bucketize();
if (gameobj->IsDupliGroup())
grouplist.insert(blenderobject->dup_group);
}
else
{
@ -2059,6 +2057,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
//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 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
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 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
// 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);

@ -127,12 +127,17 @@ void SCA_LogicManager::RegisterGameMeshName(const STR_String& gamemeshname, void
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)
{
@ -146,10 +151,10 @@ CValue* SCA_LogicManager::GetGameObjectByName(const STR_String& gameobjname)
}
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;
}

@ -109,7 +109,7 @@ class SCA_LogicManager
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 @@ public:
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

@ -650,7 +650,7 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level)
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 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject,
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 KX_Scene::NewRemoveObject(class CValue* gameobj)
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());