Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

321 lines
8.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "movieobjects/dmepackoperators.h"
  7. #include "movieobjects_interfaces.h"
  8. #include "datamodel/dmelementfactoryhelper.h"
  9. #include "datamodel/dmattribute.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. //-----------------------------------------------------------------------------
  13. // CDmePackColorOperator
  14. //-----------------------------------------------------------------------------
  15. IMPLEMENT_ELEMENT_FACTORY( DmePackColorOperator, CDmePackColorOperator );
  16. void CDmePackColorOperator::OnConstruction()
  17. {
  18. m_color.Init( this, "color" );
  19. m_red .Init( this, "red" );
  20. m_green.Init( this, "green" );
  21. m_blue .Init( this, "blue" );
  22. m_alpha.Init( this, "alpha" );
  23. }
  24. void CDmePackColorOperator::OnDestruction()
  25. {
  26. }
  27. bool CDmePackColorOperator::IsDirty()
  28. {
  29. const Color &c = m_color.Get();
  30. // float s = 255.999f;
  31. // 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();
  32. return c.r() != m_red.Get() || c.g() != m_green.Get() || c.b() != m_blue.Get() || c.a() != m_alpha.Get();
  33. }
  34. void CDmePackColorOperator::Operate()
  35. {
  36. // float s = 255.999f;
  37. // m_color.Set( Color( s*m_red.Get(), s*m_green.Get(), s*m_blue.Get(), s*m_alpha.Get() ) );
  38. m_color.Set( Color( m_red.Get(), m_green.Get(), m_blue.Get(), m_alpha.Get() ) );
  39. }
  40. void CDmePackColorOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  41. {
  42. attrs.AddToTail( m_red.GetAttribute() );
  43. attrs.AddToTail( m_green.GetAttribute() );
  44. attrs.AddToTail( m_blue.GetAttribute() );
  45. attrs.AddToTail( m_alpha.GetAttribute() );
  46. }
  47. void CDmePackColorOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  48. {
  49. attrs.AddToTail( m_color.GetAttribute() );
  50. }
  51. //-----------------------------------------------------------------------------
  52. // CDmePackVector2Operator
  53. //-----------------------------------------------------------------------------
  54. IMPLEMENT_ELEMENT_FACTORY( DmePackVector2Operator, CDmePackVector2Operator );
  55. void CDmePackVector2Operator::OnConstruction()
  56. {
  57. m_vector.Init( this, "vector" );
  58. m_x.Init( this, "x" );
  59. m_y.Init( this, "y" );
  60. }
  61. void CDmePackVector2Operator::OnDestruction()
  62. {
  63. }
  64. bool CDmePackVector2Operator::IsDirty()
  65. {
  66. const Vector2D &v = m_vector.Get();
  67. return v.x != m_x.Get() || v.y != m_y.Get();
  68. }
  69. void CDmePackVector2Operator::Operate()
  70. {
  71. m_vector.Set( Vector2D( m_x.Get(), m_y.Get() ) );
  72. }
  73. void CDmePackVector2Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  74. {
  75. attrs.AddToTail( m_x.GetAttribute() );
  76. attrs.AddToTail( m_y.GetAttribute() );
  77. }
  78. void CDmePackVector2Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  79. {
  80. attrs.AddToTail( m_vector.GetAttribute() );
  81. }
  82. //-----------------------------------------------------------------------------
  83. // CDmePackVector3Operator
  84. //-----------------------------------------------------------------------------
  85. IMPLEMENT_ELEMENT_FACTORY( DmePackVector3Operator, CDmePackVector3Operator );
  86. void CDmePackVector3Operator::OnConstruction()
  87. {
  88. m_vector.Init( this, "vector" );
  89. m_x.Init( this, "x" );
  90. m_y.Init( this, "y" );
  91. m_z.Init( this, "z" );
  92. }
  93. void CDmePackVector3Operator::OnDestruction()
  94. {
  95. }
  96. bool CDmePackVector3Operator::IsDirty()
  97. {
  98. const Vector &v = m_vector.Get();
  99. return v.x != m_x.Get() || v.y != m_y.Get() || v.z != m_z.Get();
  100. }
  101. void CDmePackVector3Operator::Operate()
  102. {
  103. m_vector.Set( Vector( m_x.Get(), m_y.Get(), m_z.Get() ) );
  104. }
  105. void CDmePackVector3Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  106. {
  107. attrs.AddToTail( m_x.GetAttribute() );
  108. attrs.AddToTail( m_y.GetAttribute() );
  109. attrs.AddToTail( m_z.GetAttribute() );
  110. }
  111. void CDmePackVector3Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  112. {
  113. attrs.AddToTail( m_vector.GetAttribute() );
  114. }
  115. //-----------------------------------------------------------------------------
  116. // CDmePackVector4Operator
  117. //-----------------------------------------------------------------------------
  118. IMPLEMENT_ELEMENT_FACTORY( DmePackVector4Operator, CDmePackVector4Operator );
  119. void CDmePackVector4Operator::OnConstruction()
  120. {
  121. m_vector.Init( this, "vector" );
  122. m_x.Init( this, "x" );
  123. m_y.Init( this, "y" );
  124. m_z.Init( this, "z" );
  125. m_w.Init( this, "w" );
  126. }
  127. void CDmePackVector4Operator::OnDestruction()
  128. {
  129. }
  130. bool CDmePackVector4Operator::IsDirty()
  131. {
  132. const Vector4D &v = m_vector.Get();
  133. return v.x != m_x.Get() || v.y != m_y.Get() || v.z != m_z.Get() || v.w != m_w.Get();
  134. }
  135. void CDmePackVector4Operator::Operate()
  136. {
  137. m_vector.Set( Vector4D( m_x.Get(), m_y.Get(), m_z.Get(), m_w.Get() ) );
  138. }
  139. void CDmePackVector4Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  140. {
  141. attrs.AddToTail( m_x.GetAttribute() );
  142. attrs.AddToTail( m_y.GetAttribute() );
  143. attrs.AddToTail( m_z.GetAttribute() );
  144. attrs.AddToTail( m_w.GetAttribute() );
  145. }
  146. void CDmePackVector4Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  147. {
  148. attrs.AddToTail( m_vector.GetAttribute() );
  149. }
  150. //-----------------------------------------------------------------------------
  151. // CDmePackQAngleOperator
  152. //-----------------------------------------------------------------------------
  153. IMPLEMENT_ELEMENT_FACTORY( DmePackQAngleOperator, CDmePackQAngleOperator );
  154. void CDmePackQAngleOperator::OnConstruction()
  155. {
  156. m_qangle.Init( this, "qangle" );
  157. m_x.Init( this, "x" );
  158. m_y.Init( this, "y" );
  159. m_z.Init( this, "z" );
  160. }
  161. void CDmePackQAngleOperator::OnDestruction()
  162. {
  163. }
  164. bool CDmePackQAngleOperator::IsDirty()
  165. {
  166. const QAngle &q = m_qangle.Get();
  167. return q.x != m_x.Get() || q.y != m_y.Get() || q.z != m_z.Get();
  168. }
  169. void CDmePackQAngleOperator::Operate()
  170. {
  171. m_qangle.Set( QAngle( m_x.Get(), m_y.Get(), m_z.Get() ) );
  172. }
  173. void CDmePackQAngleOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  174. {
  175. attrs.AddToTail( m_x.GetAttribute() );
  176. attrs.AddToTail( m_y.GetAttribute() );
  177. attrs.AddToTail( m_z.GetAttribute() );
  178. }
  179. void CDmePackQAngleOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  180. {
  181. attrs.AddToTail( m_qangle.GetAttribute() );
  182. }
  183. //-----------------------------------------------------------------------------
  184. // CDmePackQuaternionOperator
  185. //-----------------------------------------------------------------------------
  186. IMPLEMENT_ELEMENT_FACTORY( DmePackQuaternionOperator, CDmePackQuaternionOperator );
  187. void CDmePackQuaternionOperator::OnConstruction()
  188. {
  189. m_quaternion.Init( this, "quaternion" );
  190. m_x.Init( this, "x" );
  191. m_y.Init( this, "y" );
  192. m_z.Init( this, "z" );
  193. m_w.Init( this, "w" );
  194. }
  195. void CDmePackQuaternionOperator::OnDestruction()
  196. {
  197. }
  198. bool CDmePackQuaternionOperator::IsDirty()
  199. {
  200. const Quaternion &q = m_quaternion.Get();
  201. return q.x != m_x.Get() || q.y != m_y.Get() || q.z != m_z.Get() || q.w != m_w.Get();
  202. }
  203. void CDmePackQuaternionOperator::Operate()
  204. {
  205. m_quaternion.Set( Quaternion( m_x.Get(), m_y.Get(), m_z.Get(), m_w.Get() ) );
  206. }
  207. void CDmePackQuaternionOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  208. {
  209. attrs.AddToTail( m_x.GetAttribute() );
  210. attrs.AddToTail( m_y.GetAttribute() );
  211. attrs.AddToTail( m_z.GetAttribute() );
  212. attrs.AddToTail( m_w.GetAttribute() );
  213. }
  214. void CDmePackQuaternionOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  215. {
  216. attrs.AddToTail( m_quaternion.GetAttribute() );
  217. }
  218. //-----------------------------------------------------------------------------
  219. // CDmePackVMatrixOperator
  220. //-----------------------------------------------------------------------------
  221. IMPLEMENT_ELEMENT_FACTORY( DmePackVMatrixOperator, CDmePackVMatrixOperator );
  222. void CDmePackVMatrixOperator::OnConstruction()
  223. {
  224. m_vmatrix.Init( this, "vmatrix" );
  225. char name[ 4 ];
  226. for ( uint i = 0; i < 16; ++i )
  227. {
  228. Q_snprintf( name, sizeof(name), "m%d%d", i >> 2, i & 0x3 );
  229. m_cells[ i ].Init( this, name );
  230. }
  231. }
  232. void CDmePackVMatrixOperator::OnDestruction()
  233. {
  234. }
  235. bool CDmePackVMatrixOperator::IsDirty()
  236. {
  237. const VMatrix &v = m_vmatrix.Get();
  238. for ( uint i = 0; i < 16; ++i )
  239. {
  240. if ( *( v[ i ] ) != m_cells[ i ].Get() )
  241. return true;
  242. }
  243. return false;
  244. }
  245. void CDmePackVMatrixOperator::Operate()
  246. {
  247. VMatrix v;
  248. for ( uint i = 0; i < 16; ++i )
  249. {
  250. *( v[ i ] ) = m_cells[ i ].Get();
  251. }
  252. m_vmatrix.Set( v );
  253. }
  254. void CDmePackVMatrixOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  255. {
  256. for ( uint i = 0; i < 16; ++i )
  257. {
  258. attrs.AddToTail( m_cells[i].GetAttribute() );
  259. }
  260. }
  261. void CDmePackVMatrixOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  262. {
  263. attrs.AddToTail( m_vmatrix.GetAttribute() );
  264. }