afxParticlePool.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #ifndef _AFX_PARTICLE_POOL_H_
  25. #define _AFX_PARTICLE_POOL_H_
  26. class afxParticlePoolData : public GameBaseData
  27. {
  28. private:
  29. typedef GameBaseData Parent;
  30. public:
  31. enum PoolType
  32. {
  33. POOL_NORMAL,
  34. POOL_TWOPASS
  35. };
  36. U32 pool_type;
  37. LinearColorF base_color;
  38. F32 blend_weight;
  39. public:
  40. /*C*/ afxParticlePoolData();
  41. /*C*/ afxParticlePoolData(const afxParticlePoolData&, bool = false);
  42. /*D*/ ~afxParticlePoolData();
  43. virtual void packData(BitStream*);
  44. virtual void unpackData(BitStream*);
  45. virtual bool allowSubstitutions() const { return true; }
  46. static void initPersistFields();
  47. DECLARE_CONOBJECT(afxParticlePoolData);
  48. DECLARE_CATEGORY("AFX");
  49. };
  50. typedef afxParticlePoolData::PoolType afxParticlePool_PoolType;
  51. DefineEnumType( afxParticlePool_PoolType );
  52. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  53. struct Particle;
  54. class ParticleEmitter;
  55. class afxChoreographer;
  56. typedef Vector<ParticleEmitter*> ParticleEmitterList;
  57. class afxParticlePool : public GameBase
  58. {
  59. typedef GameBase Parent;
  60. class ObjectDeleteEvent : public SimEvent
  61. {
  62. public:
  63. void process(SimObject *obj) { if (obj) obj->deleteObject(); }
  64. };
  65. struct SortParticlePool
  66. {
  67. Particle* p;
  68. F32 k; // interpreted differently depending on rendering method
  69. ParticleEmitter* emitter;
  70. };
  71. private:
  72. afxParticlePoolData* mDataBlock;
  73. afxParticlePoolData* key_block;
  74. U32 key_index;
  75. ParticleEmitterList emitters;
  76. afxChoreographer* choreographer;
  77. S8 sort_priority;
  78. static Vector<SortParticlePool> orderedVector;
  79. static int QSORT_CALLBACK cmpSortParticlePool(const void* p1, const void* p2);
  80. S32 mCurBuffSize;
  81. GFXVertexBufferHandle<GFXVertexPCT> mVertBuff;
  82. S32 mCurBuffSize2;
  83. GFXVertexBufferHandle<GFXVertexPCT> mVertBuff2;
  84. protected:
  85. virtual void prepRenderImage(SceneRenderState*);
  86. void pool_prepBatchRender(RenderPassManager*, const Point3F &camPos, const LinearColorF &ambientColor);
  87. void pool_renderObject_Normal(RenderPassManager*, const Point3F &camPos, const LinearColorF &ambientColor);
  88. void pool_renderObject_TwoPass(RenderPassManager*, const Point3F &camPos, const LinearColorF &ambientColor);
  89. virtual bool onAdd();
  90. virtual void onRemove();
  91. void renderBillboardParticle_blend(Particle&, const Point3F* basePnts, const MatrixF& camView, const F32 spinFactor,
  92. const F32 blend_factor, ParticleEmitter*);
  93. void renderBillboardParticle_color(Particle&, const Point3F* basePnts, const MatrixF& camView, const F32 spinFactor,
  94. const LinearColorF& color, ParticleEmitter*);
  95. public:
  96. /*C*/ afxParticlePool();
  97. /*D*/ ~afxParticlePool();
  98. virtual bool onNewDataBlock(GameBaseData* dptr, bool reload);
  99. void addParticleEmitter(ParticleEmitter*);
  100. void removeParticleEmitter(ParticleEmitter*);
  101. void setChoreographer(afxChoreographer* ch) { choreographer = ch; }
  102. void setKeyBlock(afxParticlePoolData* db, U32 idx) { key_block = db; key_index = idx; }
  103. bool hasMatchingKeyBlock(const afxParticlePoolData* db, U32 idx) const { return (db == key_block && idx == key_index); }
  104. void updatePoolBBox(ParticleEmitter*);
  105. void setSortPriority(S8 priority);
  106. DECLARE_CONOBJECT(afxParticlePool);
  107. DECLARE_CATEGORY("AFX");
  108. };
  109. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  110. #endif // _AFX_PARTICLE_POOL_H_