staticaabtreecull.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/staticaabtreecull.h $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 4/19/01 2:41p $*
  31. * *
  32. * $Revision:: 5 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if defined(_MSC_VER)
  38. #pragma once
  39. #endif
  40. #ifndef STATICAABTREECULL_H
  41. #define STATICAABTREECULL_H
  42. #include "always.h"
  43. #include "physaabtreecull.h"
  44. #include "wwdebug.h"
  45. #include "physlist.h"
  46. class VisTableClass;
  47. class CameraClass;
  48. class VisRenderContextClass;
  49. class VisSampleClass;
  50. class ChunkLoadClass;
  51. class ChunkSaveClass;
  52. /*
  53. ** StaticAABTreeCullClass
  54. ** This is a derived axis-aligned bounding box tree for culling static objects.
  55. ** It adds the visibility code to the basic AAB-Tree culling system
  56. */
  57. class StaticAABTreeCullClass : public PhysAABTreeCullClass
  58. {
  59. public:
  60. StaticAABTreeCullClass(PhysicsSceneClass * pscene);
  61. ~StaticAABTreeCullClass(void);
  62. /*
  63. ** StaticAABTreeCullClass over-rides the add and remove methods in order to add
  64. ** vis-data support.
  65. ** NOTE: the objects added should be derived from StaticPhysClass's. This is
  66. ** asserted internally.
  67. */
  68. virtual void Add_Object(PhysClass * obj,int cull_node_id = -1);
  69. virtual void Remove_Object(PhysClass * obj);
  70. virtual void Update_Culling(CullableClass * obj);
  71. /*
  72. ** PhysAABTreeCullClass adds a new collect function which takes the pvs data
  73. ** into account. It also puts objects into one of two lists, separating
  74. ** world-space-meshes from the other objects.
  75. */
  76. void Collect_Visible_Objects( const FrustumClass & frustum,
  77. VisTableClass * pvs,
  78. RefPhysListClass & visobjlist,
  79. RefPhysListClass & wsmeshlist );
  80. /*
  81. ** Save/Load system.
  82. */
  83. virtual void Save_Static_Data(ChunkSaveClass & csave);
  84. virtual void Load_Static_Data(ChunkLoadClass & cload);
  85. protected:
  86. /*
  87. ** VisObjCollectContextClass - this object is passed into the recursive function that collects
  88. ** the visible objects each frame.
  89. */
  90. class VisObjCollectContextClass
  91. {
  92. public:
  93. VisObjCollectContextClass
  94. (
  95. const FrustumClass & frustum,
  96. VisTableClass & pvs,
  97. RefPhysListClass & visobjlist,
  98. RefPhysListClass & wsmeshlist
  99. ) :
  100. Frustum(frustum),
  101. PVS(pvs),
  102. VisObjList(visobjlist),
  103. WSMeshList(wsmeshlist),
  104. PlanesPassed(0)
  105. {
  106. }
  107. const FrustumClass & Frustum;
  108. VisTableClass & PVS;
  109. RefPhysListClass & VisObjList;
  110. RefPhysListClass & WSMeshList;
  111. int PlanesPassed;
  112. };
  113. /*
  114. ** Run-time visiblity support
  115. */
  116. void Collect_Visible_Objects_Recursive(AABTreeNodeClass * node,VisObjCollectContextClass & context);
  117. void Collect_Visible_Objects_No_HVis_Recursive(AABTreeNodeClass * node,VisObjCollectContextClass & context);
  118. int Get_Vis_Sector_ID(const Vector3 & sample_point);
  119. StaticPhysClass * Find_Vis_Tile(const Vector3 & sample_point);
  120. /*
  121. ** Visibility Preprocessing support
  122. */
  123. void Assign_Vis_IDs(void);
  124. void Evaluate_Occluder_Visibility(VisRenderContextClass & context,VisSampleClass & sample);
  125. void Evaluate_Non_Occluder_Visibility(VisRenderContextClass & context,VisSampleClass & sample);
  126. void Render_Occluders(AABTreeNodeClass * node,VisRenderContextClass & context);
  127. void Collect_Non_Occluders(AABTreeNodeClass * node,VisRenderContextClass & context,RefPhysListClass & non_occluder_list);
  128. void Propogate_Hierarchical_Visibility(VisTableClass * pvs);
  129. void Propogate_Hierarchical_Visibility_Recursive(AABTreeNodeClass * node,VisTableClass * pvs);
  130. bool Is_Child_Visible(AABTreeNodeClass * node,VisTableClass * pvs);
  131. /*
  132. ** Visibility Optimization support (preprocessing still)
  133. */
  134. void Merge_Vis_Object_IDs(uint32 id0,uint32 id1);
  135. void Merge_Vis_Sector_IDs(uint32 id0,uint32 id1);
  136. /*
  137. ** Making Physics Scene a friend so that some of the more ugly vis-system interfaces
  138. ** can be accessed by it without exposing them to everyone else...
  139. */
  140. friend class PhysicsSceneClass;
  141. };
  142. #endif //STATICAABTREECULL_H