Skip to content

Commit

Permalink
Merge pull request #183 from lilligreen/behaviorIdFix
Browse files Browse the repository at this point in the history
Behavior Connection fixes
  • Loading branch information
lilligreen committed Apr 28, 2014
2 parents 2dd88af + 466e84e commit 32990c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 18 additions & 14 deletions engine/source/component/behaviors/behaviorComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@

//-----------------------------------------------------------------------------

#define BEHAVIOR_ID_FIELD_NAME "Id"
#define BEHAVIOR_NODE_NAME "Behaviors"
#define BEHAVIOR_CONNECTION_TYPE_NAME "Connection"
static StringTableEntry behaviorIdFieldName = StringTable->insert( "Id" );
static StringTableEntry behaviorNodeName = StringTable->insert( "Behaviors" );
static StringTableEntry behaviorConnectionTypeName = StringTable->insert( "Connection" );
static StringTableEntry behaviorTemplateAssetName = StringTable->insert( "Asset" );

//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -1077,10 +1078,10 @@ void BehaviorComponent::onTamlCustomWrite( TamlCustomNodes& customNodes )
return;

// Fetch behavior template asset field type.
StringTableEntry behaviorTemplateAssetFieldType = StringTable->insert( BEHAVIORTEMPLATE_ASSET_FIELDTYPE );
StringTableEntry behaviorTemplateAssetFieldType = StringTable->insert( behaviorTemplateAssetName );

// Add custom behaviors node.
TamlCustomNode* pCustomBehaviorNode = customNodes.addNode( BEHAVIOR_NODE_NAME );
TamlCustomNode* pCustomBehaviorNode = customNodes.addNode( behaviorNodeName );

// Iterate behaviors.
for( SimSet::iterator behaviorItr = mBehaviors.begin(); behaviorItr != mBehaviors.end(); ++behaviorItr )
Expand All @@ -1095,7 +1096,7 @@ void BehaviorComponent::onTamlCustomWrite( TamlCustomNodes& customNodes )
TamlCustomNode* pBehaviorNode = pCustomBehaviorNode->addNode( pBehaviorInstance->getTemplateName() );

// Add behavior Id field.
pBehaviorNode->addField( BEHAVIOR_ID_FIELD_NAME, pBehaviorInstance->getBehaviorId() );
pBehaviorNode->addField( behaviorIdFieldName, pBehaviorInstance->getBehaviorId() );

// Fetch field count,
const U32 behaviorFieldCount = pBehaviorTemplate->getBehaviorFieldCount();
Expand Down Expand Up @@ -1150,7 +1151,7 @@ void BehaviorComponent::onTamlCustomWrite( TamlCustomNodes& customNodes )
BehaviorPortConnection* pConnection = connectionItr;

// Add connectionnode.
TamlCustomNode* pConnectionNode = pCustomBehaviorNode->addNode( BEHAVIOR_CONNECTION_TYPE_NAME );
TamlCustomNode* pConnectionNode = pCustomBehaviorNode->addNode( behaviorConnectionTypeName );

// Add behavior field.
pConnectionNode->addField( pConnection->mOutputName, pConnection->mOutputInstance->getBehaviorId() );
Expand All @@ -1168,7 +1169,7 @@ void BehaviorComponent::onTamlCustomRead( const TamlCustomNodes& customNodes )
Parent::onTamlCustomRead( customNodes );

// Find custom behaviors node.
const TamlCustomNode* pCustomBehaviorNode = customNodes.findNode( BEHAVIOR_NODE_NAME );
const TamlCustomNode* pCustomBehaviorNode = customNodes.findNode( behaviorNodeName );

// Do we have the property?
if ( pCustomBehaviorNode != NULL )
Expand All @@ -1177,10 +1178,10 @@ void BehaviorComponent::onTamlCustomRead( const TamlCustomNodes& customNodes )
S32 maximumBehaviorId = 0;

// Fetch behavior Id field name.
StringTableEntry behaviorFieldIdName = StringTable->insert( BEHAVIOR_ID_FIELD_NAME );
StringTableEntry behaviorFieldIdName = StringTable->insert( behaviorIdFieldName );

// Fetch behavior template asset field type.
StringTableEntry behaviorTemplateAssetFieldType = StringTable->insert( BEHAVIORTEMPLATE_ASSET_FIELDTYPE );
StringTableEntry behaviorTemplateAssetFieldType = StringTable->insert( behaviorTemplateAssetName );

// Fetch children behavior nodes.
const TamlCustomNodeVector& behaviorNodes = pCustomBehaviorNode->getChildren();
Expand All @@ -1191,7 +1192,7 @@ void BehaviorComponent::onTamlCustomRead( const TamlCustomNodes& customNodes )
// Fetch behavior node.
TamlCustomNode* pBehaviorNode = *behaviorNodeItr;

if ( pBehaviorNode->getNodeName() == BEHAVIOR_CONNECTION_TYPE_NAME )
if ( pBehaviorNode->getNodeName() == behaviorConnectionTypeName )
{
// Fetch field nodes.
const TamlCustomFieldVector& connectionFieldNodes = pBehaviorNode->getFields();
Expand Down Expand Up @@ -1390,9 +1391,12 @@ void BehaviorComponent::onTamlCustomRead( const TamlCustomNodes& customNodes )
// Add behavior.
addBehavior( pBehaviorInstance );

// Override the automatically allocated behavior Id when adding the behavior.
// Override the automatically allocated behavior Id if the Id field is already defined in the TAML file.
// NOTE: This must be done after adding the behavior.
pBehaviorInstance->setBehaviorId( behaviorId );
if (behaviorId != 0)
{
pBehaviorInstance->setBehaviorId( behaviorId );
}
}
}

Expand All @@ -1410,7 +1414,7 @@ static void WriteCustomTamlSchema( const AbstractClassRep* pClassRep, TiXmlEleme
AssertFatal( pParentElement != NULL, "BehaviorComponent::WriteCustomTamlSchema() - Parent Element cannot be NULL." );

// Write an unrestricted custom Taml schema.
Taml::WriteUnrestrictedCustomTamlSchema( BEHAVIOR_NODE_NAME, pClassRep, pParentElement );
Taml::WriteUnrestrictedCustomTamlSchema( behaviorNodeName, pClassRep, pParentElement );
}

//-----------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions engine/source/component/behaviors/behaviorTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@

//-----------------------------------------------------------------------------

#define BEHAVIORTEMPLATE_ASSET_FIELDTYPE "Asset"

//-----------------------------------------------------------------------------

class BehaviorTemplate : public SimObject
{
typedef SimObject Parent;
Expand Down

0 comments on commit 32990c3

Please sign in to comment.