Torque3D Documentation / _generateds / afxEA_Debris.cpp

afxEA_Debris.cpp

Engine/source/afx/ea/afxEA_Debris.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/debris.h"
 31
 32#include "afx/afxEffectDefs.h"
 33#include "afx/afxEffectWrapper.h"
 34#include "afx/afxChoreographer.h"
 35
 36//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 37// afxEA_Debris 
 38
 39class afxEA_Debris : public afxEffectWrapper
 40{
 41  typedef afxEffectWrapper Parent;
 42
 43  DebrisData*       debris_data;
 44  Debris*           debris;
 45  bool              exploded;
 46  bool              debris_done;
 47
 48  void              do_runtime_substitutions();
 49
 50public:
 51  /*C*/             afxEA_Debris();
 52  /*D*/             ~afxEA_Debris();
 53
 54  virtual bool      isDone();
 55
 56  virtual void      ea_set_datablock(SimDataBlock*);
 57  virtual bool      ea_start();
 58  virtual bool      ea_update(F32 dt);
 59  virtual void      ea_finish(bool was_stopped);
 60
 61  virtual void      onDeleteNotify(SimObject*);
 62};
 63
 64//~~~~~~~~~~~~~~~~~~~~//
 65
 66afxEA_Debris::afxEA_Debris()
 67{
 68  debris_data = 0;
 69  debris = 0;
 70  exploded = false;
 71  debris_done = false;
 72}
 73
 74afxEA_Debris::~afxEA_Debris()
 75{
 76  if (debris)
 77    clearNotify(debris);
 78}
 79
 80bool afxEA_Debris::isDone()
 81{
 82  return (mDatablock->use_as_cons_obj) ? debris_done : exploded;
 83}
 84
 85void afxEA_Debris::ea_set_datablock(SimDataBlock* db)
 86{
 87  debris_data = dynamic_cast<DebrisData*>(db);
 88}
 89
 90bool afxEA_Debris::ea_start()
 91{
 92  if (!debris_data)
 93  {
 94    Con::errorf("afxEA_Debris::ea_start() -- missing or incompatible datablock.");
 95    return false;
 96  }
 97
 98  do_runtime_substitutions();
 99
100  debris = new Debris();
101  debris->onNewDataBlock(debris_data, false);
102
103  return true;
104}
105
106bool afxEA_Debris::ea_update(F32 dt)
107{
108  if (exploded && debris)
109  {
110    if (mIn_scope)
111    {
112      mUpdated_xfm = debris->getRenderTransform();
113     mUpdated_xfm.getColumn(3, &mUpdated_pos);
114    }
115  }
116
117  if (!exploded && debris)
118  {
119    if (mIn_scope)
120    {     
121      Point3F dir_vec(0,1,0);
122     mUpdated_xfm.mulV(dir_vec);
123
124      debris->init(mUpdated_pos, dir_vec);
125      if (!debris->registerObject())
126      {
127        delete debris;
128        debris = 0;
129        Con::errorf("afxEA_Debris::ea_update() -- effect failed to register.");
130        return false;
131      }
132      deleteNotify(debris);
133    }
134    exploded = true;
135  }
136
137  return true;
138}
139
140void afxEA_Debris::ea_finish(bool was_stopped)
141{
142  if (debris)
143  {
144    clearNotify(debris);
145    debris = 0;
146  }
147  exploded = false;
148}
149
150void afxEA_Debris::onDeleteNotify(SimObject* obj)
151{
152  // debris deleted?
153  Debris* del_debris = dynamic_cast<Debris*>(obj);
154  if (del_debris == debris)
155  {
156    debris = NULL;
157    debris_done = true;
158  }
159}
160
161void afxEA_Debris::do_runtime_substitutions()
162{
163  // only clone the datablock if there are substitutions
164  if (debris_data->getSubstitutionCount() > 0)
165  {
166    // clone the datablock and perform substitutions
167    DebrisData* orig_db = debris_data;
168    debris_data = new DebrisData(*orig_db, true);
169    orig_db->performSubstitutions(debris_data, mChoreographer, mGroup_index);
170  }
171}
172
173//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
174
175class afxEA_DebrisDesc : public afxEffectAdapterDesc, public afxEffectDefs 
176{
177  static afxEA_DebrisDesc desc;
178
179public:
180  virtual bool  testEffectType(const SimDataBlock*) const;
181  virtual bool  requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const;
182  virtual bool  runsOnServer(const afxEffectWrapperData*) const { return false; }
183  virtual bool  runsOnClient(const afxEffectWrapperData*) const { return true; }
184
185  virtual afxEffectWrapper* create() const { return new afxEA_Debris; }
186};
187
188afxEA_DebrisDesc afxEA_DebrisDesc::desc;
189
190bool afxEA_DebrisDesc::testEffectType(const SimDataBlock* db) const
191{
192  return (typeid(DebrisData) == typeid(*db));
193}
194
195bool afxEA_DebrisDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const
196{
197  return (ew->use_as_cons_obj && timing.lifetime < 0);
198}
199
200//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
201