ParticleAssetField.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. bool doesKeyExist(const F32 time);
  82. S32 addDataKey( const F32 time, const F32 value );
  83. bool removeDataKey( const U32 index );
  84. void clearDataKeys( void );
  85. bool setDataKeyValue( const U32 index, const F32 value );
  86. F32 getDataKeyValue( const U32 index ) const;
  87. F32 getDataKeyTime( const U32 index ) const;
  88. inline U32 getDataKeyCount( void ) const { return (U32)mDataKeys.size(); }
  89. const DataKey& getDataKey( const U32 index ) const;
  90. F32 getFieldValue( F32 time ) const;
  91. static F32 calculateFieldBV( const ParticleAssetField& base, const ParticleAssetField& variation, const F32 effectAge, const bool modulate = false, const F32 modulo = 0.0f );
  92. static F32 calculateFieldBVE( const ParticleAssetField& base, const ParticleAssetField& variation, const ParticleAssetField& effect, const F32 effectAge, const bool modulate = false, const F32 modulo = 0.0f );
  93. 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 );
  94. void onTamlCustomWrite( TamlCustomNode* pCustomNode );
  95. void onTamlCustomRead( const TamlCustomNode* pCustomNode );
  96. void WriteCustomTamlSchema( const AbstractClassRep* pClassRep, TiXmlElement* pParentElement );
  97. };
  98. //-----------------------------------------------------------------------------
  99. /// Base field.
  100. class ParticleAssetFieldBase
  101. {
  102. private:
  103. ParticleAssetField mBase;
  104. public:
  105. inline ParticleAssetField& getBase( void ) { return mBase; }
  106. virtual void copyTo( ParticleAssetFieldBase& particleField )
  107. {
  108. mBase.copyTo( particleField.getBase() );
  109. };
  110. };
  111. //-----------------------------------------------------------------------------
  112. /// Life field.
  113. class ParticleAssetFieldLife
  114. {
  115. private:
  116. ParticleAssetField mLife;
  117. public:
  118. inline ParticleAssetField& getLife( void ) { return mLife; }
  119. void copyTo( ParticleAssetFieldLife& particleField )
  120. {
  121. mLife.copyTo( particleField.getLife() );
  122. };
  123. };
  124. //-----------------------------------------------------------------------------
  125. /// Variation field.
  126. class ParticleAssetFieldVariation
  127. {
  128. private:
  129. ParticleAssetField mVariation;
  130. public:
  131. inline ParticleAssetField& getVariation( void ) { return mVariation; }
  132. virtual void copyTo( ParticleAssetFieldVariation& particleField )
  133. {
  134. mVariation.copyTo( particleField.getVariation() );
  135. };
  136. };
  137. //-----------------------------------------------------------------------------
  138. /// Base and variation fields.
  139. class ParticleAssetFieldBaseVariation :
  140. public ParticleAssetFieldBase,
  141. public ParticleAssetFieldVariation
  142. {
  143. public:
  144. void copyTo( ParticleAssetFieldBaseVariation& particleField )
  145. {
  146. getBase().copyTo( particleField.getBase() );
  147. getVariation().copyTo( particleField.getVariation() );
  148. };
  149. };
  150. //-----------------------------------------------------------------------------
  151. /// Base, variation and life fields.
  152. class ParticleAssetFieldBaseVariationLife :
  153. public ParticleAssetFieldBase,
  154. public ParticleAssetFieldVariation,
  155. public ParticleAssetFieldLife
  156. {
  157. public:
  158. void copyTo( ParticleAssetFieldBaseVariationLife& particleField )
  159. {
  160. getBase().copyTo( particleField.getBase() );
  161. getVariation().copyTo( particleField.getVariation() );
  162. getLife().copyTo( particleField.getLife() );
  163. };
  164. };
  165. #endif // _PARTICLE_ASSET_FIELD_H_