Torque3D Documentation / _generateds / afxEA_Mooring.cpp

afxEA_Mooring.cpp

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