afxEA_Billboard.cpp
Engine/source/afx/ea/afxEA_Billboard.cpp
Classes:
class
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/afxResidueMgr.h" 33#include "afx/ce/afxBillboard.h" 34 35//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 36// afxEA_Billboard -- This is the adapter for geometry primitives. 37 38class afxEA_Billboard : public afxEffectWrapper 39{ 40 typedef afxEffectWrapper Parent; 41 42 afxBillboardData* bb_data; 43 afxBillboard* bb; 44 45 void do_runtime_substitutions(); 46 47public: 48 /*C*/ afxEA_Billboard(); 49 /*D*/ ~afxEA_Billboard(); 50 51 virtual void ea_set_datablock(SimDataBlock*); 52 virtual bool ea_start(); 53 virtual bool ea_update(F32 dt); 54 virtual void ea_finish(bool was_stopped); 55 virtual void ea_set_scope_status(bool flag); 56 virtual void onDeleteNotify(SimObject*); 57 virtual void getUpdatedBoxCenter(Point3F& pos); 58 virtual void getBaseColor(LinearColorF& color) { if (bb_data) color = bb_data->color; } 59}; 60 61 62afxEA_Billboard::afxEA_Billboard() 63{ 64 bb_data = 0; 65 bb = 0; 66} 67 68afxEA_Billboard::~afxEA_Billboard() 69{ 70 if (bb) 71 bb->deleteObject(); 72 if (bb_data && bb_data->isTempClone()) 73 delete bb_data; 74 bb_data = 0; 75} 76 77void afxEA_Billboard::ea_set_datablock(SimDataBlock* db) 78{ 79 bb_data = dynamic_cast<afxBillboardData*>(db); 80} 81 82bool afxEA_Billboard::ea_start() 83{ 84 if (!bb_data) 85 { 86 Con::errorf("afxEA_Billboard::ea_start() -- missing or incompatible datablock."); 87 return false; 88 } 89 90 do_runtime_substitutions(); 91 92 return true; 93} 94 95bool afxEA_Billboard::ea_update(F32 dt) 96{ 97 if (!bb) 98 { 99 // create and register effect 100 bb = new afxBillboard(); 101 bb->onNewDataBlock(bb_data, false); 102 if (!bb->registerObject()) 103 { 104 delete bb; 105 bb = 0; 106 Con::errorf("afxEA_Billboard::ea_update() -- effect failed to register."); 107 return false; 108 } 109 deleteNotify(bb); 110 111 ///bb->setSequenceRateFactor(datablock->rate_factor/prop_time_factor); 112 bb->setSortPriority(mDatablock->sort_priority); 113 } 114 115 if (bb) 116 { 117 bb->live_color = mUpdated_color; 118 if (mDo_fades) 119 { 120 bb->setFadeAmount(mFade_value); 121 } 122 bb->setTransform(mUpdated_xfm); 123 bb->setScale(mUpdated_scale); 124 } 125 126 return true; 127} 128 129void afxEA_Billboard::ea_finish(bool was_stopped) 130{ 131 if (!bb) 132 return; 133 134 bb->deleteObject(); 135 bb = 0; 136} 137 138void afxEA_Billboard::ea_set_scope_status(bool in_scope) 139{ 140 if (bb) 141 bb->setVisibility(in_scope); 142} 143 144void afxEA_Billboard::onDeleteNotify(SimObject* obj) 145{ 146 if (bb == dynamic_cast<afxBillboard*>(obj)) 147 bb = 0; 148 149 Parent::onDeleteNotify(obj); 150} 151 152void afxEA_Billboard::getUpdatedBoxCenter(Point3F& pos) 153{ 154 if (bb) 155 pos = bb->getBoxCenter(); 156} 157 158void afxEA_Billboard::do_runtime_substitutions() 159{ 160 // only clone the datablock if there are substitutions 161 if (bb_data->getSubstitutionCount() > 0) 162 { 163 // clone the datablock and perform substitutions 164 afxBillboardData* orig_db = bb_data; 165 bb_data = new afxBillboardData(*orig_db, true); 166 orig_db->performSubstitutions(bb_data, mChoreographer, mGroup_index); 167 } 168} 169 170 171//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 172 173class afxEA_BillboardDesc : public afxEffectAdapterDesc, public afxEffectDefs 174{ 175 static afxEA_BillboardDesc desc; 176 177public: 178 virtual bool testEffectType(const SimDataBlock*) const; 179 virtual bool requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const; 180 virtual bool runsOnServer(const afxEffectWrapperData*) const { return false; } 181 virtual bool runsOnClient(const afxEffectWrapperData*) const { return true; } 182 183 virtual afxEffectWrapper* create() const { return new afxEA_Billboard; } 184}; 185 186//~~~~~~~~~~~~~~~~~~~~// 187 188afxEA_BillboardDesc afxEA_BillboardDesc::desc; 189 190bool afxEA_BillboardDesc::testEffectType(const SimDataBlock* db) const 191{ 192 return (typeid(afxBillboardData) == typeid(*db)); 193} 194 195bool afxEA_BillboardDesc::requiresStop(const afxEffectWrapperData* ew, const afxEffectTimingData& timing) const 196{ 197 return (timing.lifetime < 0); 198} 199 200//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 201