Torque3D Documentation / _generateds / afxEA_PlayerMovement.cpp

afxEA_PlayerMovement.cpp

Engine/source/afx/ea/afxEA_PlayerMovement.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/player.h"
 31
 32#include "afx/afxChoreographer.h"
 33#include "afx/afxEffectDefs.h"
 34#include "afx/afxEffectWrapper.h"
 35#include "afx/ce/afxPlayerMovement.h"
 36
 37//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 38// afxEA_PlayerMovement 
 39
 40class afxEA_PlayerMovement : public afxEffectWrapper
 41{
 42  typedef afxEffectWrapper Parent;
 43
 44  afxPlayerMovementData*  movement_data;
 45  U32                     tag;
 46
 47  void              do_runtime_substitutions();
 48
 49public:
 50  /*C*/             afxEA_PlayerMovement();
 51  /*C*/             ~afxEA_PlayerMovement();
 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_PlayerMovement::afxEA_PlayerMovement()
 62{
 63  movement_data = 0;
 64  tag = 0;
 65}
 66
 67afxEA_PlayerMovement::~afxEA_PlayerMovement()
 68{
 69  if (movement_data && movement_data->isTempClone())
 70    delete movement_data;
 71  movement_data = 0;
 72}
 73
 74void afxEA_PlayerMovement::ea_set_datablock(SimDataBlock* db)
 75{
 76  movement_data = dynamic_cast<afxPlayerMovementData*>(db);
 77}
 78
 79bool afxEA_PlayerMovement::ea_start()
 80{
 81  if (!movement_data)
 82  {
 83    Con::errorf("afxEA_PlayerMovement::ea_start() -- missing or incompatible datablock.");
 84    return false;
 85  }
 86
 87  do_runtime_substitutions();
 88  tag = 0;
 89
 90  afxConstraint* pos_cons = getPosConstraint();
 91  if (!pos_cons)
 92  {
 93    Con::warnf("afxEA_PlayerMovement::ea_start() -- missing position constraint.");
 94    return false;
 95  }
 96
 97  Player* player = dynamic_cast<Player*>(pos_cons->getSceneObject());
 98  if (!player)
 99  {
100    Con::warnf("afxEA_PlayerMovement::ea_start() -- position constraint is not a Player.");
101    return false;
102  }
103
104  // setup player overrides
105  if (movement_data->hasMovementOverride())
106    tag = player->setMovementOverride(movement_data->speed_bias, &movement_data->movement, movement_data->movement_op);
107  else
108    tag = player->setMovementOverride(movement_data->speed_bias);
109
110  return true;
111}
112
113bool afxEA_PlayerMovement::ea_update(F32 dt)
114{
115  return true;
116}
117
118void afxEA_PlayerMovement::ea_finish(bool was_stopped)
119{
120  afxConstraint* pos_cons = getPosConstraint();
121  if (!pos_cons)
122    return;
123
124  Player* player = dynamic_cast<Player*>(pos_cons->getSceneObject());
125  if (!player)
126    return;
127
128  // restore player overrides
129  player->restoreMovement(tag);
130}
131
132void afxEA_PlayerMovement::do_runtime_substitutions()
133{
134  // only clone the datablock if there are substitutions
135  if (movement_data->getSubstitutionCount() > 0)
136  {
137    // clone the datablock and perform substitutions
138    afxPlayerMovementData* orig_db = movement_data;
139    movement_data = new afxPlayerMovementData(*orig_db, true);
140    orig_db->performSubstitutions(movement_data, mChoreographer, mGroup_index);
141  }
142}
143
144//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
145
146class afxEA_PlayerMovementDesc : public afxEffectAdapterDesc, public afxEffectDefs 
147{
148  static afxEA_PlayerMovementDesc desc;
149
150public:
151  virtual bool  testEffectType(const SimDataBlock*) const;
152  virtual bool  requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const;
153  virtual bool  runsOnServer(const afxEffectWrapperData*) const { return true; }
154  virtual bool  runsOnClient(const afxEffectWrapperData*) const { return false; }
155
156  virtual afxEffectWrapper* create() const { return new afxEA_PlayerMovement; }
157};
158
159afxEA_PlayerMovementDesc afxEA_PlayerMovementDesc::desc;
160
161bool afxEA_PlayerMovementDesc::testEffectType(const SimDataBlock* db) const
162{
163  return (typeid(afxPlayerMovementData) == typeid(*db));
164}
165
166bool afxEA_PlayerMovementDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const
167{
168  return (timing.lifetime < 0);
169}
170
171//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
172