afxParticlePool.cpp
Engine/source/afx/util/afxParticlePool.cpp
Public Variables
Public Functions
ConsoleDocClass(afxParticlePool , "@brief A ParticlePool object as defined by an <a href="/coding/class/classafxparticlepooldata/">afxParticlePoolData</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxUtil\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )
ConsoleDocClass(afxParticlePoolData , "@brief A ParticlePool <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxUtil\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )
ImplementEnumType(afxParticlePool_PoolType , "Possible particle pool <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxParticlePool\n\n</a>" )
Detailed Description
Public Variables
EndImplementEnumType
Public Functions
ConsoleDocClass(afxParticlePool , "@brief A ParticlePool object as defined by an <a href="/coding/class/classafxparticlepooldata/">afxParticlePoolData</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxUtil\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )
ConsoleDocClass(afxParticlePoolData , "@brief A ParticlePool <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxUtil\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )
IMPLEMENT_CO_DATABLOCK_V1(afxParticlePoolData )
IMPLEMENT_CO_NETOBJECT_V1(afxParticlePool )
ImplementEnumType(afxParticlePool_PoolType , "Possible particle pool <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">types.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxParticlePool\n\n</a>" )
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 "T3D/fx/particleEmitter.h" 30 31#include "afx/afxChoreographer.h" 32#include "afx/util/afxParticlePool.h" 33 34//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 35 36IMPLEMENT_CO_DATABLOCK_V1(afxParticlePoolData); 37 38ConsoleDocClass( afxParticlePoolData, 39 "@brief A ParticlePool datablock.\n\n" 40 41 "@ingroup afxUtil\n" 42 "@ingroup AFX\n" 43); 44 45Vector<afxParticlePool::SortParticlePool> afxParticlePool::orderedVector; 46 47afxParticlePoolData::afxParticlePoolData() 48{ 49 pool_type = POOL_NORMAL; 50 base_color.set(0.0f, 0.0f, 0.0f, 1.0f); 51 blend_weight = 1.0f; 52} 53 54afxParticlePoolData::afxParticlePoolData(const afxParticlePoolData& other, bool temp_clone) : GameBaseData(other, temp_clone) 55{ 56 pool_type = other.pool_type; 57 base_color = other.base_color; 58 blend_weight = other.blend_weight; 59} 60 61ImplementEnumType( afxParticlePool_PoolType, "Possible particle pool types.\n" "@ingroup afxParticlePool\n\n" ) 62 { afxParticlePoolData::POOL_NORMAL, "normal", "..." }, 63 { afxParticlePoolData::POOL_TWOPASS, "two-pass", "..." }, 64// Alias... 65 { afxParticlePoolData::POOL_TWOPASS, "twopass", "..." }, 66EndImplementEnumType; 67 68afxParticlePoolData::~afxParticlePoolData() 69{ 70} 71 72void afxParticlePoolData::initPersistFields() 73{ 74 addField("poolType", TYPEID< afxParticlePoolData::PoolType >(), Offset(pool_type, afxParticlePoolData), 75 "..."); 76 addField("baseColor", TypeColorF, Offset(base_color, afxParticlePoolData), 77 "..."); 78 addField("blendWeight", TypeF32, Offset(blend_weight, afxParticlePoolData), 79 "..."); 80 81 Parent::initPersistFields(); 82}; 83 84void afxParticlePoolData::packData(BitStream* stream) 85{ 86 Parent::packData(stream); 87 88 stream->write(pool_type); 89 stream->write(base_color); 90 stream->write(blend_weight); 91}; 92 93void afxParticlePoolData::unpackData(BitStream* stream) 94{ 95 Parent::unpackData(stream); 96 97 stream->read(&pool_type); 98 stream->read(&base_color); 99 stream->read(&blend_weight); 100}; 101 102//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 103 104IMPLEMENT_CO_NETOBJECT_V1(afxParticlePool); 105 106ConsoleDocClass( afxParticlePool, 107 "@brief A ParticlePool object as defined by an afxParticlePoolData datablock.\n\n" 108 109 "@ingroup afxUtil\n" 110 "@ingroup AFX\n" 111); 112 113afxParticlePool::afxParticlePool() 114{ 115 mDataBlock = 0; 116 key_block = 0; 117 key_index = 0; 118 choreographer = 0; 119 sort_priority = S8_MAX; 120 121 mNetFlags.set(IsGhost); 122 mTypeMask |= StaticObjectType; 123 124 mCurBuffSize = mCurBuffSize2 = 0; 125}; 126 127afxParticlePool::~afxParticlePool() 128{ 129 for (S32 i = 0; i < emitters.size(); i++) 130 if (emitters[i]) 131 emitters[i]->clearPool(); 132 133 if (choreographer) 134 choreographer->unregisterParticlePool(this); 135 136 if (mDataBlock && mDataBlock->isTempClone()) 137 { 138 delete mDataBlock; 139 mDataBlock = 0; 140 } 141} 142 143bool afxParticlePool::onNewDataBlock(GameBaseData* dptr, bool reload) 144{ 145 mDataBlock = dynamic_cast<afxParticlePoolData*>(dptr); 146 if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload)) 147 return false; 148 149 return true; 150} 151 152bool afxParticlePool::onAdd() 153{ 154 if (!Parent::onAdd()) 155 return false; 156 157 mObjBox.minExtents.set(-0.5, -0.5, -0.5); 158 mObjBox.maxExtents.set( 0.5, 0.5, 0.5); 159 160 resetWorldBox(); 161 162 addToScene(); 163 164 return true; 165}; 166 167void afxParticlePool::onRemove() 168{ 169 removeFromScene(); 170 171 Parent::onRemove(); 172}; 173 174void afxParticlePool::addParticleEmitter(ParticleEmitter* emitter) 175{ 176 emitters.push_back(emitter); 177} 178 179void afxParticlePool::removeParticleEmitter(ParticleEmitter* emitter) 180{ 181 for (U32 i=0; i < emitters.size(); i++) 182 if (emitters[i] == emitter) 183 { 184 emitters.erase(i); 185 break; 186 } 187 188 if (emitters.empty()) 189 { 190 if (choreographer) 191 { 192 choreographer->unregisterParticlePool(this); 193 choreographer = 0; 194 } 195 Sim::postEvent(this, new ObjectDeleteEvent, Sim::getCurrentTime() + 500); 196 } 197} 198 199void afxParticlePool::updatePoolBBox(ParticleEmitter* emitter) 200{ 201 if (emitter->mObjBox.minExtents.x < mObjBox.minExtents.x) 202 mObjBox.minExtents.x = emitter->mObjBox.minExtents.x; 203 if (emitter->mObjBox.minExtents.y < mObjBox.minExtents.y) 204 mObjBox.minExtents.y = emitter->mObjBox.minExtents.y; 205 if (emitter->mObjBox.minExtents.z < mObjBox.minExtents.z) 206 mObjBox.minExtents.z = emitter->mObjBox.minExtents.z; 207 if (emitter->mObjBox.maxExtents.x > mObjBox.maxExtents.x) 208 mObjBox.maxExtents.x = emitter->mObjBox.maxExtents.x; 209 if (emitter->mObjBox.maxExtents.y > mObjBox.maxExtents.y) 210 mObjBox.maxExtents.y = emitter->mObjBox.maxExtents.y; 211 if (emitter->mObjBox.maxExtents.z > mObjBox.maxExtents.z) 212 mObjBox.maxExtents.z = emitter->mObjBox.maxExtents.z; 213 214 resetWorldBox(); 215} 216 217void afxParticlePool::setSortPriority(S8 priority) 218{ 219 if (priority < sort_priority) 220 sort_priority = (priority == 0) ? 1 : priority; 221} 222 223int QSORT_CALLBACK afxParticlePool::cmpSortParticlePool(const void* p1, const void* p2) 224{ 225 const SortParticlePool* sp1 = (const SortParticlePool*)p1; 226 const SortParticlePool* sp2 = (const SortParticlePool*)p2; 227 if (sp2->k > sp1->k) 228 return 1; 229 else if (sp2->k == sp1->k) 230 return 0; 231 else 232 return -1; 233} 234 235//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 236 237