cullsys.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 : WWMath *
  23. * *
  24. * $Archive:: /Commando/Code/wwmath/cullsys.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 5/08/01 6:33p $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef CULLSYS_H
  39. #define CULLSYS_H
  40. #include "wwdebug.h"
  41. #include "stdlib.h"
  42. #include "refcount.h"
  43. #include "aabox.h"
  44. class CullableClass;
  45. class CullSystemClass;
  46. class FrustumClass;
  47. /*
  48. ** CullLinkClass
  49. ** This class will serve as a base class for the various types of linkage information
  50. ** that the Cullable instances will need. Each CullableClass will have a pointer to
  51. ** a class derived from CullLinkClass where the different culling systems can store
  52. ** things.
  53. */
  54. class CullLinkClass
  55. {
  56. public:
  57. WWINLINE CullLinkClass(CullSystemClass * system) { System = system; WWASSERT(System); }
  58. virtual ~CullLinkClass(void) { WWASSERT(System == NULL); }
  59. WWINLINE void Set_Culling_System(CullSystemClass * sys) { System = sys; }
  60. WWINLINE CullSystemClass * Get_Culling_System(void) { return System; }
  61. protected:
  62. CullSystemClass * System;
  63. };
  64. /*
  65. ** CullableClass
  66. ** This is the base class for any object that can be inserted into a culling system
  67. ** This class provides an axis aligned bounding box and some linkage variables which
  68. ** allow it to be processed by any culling system.
  69. */
  70. class CullableClass : public RefCountClass
  71. {
  72. public:
  73. CullableClass(void);
  74. virtual ~CullableClass(void);
  75. /*
  76. ** Access to the culling box for this object. When you set the cull box, you are
  77. ** basically guaranteeing that the object is contained within the given box. The
  78. ** object will automatically be updated in whatever culling system it is currently
  79. ** contained in (if any)
  80. */
  81. WWINLINE const AABoxClass & Get_Cull_Box(void) const { return CullBox; }
  82. void Set_Cull_Box(const AABoxClass & box,bool just_loaded = false);
  83. /*
  84. ** These functions are used by various culling systems to manage the linkage
  85. ** pointers. *The average user should NEVER call these*
  86. */
  87. void Set_Culling_System(CullSystemClass * sys);
  88. CullSystemClass * Get_Culling_System(void) const;
  89. WWINLINE void Set_Cull_Link(CullLinkClass * c) { CullLink = c; }
  90. WWINLINE CullLinkClass * Get_Cull_Link(void) const { return CullLink; }
  91. private:
  92. WWINLINE void Set_Next_Collected(CullableClass * c) { NextCollected = c; }
  93. WWINLINE CullableClass * Get_Next_Collected(void) { return NextCollected; }
  94. /*
  95. ** Culling Data
  96. ** Each object can be linked into various types of culling systems.
  97. ** Each culling system can use its own linkage data structure (derived
  98. ** from CullLinkClass) to keep track of the object. The CullData pointer
  99. ** will point to one of the culling link objects and NULL
  100. ** if its not in any system.
  101. */
  102. CullLinkClass * CullLink;
  103. /*
  104. ** Bounding Box
  105. ** Any objects derived from Cullable should update the bounding box
  106. ** whenever the object moves or changes size. In order to do this,
  107. ** call Set_Cull_Box...
  108. */
  109. AABoxClass CullBox;
  110. /*
  111. ** NextCollected
  112. ** This pointer is used by the culling system to keep a singly linked
  113. ** list of cullable object that have been "collected".
  114. */
  115. CullableClass * NextCollected;
  116. // Not Implemented:
  117. CullableClass(const CullableClass & src);
  118. CullableClass & operator = (const CullableClass & src);
  119. friend class CullSystemClass;
  120. };
  121. /*
  122. ** CullSystemClass
  123. ** Base class of any culling system. This interface exists so that things can
  124. ** be shuffled around without having explicit knowledge of what system they are in.
  125. */
  126. class CullSystemClass
  127. {
  128. public:
  129. CullSystemClass(void);
  130. virtual ~CullSystemClass(void);
  131. /*
  132. ** Collect_Objects. Updates the internal collection list with the
  133. ** objects that overlap the given primitive.
  134. ** WARNING: This builds an internal list that is only valid until
  135. ** another list is built, only one list can be valid at any time.
  136. ** WARNING: Always call Reset_Collection if you want to start a
  137. ** fresh collection!
  138. */
  139. void Reset_Collection(void);
  140. virtual void Collect_Objects(const Vector3 & point) = 0;
  141. virtual void Collect_Objects(const AABoxClass & box) = 0;
  142. virtual void Collect_Objects(const OBBoxClass & box) = 0;
  143. virtual void Collect_Objects(const FrustumClass & frustum) = 0;
  144. /*
  145. ** This object has moved or changed size, update it
  146. */
  147. virtual void Update_Culling(CullableClass * obj) = 0;
  148. protected:
  149. /*
  150. ** Iterate through the collected objects
  151. */
  152. CullableClass * Get_First_Collected_Object_Internal(void);
  153. CullableClass * Get_Next_Collected_Object_Internal(CullableClass * obj);
  154. CullableClass * Peek_First_Collected_Object_Internal(void);
  155. CullableClass * Peek_Next_Collected_Object_Internal(CullableClass * obj);
  156. /*
  157. ** Build the list of collected objects
  158. */
  159. void Add_To_Collection(CullableClass * obj);
  160. /*
  161. ** Pointer to the head of the current collection of objects
  162. */
  163. CullableClass * CollectionHead;
  164. friend class CullableClass;
  165. };
  166. #endif