explosion.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 _EXPLOSION_H_
  23. #define _EXPLOSION_H_
  24. #ifndef _GAMEBASE_H_
  25. #include "T3D/gameBase/gameBase.h"
  26. #endif
  27. #ifndef _TSSHAPE_H_
  28. #include "ts/tsShape.h"
  29. #endif
  30. #ifndef __RESOURCE_H__
  31. #include "core/resource.h"
  32. #endif
  33. #ifndef _LIGHTINFO_H_
  34. #include "lighting/lightInfo.h"
  35. #endif
  36. class ParticleEmitter;
  37. class ParticleEmitterData;
  38. class TSThread;
  39. class SFXTrack;
  40. struct DebrisData;
  41. class ShockwaveData;
  42. //--------------------------------------------------------------------------
  43. class ExplosionData : public GameBaseData {
  44. public:
  45. typedef GameBaseData Parent;
  46. enum ExplosionConsts
  47. {
  48. EC_NUM_DEBRIS_TYPES = 1,
  49. EC_NUM_EMITTERS = 4,
  50. EC_MAX_SUB_EXPLOSIONS = 5,
  51. EC_NUM_TIME_KEYS = 4,
  52. };
  53. public:
  54. StringTableEntry dtsFileName;
  55. bool faceViewer;
  56. S32 particleDensity;
  57. F32 particleRadius;
  58. SFXTrack* soundProfile;
  59. ParticleEmitterData* particleEmitter;
  60. S32 particleEmitterId;
  61. Point3F explosionScale;
  62. F32 playSpeed;
  63. Resource<TSShape> explosionShape;
  64. S32 explosionAnimation;
  65. ParticleEmitterData* emitterList[EC_NUM_EMITTERS];
  66. S32 emitterIDList[EC_NUM_EMITTERS];
  67. ShockwaveData * shockwave;
  68. S32 shockwaveID;
  69. bool shockwaveOnTerrain;
  70. DebrisData * debrisList[EC_NUM_DEBRIS_TYPES];
  71. S32 debrisIDList[EC_NUM_DEBRIS_TYPES];
  72. F32 debrisThetaMin;
  73. F32 debrisThetaMax;
  74. F32 debrisPhiMin;
  75. F32 debrisPhiMax;
  76. S32 debrisNum;
  77. S32 debrisNumVariance;
  78. F32 debrisVelocity;
  79. F32 debrisVelocityVariance;
  80. // sub - explosions
  81. ExplosionData* explosionList[EC_MAX_SUB_EXPLOSIONS];
  82. S32 explosionIDList[EC_MAX_SUB_EXPLOSIONS];
  83. S32 delayMS;
  84. S32 delayVariance;
  85. S32 lifetimeMS;
  86. S32 lifetimeVariance;
  87. F32 offset;
  88. Point3F sizes[ EC_NUM_TIME_KEYS ];
  89. F32 times[ EC_NUM_TIME_KEYS ];
  90. // camera shake data
  91. bool shakeCamera;
  92. VectorF camShakeFreq;
  93. VectorF camShakeAmp;
  94. F32 camShakeDuration;
  95. F32 camShakeRadius;
  96. F32 camShakeFalloff;
  97. // Dynamic Lighting. The light is smoothly
  98. // interpolated from start to end time.
  99. F32 lightStartRadius;
  100. F32 lightEndRadius;
  101. ColorF lightStartColor;
  102. ColorF lightEndColor;
  103. F32 lightStartBrightness;
  104. F32 lightEndBrightness;
  105. F32 lightNormalOffset;
  106. ExplosionData();
  107. DECLARE_CONOBJECT(ExplosionData);
  108. bool onAdd();
  109. bool preload(bool server, String &errorStr);
  110. static void initPersistFields();
  111. virtual void packData(BitStream* stream);
  112. virtual void unpackData(BitStream* stream);
  113. };
  114. //--------------------------------------------------------------------------
  115. class Explosion : public GameBase, public ISceneLight
  116. {
  117. typedef GameBase Parent;
  118. private:
  119. ExplosionData* mDataBlock;
  120. TSShapeInstance* mExplosionInstance;
  121. TSThread* mExplosionThread;
  122. SimObjectPtr<ParticleEmitter> mEmitterList[ ExplosionData::EC_NUM_EMITTERS ];
  123. SimObjectPtr<ParticleEmitter> mMainEmitter;
  124. U32 mCurrMS;
  125. U32 mEndingMS;
  126. F32 mRandAngle;
  127. LightInfo* mLight;
  128. protected:
  129. Point3F mInitialNormal;
  130. F32 mFade;
  131. bool mActive;
  132. S32 mDelayMS;
  133. F32 mRandomVal;
  134. U32 mCollideType;
  135. protected:
  136. bool onAdd();
  137. void onRemove();
  138. bool explode();
  139. void processTick(const Move *move);
  140. void advanceTime(F32 dt);
  141. void updateEmitters( F32 dt );
  142. void launchDebris( Point3F &axis );
  143. void spawnSubExplosions();
  144. void setCurrentScale();
  145. // Rendering
  146. protected:
  147. void prepRenderImage( SceneRenderState *state );
  148. void prepBatchRender(SceneRenderState *state);
  149. void prepModelView(SceneRenderState*);
  150. public:
  151. Explosion();
  152. ~Explosion();
  153. void setInitialState(const Point3F& point, const Point3F& normal, const F32 fade = 1.0);
  154. // ISceneLight
  155. virtual void submitLights( LightManager *lm, bool staticLighting );
  156. virtual LightInfo* getLight() { return mLight; }
  157. bool onNewDataBlock( GameBaseData *dptr, bool reload );
  158. void setCollideType( U32 cType ){ mCollideType = cType; }
  159. DECLARE_CONOBJECT(Explosion);
  160. static void initPersistFields();
  161. };
  162. #endif // _H_EXPLOSION