afxParticlePool.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. void packData(BitStream*) override;
  44. void unpackData(BitStream*) override;
  45. bool allowSubstitutions() const override { return true; }
  46. static void initPersistFields();
  47. DECLARE_CONOBJECT(afxParticlePoolData);
  48. };
  49. typedef afxParticlePoolData::PoolType afxParticlePool_PoolType;
  50. DefineEnumType( afxParticlePool_PoolType );
  51. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  52. struct Particle;
  53. class ParticleEmitter;
  54. class afxChoreographer;
  55. typedef Vector<ParticleEmitter*> ParticleEmitterList;
  56. class afxParticlePool : public GameBase
  57. {
  58. typedef GameBase Parent;
  59. class ObjectDeleteEvent : public SimEvent
  60. {
  61. public:
  62. void process(SimObject *obj) override { if (obj) obj->deleteObject(); }
  63. };
  64. struct SortParticlePool
  65. {
  66. Particle* p;
  67. F32 k; // interpreted differently depending on rendering method
  68. ParticleEmitter* emitter;
  69. };
  70. private:
  71. afxParticlePoolData* mDataBlock;
  72. afxParticlePoolData* key_block;
  73. U32 key_index;
  74. ParticleEmitterList emitters;
  75. afxChoreographer* choreographer;
  76. S8 sort_priority;
  77. static Vector<SortParticlePool> orderedVector;
  78. static int QSORT_CALLBACK cmpSortParticlePool(const void* p1, const void* p2);
  79. S32 mCurBuffSize;
  80. GFXVertexBufferHandle<GFXVertexPCT> mVertBuff;
  81. S32 mCurBuffSize2;
  82. GFXVertexBufferHandle<GFXVertexPCT> mVertBuff2;
  83. protected:
  84. void prepRenderImage(SceneRenderState*) override;
  85. void pool_prepBatchRender(RenderPassManager*, const Point3F &camPos, const LinearColorF &ambientColor);
  86. void pool_renderObject_Normal(RenderPassManager*, const Point3F &camPos, const LinearColorF &ambientColor);
  87. void pool_renderObject_TwoPass(RenderPassManager*, const Point3F &camPos, const LinearColorF &ambientColor);
  88. bool onAdd() override;
  89. void onRemove() override;
  90. void renderBillboardParticle_blend(Particle&, const Point3F* basePnts, const MatrixF& camView, const F32 spinFactor,
  91. const F32 blend_factor, ParticleEmitter*);
  92. void renderBillboardParticle_color(Particle&, const Point3F* basePnts, const MatrixF& camView, const F32 spinFactor,
  93. const LinearColorF& color, ParticleEmitter*);
  94. public:
  95. /*C*/ afxParticlePool();
  96. /*D*/ ~afxParticlePool();
  97. bool onNewDataBlock(GameBaseData* dptr, bool reload) override;
  98. void addParticleEmitter(ParticleEmitter*);
  99. void removeParticleEmitter(ParticleEmitter*);
  100. void setChoreographer(afxChoreographer* ch) { choreographer = ch; }
  101. void setKeyBlock(afxParticlePoolData* db, U32 idx) { key_block = db; key_index = idx; }
  102. bool hasMatchingKeyBlock(const afxParticlePoolData* db, U32 idx) const { return (db == key_block && idx == key_index); }
  103. void updatePoolBBox(ParticleEmitter*);
  104. void setSortPriority(S8 priority);
  105. DECLARE_CONOBJECT(afxParticlePool);
  106. };
  107. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  108. #endif // _AFX_PARTICLE_POOL_H_