Torque3D Documentation / _generateds / afxEA_AnimClip.cpp

afxEA_AnimClip.cpp

Engine/source/afx/ea/afxEA_AnimClip.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#include "afx/afxEffectDefs.h"
 30#include "afx/afxEffectWrapper.h"
 31#include "afx/afxChoreographer.h"
 32#include "afx/ce/afxAnimClip.h"
 33
 34//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 35// afxEA_AnimClip 
 36
 37class afxEA_AnimClip : public afxEffectWrapper
 38{
 39  typedef afxEffectWrapper Parent;
 40
 41  afxAnimClipData*  clip_data;
 42  bool              started;
 43  F32               anim_lifetime;
 44  U32               anim_tag;
 45  U32               lock_tag;
 46
 47  void              do_runtime_substitutions();
 48
 49public:
 50  /*C*/             afxEA_AnimClip();
 51  /*C*/             ~afxEA_AnimClip();
 52
 53  virtual void      ea_set_datablock(SimDataBlock*);
 54  virtual bool      ea_start();
 55  virtual bool      ea_update(F32 dt);
 56  virtual void      ea_finish(bool was_stopped);
 57};
 58
 59//~~~~~~~~~~~~~~~~~~~~//
 60
 61afxEA_AnimClip::afxEA_AnimClip()
 62{
 63  clip_data = 0;
 64  started = false;
 65  anim_lifetime = 0;
 66  anim_tag = 0;
 67  lock_tag = 0;
 68}
 69
 70afxEA_AnimClip::~afxEA_AnimClip()
 71{
 72  if (clip_data && clip_data->isTempClone())
 73    delete clip_data;
 74  clip_data = 0;
 75}
 76
 77void afxEA_AnimClip::ea_set_datablock(SimDataBlock* db)
 78{
 79  clip_data = dynamic_cast<afxAnimClipData*>(db);
 80}
 81
 82bool afxEA_AnimClip::ea_start()
 83{
 84  if (!clip_data)
 85  {
 86    Con::errorf("afxEA_AnimClip::ea_start() -- missing or incompatible datablock.");
 87    return false;
 88  }
 89
 90  do_runtime_substitutions();
 91
 92  afxConstraint* pos_constraint = getPosConstraint();
 93  if (mFull_lifetime == INFINITE_LIFETIME && pos_constraint != 0)
 94    anim_lifetime = pos_constraint->getAnimClipDuration(clip_data->clip_name);
 95  else 
 96    anim_lifetime = mFull_lifetime;
 97
 98  anim_tag = 0;
 99  lock_tag = 0;
100
101  return true;
102}
103
104bool afxEA_AnimClip::ea_update(F32 dt)
105{
106  afxConstraint* pos_constraint = getPosConstraint();
107  if (!started && pos_constraint != 0)
108  {
109    bool go_for_it = true;
110
111    if (pos_constraint->getDamageState() == ShapeBase::Enabled)
112      go_for_it = !clip_data->ignore_enabled;
113    else if (pos_constraint->getDamageState() == ShapeBase::Disabled)
114      go_for_it = !clip_data->ignore_disabled;
115
116    if (go_for_it && (clip_data->ignore_first_person || clip_data->ignore_third_person))
117    {
118      ShapeBase* shape = dynamic_cast<ShapeBase*>(pos_constraint->getSceneObject());
119      if (shape)
120      {
121        bool is_first_person = shape->isFirstPerson();
122        if (clip_data->ignore_first_person && is_first_person)
123          go_for_it = false;
124        if (clip_data->ignore_third_person && !is_first_person)
125          go_for_it = false;
126      }
127    }
128
129    if (go_for_it)
130    {
131      F32 rate = clip_data->rate/<a href="/coding/class/classafxeffectwrapper/#classafxeffectwrapper_1a083f9e20fa36c9955f7fc830208121ae">mProp_time_factor</a>;
132      F32 pos = mFmod(mLife_elapsed, anim_lifetime)/anim_lifetime;
133      pos = mFmod(pos + clip_data->pos_offset, 1.0);
134      if (clip_data->rate < 0) 
135        pos = 1.0f - pos;
136      anim_tag = pos_constraint->setAnimClip(clip_data->clip_name, pos, rate, clip_data->trans, 
137                                             clip_data->is_death_anim);
138      if (clip_data->lock_anim)
139        lock_tag = pos_constraint->lockAnimation();
140    }
141    started = true;
142  }
143
144  return true;
145}
146
147void afxEA_AnimClip::ea_finish(bool was_stopped)
148{
149  afxConstraint* pos_constraint = getPosConstraint();
150  if (pos_constraint && anim_tag != 0)
151  {
152    pos_constraint->resetAnimation(anim_tag);
153  }
154  if (pos_constraint && lock_tag != 0)
155    pos_constraint->unlockAnimation(lock_tag);
156
157  started = false;
158}
159
160void afxEA_AnimClip::do_runtime_substitutions()
161{
162  // only clone the datablock if there are substitutions
163  if (clip_data->getSubstitutionCount() > 0)
164  {
165    // clone the datablock and perform substitutions
166    afxAnimClipData* orig_db = clip_data;
167    clip_data = new afxAnimClipData(*orig_db, true);
168    orig_db->performSubstitutions(clip_data, mChoreographer, mGroup_index);
169  }
170}
171
172//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
173// afxEA_AnimClipDesc
174
175class afxEA_AnimClipDesc : public afxEffectAdapterDesc, public afxEffectDefs 
176{
177  static afxEA_AnimClipDesc 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 true; }
183  virtual bool  runsOnClient(const afxEffectWrapperData*) const { return true; }
184  virtual bool  isPositional(const afxEffectWrapperData*) const { return false; }
185
186  virtual afxEffectWrapper* create() const { return new afxEA_AnimClip; }
187};
188
189afxEA_AnimClipDesc afxEA_AnimClipDesc::desc;
190
191bool afxEA_AnimClipDesc::testEffectType(const SimDataBlock* db) const
192{
193  return (typeid(afxAnimClipData) == typeid(*db));
194}
195
196bool afxEA_AnimClipDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const
197{
198  return (timing.lifetime < 0);
199}
200
201//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
202