SoundCullObj.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 : WWAudio *
  23. * *
  24. * $Archive:: /Commando/Code/WWAudio/SoundCullObj.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 6/26/01 5:36p $*
  29. * *
  30. * $Revision:: 8 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __SOUNDCULLOBJ_H
  39. #define __SOUNDCULLOBJ_H
  40. #include "soundsceneobj.h"
  41. #include "cullsys.h"
  42. #include "refcount.h"
  43. #include "mempool.h"
  44. #include "multilist.h"
  45. /////////////////////////////////////////////////////////////////////////////
  46. //
  47. // SoundCullObjClass
  48. //
  49. // Simple 'sound physics' object that wraps a SoundClass object and is derived
  50. // from PhysClass so it can be used with the different culling systems.
  51. //
  52. class SoundCullObjClass : public MultiListObjectClass, public CullableClass
  53. {
  54. public:
  55. //////////////////////////////////////////////////////////////////////
  56. // Public constructors/destructors
  57. //////////////////////////////////////////////////////////////////////
  58. SoundCullObjClass (void)
  59. : m_SoundObj (NULL),
  60. m_Transform (1) {}
  61. virtual ~SoundCullObjClass (void) { REF_PTR_RELEASE (m_SoundObj); }
  62. //////////////////////////////////////////////////////////////////////
  63. // Get the 'bounds' of this sound
  64. //////////////////////////////////////////////////////////////////////
  65. virtual const AABoxClass & Get_Bounding_Box (void) const;
  66. //////////////////////////////////////////////////////////////////////
  67. // Access to the Position/Orientation state of the object
  68. //////////////////////////////////////////////////////////////////////
  69. virtual const Matrix3D & Get_Transform (void) const;
  70. virtual void Set_Transform (const Matrix3D &transform);
  71. //////////////////////////////////////////////////////////////////////
  72. // Timestep methods
  73. //////////////////////////////////////////////////////////////////////
  74. virtual void Timestep (float dt) {}
  75. //////////////////////////////////////////////////////////////////////
  76. // Sound object wrapping
  77. //////////////////////////////////////////////////////////////////////
  78. virtual void Set_Sound_Obj (SoundSceneObjClass *sound_obj);
  79. virtual SoundSceneObjClass * Peek_Sound_Obj (void) const { return m_SoundObj; }
  80. protected:
  81. //////////////////////////////////////////////////////////////////////
  82. // Protected methods
  83. //////////////////////////////////////////////////////////////////////
  84. private:
  85. //////////////////////////////////////////////////////////////////////
  86. // Private member data
  87. //////////////////////////////////////////////////////////////////////
  88. SoundSceneObjClass * m_SoundObj;
  89. mutable Matrix3D m_Transform;
  90. mutable AABoxClass m_AABox;
  91. };
  92. __inline const Matrix3D &
  93. SoundCullObjClass::Get_Transform (void) const
  94. {
  95. // Determine the transform to use
  96. if (m_SoundObj != NULL) {
  97. m_Transform = m_SoundObj->Get_Transform ();
  98. }
  99. // Return a reference to the matrix
  100. return m_Transform;
  101. }
  102. __inline void
  103. SoundCullObjClass::Set_Transform (const Matrix3D &transform)
  104. {
  105. m_Transform = transform;
  106. // Pass the tranform on
  107. if (m_SoundObj != NULL) {
  108. m_SoundObj->Set_Transform (m_Transform);
  109. Set_Cull_Box (Get_Bounding_Box ());
  110. }
  111. return ;
  112. }
  113. __inline void
  114. SoundCullObjClass::Set_Sound_Obj (SoundSceneObjClass *sound_obj)
  115. {
  116. // Start using this sound object
  117. REF_PTR_SET (m_SoundObj, sound_obj);
  118. //m_SoundObj = sound_obj;
  119. if (m_SoundObj != NULL) {
  120. m_Transform = m_SoundObj->Get_Transform ();
  121. Set_Cull_Box (Get_Bounding_Box ());
  122. }
  123. return ;
  124. }
  125. __inline const AABoxClass &
  126. SoundCullObjClass::Get_Bounding_Box (void) const
  127. {
  128. // Get the 'real' values from the
  129. if (m_SoundObj != NULL) {
  130. m_Transform = m_SoundObj->Get_Transform ();
  131. m_AABox.Extent.X = m_SoundObj->Get_DropOff_Radius ();
  132. m_AABox.Extent.Y = m_SoundObj->Get_DropOff_Radius ();
  133. m_AABox.Extent.Z = m_SoundObj->Get_DropOff_Radius ();
  134. } else {
  135. m_AABox.Extent.X = 0;
  136. m_AABox.Extent.Y = 0;
  137. m_AABox.Extent.Z = 0;
  138. }
  139. m_AABox.Center = m_Transform.Get_Translation ();
  140. return m_AABox;
  141. }
  142. #endif //__SOUNDCULLOBJ_H