explosion.h 6.4 KB

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