splash.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 _SPLASH_H_
  23. #define _SPLASH_H_
  24. #ifndef _GAMEBASE_H_
  25. #include "T3D/gameBase/gameBase.h"
  26. #endif
  27. #ifndef _TORQUE_LIST_
  28. #include "core/util/tList.h"
  29. #endif
  30. #include "gfx/gfxTextureHandle.h"
  31. #include "T3D/assets/ImageAsset.h"
  32. #include "T3D/assets/SoundAsset.h"
  33. class ParticleEmitter;
  34. class ParticleEmitterData;
  35. class AudioProfile;
  36. class ExplosionData;
  37. //--------------------------------------------------------------------------
  38. // Ring Point
  39. //--------------------------------------------------------------------------
  40. struct SplashRingPoint
  41. {
  42. Point3F position;
  43. Point3F velocity;
  44. };
  45. //--------------------------------------------------------------------------
  46. // Splash Ring
  47. //--------------------------------------------------------------------------
  48. struct SplashRing
  49. {
  50. Vector <SplashRingPoint> points;
  51. LinearColorF color;
  52. F32 lifetime;
  53. F32 elapsedTime;
  54. F32 v;
  55. SplashRing()
  56. {
  57. color.set( 0.0, 0.0, 0.0, 1.0 );
  58. lifetime = 0.0;
  59. elapsedTime = 0.0;
  60. v = 0.0;
  61. }
  62. bool isActive()
  63. {
  64. return elapsedTime < lifetime;
  65. }
  66. };
  67. //--------------------------------------------------------------------------
  68. // Splash Data
  69. //--------------------------------------------------------------------------
  70. class SplashData : public GameBaseData
  71. {
  72. public:
  73. typedef GameBaseData Parent;
  74. enum Constants
  75. {
  76. NUM_EMITTERS = 3,
  77. NUM_TIME_KEYS = 4,
  78. NUM_TEX = 2,
  79. };
  80. public:
  81. //AudioProfile* soundProfile;
  82. //S32 soundProfileId;
  83. DECLARE_SOUNDASSET(SplashData, Sound);
  84. DECLARE_ASSET_SETGET(SplashData, Sound);
  85. ParticleEmitterData* emitterList[NUM_EMITTERS];
  86. S32 emitterIDList[NUM_EMITTERS];
  87. S32 delayMS;
  88. S32 delayVariance;
  89. S32 lifetimeMS;
  90. S32 lifetimeVariance;
  91. Point3F scale;
  92. F32 width;
  93. F32 height;
  94. U32 numSegments;
  95. F32 velocity;
  96. F32 acceleration;
  97. F32 texWrap;
  98. F32 texFactor;
  99. F32 ejectionFreq;
  100. F32 ejectionAngle;
  101. F32 ringLifetime;
  102. F32 startRadius;
  103. F32 times[ NUM_TIME_KEYS ];
  104. LinearColorF colors[ NUM_TIME_KEYS ];
  105. DECLARE_IMAGEASSET_ARRAY(SplashData, Texture, NUM_TEX);
  106. DECLARE_IMAGEASSET_ARRAY_SETGET(SplashData, Texture)
  107. ExplosionData* explosion;
  108. S32 explosionId;
  109. SplashData();
  110. DECLARE_CONOBJECT(SplashData);
  111. bool onAdd();
  112. bool preload(bool server, String &errorStr);
  113. static void initPersistFields();
  114. virtual void packData(BitStream* stream);
  115. virtual void unpackData(BitStream* stream);
  116. };
  117. //--------------------------------------------------------------------------
  118. // Splash
  119. //--------------------------------------------------------------------------
  120. class Splash : public GameBase
  121. {
  122. typedef GameBase Parent;
  123. private:
  124. SplashData* mDataBlock;
  125. SimObjectPtr<ParticleEmitter> mEmitterList[ SplashData::NUM_EMITTERS ];
  126. typedef Torque::List<SplashRing> SplashRingList;
  127. SplashRingList ringList;
  128. U32 mCurrMS;
  129. U32 mEndingMS;
  130. F32 mRandAngle;
  131. F32 mRadius;
  132. F32 mVelocity;
  133. F32 mHeight;
  134. LinearColorF mColor;
  135. F32 mTimeSinceLastRing;
  136. bool mDead;
  137. F32 mElapsedTime;
  138. protected:
  139. Point3F mInitialPosition;
  140. Point3F mInitialNormal;
  141. F32 mFade;
  142. F32 mFog;
  143. bool mActive;
  144. S32 mDelayMS;
  145. protected:
  146. bool onAdd();
  147. void onRemove();
  148. void processTick(const Move *move);
  149. void advanceTime(F32 dt);
  150. void updateEmitters( F32 dt );
  151. void updateWave( F32 dt );
  152. void updateColor();
  153. SplashRing createRing();
  154. void updateRings( F32 dt );
  155. void updateRing( SplashRing& ring, F32 dt );
  156. void emitRings( F32 dt );
  157. void spawnExplosion();
  158. public:
  159. Splash();
  160. ~Splash();
  161. void setInitialState(const Point3F& point, const Point3F& normal, const F32 fade = 1.0);
  162. U32 packUpdate (NetConnection *conn, U32 mask, BitStream* stream);
  163. void unpackUpdate(NetConnection *conn, BitStream* stream);
  164. bool onNewDataBlock( GameBaseData *dptr, bool reload );
  165. DECLARE_CONOBJECT(Splash);
  166. };
  167. #endif // _H_SPLASH