ParticleAssetField.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. inline 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. };
  96. //-----------------------------------------------------------------------------
  97. /// Base field.
  98. class ParticleAssetFieldBase
  99. {
  100. private:
  101. ParticleAssetField mBase;
  102. public:
  103. inline ParticleAssetField& getBase( void ) { return mBase; }
  104. virtual void copyTo( ParticleAssetFieldBase& particleField )
  105. {
  106. mBase.copyTo( particleField.getBase() );
  107. };
  108. };
  109. //-----------------------------------------------------------------------------
  110. /// Life field.
  111. class ParticleAssetFieldLife
  112. {
  113. private:
  114. ParticleAssetField mLife;
  115. public:
  116. inline ParticleAssetField& getLife( void ) { return mLife; }
  117. void copyTo( ParticleAssetFieldLife& particleField )
  118. {
  119. mLife.copyTo( particleField.getLife() );
  120. };
  121. };
  122. //-----------------------------------------------------------------------------
  123. /// Variation field.
  124. class ParticleAssetFieldVariation
  125. {
  126. private:
  127. ParticleAssetField mVariation;
  128. public:
  129. inline ParticleAssetField& getVariation( void ) { return mVariation; }
  130. virtual void copyTo( ParticleAssetFieldVariation& particleField )
  131. {
  132. mVariation.copyTo( particleField.getVariation() );
  133. };
  134. };
  135. //-----------------------------------------------------------------------------
  136. /// Base and variation fields.
  137. class ParticleAssetFieldBaseVariation :
  138. public ParticleAssetFieldBase,
  139. public ParticleAssetFieldVariation
  140. {
  141. public:
  142. void copyTo( ParticleAssetFieldBaseVariation& particleField )
  143. {
  144. getBase().copyTo( particleField.getBase() );
  145. getVariation().copyTo( particleField.getVariation() );
  146. };
  147. };
  148. //-----------------------------------------------------------------------------
  149. /// Base, variation and life fields.
  150. class ParticleAssetFieldBaseVariationLife :
  151. public ParticleAssetFieldBase,
  152. public ParticleAssetFieldVariation,
  153. public ParticleAssetFieldLife
  154. {
  155. public:
  156. void copyTo( ParticleAssetFieldBaseVariationLife& particleField )
  157. {
  158. getBase().copyTo( particleField.getBase() );
  159. getVariation().copyTo( particleField.getVariation() );
  160. getLife().copyTo( particleField.getLife() );
  161. };
  162. };
  163. #endif // _PARTICLE_ASSET_FIELD_H_