explosion.h 5.6 KB

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