explosion.h 6.6 KB

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