afxEA_PlayerPuppet.cpp
Engine/source/afx/ea/afxEA_PlayerPuppet.cpp
Classes:
class
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/afxPlayerPuppet.h" 36 37//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 38// afxEA_PlayerPuppet 39 40class afxEA_PlayerPuppet : public afxEffectWrapper 41{ 42 typedef afxEffectWrapper Parent; 43 44 afxPlayerPuppetData* mover_data; 45 afxConstraint* obj_cons; 46 47 void do_runtime_substitutions(); 48 49public: 50 /*C*/ afxEA_PlayerPuppet(); 51 52 virtual void ea_set_datablock(SimDataBlock*); 53 virtual bool ea_start(); 54 virtual bool ea_update(F32 dt); 55 virtual void ea_finish(bool was_stopped); 56 57 virtual void getUnconstrainedPosition(Point3F& pos); 58 virtual void getUnconstrainedTransform(MatrixF& xfm); 59}; 60 61//~~~~~~~~~~~~~~~~~~~~// 62 63afxEA_PlayerPuppet::afxEA_PlayerPuppet() 64{ 65 mover_data = 0; 66 obj_cons = 0; 67} 68 69void afxEA_PlayerPuppet::ea_set_datablock(SimDataBlock* db) 70{ 71 mover_data = dynamic_cast<afxPlayerPuppetData*>(db); 72} 73 74bool afxEA_PlayerPuppet::ea_start() 75{ 76 if (!mover_data) 77 { 78 Con::errorf("afxEA_PlayerPuppet::ea_start() -- missing or incompatible datablock."); 79 return false; 80 } 81 82 do_runtime_substitutions(); 83 84 afxConstraintID obj_id = mCons_mgr->getConstraintId(mover_data->obj_def); 85 obj_cons = mCons_mgr->getConstraint(obj_id); 86 87 Player* player = dynamic_cast<Player*>((obj_cons) ? obj_cons->getSceneObject() : 0); 88 if (player) 89 player->ignore_updates = true; 90 91 return true; 92} 93 94bool afxEA_PlayerPuppet::ea_update(F32 dt) 95{ 96 SceneObject* obj = (obj_cons) ? obj_cons->getSceneObject() : 0; 97 98 if (obj && mIn_scope) 99 { 100 obj->setTransform(mUpdated_xfm); 101 } 102 103 return true; 104} 105 106void afxEA_PlayerPuppet::ea_finish(bool was_stopped) 107{ 108 Player* player = dynamic_cast<Player*>((obj_cons) ? obj_cons->getSceneObject() : 0); 109 if (player) 110 { 111 player->resetContactTimer(); 112 player->ignore_updates = false; 113 } 114} 115 116void afxEA_PlayerPuppet::getUnconstrainedPosition(Point3F& pos) 117{ 118 SceneObject* obj = (obj_cons) ? obj_cons->getSceneObject() : 0; 119 if (obj) 120 pos = obj->getRenderPosition(); 121 else 122 pos.zero(); 123} 124 125void afxEA_PlayerPuppet::getUnconstrainedTransform(MatrixF& xfm) 126{ 127 SceneObject* obj = (obj_cons) ? obj_cons->getSceneObject() : 0; 128 if (obj) 129 xfm = obj->getRenderTransform(); 130 else 131 xfm.identity(); 132} 133 134void afxEA_PlayerPuppet::do_runtime_substitutions() 135{ 136 // only clone the datablock if there are substitutions 137 if (mover_data->getSubstitutionCount() > 0) 138 { 139 // clone the datablock and perform substitutions 140 afxPlayerPuppetData* orig_db = mover_data; 141 mover_data = new afxPlayerPuppetData(*orig_db, true); 142 orig_db->performSubstitutions(mover_data, mChoreographer, mGroup_index); 143 } 144} 145 146//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 147 148class afxEA_PlayerPuppetDesc : public afxEffectAdapterDesc, public afxEffectDefs 149{ 150 static afxEA_PlayerPuppetDesc desc; 151 152public: 153 virtual bool testEffectType(const SimDataBlock*) const; 154 virtual bool requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const; 155 virtual bool runsOnServer(const afxEffectWrapperData*) const; 156 virtual bool runsOnClient(const afxEffectWrapperData*) const; 157 158 virtual afxEffectWrapper* create() const { return new afxEA_PlayerPuppet; } 159}; 160 161afxEA_PlayerPuppetDesc afxEA_PlayerPuppetDesc::desc; 162 163bool afxEA_PlayerPuppetDesc::testEffectType(const SimDataBlock* db) const 164{ 165 return (typeid(afxPlayerPuppetData) == typeid(*db)); 166} 167 168bool afxEA_PlayerPuppetDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const 169{ 170 return (timing.lifetime < 0); 171} 172 173bool afxEA_PlayerPuppetDesc::runsOnServer(const afxEffectWrapperData* ew) const 174{ 175 U8 networking = ((const afxPlayerPuppetData*)ew->effect_data)->networking; 176 return ((networking & (SERVER_ONLY | SERVER_AND_CLIENT)) != 0); 177} 178 179bool afxEA_PlayerPuppetDesc::runsOnClient(const afxEffectWrapperData* ew) const 180{ 181 U8 networking = ((const afxPlayerPuppetData*)ew->effect_data)->networking; 182 return ((networking & (CLIENT_ONLY | SERVER_AND_CLIENT)) != 0); 183} 184 185//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 186