Counter Strike : Global Offensive Source Code
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.

334 lines
8.8 KiB

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