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