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