DynamicAudioEventInfo.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: DynamicAudioEventInfo.cpp /////////////////////////////////////////////////////////////////////////
  24. // Derivation of AudioEventInfo structure, for customized sounds
  25. // Author: Ian Barkley-Yeung, June 2003
  26. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  27. #include "Common/DynamicAudioEventInfo.h"
  28. #include "Common/Xfer.h"
  29. /** Default constructor */
  30. DynamicAudioEventInfo::DynamicAudioEventInfo()
  31. {
  32. }
  33. /** Initialize AudioEventInfo portion of DynamicAudioEventInfo as copy; leave remainder uninitialized */
  34. DynamicAudioEventInfo::DynamicAudioEventInfo( const AudioEventInfo & baseInfo )
  35. : AudioEventInfo( baseInfo )
  36. {
  37. }
  38. DynamicAudioEventInfo::~DynamicAudioEventInfo()
  39. {
  40. }
  41. /** Override; dynamic audio events are used only for level-specific stuff at the moment */
  42. Bool DynamicAudioEventInfo::isLevelSpecific() const
  43. {
  44. return true;
  45. }
  46. /** Override; cheap dynamic casting */
  47. DynamicAudioEventInfo * DynamicAudioEventInfo::getDynamicAudioEventInfo()
  48. {
  49. return this;
  50. }
  51. /** Override; cheap dynamic casting */
  52. const DynamicAudioEventInfo * DynamicAudioEventInfo::getDynamicAudioEventInfo() const
  53. {
  54. return this;
  55. }
  56. /** Override; change the name of this audio event*/
  57. void DynamicAudioEventInfo::overrideAudioName( const AsciiString & newName )
  58. {
  59. // Record new name. Needed later for load & save
  60. m_originalName = m_audioName;
  61. m_overriddenFields.set( OVERRIDE_NAME );
  62. m_audioName = newName;
  63. }
  64. /** Override; change the looping property of this audio event */
  65. void DynamicAudioEventInfo::overrideLoopFlag( Bool newLoopFlag )
  66. {
  67. m_overriddenFields.set( OVERRIDE_LOOP_FLAG );
  68. if ( newLoopFlag)
  69. BitSet( m_control, AC_LOOP );
  70. else
  71. BitClear( m_control, AC_LOOP );
  72. }
  73. /** Override; change the looping properties of this audio event*/
  74. void DynamicAudioEventInfo::overrideLoopCount( Int newLoopCount )
  75. {
  76. m_overriddenFields.set( OVERRIDE_LOOP_COUNT );
  77. m_loopCount = newLoopCount;
  78. }
  79. /** Override; change the volume of this audio event*/
  80. void DynamicAudioEventInfo::overrideVolume( Real newVolume )
  81. {
  82. m_overriddenFields.set( OVERRIDE_VOLUME );
  83. m_volume = newVolume;
  84. }
  85. /** Override; change the minimum volume of this audio event*/
  86. void DynamicAudioEventInfo::overrideMinVolume( Real newMinVolume )
  87. {
  88. m_overriddenFields.set( OVERRIDE_MIN_VOLUME );
  89. m_minVolume = newMinVolume;
  90. }
  91. /** Override; change the name of this audio event*/
  92. void DynamicAudioEventInfo::overrideMinRange( Real newMinRange )
  93. {
  94. m_overriddenFields.set( OVERRIDE_MIN_RANGE );
  95. m_minDistance = newMinRange;
  96. }
  97. /** Override; change the name of this audio event*/
  98. void DynamicAudioEventInfo::overrideMaxRange( Real newMaxRange )
  99. {
  100. m_overriddenFields.set( OVERRIDE_MAX_RANGE );
  101. m_maxDistance = newMaxRange;
  102. }
  103. /** Override; change the name of this audio event*/
  104. void DynamicAudioEventInfo::overridePriority( AudioPriority newPriority )
  105. {
  106. m_overriddenFields.set( OVERRIDE_PRIORITY );
  107. m_priority = newPriority;
  108. }
  109. /** Get the name of the INI entry this event info was derived from */
  110. const AsciiString & DynamicAudioEventInfo::getOriginalName() const
  111. {
  112. if ( wasAudioNameOverriden() )
  113. {
  114. return m_originalName;
  115. }
  116. else
  117. {
  118. return m_audioName;
  119. }
  120. }
  121. /** Transfer all overridden fields except the customized name */
  122. void DynamicAudioEventInfo::xferNoName( Xfer * xfer )
  123. {
  124. const XferVersion currentVersion = 1;
  125. XferVersion version = currentVersion;
  126. xfer->xferVersion( &version, currentVersion );
  127. // The default BitFlags xfer function is really strange. It also requires us to name our
  128. // bits, which I don't want to do, since it forces anyone who has the same number of bits
  129. // as us to use our names. Instead, just transfer directly and count on our local version
  130. // to keep things straight, If you change the list, be sure to change this code too...
  131. if ( xfer->getXferMode() == XFER_LOAD )
  132. {
  133. UnsignedByte overriddenFlags;
  134. DEBUG_ASSERTCRASH( OVERRIDE_COUNT <= sizeof( overriddenFlags ) * 8, ("Save/load code assumes override flags can fit into UnsignedByte, but it doesn't work anymore! Move up to larger integer type") );
  135. xfer->xferUnsignedByte( &overriddenFlags );
  136. Int field;
  137. for ( field = 0; field < OVERRIDE_COUNT; field++ )
  138. {
  139. m_overriddenFields.set( field, BitTest( overriddenFlags, 1 << field ) );
  140. }
  141. }
  142. else
  143. {
  144. UnsignedByte overriddenFlags = 0;
  145. DEBUG_ASSERTCRASH( OVERRIDE_COUNT <= sizeof( overriddenFlags ) * 8, ("Save/load code assumes override flags can fit into UnsignedByte, but it doesn't work anymore! Move up to larger integer type") );
  146. Int field;
  147. for ( field = 0; field < OVERRIDE_COUNT; field++ )
  148. {
  149. if ( m_overriddenFields.test( field ) )
  150. {
  151. BitSet( overriddenFlags, 1 << field );
  152. }
  153. }
  154. xfer->xferUnsignedByte( &overriddenFlags );
  155. }
  156. if ( wasLoopFlagOverriden() )
  157. {
  158. Bool loopFlag = BitTest( m_control, AC_LOOP );
  159. xfer->xferBool( &loopFlag );
  160. if ( loopFlag )
  161. {
  162. BitSet( m_control, AC_LOOP );
  163. }
  164. else
  165. {
  166. BitClear( m_control, AC_LOOP );
  167. }
  168. }
  169. if ( wasLoopCountOverriden() )
  170. {
  171. xfer->xferInt( &m_loopCount );
  172. }
  173. if ( wasVolumeOverriden() )
  174. {
  175. xfer->xferReal( &m_volume );
  176. }
  177. if ( wasMinVolumeOverriden() )
  178. {
  179. xfer->xferReal( &m_minVolume );
  180. }
  181. if ( wasMinRangeOverriden() )
  182. {
  183. xfer->xferReal( &m_minDistance );
  184. }
  185. if ( wasMaxRangeOverriden() )
  186. {
  187. xfer->xferReal( &m_maxDistance );
  188. }
  189. if ( wasPriorityOverriden() )
  190. {
  191. UnsignedByte priority = (UnsignedByte)m_priority;
  192. xfer->xferUnsignedByte( &priority );
  193. m_priority = (AudioPriority)priority;
  194. }
  195. }