-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathdmeconnectionoperator.cpp
More file actions
188 lines (153 loc) · 6.86 KB
/
dmeconnectionoperator.cpp
File metadata and controls
188 lines (153 loc) · 6.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//====== Copyright © 1996-2009, Valve Corporation, All rights reserved. =======
//
// Purpose: Declaration of the CDmeConnectionOperator class, a CDmeOperator
// which copies one attribute value to another, providing similar functionality
// to CDmeChannel, but does not store a log and is not effected by the
// recording mode.
//
//=============================================================================
#include "movieobjects/dmeconnectionoperator.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "tier1/fmtstr.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-------------------------------------------------------------------------------------------------
// Expose this class to the scene database
//-------------------------------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeConnectionOperator, CDmeConnectionOperator );
//-------------------------------------------------------------------------------------------------
// Purpose: Constructor, initializes attributes, create the embedded target
//-------------------------------------------------------------------------------------------------
void CDmeConnectionOperator::OnConstruction()
{
m_Input.InitAndCreate( this, "input" );
m_Outputs.Init( this, "outputs" );
}
//-------------------------------------------------------------------------------------------------
// Purpose: Perform destruction tasks, destroy the internal elements of the constraint.
//-------------------------------------------------------------------------------------------------
void CDmeConnectionOperator::OnDestruction()
{
g_pDataModel->DestroyElement( m_Input.GetHandle() );
int nOutputs = m_Outputs.Count();
for ( int i = 0 ;i < nOutputs; ++i )
{
if ( m_Outputs[ i ] )
{
g_pDataModel->DestroyElement( m_Outputs[ i ]->GetHandle() );
}
}
m_Outputs.RemoveAll();
}
//-------------------------------------------------------------------------------------------------
// Purpose: Run the operator, which copies the value from the source attribute to the destination
// attributes.
//-------------------------------------------------------------------------------------------------
void CDmeConnectionOperator::Operate()
{
if ( !m_Input->IsValid() )
return;
int nOutputs = m_Outputs.Count();
if ( nOutputs == 0 )
return;
DmAttributeType_t inputType = AT_UNKNOWN;
const void *pValue = m_Input->GetAttributeValue( inputType );
for ( int iOutput = 0; iOutput < nOutputs; ++iOutput )
{
m_Outputs[ iOutput ]->SetAttributeValue( pValue, inputType );
}
}
//-------------------------------------------------------------------------------------------------
// Purpose: Determine if data has changed and the operator needs to be updated
//-------------------------------------------------------------------------------------------------
bool CDmeConnectionOperator::IsDirty()
{
CDmAttribute* pAttr = m_Input->GetReferencedAttribute();
if ( pAttr )
{
return pAttr->IsFlagSet( FATTRIB_DIRTY );
}
return false;
}
//-------------------------------------------------------------------------------------------------
// Purpose: Add the input attribute used by the operator to the provided list of attributes, This
// is generally used by the evaluation process to find the attributes an operator is dependent on.
//-------------------------------------------------------------------------------------------------
void CDmeConnectionOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
CDmAttribute *pInputAttr = m_Input->GetReferencedAttribute();
if ( pInputAttr )
{
attrs.AddToTail( pInputAttr );
}
}
//-------------------------------------------------------------------------------------------------
// Purpose: Add each of attributes the connection operator outputs to the provided list of
// attributes. This is generally used by the evaluation process to find out what attributes are
// written by the operator in order to determine what other operators are dependent on this
// operator.
//-------------------------------------------------------------------------------------------------
void CDmeConnectionOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
int nOutputs = m_Outputs.Count();
for ( int iOutput = 0; iOutput < nOutputs; ++iOutput )
{
CDmAttribute *pOutputAttr = m_Outputs[ iOutput ]->GetReferencedAttribute();
if ( pOutputAttr )
{
attrs.AddToTail( pOutputAttr );
}
}
}
//-------------------------------------------------------------------------------------------------
// Purpose: Set the input attribute of the connection.
//-------------------------------------------------------------------------------------------------
void CDmeConnectionOperator::SetInput( CDmElement* pElement, const char* pchAttributeName, int index )
{
m_Input->SetAttribute( pElement, pchAttributeName, index );
}
//-------------------------------------------------------------------------------------------------
// Purpose: Add an attribute to be written to by the connection.
//-------------------------------------------------------------------------------------------------
void CDmeConnectionOperator::AddOutput( CDmElement* pElement, const char* pchAttributeName, int index )
{
if ( ( pElement == NULL ) || ( pchAttributeName == NULL ) )
return;
CDmeAttributeReference *pAttrRef = CreateElement< CDmeAttributeReference >( CFmtStr( "%s_%s", pElement->GetName() , pchAttributeName ), GetFileId() );
if ( pAttrRef )
{
if ( pAttrRef->SetAttribute( pElement, pchAttributeName, index ) )
{
// Add the new reference to the list of outputs of the connection.
m_Outputs.AddToTail( pAttrRef );
}
else
{
// If the specified attribute was not valid destroy the reference.
g_pDataModel->DestroyElement( pAttrRef->GetHandle() );
}
}
}
//-------------------------------------------------------------------------------------------------
// Purpose: Get the number of output attributes
//-------------------------------------------------------------------------------------------------
int CDmeConnectionOperator::NumOutputAttributes() const
{
return m_Outputs.Count();
}
//-------------------------------------------------------------------------------------------------
// Purpose: Get the specified output attribute
//-------------------------------------------------------------------------------------------------
CDmAttribute *CDmeConnectionOperator::GetOutputAttribute( int index ) const
{
if ( index >= m_Outputs.Count() )
return NULL;
return m_Outputs[ index ]->GetReferencedAttribute();
}
//-------------------------------------------------------------------------------------------------
// Purpose: Get the input attribute
//-------------------------------------------------------------------------------------------------
CDmAttribute *CDmeConnectionOperator::GetInputAttribute()
{
return m_Input.GetAttribute();
}