Torque3D Documentation / _generateds / afxEA_PhysicalZone.cpp

afxEA_PhysicalZone.cpp

Engine/source/afx/ea/afxEA_PhysicalZone.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/physicalZone.h"
 31
 32#include "afx/afxEffectDefs.h"
 33#include "afx/afxEffectWrapper.h"
 34#include "afx/afxChoreographer.h"
 35#include "afx/ce/afxPhysicalZone.h"
 36
 37//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 38// afxEA_PhysicalZone 
 39
 40class afxEA_PhysicalZone : public afxEffectWrapper
 41{
 42  typedef afxEffectWrapper Parent;
 43
 44  afxPhysicalZoneData* zone_data;
 45  PhysicalZone*     physical_zone;
 46  SceneObject*      cons_obj;
 47
 48  void              do_runtime_substitutions();
 49  void              set_cons_object(SceneObject*);
 50
 51public:
 52  /*C*/             afxEA_PhysicalZone();
 53  /*D*/             ~afxEA_PhysicalZone();
 54
 55  virtual void      ea_set_datablock(SimDataBlock*);
 56  virtual bool      ea_start();
 57  virtual bool      ea_update(F32 dt);
 58  virtual void      ea_finish(bool was_stopped);
 59  virtual void      ea_set_scope_status(bool flag);
 60  virtual void      onDeleteNotify(SimObject*);
 61};
 62
 63//~~~~~~~~~~~~~~~~~~~~//
 64
 65afxEA_PhysicalZone::afxEA_PhysicalZone()
 66{
 67  zone_data = 0;
 68  physical_zone = 0;
 69  cons_obj = 0;
 70}
 71
 72afxEA_PhysicalZone::~afxEA_PhysicalZone()
 73{
 74  if (physical_zone)
 75    physical_zone->deleteObject();
 76  if (zone_data && zone_data->isTempClone())
 77    delete zone_data;
 78  zone_data = 0;
 79}
 80
 81void afxEA_PhysicalZone::ea_set_datablock(SimDataBlock* db)
 82{
 83  zone_data = dynamic_cast<afxPhysicalZoneData*>(db);
 84}
 85
 86bool afxEA_PhysicalZone::ea_start()
 87{
 88  if (!zone_data)
 89  {
 90    Con::errorf("afxEA_PhysicalZone::ea_start() -- missing or incompatible datablock.");
 91    return false;
 92  }
 93
 94  do_runtime_substitutions();
 95
 96  return true;
 97}
 98
 99bool afxEA_PhysicalZone::ea_update(F32 dt)
100{
101  if (!physical_zone)
102  {
103    // create and register effect
104    physical_zone = new PhysicalZone();
105    physical_zone->mVelocityMod = zone_data->mVelocityMod;
106    physical_zone->mGravityMod = zone_data->mGravityMod;
107    physical_zone->mAppliedForce = zone_data->mAppliedForce;
108    physical_zone->force_type = zone_data->force_type;
109    physical_zone->orient_force = zone_data->orient_force;
110    physical_zone->setField("polyhedron", zone_data->mPolyhedron);
111
112    if (!physical_zone->registerObject())
113    {
114      delete physical_zone;
115      physical_zone = 0;
116      Con::errorf("afxEA_PhysicalZone::ea_update() -- effect failed to register.");
117      return false;
118    }
119    deleteNotify(physical_zone);
120    physical_zone->activate();
121  }
122
123  if (physical_zone)
124  {
125    if (zone_data->exclude_cons_obj)
126    {
127      afxConstraint* pos_constraint = getPosConstraint();
128      set_cons_object((pos_constraint) ? pos_constraint->getSceneObject() : 0);
129    }
130
131    if (mDo_fades)
132      physical_zone->setFadeAmount(mFade_value);
133    physical_zone->setTransform(mUpdated_xfm);
134  }
135
136  return true;
137}
138
139void afxEA_PhysicalZone::ea_finish(bool was_stopped)
140{
141  if (physical_zone)
142  {
143    set_cons_object(0);
144    physical_zone->deleteObject();
145    physical_zone = 0;
146  }
147}
148
149void afxEA_PhysicalZone::ea_set_scope_status(bool in_scope)
150{
151  if (physical_zone)
152  {
153    if (in_scope && !physical_zone->isActive())
154      physical_zone->activate();
155    else if (!in_scope && physical_zone->isActive())
156      physical_zone->deactivate();
157  }
158}
159
160void afxEA_PhysicalZone::onDeleteNotify(SimObject* obj)
161{
162  if (physical_zone == dynamic_cast<PhysicalZone*>(obj))
163    physical_zone = 0;
164
165  Parent::onDeleteNotify(obj);
166}
167
168void afxEA_PhysicalZone::do_runtime_substitutions()
169{
170  // only clone the datablock if there are substitutions
171  if (zone_data->getSubstitutionCount() > 0)
172  {
173    // clone the datablock and perform substitutions
174    afxPhysicalZoneData* orig_db = zone_data;
175    zone_data = new afxPhysicalZoneData(*orig_db, true);
176    orig_db->performSubstitutions(zone_data, mChoreographer, mGroup_index);
177  }
178}
179
180void afxEA_PhysicalZone::set_cons_object(SceneObject* new_obj)
181{
182  if (cons_obj == new_obj)
183    return;
184
185  if (cons_obj)
186  {
187    physical_zone->unregisterExcludedObject(cons_obj);
188    //clearNotify(shape);
189  }
190  
191  cons_obj = new_obj;
192
193  if (cons_obj)
194  {
195    //deleteNotify(shape);
196    physical_zone->registerExcludedObject(cons_obj);
197  }
198}
199
200//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
201
202class afxEA_PhysicalZoneDesc : public afxEffectAdapterDesc, public afxEffectDefs 
203{
204  static afxEA_PhysicalZoneDesc desc;
205
206public:
207  virtual bool  testEffectType(const SimDataBlock*) const;
208  virtual bool  requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const;
209  virtual bool  runsOnServer(const afxEffectWrapperData*) const { return true; }
210  virtual bool  runsOnClient(const afxEffectWrapperData*) const { return false; }
211
212  virtual afxEffectWrapper* create() const { return new afxEA_PhysicalZone; }
213};
214
215afxEA_PhysicalZoneDesc afxEA_PhysicalZoneDesc::desc;
216
217bool afxEA_PhysicalZoneDesc::testEffectType(const SimDataBlock* db) const
218{
219  return (typeid(afxPhysicalZoneData) == typeid(*db));
220}
221
222bool afxEA_PhysicalZoneDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const
223{
224  return (timing.lifetime < 0);
225}
226
227//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
228