-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathdmepackoperators.cpp
More file actions
324 lines (267 loc) · 8.51 KB
/
dmepackoperators.cpp
File metadata and controls
324 lines (267 loc) · 8.51 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
//
// Purpose:
//
//=============================================================================
#include "movieobjects/dmepackoperators.h"
#include "movieobjects_interfaces.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "datamodel/dmattribute.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// CDmePackColorOperator
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmePackColorOperator, CDmePackColorOperator );
void CDmePackColorOperator::OnConstruction()
{
m_color.Init( this, "color" );
m_red .Init( this, "red" );
m_green.Init( this, "green" );
m_blue .Init( this, "blue" );
m_alpha.Init( this, "alpha" );
}
void CDmePackColorOperator::OnDestruction()
{
}
bool CDmePackColorOperator::IsDirty()
{
const Color &c = m_color.Get();
float s = 255.999f;
return c.r() != s*m_red.Get() || c.g() != s*m_green.Get() || c.b() != s*m_blue.Get() || c.a() != s*m_alpha.Get();
// return c.r() != m_red.Get() || c.g() != m_green.Get() || c.b() != m_blue.Get() || c.a() != m_alpha.Get();
}
void CDmePackColorOperator::Operate()
{
float s = 255.999f;
int r = clamp( s*m_red.Get(), 0, 255 );
int g = clamp( s*m_green.Get(), 0, 255 );
int b = clamp( s*m_blue.Get(), 0, 255 );
int a = clamp( s*m_alpha.Get(), 0, 255 );
m_color.Set( Color( r, g, b, a ) );
}
void CDmePackColorOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_red.GetAttribute() );
attrs.AddToTail( m_green.GetAttribute() );
attrs.AddToTail( m_blue.GetAttribute() );
attrs.AddToTail( m_alpha.GetAttribute() );
}
void CDmePackColorOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_color.GetAttribute() );
}
//-----------------------------------------------------------------------------
// CDmePackVector2Operator
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmePackVector2Operator, CDmePackVector2Operator );
void CDmePackVector2Operator::OnConstruction()
{
m_vector.Init( this, "vector" );
m_x.Init( this, "x" );
m_y.Init( this, "y" );
}
void CDmePackVector2Operator::OnDestruction()
{
}
bool CDmePackVector2Operator::IsDirty()
{
const Vector2D &v = m_vector.Get();
return v.x != m_x.Get() || v.y != m_y.Get();
}
void CDmePackVector2Operator::Operate()
{
m_vector.Set( Vector2D( m_x.Get(), m_y.Get() ) );
}
void CDmePackVector2Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_x.GetAttribute() );
attrs.AddToTail( m_y.GetAttribute() );
}
void CDmePackVector2Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_vector.GetAttribute() );
}
//-----------------------------------------------------------------------------
// CDmePackVector3Operator
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmePackVector3Operator, CDmePackVector3Operator );
void CDmePackVector3Operator::OnConstruction()
{
m_vector.Init( this, "vector" );
m_x.Init( this, "x" );
m_y.Init( this, "y" );
m_z.Init( this, "z" );
}
void CDmePackVector3Operator::OnDestruction()
{
}
bool CDmePackVector3Operator::IsDirty()
{
const Vector &v = m_vector.Get();
return v.x != m_x.Get() || v.y != m_y.Get() || v.z != m_z.Get();
}
void CDmePackVector3Operator::Operate()
{
m_vector.Set( Vector( m_x.Get(), m_y.Get(), m_z.Get() ) );
}
void CDmePackVector3Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_x.GetAttribute() );
attrs.AddToTail( m_y.GetAttribute() );
attrs.AddToTail( m_z.GetAttribute() );
}
void CDmePackVector3Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_vector.GetAttribute() );
}
//-----------------------------------------------------------------------------
// CDmePackVector4Operator
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmePackVector4Operator, CDmePackVector4Operator );
void CDmePackVector4Operator::OnConstruction()
{
m_vector.Init( this, "vector" );
m_x.Init( this, "x" );
m_y.Init( this, "y" );
m_z.Init( this, "z" );
m_w.Init( this, "w" );
}
void CDmePackVector4Operator::OnDestruction()
{
}
bool CDmePackVector4Operator::IsDirty()
{
const Vector4D &v = m_vector.Get();
return v.x != m_x.Get() || v.y != m_y.Get() || v.z != m_z.Get() || v.w != m_w.Get();
}
void CDmePackVector4Operator::Operate()
{
m_vector.Set( Vector4D( m_x.Get(), m_y.Get(), m_z.Get(), m_w.Get() ) );
}
void CDmePackVector4Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_x.GetAttribute() );
attrs.AddToTail( m_y.GetAttribute() );
attrs.AddToTail( m_z.GetAttribute() );
attrs.AddToTail( m_w.GetAttribute() );
}
void CDmePackVector4Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_vector.GetAttribute() );
}
//-----------------------------------------------------------------------------
// CDmePackQAngleOperator
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmePackQAngleOperator, CDmePackQAngleOperator );
void CDmePackQAngleOperator::OnConstruction()
{
m_qangle.Init( this, "qangle" );
m_x.Init( this, "x" );
m_y.Init( this, "y" );
m_z.Init( this, "z" );
}
void CDmePackQAngleOperator::OnDestruction()
{
}
bool CDmePackQAngleOperator::IsDirty()
{
const QAngle &q = m_qangle.Get();
return q.x != m_x.Get() || q.y != m_y.Get() || q.z != m_z.Get();
}
void CDmePackQAngleOperator::Operate()
{
m_qangle.Set( QAngle( m_x.Get(), m_y.Get(), m_z.Get() ) );
}
void CDmePackQAngleOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_x.GetAttribute() );
attrs.AddToTail( m_y.GetAttribute() );
attrs.AddToTail( m_z.GetAttribute() );
}
void CDmePackQAngleOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_qangle.GetAttribute() );
}
//-----------------------------------------------------------------------------
// CDmePackQuaternionOperator
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmePackQuaternionOperator, CDmePackQuaternionOperator );
void CDmePackQuaternionOperator::OnConstruction()
{
m_quaternion.Init( this, "quaternion" );
m_x.Init( this, "x" );
m_y.Init( this, "y" );
m_z.Init( this, "z" );
m_w.Init( this, "w" );
}
void CDmePackQuaternionOperator::OnDestruction()
{
}
bool CDmePackQuaternionOperator::IsDirty()
{
const Quaternion &q = m_quaternion.Get();
return q.x != m_x.Get() || q.y != m_y.Get() || q.z != m_z.Get() || q.w != m_w.Get();
}
void CDmePackQuaternionOperator::Operate()
{
m_quaternion.Set( Quaternion( m_x.Get(), m_y.Get(), m_z.Get(), m_w.Get() ) );
}
void CDmePackQuaternionOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_x.GetAttribute() );
attrs.AddToTail( m_y.GetAttribute() );
attrs.AddToTail( m_z.GetAttribute() );
attrs.AddToTail( m_w.GetAttribute() );
}
void CDmePackQuaternionOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_quaternion.GetAttribute() );
}
//-----------------------------------------------------------------------------
// CDmePackVMatrixOperator
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmePackVMatrixOperator, CDmePackVMatrixOperator );
void CDmePackVMatrixOperator::OnConstruction()
{
m_vmatrix.Init( this, "vmatrix" );
char name[ 4 ];
for ( uint i = 0; i < 16; ++i )
{
Q_snprintf( name, sizeof(name), "m%d%d", i >> 2, i & 0x3 );
m_cells[ i ].Init( this, name );
}
}
void CDmePackVMatrixOperator::OnDestruction()
{
}
bool CDmePackVMatrixOperator::IsDirty()
{
const VMatrix &v = m_vmatrix.Get();
for ( uint i = 0; i < 16; ++i )
{
if ( *( v[ i ] ) != m_cells[ i ].Get() )
return true;
}
return false;
}
void CDmePackVMatrixOperator::Operate()
{
VMatrix v;
for ( uint i = 0; i < 16; ++i )
{
*( v[ i ] ) = m_cells[ i ].Get();
}
m_vmatrix.Set( v );
}
void CDmePackVMatrixOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
for ( uint i = 0; i < 16; ++i )
{
attrs.AddToTail( m_cells[i].GetAttribute() );
}
}
void CDmePackVMatrixOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
{
attrs.AddToTail( m_vmatrix.GetAttribute() );
}