explosion.h

Engine/source/T3D/fx/explosion.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
 26// Copyright (C) 2015 Faust Logic, Inc.
 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 28
 29#ifndef _EXPLOSION_H_
 30#define _EXPLOSION_H_
 31
 32#ifndef _GAMEBASE_H_
 33#include "T3D/gameBase/gameBase.h"
 34#endif
 35#ifndef _TSSHAPE_H_
 36#include "ts/tsShape.h"
 37#endif
 38#ifndef __RESOURCE_H__
 39#include "core/resource.h"
 40#endif
 41#ifndef _LIGHTINFO_H_
 42#include "lighting/lightInfo.h"
 43#endif
 44
 45class ParticleEmitter;
 46class ParticleEmitterData;
 47class TSThread;
 48class SFXTrack;
 49struct DebrisData;
 50
 51class SFXProfile;
 52//--------------------------------------------------------------------------
 53class ExplosionData : public GameBaseData {
 54  public:
 55   typedef GameBaseData Parent;
 56
 57   enum ExplosionConsts
 58   {
 59      EC_NUM_DEBRIS_TYPES = 1,
 60      EC_NUM_EMITTERS = 4,
 61      EC_MAX_SUB_EXPLOSIONS = 5,
 62      EC_NUM_TIME_KEYS = 4,
 63   };
 64
 65  public:
 66   StringTableEntry dtsFileName;
 67
 68   bool faceViewer;
 69
 70   S32 particleDensity;
 71   F32 particleRadius;
 72
 73   SFXTrack*        soundProfile;
 74   ParticleEmitterData* particleEmitter;
 75   S32                  particleEmitterId;
 76
 77   Point3F              explosionScale;
 78   F32                  playSpeed;
 79
 80   Resource<TSShape> explosionShape;
 81   S32               explosionAnimation;
 82
 83   ParticleEmitterData*    emitterList[EC_NUM_EMITTERS];
 84   S32                     emitterIDList[EC_NUM_EMITTERS];
 85
 86   DebrisData *   debrisList[EC_NUM_DEBRIS_TYPES];
 87   S32            debrisIDList[EC_NUM_DEBRIS_TYPES];
 88
 89   F32            debrisThetaMin;
 90   F32            debrisThetaMax;
 91   F32            debrisPhiMin;
 92   F32            debrisPhiMax;
 93   S32            debrisNum;
 94   S32            debrisNumVariance;
 95   F32            debrisVelocity;
 96   F32            debrisVelocityVariance;
 97
 98   // sub - explosions
 99   ExplosionData*    explosionList[EC_MAX_SUB_EXPLOSIONS];
100   S32               explosionIDList[EC_MAX_SUB_EXPLOSIONS];
101
102   S32               delayMS;
103   S32               delayVariance;
104   S32               lifetimeMS;
105   S32               lifetimeVariance;
106
107   F32               offset;
108   Point3F           sizes[ EC_NUM_TIME_KEYS ];
109   F32               times[ EC_NUM_TIME_KEYS ];
110
111   // camera shake data
112   bool              shakeCamera;
113   VectorF           camShakeFreq;
114   VectorF           camShakeAmp;
115   F32               camShakeDuration;
116   F32               camShakeRadius;
117   F32               camShakeFalloff;
118
119   // Dynamic Lighting. The light is smoothly
120   // interpolated from start to end time.
121   F32               lightStartRadius;
122   F32               lightEndRadius;
123   LinearColorF            lightStartColor;
124   LinearColorF            lightEndColor;
125   F32               lightStartBrightness;
126   F32               lightEndBrightness;
127   F32               lightNormalOffset;
128
129   ExplosionData();
130   DECLARE_CONOBJECT(ExplosionData);
131   bool onAdd();
132   bool preload(bool server, String &errorStr);
133   static void  initPersistFields();
134   virtual void packData(BitStream* stream);
135   virtual void unpackData(BitStream* stream);
136public:
137   /*C*/          ExplosionData(const ExplosionData&, bool = false);
138   /*D*/          ~ExplosionData();
139   ExplosionData* cloneAndPerformSubstitutions(const SimObject*, S32 index=0);
140   virtual bool   allowSubstitutions() const { return true; }
141};
142
143
144//--------------------------------------------------------------------------
145class Explosion : public GameBase, public ISceneLight
146{
147   typedef GameBase Parent;
148
149  private:
150   ExplosionData*   mDataBlock;
151
152   TSShapeInstance* mExplosionInstance;
153   TSThread*        mExplosionThread;
154
155   SimObjectPtr<ParticleEmitter> mEmitterList[ ExplosionData::EC_NUM_EMITTERS ];
156   SimObjectPtr<ParticleEmitter> mMainEmitter;
157
158   U32               mCurrMS;
159   U32               mEndingMS;
160   F32               mRandAngle;
161   LightInfo*        mLight;
162
163  protected:
164   Point3F  mInitialNormal;
165   F32      mFade;
166   bool     mActive;
167   S32      mDelayMS;
168   F32      mRandomVal;
169   U32      mCollideType;
170
171  protected:
172   bool onAdd();
173   void onRemove();
174   bool explode();
175
176   void processTick(const Move *move);
177   void advanceTime(F32 dt);
178   void updateEmitters( F32 dt );
179   void launchDebris( Point3F &axis );
180   void spawnSubExplosions();
181   void setCurrentScale();
182
183   // Rendering
184  protected:
185   void prepRenderImage( SceneRenderState *state );
186   void prepBatchRender(SceneRenderState *state);
187   void prepModelView(SceneRenderState*);
188
189  public:
190   Explosion();
191   ~Explosion();
192   void setInitialState(const Point3F& point, const Point3F& normal, const F32 fade = 1.0);
193
194   // ISceneLight
195   virtual void submitLights( LightManager *lm, bool staticLighting );
196   virtual LightInfo* getLight() { return mLight; }
197
198   bool onNewDataBlock( GameBaseData *dptr, bool reload );
199   void setCollideType( U32 cType ){ mCollideType = cType; }
200
201   DECLARE_CONOBJECT(Explosion);
202   static void initPersistFields();
203private:
204   SimObject*     ss_object;
205   S32            ss_index;
206   SFXProfile*    soundProfile_clone;
207public:
208   void           setSubstitutionData(SimObject* obj, S32 idx=0) { ss_object = obj; ss_index = idx; }
209};
210
211#endif // _H_EXPLOSION
212
213