Torque3D Documentation / _generateds / afxEA_Force.cpp

afxEA_Force.cpp

Engine/source/afx/forces/afxEA_Force.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 "afx/arcaneFX.h"
 28#include "afx/afxChoreographer.h"
 29#include "afx/afxEffectDefs.h"
 30#include "afx/afxEffectWrapper.h"
 31#include "afx/forces/afxForce.h"
 32#include "afx/forces/afxForceSet.h"
 33
 34//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 35// afxEA_Force 
 36
 37class afxEA_Force : public afxEffectWrapper
 38{
 39  typedef afxEffectWrapper Parent;
 40
 41  afxForceData*     force_data;
 42  afxForce*         force;
 43  afxForceSetMgr*   force_set_mgr;
 44
 45  void              do_runtime_substitutions();
 46
 47public:
 48  /*C*/             afxEA_Force();
 49  /*D*/             ~afxEA_Force();
 50
 51  virtual void      ea_set_datablock(SimDataBlock*);
 52  virtual bool      ea_start();
 53  virtual bool      ea_update(F32 dt);
 54  virtual void      ea_finish(bool was_stopped);
 55};
 56
 57//~~~~~~~~~~~~~~~~~~~~//
 58
 59afxEA_Force::afxEA_Force()
 60{
 61  force_data = 0;
 62  force = 0;
 63  force_set_mgr = 0;
 64}
 65
 66afxEA_Force::~afxEA_Force()
 67{
 68  if (force)
 69  {
 70    if (force_set_mgr) 
 71      force_set_mgr->unregisterForce(force_data->force_set_name, force);
 72    delete force;
 73  }
 74
 75  if (force_data && force_data->isTempClone())
 76  {
 77    delete force_data;
 78    force_data = 0;
 79  }
 80
 81  force_set_mgr = 0;
 82}
 83
 84void afxEA_Force::ea_set_datablock(SimDataBlock* db)
 85{
 86  force_data = dynamic_cast<afxForceData*>(db);
 87}
 88
 89bool afxEA_Force::ea_start()
 90{
 91  if (!force_data)
 92  {
 93    Con::errorf("afxEA_Force::ea_start() -- missing or incompatible datablock.");
 94    return false;
 95  }
 96
 97  do_runtime_substitutions();
 98
 99  force_set_mgr = mChoreographer->getForceSetMgr();
100
101  return true;
102}
103
104bool afxEA_Force::ea_update(F32 dt)
105{
106  if (!force)
107  {
108    force = (force_data->force_desc) ? force_data->force_desc->create() : 0;
109    if (!force)
110    {
111      delete force;
112      force = 0;
113      Con::errorf(ConsoleLogEntry::General, "Force effect failed to instantiate. (%s)", mDatablock->getName());
114      return false;
115    }
116    force->onNewDataBlock(force_data, false);
117
118    if (force)
119    {
120      force_set_mgr->registerForce(force_data->force_set_name, force);
121      force->start();
122    }
123  }
124
125  if (force) // && in_scope)
126  {
127    if (mDo_fades)
128      force->setFadeAmount(mFade_value);
129    
130    force->update(dt);
131  }
132
133  return true;
134}
135
136void afxEA_Force::ea_finish(bool was_stopped)
137{
138  if (!force)
139    return;
140
141  if (force_set_mgr) 
142    force_set_mgr->unregisterForce(force_data->force_set_name, force);
143  delete force;
144  force = 0;
145}
146
147void afxEA_Force::do_runtime_substitutions()
148{
149  force_data = force_data->cloneAndPerformSubstitutions(mChoreographer, mGroup_index);
150}
151
152//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
153
154class afxEA_ForceDesc : public afxEffectAdapterDesc, public afxEffectDefs 
155{
156  static afxEA_ForceDesc desc;
157
158public:
159  virtual bool  testEffectType(const SimDataBlock*) const;
160  virtual bool  requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const;
161  virtual bool  runsOnServer(const afxEffectWrapperData*) const { return false; }
162  virtual bool  runsOnClient(const afxEffectWrapperData*) const { return true; }
163
164  virtual afxEffectWrapper* create() const { return new afxEA_Force; }
165};
166
167afxEA_ForceDesc afxEA_ForceDesc::desc;
168
169bool afxEA_ForceDesc::testEffectType(const SimDataBlock* db) const
170{
171  if (dynamic_cast<const afxForceData*>(db) != 0)
172    return afxForceDesc::identifyForce((afxForceData*) db);
173
174  return false;
175}
176
177bool afxEA_ForceDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const
178{
179  return (timing.lifetime < 0);
180}
181
182//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
183
184
185