afxResidueMgr.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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_RESIDUE_MGR_H_
  25. #define _AFX_RESIDUE_MGR_H_
  26. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  27. class afxZodiacData;
  28. class afxModel;
  29. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  30. // afxResidueMgr
  31. //
  32. // Manage transient objects in the world.
  33. class afxResidueMgr : public GameBase
  34. {
  35. typedef GameBase Parent;
  36. enum {
  37. ZODIAC,
  38. MODEL
  39. };
  40. struct Residue
  41. {
  42. struct ZodiacParams
  43. {
  44. F32 pos_x, pos_y, pos_z;
  45. F32 rad, vrange_dn, vrange_up;
  46. U8 r,g,b,a;
  47. F32 ang;
  48. bool on_terrain;
  49. };
  50. union ResidueParams
  51. {
  52. ZodiacParams zodiac;
  53. };
  54. union ResidueData
  55. {
  56. afxZodiacData* zodiac;
  57. afxModel* model;
  58. SimObject* simobject;
  59. };
  60. U32 type;
  61. ResidueData data;
  62. ResidueParams params;
  63. U32 fade_time;
  64. U32 stop_time;
  65. F32 fade;
  66. Residue* next;
  67. };
  68. class ResidueList
  69. {
  70. Vector<Residue*> m_array_a;
  71. Vector<Residue*> m_array_b;
  72. Vector<Residue*>* m_array;
  73. Vector<Residue*>* m_scratch_array;
  74. bool m_dirty;
  75. S32 m_pending;
  76. void swap_array_ptrs();
  77. void free_residue(Residue*);
  78. public:
  79. /*C*/ ResidueList();
  80. /*D*/ ~ResidueList();
  81. void clear();
  82. S32 size() { return m_array->size(); }
  83. bool empty() { return m_array->empty(); }
  84. void sortIfDirty() { if (m_dirty) sort(); }
  85. void sort();
  86. void fadeAndCull(U32 now);
  87. void stripMatchingObjects(SimObject* db, bool del_notify=false);
  88. void add(Residue*);
  89. void manage();
  90. U32 findPendingBestBump(U32 look_max=256);
  91. void bumpPending();
  92. static int QSORT_CALLBACK compare_residue(const void* p1, const void* p2);
  93. };
  94. friend class ResidueList;
  95. private:
  96. enum { FREE_POOL_BLOCK_SIZE = 256 };
  97. static afxResidueMgr* the_mgr;
  98. static U32 m_max_residue_objs;
  99. static bool enabled;
  100. ResidueList m_managed;
  101. Vector<Residue*> m_free_pool_blocks;
  102. Residue* m_next_free;
  103. Residue* alloc_free_pool_block();
  104. Residue* alloc_residue();
  105. void free_residue(Residue*);
  106. void bump_residue();
  107. void add_residue(Residue*);
  108. static void add_zodiac(F32 dur, F32 fade_dur, afxZodiacData*, const Point3F& pos, F32 rad,
  109. const Point2F& vrange, const LinearColorF& col, F32 ang, bool on_terrain);
  110. protected:
  111. void deleteResidueObject(SimObject* obj, bool del_notify=false);
  112. void manage_residue(const Residue* r);
  113. bool requires_delete_tracking(Residue*);
  114. void enable_delete_tracking(Residue*);
  115. void disable_delete_tracking(Residue*);
  116. public:
  117. /*C*/ afxResidueMgr();
  118. /*D*/ ~afxResidueMgr();
  119. void cleanup();
  120. virtual void onDeleteNotify(SimObject *obj);
  121. public:
  122. void residueAdvanceTime();
  123. // ZODIAC
  124. static void add_terrain_zodiac(F32 dur, F32 fade_dur, afxZodiacData*, const Point3F& pos, F32 rad,
  125. const LinearColorF& col, F32 ang);
  126. static void add_interior_zodiac(F32 dur, F32 fade_dur, afxZodiacData*, const Point3F& pos, F32 rad,
  127. const Point2F& vrange, const LinearColorF& col, F32 ang);
  128. // MODEL
  129. static void add(F32 dur, F32 fade_dur, afxModel*);
  130. static afxResidueMgr* getMaster() { return the_mgr; }
  131. static void setMaster(afxResidueMgr* m) { the_mgr = m; }
  132. DECLARE_CONOBJECT(afxResidueMgr);
  133. DECLARE_CATEGORY("AFX");
  134. };
  135. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  136. #endif // _AFX_RESIDUE_MGR_H_