cullsys.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. ** Command & Conquer Generals(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:: /VSS_Sync/wwmath/cullsys.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 10/16/00 11:42a $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "cullsys.h"
  36. #include "wwdebug.h"
  37. #include "wwprofile.h"
  38. /*************************************************************************
  39. **
  40. ** CullableClass Implementation
  41. **
  42. *************************************************************************/
  43. CullableClass::CullableClass(void) :
  44. CullLink(NULL),
  45. NextCollected(NULL)
  46. {
  47. CullBox.Init(Vector3(0,0,0),Vector3(1,1,1));
  48. }
  49. CullableClass::~CullableClass(void)
  50. {
  51. // the cull system that contains us is responsible for any culling link
  52. // so we better be out of it and it should have cleared our pointer before
  53. // we are deleted.
  54. WWASSERT(CullLink == NULL);
  55. }
  56. void CullableClass::Set_Cull_Box(const AABoxClass & box,bool just_loaded)
  57. {
  58. CullBox = box;
  59. WWPROFILE("Cullable::Set_Cull_Box");
  60. // Just_loaded flag allows us to update the box without notifying the
  61. // culling system. Use this when you've saved and loaded the linkage
  62. // so you know you're in the right node of the culling system...
  63. if (!just_loaded) {
  64. CullSystemClass * sys = Get_Culling_System();
  65. if (sys != NULL) {
  66. sys->Update_Culling(this);
  67. }
  68. }
  69. }
  70. void CullableClass::Set_Culling_System(CullSystemClass * sys)
  71. {
  72. if (CullLink) {
  73. CullLink->Set_Culling_System(sys);
  74. }
  75. }
  76. CullSystemClass * CullableClass::Get_Culling_System(void) const
  77. {
  78. if (CullLink) {
  79. return CullLink->Get_Culling_System();
  80. }
  81. return NULL;
  82. }
  83. /*************************************************************************
  84. **
  85. ** CullSystemClass Implementation
  86. **
  87. ** The base CullSystemClass mainly contains code for maintaining the
  88. ** current collection list and iterating through it.
  89. **
  90. *************************************************************************/
  91. CullSystemClass::CullSystemClass(void) :
  92. CollectionHead(NULL)
  93. {
  94. }
  95. CullSystemClass::~CullSystemClass(void)
  96. {
  97. }
  98. // NOTE: THE Get_() functions currently are the same as the Peek_() functions (e.g., they do not
  99. // add a Ref). This is wrong and will be fixed.
  100. CullableClass * CullSystemClass::Get_First_Collected_Object_Internal(void)
  101. {
  102. return CollectionHead;
  103. }
  104. CullableClass * CullSystemClass::Get_Next_Collected_Object_Internal(CullableClass * obj)
  105. {
  106. if (obj != NULL) {
  107. return obj->NextCollected;
  108. }
  109. return NULL;
  110. }
  111. CullableClass * CullSystemClass::Peek_First_Collected_Object_Internal(void)
  112. {
  113. return CollectionHead;
  114. }
  115. CullableClass * CullSystemClass::Peek_Next_Collected_Object_Internal(CullableClass * obj)
  116. {
  117. if (obj != NULL) {
  118. return obj->NextCollected;
  119. }
  120. return NULL;
  121. }
  122. void CullSystemClass::Reset_Collection(void)
  123. {
  124. CollectionHead = NULL;
  125. }
  126. void CullSystemClass::Add_To_Collection(CullableClass * obj)
  127. {
  128. WWASSERT(obj != NULL);
  129. obj->NextCollected = CollectionHead;
  130. CollectionHead = obj;
  131. }