afxEA_StaticShape.cpp
Engine/source/afx/ea/afxEA_StaticShape.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#include "afx/afxEffectDefs.h" 30#include "afx/afxEffectWrapper.h" 31#include "afx/afxChoreographer.h" 32#include "afx/ce/afxStaticShape.h" 33 34//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 35// afxEA_StaticShape 36 37class afxEA_StaticShape : public afxEffectWrapper 38{ 39 typedef afxEffectWrapper Parent; 40 41 StaticShapeData* shape_data; 42 afxStaticShape* static_shape; 43 bool fade_out_started; 44 bool do_spawn; 45 46 void do_runtime_substitutions(); 47 48public: 49 /*C*/ afxEA_StaticShape(); 50 /*D*/ ~afxEA_StaticShape(); 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 virtual void ea_set_scope_status(bool flag); 57 virtual void onDeleteNotify(SimObject*); 58 59 virtual void getUpdatedBoxCenter(Point3F& pos); 60 virtual TSShape* getTSShape(); 61 virtual TSShapeInstance* getTSShapeInstance(); 62}; 63 64//~~~~~~~~~~~~~~~~~~~~// 65 66afxEA_StaticShape::afxEA_StaticShape() 67{ 68 shape_data = 0; 69 static_shape = 0; 70 fade_out_started = false; 71 do_spawn = true; 72} 73 74afxEA_StaticShape::~afxEA_StaticShape() 75{ 76 if (static_shape) 77 static_shape->deleteObject(); 78 if (shape_data && shape_data->isTempClone()) 79 delete shape_data; 80 shape_data = 0; 81} 82 83void afxEA_StaticShape::ea_set_datablock(SimDataBlock* db) 84{ 85 shape_data = dynamic_cast<StaticShapeData*>(db); 86 afxStaticShapeData* afx_shape_data = dynamic_cast<afxStaticShapeData*>(shape_data); 87 do_spawn = (afx_shape_data) ? afx_shape_data->do_spawn : false; 88} 89 90bool afxEA_StaticShape::ea_start() 91{ 92 if (!shape_data) 93 { 94 Con::errorf("afxEA_StaticShape::ea_start() -- missing or incompatible datablock."); 95 return false; 96 } 97 98 do_runtime_substitutions(); 99 100 // fades are handled using startFade() calls. 101 mDo_fades = false; 102 103 return true; 104} 105 106bool afxEA_StaticShape::ea_update(F32 dt) 107{ 108 if (!static_shape) 109 { 110 // create and register effect 111 static_shape = new afxStaticShape(); 112 if (mDatablock->use_ghost_as_cons_obj && mDatablock->effect_name != ST_NULLSTRING) 113 static_shape->init(mChoreographer->getChoreographerId(), mDatablock->effect_name); 114 115 static_shape->onNewDataBlock(shape_data, false); 116 if (!static_shape->registerObject()) 117 { 118 delete static_shape; 119 static_shape = 0; 120 Con::errorf("afxEA_StaticShape::ea_update() -- effect failed to register."); 121 return false; 122 } 123 deleteNotify(static_shape); 124 registerForCleanup(static_shape); 125 126 if (mEW_timing.fade_in_time > 0.0f) 127 static_shape->startFade(mEW_timing.fade_in_time, 0, false); 128 } 129 130 if (static_shape) 131 { 132 if (!fade_out_started && mElapsed > mFade_out_start) 133 { 134 if (!do_spawn) 135 { 136 if (mEW_timing.fade_out_time > 0.0f) 137 static_shape->startFade(mEW_timing.fade_out_time, 0, true); 138 } 139 fade_out_started = true; 140 } 141 142 if (mIn_scope) 143 { 144 static_shape->setTransform(mUpdated_xfm); 145 static_shape->setScale(mUpdated_scale); 146 } 147 } 148 149 return true; 150} 151 152void afxEA_StaticShape::ea_finish(bool was_stopped) 153{ 154 if (!static_shape) 155 return; 156 157 if (do_spawn) 158 { 159 Con::executef(shape_data, "onSpawn", static_shape->getIdString(), mDatablock->effect_name); 160 clearNotify(static_shape); 161 } 162 else 163 static_shape->deleteObject(); 164 165 static_shape = 0; 166} 167 168void afxEA_StaticShape::ea_set_scope_status(bool in_scope) 169{ 170 if (static_shape) 171 static_shape->setVisibility(do_spawn || in_scope); 172} 173 174void afxEA_StaticShape::onDeleteNotify(SimObject* obj) 175{ 176 if (static_shape == dynamic_cast<afxStaticShape*>(obj)) 177 static_shape = 0; 178 179 Parent::onDeleteNotify(obj); 180} 181 182void afxEA_StaticShape::getUpdatedBoxCenter(Point3F& pos) 183{ 184 if (static_shape) 185 pos = static_shape->getBoxCenter(); 186} 187 188 189TSShape* afxEA_StaticShape::getTSShape() 190{ 191 return (static_shape) ? ((TSShape*)static_shape->getShape()) : 0; 192} 193 194TSShapeInstance* afxEA_StaticShape::getTSShapeInstance() 195{ 196 return (static_shape) ? static_shape->getShapeInstance() : 0; 197} 198 199void afxEA_StaticShape::do_runtime_substitutions() 200{ 201 // only clone the datablock if there are substitutions 202 if (shape_data->getSubstitutionCount() > 0) 203 { 204 if (typeid(afxStaticShapeData) == typeid(*shape_data)) 205 { 206 afxStaticShapeData* orig_db = (afxStaticShapeData*)shape_data; 207 shape_data = new afxStaticShapeData(*orig_db, true); 208 orig_db->performSubstitutions(shape_data, mChoreographer, mGroup_index); 209 } 210 else 211 { 212 StaticShapeData* orig_db = shape_data; 213 shape_data = new StaticShapeData(*orig_db, true); 214 orig_db->performSubstitutions(shape_data, mChoreographer, mGroup_index); 215 } 216 } 217} 218 219//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 220 221class afxEA_StaticShapeDesc : public afxEffectAdapterDesc, public afxEffectDefs 222{ 223 static afxEA_StaticShapeDesc desc; 224 225public: 226 virtual bool testEffectType(const SimDataBlock*) const; 227 virtual bool requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const; 228 virtual bool runsOnServer(const afxEffectWrapperData*) const { return true; } 229 virtual bool runsOnClient(const afxEffectWrapperData*) const { return false; } 230 231 virtual afxEffectWrapper* create() const { return new afxEA_StaticShape; } 232}; 233 234afxEA_StaticShapeDesc afxEA_StaticShapeDesc::desc; 235 236bool afxEA_StaticShapeDesc::testEffectType(const SimDataBlock* db) const 237{ 238 if (typeid(StaticShapeData) == typeid(*db)) 239 return true; 240 if (typeid(afxStaticShapeData) == typeid(*db)) 241 return true; 242 return false; 243} 244 245bool afxEA_StaticShapeDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const 246{ 247 return (timing.lifetime < 0); 248} 249 250//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 251