ParticleAssetField.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _PARTICLE_ASSET_FIELD_H_
  23. #define _PARTICLE_ASSET_FIELD_H_
  24. #ifndef _VECTOR_H_
  25. #include "collection/vector.h"
  26. #endif
  27. #ifndef _TAML_CUSTOM_H_
  28. #include "persistence/taml/tamlCustom.h"
  29. #endif
  30. ///-----------------------------------------------------------------------------
  31. class ParticleAssetField
  32. {
  33. public:
  34. /// Data Key Node.
  35. struct DataKey
  36. {
  37. DataKey() {}
  38. DataKey( const F32 time, const F32 value ) : mTime( time ), mValue( value ) {}
  39. bool operator==( const DataKey& dataKey ) const
  40. {
  41. return mIsEqual( mTime, dataKey.mTime ) && mIsEqual( mValue, dataKey.mValue );
  42. }
  43. bool operator!=( const DataKey& dataKey ) const
  44. {
  45. return mNotEqual( mTime, dataKey.mTime ) || mNotEqual( mValue, dataKey.mValue );
  46. }
  47. F32 mTime;
  48. F32 mValue;
  49. };
  50. static ParticleAssetField::DataKey BadDataKey;
  51. private:
  52. StringTableEntry mFieldName;
  53. F32 mRepeatTime;
  54. F32 mMaxTime;
  55. F32 mMinValue;
  56. F32 mMaxValue;
  57. F32 mValueScale;
  58. F32 mDefaultValue;
  59. bool mValueBoundsDirty;
  60. Vector<DataKey> mDataKeys;
  61. public:
  62. ParticleAssetField();
  63. virtual ~ParticleAssetField();
  64. void copyTo( ParticleAssetField& field );
  65. void initialize( const F32 maxTime, const F32 minValue, const F32 maxValue, const F32 defaultValue );
  66. void setValueBounds( F32 maxTime, F32 minValue, F32 maxValue, F32 defaultValue );
  67. void setFieldName( const char* pFieldName );
  68. inline StringTableEntry getFieldName( void ) const { return mFieldName; }
  69. bool setValueScale( const F32 valueScale );
  70. inline F32 getValueScale( void ) { return mValueScale; }
  71. bool setRepeatTime( const F32 repeatTime );
  72. inline F32 getRepeatTime( void ) const { return mRepeatTime; }
  73. inline F32 getMinValue( void ) const { return mMinValue; };
  74. inline F32 getMaxValue( void ) const { return mMaxValue; };
  75. inline F32 getMinTime( void ) const { return 0.0f; }
  76. inline F32 getMaxTime( void ) const { return mMaxTime; };
  77. inline F32 getValueScale( void ) const { return mValueScale; };
  78. inline F32 getDefaultValue( void ) const { return mDefaultValue; }
  79. void resetDataKeys( void );
  80. S32 setSingleDataKey( const F32 value );
  81. S32 addDataKey( const F32 time, const F32 value );
  82. bool removeDataKey( const U32 index );
  83. void clearDataKeys( void );
  84. bool setDataKeyValue( const U32 index, const F32 value );
  85. F32 getDataKeyValue( const U32 index ) const;
  86. F32 getDataKeyTime( const U32 index ) const;
  87. inline U32 getDataKeyCount( void ) const { return (U32)mDataKeys.size(); }
  88. const DataKey& getDataKey( const U32 index ) const;
  89. F32 getFieldValue( F32 time ) const;
  90. static F32 calculateFieldBV( const ParticleAssetField& base, const ParticleAssetField& variation, const F32 effectAge, const bool modulate = false, const F32 modulo = 0.0f );
  91. static F32 calculateFieldBVE( const ParticleAssetField& base, const ParticleAssetField& variation, const ParticleAssetField& effect, const F32 effectAge, const bool modulate = false, const F32 modulo = 0.0f );
  92. static F32 calculateFieldBVLE( const ParticleAssetField& base, const ParticleAssetField& variation, const ParticleAssetField& overlife, const ParticleAssetField& effect, const F32 effectTime, const F32 particleAge, const bool modulate = false, const F32 modulo = 0.0f );
  93. void onTamlCustomWrite( TamlCustomNode* pCustomNode );
  94. void onTamlCustomRead( const TamlCustomNode* pCustomNode );
  95. void WriteCustomTamlSchema( const AbstractClassRep* pClassRep, TiXmlElement* pParentElement );
  96. };
  97. //-----------------------------------------------------------------------------
  98. /// Base field.
  99. class ParticleAssetFieldBase
  100. {
  101. private:
  102. ParticleAssetField mBase;
  103. public:
  104. inline ParticleAssetField& getBase( void ) { return mBase; }
  105. virtual void copyTo( ParticleAssetFieldBase& particleField )
  106. {
  107. mBase.copyTo( particleField.getBase() );
  108. };
  109. };
  110. //-----------------------------------------------------------------------------
  111. /// Life field.
  112. class ParticleAssetFieldLife
  113. {
  114. private:
  115. ParticleAssetField mLife;
  116. public:
  117. inline ParticleAssetField& getLife( void ) { return mLife; }
  118. void copyTo( ParticleAssetFieldLife& particleField )
  119. {
  120. mLife.copyTo( particleField.getLife() );
  121. };
  122. };
  123. //-----------------------------------------------------------------------------
  124. /// Variation field.
  125. class ParticleAssetFieldVariation
  126. {
  127. private:
  128. ParticleAssetField mVariation;
  129. public:
  130. inline ParticleAssetField& getVariation( void ) { return mVariation; }
  131. virtual void copyTo( ParticleAssetFieldVariation& particleField )
  132. {
  133. mVariation.copyTo( particleField.getVariation() );
  134. };
  135. };
  136. //-----------------------------------------------------------------------------
  137. /// Base and variation fields.
  138. class ParticleAssetFieldBaseVariation :
  139. public ParticleAssetFieldBase,
  140. public ParticleAssetFieldVariation
  141. {
  142. public:
  143. void copyTo( ParticleAssetFieldBaseVariation& particleField )
  144. {
  145. getBase().copyTo( particleField.getBase() );
  146. getVariation().copyTo( particleField.getVariation() );
  147. };
  148. };
  149. //-----------------------------------------------------------------------------
  150. /// Base, variation and life fields.
  151. class ParticleAssetFieldBaseVariationLife :
  152. public ParticleAssetFieldBase,
  153. public ParticleAssetFieldVariation,
  154. public ParticleAssetFieldLife
  155. {
  156. public:
  157. void copyTo( ParticleAssetFieldBaseVariationLife& particleField )
  158. {
  159. getBase().copyTo( particleField.getBase() );
  160. getVariation().copyTo( particleField.getVariation() );
  161. getLife().copyTo( particleField.getLife() );
  162. };
  163. };
  164. #endif // _PARTICLE_ASSET_FIELD_H_