splash.h 5.4 KB

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