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.

335 lines
8.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "movieobjects/dmeunpackoperators.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. // CDmeUnpackColorOperator
  14. //-----------------------------------------------------------------------------
  15. IMPLEMENT_ELEMENT_FACTORY( DmeUnpackColorOperator, CDmeUnpackColorOperator );
  16. void CDmeUnpackColorOperator::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 CDmeUnpackColorOperator::OnDestruction()
  25. {
  26. }
  27. bool CDmeUnpackColorOperator::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 CDmeUnpackColorOperator::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_red .Set( m_color.Get().r() );
  39. m_green.Set( m_color.Get().g() );
  40. m_blue .Set( m_color.Get().b() );
  41. m_alpha.Set( m_color.Get().a() );
  42. }
  43. void CDmeUnpackColorOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  44. {
  45. attrs.AddToTail( m_color.GetAttribute() );
  46. }
  47. void CDmeUnpackColorOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  48. {
  49. attrs.AddToTail( m_red.GetAttribute() );
  50. attrs.AddToTail( m_green.GetAttribute() );
  51. attrs.AddToTail( m_blue.GetAttribute() );
  52. attrs.AddToTail( m_alpha.GetAttribute() );
  53. }
  54. //-----------------------------------------------------------------------------
  55. // CDmeUnpackVector2Operator
  56. //-----------------------------------------------------------------------------
  57. IMPLEMENT_ELEMENT_FACTORY( DmeUnpackVector2Operator, CDmeUnpackVector2Operator );
  58. void CDmeUnpackVector2Operator::OnConstruction()
  59. {
  60. m_vector.Init( this, "vector" );
  61. m_x.Init( this, "x" );
  62. m_y.Init( this, "y" );
  63. }
  64. void CDmeUnpackVector2Operator::OnDestruction()
  65. {
  66. }
  67. bool CDmeUnpackVector2Operator::IsDirty()
  68. {
  69. const Vector2D &v = m_vector.Get();
  70. return v.x != m_x.Get() || v.y != m_y.Get();
  71. }
  72. void CDmeUnpackVector2Operator::Operate()
  73. {
  74. m_x.Set( m_vector.Get().x );
  75. m_y.Set( m_vector.Get().y );
  76. }
  77. void CDmeUnpackVector2Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  78. {
  79. attrs.AddToTail( m_vector.GetAttribute() );
  80. }
  81. void CDmeUnpackVector2Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  82. {
  83. attrs.AddToTail( m_x.GetAttribute() );
  84. attrs.AddToTail( m_y.GetAttribute() );
  85. }
  86. //-----------------------------------------------------------------------------
  87. // CDmeUnpackVector3Operator
  88. //-----------------------------------------------------------------------------
  89. IMPLEMENT_ELEMENT_FACTORY( DmeUnpackVector3Operator, CDmeUnpackVector3Operator );
  90. void CDmeUnpackVector3Operator::OnConstruction()
  91. {
  92. m_vector.Init( this, "vector" );
  93. m_x.Init( this, "x" );
  94. m_y.Init( this, "y" );
  95. m_z.Init( this, "z" );
  96. }
  97. void CDmeUnpackVector3Operator::OnDestruction()
  98. {
  99. }
  100. bool CDmeUnpackVector3Operator::IsDirty()
  101. {
  102. const Vector &v = m_vector.Get();
  103. return v.x != m_x.Get() || v.y != m_y.Get() || v.z != m_z.Get();
  104. }
  105. void CDmeUnpackVector3Operator::Operate()
  106. {
  107. m_x.Set( m_vector.Get().x );
  108. m_y.Set( m_vector.Get().y );
  109. m_z.Set( m_vector.Get().z );
  110. }
  111. void CDmeUnpackVector3Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  112. {
  113. attrs.AddToTail( m_vector.GetAttribute() );
  114. }
  115. void CDmeUnpackVector3Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  116. {
  117. attrs.AddToTail( m_x.GetAttribute() );
  118. attrs.AddToTail( m_y.GetAttribute() );
  119. attrs.AddToTail( m_z.GetAttribute() );
  120. }
  121. //-----------------------------------------------------------------------------
  122. // CDmeUnpackVector4Operator
  123. //-----------------------------------------------------------------------------
  124. IMPLEMENT_ELEMENT_FACTORY( DmeUnpackVector4Operator, CDmeUnpackVector4Operator );
  125. void CDmeUnpackVector4Operator::OnConstruction()
  126. {
  127. m_vector.Init( this, "vector" );
  128. m_x.Init( this, "x" );
  129. m_y.Init( this, "y" );
  130. m_z.Init( this, "z" );
  131. m_w.Init( this, "w" );
  132. }
  133. void CDmeUnpackVector4Operator::OnDestruction()
  134. {
  135. }
  136. bool CDmeUnpackVector4Operator::IsDirty()
  137. {
  138. const Vector4D &v = m_vector.Get();
  139. return v.x != m_x.Get() || v.y != m_y.Get() || v.z != m_z.Get() || v.w != m_w.Get();
  140. }
  141. void CDmeUnpackVector4Operator::Operate()
  142. {
  143. m_x.Set( m_vector.Get().x );
  144. m_y.Set( m_vector.Get().y );
  145. m_z.Set( m_vector.Get().z );
  146. m_w.Set( m_vector.Get().w );
  147. }
  148. void CDmeUnpackVector4Operator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  149. {
  150. attrs.AddToTail( m_vector.GetAttribute() );
  151. }
  152. void CDmeUnpackVector4Operator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  153. {
  154. attrs.AddToTail( m_x.GetAttribute() );
  155. attrs.AddToTail( m_y.GetAttribute() );
  156. attrs.AddToTail( m_z.GetAttribute() );
  157. attrs.AddToTail( m_w.GetAttribute() );
  158. }
  159. //-----------------------------------------------------------------------------
  160. // CDmeUnpackQAngleOperator
  161. //-----------------------------------------------------------------------------
  162. IMPLEMENT_ELEMENT_FACTORY( DmeUnpackQAngleOperator, CDmeUnpackQAngleOperator );
  163. void CDmeUnpackQAngleOperator::OnConstruction()
  164. {
  165. m_qangle.Init( this, "qangle" );
  166. m_x.Init( this, "x" );
  167. m_y.Init( this, "y" );
  168. m_z.Init( this, "z" );
  169. }
  170. void CDmeUnpackQAngleOperator::OnDestruction()
  171. {
  172. }
  173. bool CDmeUnpackQAngleOperator::IsDirty()
  174. {
  175. const QAngle &q = m_qangle.Get();
  176. return q.x != m_x.Get() || q.y != m_y.Get() || q.z != m_z.Get();
  177. }
  178. void CDmeUnpackQAngleOperator::Operate()
  179. {
  180. m_x.Set( m_qangle.Get().x );
  181. m_y.Set( m_qangle.Get().y );
  182. m_z.Set( m_qangle.Get().z );
  183. }
  184. void CDmeUnpackQAngleOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  185. {
  186. attrs.AddToTail( m_qangle.GetAttribute() );
  187. }
  188. void CDmeUnpackQAngleOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  189. {
  190. attrs.AddToTail( m_x.GetAttribute() );
  191. attrs.AddToTail( m_y.GetAttribute() );
  192. attrs.AddToTail( m_z.GetAttribute() );
  193. }
  194. //-----------------------------------------------------------------------------
  195. // CDmeUnpackQuaternionOperator
  196. //-----------------------------------------------------------------------------
  197. IMPLEMENT_ELEMENT_FACTORY( DmeUnpackQuaternionOperator, CDmeUnpackQuaternionOperator );
  198. void CDmeUnpackQuaternionOperator::OnConstruction()
  199. {
  200. m_quaternion.Init( this, "quaternion" );
  201. m_x.Init( this, "x" );
  202. m_y.Init( this, "y" );
  203. m_z.Init( this, "z" );
  204. m_w.Init( this, "w" );
  205. }
  206. void CDmeUnpackQuaternionOperator::OnDestruction()
  207. {
  208. }
  209. bool CDmeUnpackQuaternionOperator::IsDirty()
  210. {
  211. const Quaternion &q = m_quaternion.Get();
  212. return q.x != m_x.Get() || q.y != m_y.Get() || q.z != m_z.Get() || q.w != m_w.Get();
  213. }
  214. void CDmeUnpackQuaternionOperator::Operate()
  215. {
  216. m_x.Set( m_quaternion.Get().x );
  217. m_y.Set( m_quaternion.Get().y );
  218. m_z.Set( m_quaternion.Get().z );
  219. m_w.Set( m_quaternion.Get().w );
  220. }
  221. void CDmeUnpackQuaternionOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  222. {
  223. attrs.AddToTail( m_quaternion.GetAttribute() );
  224. }
  225. void CDmeUnpackQuaternionOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  226. {
  227. attrs.AddToTail( m_x.GetAttribute() );
  228. attrs.AddToTail( m_y.GetAttribute() );
  229. attrs.AddToTail( m_z.GetAttribute() );
  230. attrs.AddToTail( m_w.GetAttribute() );
  231. }
  232. //-----------------------------------------------------------------------------
  233. // CDmeUnpackVMatrixOperator
  234. //-----------------------------------------------------------------------------
  235. IMPLEMENT_ELEMENT_FACTORY( DmeUnpackVMatrixOperator, CDmeUnpackVMatrixOperator );
  236. void CDmeUnpackVMatrixOperator::OnConstruction()
  237. {
  238. m_vmatrix.Init( this, "vmatrix" );
  239. char name[ 4 ];
  240. for ( uint i = 0; i < 16; ++i )
  241. {
  242. Q_snprintf( name, sizeof(name), "m%d%d", i >> 2, i & 0x3 );
  243. m_cells[ i ].Init( this, name );
  244. }
  245. }
  246. void CDmeUnpackVMatrixOperator::OnDestruction()
  247. {
  248. }
  249. bool CDmeUnpackVMatrixOperator::IsDirty()
  250. {
  251. const VMatrix &v = m_vmatrix.Get();
  252. for ( uint i = 0; i < 16; ++i )
  253. {
  254. if ( *( v[ i ] ) != m_cells[ i ].Get() )
  255. return true;
  256. }
  257. return false;
  258. }
  259. void CDmeUnpackVMatrixOperator::Operate()
  260. {
  261. VMatrix v;
  262. for ( uint i = 0; i < 16; ++i )
  263. {
  264. m_cells[ i ].Set( *( v[ i ] ) );
  265. }
  266. m_vmatrix.Set( v );
  267. }
  268. void CDmeUnpackVMatrixOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  269. {
  270. attrs.AddToTail( m_vmatrix.GetAttribute() );
  271. }
  272. void CDmeUnpackVMatrixOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  273. {
  274. for ( uint i = 0; i < 16; ++i )
  275. {
  276. attrs.AddToTail( m_cells[i].GetAttribute() );
  277. }
  278. }