Torque3D Documentation / _generateds / afxEA_Explosion.cpp

afxEA_Explosion.cpp

Engine/source/afx/ea/afxEA_Explosion.cpp

More...

Classes:

Detailed Description

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#include <typeinfo>
 28#include "afx/arcaneFX.h"
 29
 30#include "T3D/fx/explosion.h"
 31
 32#include "afx/afxEffectDefs.h"
 33#include "afx/afxEffectWrapper.h"
 34#include "afx/afxChoreographer.h"
 35
 36//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 37// afxEA_Explosion 
 38
 39class afxEA_Explosion : public afxEffectWrapper
 40{
 41  typedef afxEffectWrapper Parent;
 42
 43  ExplosionData*    explosion_data;
 44  Explosion*        explosion;
 45  bool              exploded;
 46
 47  void              do_runtime_substitutions();
 48
 49public:
 50  /*C*/             afxEA_Explosion();
 51
 52  virtual bool      isDone() { return exploded; }
 53
 54  virtual void      ea_set_datablock(SimDataBlock*);
 55  virtual bool      ea_start();
 56  virtual bool      ea_update(F32 dt);
 57  virtual void      ea_finish(bool was_stopped);
 58};
 59
 60//~~~~~~~~~~~~~~~~~~~~//
 61
 62afxEA_Explosion::afxEA_Explosion()
 63{
 64  explosion_data = 0;
 65  explosion = 0;
 66  exploded = false;
 67}
 68
 69void afxEA_Explosion::ea_set_datablock(SimDataBlock* db)
 70{
 71  explosion_data = dynamic_cast<ExplosionData*>(db);
 72}
 73
 74bool afxEA_Explosion::ea_start()
 75{
 76  if (!explosion_data)
 77  {
 78    Con::errorf("afxEA_Explosion::ea_start() -- missing or incompatible datablock.");
 79    return false;
 80  }
 81
 82  do_runtime_substitutions();
 83
 84  explosion = new Explosion();
 85  explosion->setSubstitutionData(mChoreographer, mGroup_index);
 86  explosion->setDataBlock(explosion_data);
 87
 88  return true;
 89}
 90
 91bool afxEA_Explosion::ea_update(F32 dt)
 92{
 93  if (!exploded && explosion)
 94  {
 95    if (mIn_scope)
 96    {
 97      Point3F norm(0,0,1); mUpdated_xfm.mulV(norm);
 98      explosion->setInitialState(mUpdated_pos, norm);
 99      if (!explosion->registerObject())
100      {
101        delete explosion;
102        explosion = 0;
103        Con::errorf("afxEA_Explosion::ea_update() -- effect failed to register.");
104        return false;
105      }
106    }
107    exploded = true;
108  }
109
110  return true;
111}
112
113void afxEA_Explosion::ea_finish(bool was_stopped)
114{
115  explosion = 0;
116  exploded = false;
117}
118
119void afxEA_Explosion::do_runtime_substitutions()
120{
121  explosion_data = explosion_data->cloneAndPerformSubstitutions(mChoreographer, mGroup_index);
122}
123
124//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
125
126class afxEA_ExplosionDesc : public afxEffectAdapterDesc, public afxEffectDefs 
127{
128  static afxEA_ExplosionDesc desc;
129
130public:
131  virtual bool  testEffectType(const SimDataBlock*) const;
132  virtual bool  requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const { return false; }
133  virtual bool  runsOnServer(const afxEffectWrapperData*) const { return false; }
134  virtual bool  runsOnClient(const afxEffectWrapperData*) const { return true; }
135
136  virtual afxEffectWrapper* create() const { return new afxEA_Explosion; }
137};
138
139afxEA_ExplosionDesc afxEA_ExplosionDesc::desc;
140
141bool afxEA_ExplosionDesc::testEffectType(const SimDataBlock* db) const
142{
143  return (typeid(ExplosionData) == typeid(*db));
144}
145
146//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
147