afxXM_MountedImageNode.cpp
Engine/source/afx/xm/afxXM_MountedImageNode.cpp
Classes:
Public Functions
ConsoleDocClass(afxXM_MountedImageNodeData , "@brief An xmod <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXMods\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )
Detailed Description
Public Functions
ConsoleDocClass(afxXM_MountedImageNodeData , "@brief An xmod <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXMods\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )
IMPLEMENT_CO_DATABLOCK_V1(afxXM_MountedImageNodeData )
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 "afx/arcaneFX.h" 28 29#include "afx/afxEffectWrapper.h" 30#include "afx/afxChoreographer.h" 31#include "afx/xm/afxXfmMod.h" 32 33//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 34 35class afxXM_MountedImageNodeData : public afxXM_BaseData 36{ 37 typedef afxXM_BaseData Parent; 38 39public: 40 StringTableEntry node_name; // name of a mounted-image node 41 U32 image_slot; // which mounted-image? 42 // (0 <= image_slot < MaxMountedImages) 43public: 44 /*C*/ afxXM_MountedImageNodeData(); 45 /*C*/ afxXM_MountedImageNodeData(const afxXM_MountedImageNodeData&, bool = false); 46 47 void packData(BitStream* stream); 48 void unpackData(BitStream* stream); 49 bool onAdd(); 50 51 virtual bool allowSubstitutions() const { return true; } 52 53 static void initPersistFields(); 54 55 afxXM_Base* create(afxEffectWrapper* fx, bool on_server); 56 57 DECLARE_CONOBJECT(afxXM_MountedImageNodeData); 58 DECLARE_CATEGORY("AFX"); 59}; 60 61//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 62 63class afxXM_MountedImageNode : public afxXM_Base 64{ 65 typedef afxXM_Base Parent; 66 67 StringTableEntry mNode_name; 68 U32 mImage_slot; 69 S32 mNode_ID; 70 ShapeBase* mShape; 71 afxConstraint* mCons; 72 73 afxConstraint* find_constraint(); 74 75public: 76 /*C*/ afxXM_MountedImageNode(afxXM_MountedImageNodeData*, afxEffectWrapper*); 77 78 virtual void start(F32 timestamp); 79 virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params); 80}; 81 82//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 83 84IMPLEMENT_CO_DATABLOCK_V1(afxXM_MountedImageNodeData); 85 86ConsoleDocClass( afxXM_MountedImageNodeData, 87 "@brief An xmod datablock.\n\n" 88 89 "@ingroup afxXMods\n" 90 "@ingroup AFX\n" 91 "@ingroup Datablocks\n" 92); 93 94afxXM_MountedImageNodeData::afxXM_MountedImageNodeData() 95{ 96 image_slot = 0; 97 node_name = ST_NULLSTRING; 98} 99 100afxXM_MountedImageNodeData::afxXM_MountedImageNodeData(const afxXM_MountedImageNodeData& other, bool temp_clone) : afxXM_BaseData(other, temp_clone) 101{ 102 image_slot = other.image_slot; 103 node_name = other.node_name; 104} 105 106void afxXM_MountedImageNodeData::initPersistFields() 107{ 108 addField("imageSlot", TypeS32, Offset(image_slot, afxXM_MountedImageNodeData), 109 "..."); 110 addField("nodeName", TypeString, Offset(node_name, afxXM_MountedImageNodeData), 111 "..."); 112 113 Parent::initPersistFields(); 114} 115 116void afxXM_MountedImageNodeData::packData(BitStream* stream) 117{ 118 Parent::packData(stream); 119 stream->write(image_slot); 120 stream->writeString(node_name); 121} 122 123void afxXM_MountedImageNodeData::unpackData(BitStream* stream) 124{ 125 Parent::unpackData(stream); 126 stream->read(&image_slot); 127 node_name = stream->readSTString(); 128} 129 130bool afxXM_MountedImageNodeData::onAdd() 131{ 132 if (Parent::onAdd() == false) 133 return false; 134 135 if (image_slot >= ShapeBase::MaxMountedImages) 136 { 137 // datablock will not be added if imageSlot is out-of-bounds 138 Con::errorf(ConsoleLogEntry::General, 139 "afxXM_MountedImageNodeData(%s): imageSlot (%u) >= MaxMountedImages (%d)", 140 getName(), 141 image_slot, 142 ShapeBase::MaxMountedImages); 143 return false; 144 } 145 146 return true; 147} 148 149afxXM_Base* afxXM_MountedImageNodeData::create(afxEffectWrapper* fx, bool on_server) 150{ 151 afxXM_MountedImageNodeData* datablock = this; 152 153 if (getSubstitutionCount() > 0) 154 { 155 datablock = new afxXM_MountedImageNodeData(*this, true); 156 this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex()); 157 } 158 159 return new afxXM_MountedImageNode(datablock, fx); 160} 161 162//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 163 164afxXM_MountedImageNode::afxXM_MountedImageNode(afxXM_MountedImageNodeData* db, afxEffectWrapper* fxw) 165: afxXM_Base(db, fxw) 166{ 167 mImage_slot = db->image_slot; 168 mNode_name = db->node_name; 169 mCons = 0; 170 mNode_ID = -1; 171 mShape = 0; 172} 173 174// find the first constraint with a shape by checking pos 175// then orient constraints in that order. 176afxConstraint* afxXM_MountedImageNode::find_constraint() 177{ 178 afxConstraint* cons = fx_wrapper->getOrientConstraint(); 179 if (cons && dynamic_cast<ShapeBase*>(cons->getSceneObject())) 180 return cons; 181 182 cons = fx_wrapper->getPosConstraint(); 183 if (cons && dynamic_cast<ShapeBase*>(cons->getSceneObject())) 184 return cons; 185 186 return 0; 187} 188 189void afxXM_MountedImageNode::start(F32 timestamp) 190{ 191 // constraint won't change over the modifier's 192 // lifetime so we find it here in start(). 193 mCons = find_constraint(); 194 if (!mCons) 195 Con::errorf(ConsoleLogEntry::General, 196 "afxXM_MountedImageNode: failed to find a ShapeBase derived constraint source."); 197} 198 199void afxXM_MountedImageNode::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 200{ 201 if (!mCons) 202 return; 203 204 // validate shape 205 // The shape must be validated in case it gets deleted 206 // of goes out scope. 207 SceneObject* scene_object = mCons->getSceneObject(); 208 if (scene_object != (SceneObject*)mShape) 209 { 210 mShape = dynamic_cast<ShapeBase*>(scene_object); 211 if (mShape && mNode_name != ST_NULLSTRING) 212 { 213 mNode_ID = mShape->getNodeIndex(mImage_slot, mNode_name); 214 if (mNode_ID < 0) 215 { 216 Con::errorf(ConsoleLogEntry::General, 217 "afxXM_MountedImageNode: failed to find nodeName, \"%s\".", 218 mNode_name); 219 } 220 } 221 else 222 mNode_ID = -1; 223 } 224 225 if (mShape) 226 { 227 mShape->getImageTransform(mImage_slot, mNode_ID, ¶ms.ori); 228 params.pos = params.ori.getPosition(); 229 } 230} 231 232//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 233