BGE patch: support for partial hierarchy in dupligroup instantiation; removal of links that point to inactive objects during group instantiation.
This situation corresponds to a group containing only a portion of a parent hierarchy (the Apricot team needed that to avoid logic duplication). The BGE will instantiate only the children that are in the group so that it follows the 3D view more closely. As a result, the logic links to the objects in the portion of the hierarchy that was not replicated will point to inactive objects (if the groups are stored in inactive layers as they should be). To keep the logic system consistent, these links are automatically removed. This last part of the patch is a general fix that could go in 2.47 but as this situation does not normally occurs in pre-2.47 games, it is not needed.
This commit is contained in:
@@ -68,7 +68,7 @@ SG_Node* SG_Node::GetSGReplica()
|
||||
SG_Node* replica = new SG_Node(*this);
|
||||
if (replica == NULL) return NULL;
|
||||
|
||||
ProcessSGReplica(replica);
|
||||
ProcessSGReplica(&replica);
|
||||
|
||||
return replica;
|
||||
}
|
||||
@@ -76,25 +76,42 @@ SG_Node* SG_Node::GetSGReplica()
|
||||
void
|
||||
SG_Node::
|
||||
ProcessSGReplica(
|
||||
SG_Node* replica
|
||||
SG_Node** replica
|
||||
){
|
||||
// Apply the replication call back function.
|
||||
ActivateReplicationCallback(replica);
|
||||
if (!ActivateReplicationCallback(*replica))
|
||||
{
|
||||
delete (*replica);
|
||||
*replica = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
// clear the replica node of it's parent.
|
||||
static_cast<SG_Node*>(replica)->m_SGparent = NULL;
|
||||
static_cast<SG_Node*>(*replica)->m_SGparent = NULL;
|
||||
|
||||
if (m_children.begin() != m_children.end())
|
||||
{
|
||||
// if this node has children, the replica has too, so clear and clone children
|
||||
replica->ClearSGChildren();
|
||||
(*replica)->ClearSGChildren();
|
||||
|
||||
NodeList::iterator childit;
|
||||
for (childit = m_children.begin();childit!=m_children.end();++childit)
|
||||
{
|
||||
replica->AddChild((*childit)->GetSGReplica());
|
||||
SG_Node* childnode = (*childit)->GetSGReplica();
|
||||
if (childnode)
|
||||
(*replica)->AddChild(childnode);
|
||||
}
|
||||
}
|
||||
// Nodes without children and without client object are
|
||||
// not worth to keep, they will just take up CPU
|
||||
// This can happen in partial replication of hierarchy
|
||||
// during group duplication.
|
||||
if ((*replica)->m_children.empty() &&
|
||||
(*replica)->GetSGClientObject() == NULL)
|
||||
{
|
||||
delete (*replica);
|
||||
*replica = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user