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.

324 lines
8.5 KiB

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