explosion.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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, protected AssetPtrCallback {
  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_REFACTOR(ExplosionData, ExplosionShape)
  70. S32 explosionAnimation;
  71. ParticleEmitterData* emitterList[EC_NUM_EMITTERS];
  72. S32 emitterIDList[EC_NUM_EMITTERS];
  73. DebrisData * debrisList[EC_NUM_DEBRIS_TYPES];
  74. S32 debrisIDList[EC_NUM_DEBRIS_TYPES];
  75. F32 debrisThetaMin;
  76. F32 debrisThetaMax;
  77. F32 debrisPhiMin;
  78. F32 debrisPhiMax;
  79. S32 debrisNum;
  80. S32 debrisNumVariance;
  81. F32 debrisVelocity;
  82. F32 debrisVelocityVariance;
  83. // sub - explosions
  84. ExplosionData* explosionList[EC_MAX_SUB_EXPLOSIONS];
  85. S32 explosionIDList[EC_MAX_SUB_EXPLOSIONS];
  86. S32 delayMS;
  87. S32 delayVariance;
  88. S32 lifetimeMS;
  89. S32 lifetimeVariance;
  90. F32 offset;
  91. Point3F sizes[ EC_NUM_TIME_KEYS ];
  92. F32 times[ EC_NUM_TIME_KEYS ];
  93. // camera shake data
  94. bool shakeCamera;
  95. VectorF camShakeFreq;
  96. VectorF camShakeAmp;
  97. F32 camShakeDuration;
  98. F32 camShakeRadius;
  99. F32 camShakeFalloff;
  100. // Dynamic Lighting. The light is smoothly
  101. // interpolated from start to end time.
  102. F32 lightStartRadius;
  103. F32 lightEndRadius;
  104. LinearColorF lightStartColor;
  105. LinearColorF lightEndColor;
  106. F32 lightStartBrightness;
  107. F32 lightEndBrightness;
  108. F32 lightNormalOffset;
  109. ExplosionData();
  110. DECLARE_CONOBJECT(ExplosionData);
  111. bool onAdd() override;
  112. bool preload(bool server, String &errorStr) override;
  113. static void initPersistFields();
  114. void packData(BitStream* stream) override;
  115. void unpackData(BitStream* stream) override;
  116. public:
  117. /*C*/ ExplosionData(const ExplosionData&, bool = false);
  118. /*D*/ ~ExplosionData();
  119. ExplosionData* cloneAndPerformSubstitutions(const SimObject*, S32 index=0);
  120. bool allowSubstitutions() const override { return true; }
  121. protected:
  122. void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
  123. {
  124. reloadOnLocalClient();
  125. }
  126. };
  127. //--------------------------------------------------------------------------
  128. class Explosion : public GameBase, public ISceneLight
  129. {
  130. typedef GameBase Parent;
  131. private:
  132. ExplosionData* mDataBlock;
  133. TSShapeInstance* mExplosionInstance;
  134. TSThread* mExplosionThread;
  135. SimObjectPtr<ParticleEmitter> mEmitterList[ ExplosionData::EC_NUM_EMITTERS ];
  136. SimObjectPtr<ParticleEmitter> mMainEmitter;
  137. U32 mCurrMS;
  138. U32 mEndingMS;
  139. F32 mRandAngle;
  140. LightInfo* mLight;
  141. protected:
  142. Point3F mInitialNormal;
  143. F32 mFade;
  144. bool mActive;
  145. S32 mDelayMS;
  146. F32 mRandomVal;
  147. U32 mCollideType;
  148. protected:
  149. bool onAdd() override;
  150. void onRemove() override;
  151. bool explode();
  152. void processTick(const Move *move) override;
  153. void advanceTime(F32 dt) override;
  154. void updateEmitters( F32 dt );
  155. void launchDebris( Point3F &axis );
  156. void spawnSubExplosions();
  157. void setCurrentScale();
  158. // Rendering
  159. protected:
  160. void prepRenderImage( SceneRenderState *state ) override;
  161. void prepBatchRender(SceneRenderState *state);
  162. void prepModelView(SceneRenderState*);
  163. public:
  164. Explosion();
  165. ~Explosion();
  166. void setInitialState(const Point3F& point, const Point3F& normal, const F32 fade = 1.0);
  167. // ISceneLight
  168. void submitLights( LightManager *lm, bool staticLighting ) override;
  169. LightInfo* getLight() override { return mLight; }
  170. bool onNewDataBlock( GameBaseData *dptr, bool reload ) override;
  171. void setCollideType( U32 cType ){ mCollideType = cType; }
  172. DECLARE_CONOBJECT(Explosion);
  173. DECLARE_CATEGORY("UNLISTED");
  174. static void initPersistFields();
  175. private:
  176. SimObject* ss_object;
  177. S32 ss_index;
  178. SFXProfile* soundProfile_clone;
  179. public:
  180. void setSubstitutionData(SimObject* obj, S32 idx=0) { ss_object = obj; ss_index = idx; }
  181. };
  182. #endif // _H_EXPLOSION