DynamicAudioEventInfo.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.h /////////////////////////////////////////////////////////////////////////
  24. // Derivation of AudioEventInfo structure, for customized sounds
  25. // Author: Ian Barkley-Yeung, June 2003
  26. #pragma once
  27. #ifndef DYNAMICAUDIOEVENTINFO_H_INCLUDED
  28. #define DYNAMICAUDIOEVENTINFO_H_INCLUDED
  29. #include "Common/AudioEventInfo.h"
  30. #include "Common/Bitflags.h"
  31. class AsciiString;
  32. class Xfer;
  33. /*****************************************************************************
  34. * Derivation of AudioEventInfo structure, for customized sounds
  35. *****************************************************************************/
  36. class DynamicAudioEventInfo : public AudioEventInfo
  37. {
  38. // NOTE: This implementation would be a lot cleaner & safer if AudioEventInfo was better
  39. // written. Ideally, AudioEventInfo would be a class, not a struct, and provide only
  40. // "get" functions, not "set" functions except for the INI parsing. Then we could
  41. // force people to go through our override...() functions.
  42. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( DynamicAudioEventInfo, "DynamicAudioEventInfo" )
  43. public:
  44. DynamicAudioEventInfo();
  45. explicit DynamicAudioEventInfo( const AudioEventInfo & baseInfo );
  46. // DynamicAudioEventInfo interfacing function overrides
  47. virtual Bool isLevelSpecific() const;
  48. virtual DynamicAudioEventInfo * getDynamicAudioEventInfo();
  49. virtual const DynamicAudioEventInfo * getDynamicAudioEventInfo() const;
  50. // Change various fields from their default (INI) values
  51. void overrideAudioName( const AsciiString & newName );
  52. void overrideLoopFlag( Bool newLoopFlag );
  53. void overrideLoopCount( Int newLoopCount );
  54. void overrideVolume( Real newVolume );
  55. void overrideMinVolume( Real newMinVolume );
  56. void overrideMinRange( Real newMinRange );
  57. void overrideMaxRange( Real newMaxRange );
  58. void overridePriority( AudioPriority newPriority );
  59. // Query fields to see if they have been changed from their INI values
  60. Bool wasAudioNameOverriden() const;
  61. Bool wasLoopFlagOverriden() const;
  62. Bool wasLoopCountOverriden() const;
  63. Bool wasVolumeOverriden() const;
  64. Bool wasMinVolumeOverriden() const;
  65. Bool wasMinRangeOverriden() const;
  66. Bool wasMaxRangeOverriden() const;
  67. Bool wasPriorityOverriden() const;
  68. // Get the name of the audio event which this was based off of
  69. const AsciiString & getOriginalName() const;
  70. // Transfer all overridden fields except the customized name
  71. void xferNoName( Xfer * xfer );
  72. private:
  73. // List of fields we can override
  74. enum OverriddenFields
  75. {
  76. OVERRIDE_NAME = 0,
  77. OVERRIDE_LOOP_FLAG,
  78. OVERRIDE_LOOP_COUNT,
  79. OVERRIDE_VOLUME,
  80. OVERRIDE_MIN_VOLUME,
  81. OVERRIDE_MIN_RANGE,
  82. OVERRIDE_MAX_RANGE,
  83. OVERRIDE_PRIORITY,
  84. OVERRIDE_COUNT // Keep list
  85. };
  86. // Warning: update xferNoName if you modify the enum list!
  87. BitFlags< OVERRIDE_COUNT > m_overriddenFields;
  88. // Retain the original name so we can look it up later
  89. AsciiString m_originalName;
  90. };
  91. /** Query: was overrideAudioName called? */
  92. inline Bool DynamicAudioEventInfo::wasAudioNameOverriden() const
  93. {
  94. return m_overriddenFields.test( OVERRIDE_NAME );
  95. }
  96. /** Query: was overrideLoopFlag called? */
  97. inline Bool DynamicAudioEventInfo::wasLoopFlagOverriden() const
  98. {
  99. return m_overriddenFields.test( OVERRIDE_LOOP_FLAG );
  100. }
  101. /** Query: was overrideLoopCount called? */
  102. inline Bool DynamicAudioEventInfo::wasLoopCountOverriden() const
  103. {
  104. return m_overriddenFields.test( OVERRIDE_LOOP_COUNT );
  105. }
  106. /** Query: was overrideVolume called? */
  107. inline Bool DynamicAudioEventInfo::wasVolumeOverriden() const
  108. {
  109. return m_overriddenFields.test( OVERRIDE_VOLUME );
  110. }
  111. /** Query: was overrideMinVolume called? */
  112. inline Bool DynamicAudioEventInfo::wasMinVolumeOverriden() const
  113. {
  114. return m_overriddenFields.test( OVERRIDE_MIN_VOLUME );
  115. }
  116. /** Query: was overrideMinRange called? */
  117. inline Bool DynamicAudioEventInfo::wasMinRangeOverriden() const
  118. {
  119. return m_overriddenFields.test( OVERRIDE_MIN_RANGE );
  120. }
  121. /** Query: was overrideMaxRange called? */
  122. inline Bool DynamicAudioEventInfo::wasMaxRangeOverriden() const
  123. {
  124. return m_overriddenFields.test( OVERRIDE_MAX_RANGE );
  125. }
  126. /** Query: was overridePriority called? */
  127. inline Bool DynamicAudioEventInfo::wasPriorityOverriden() const
  128. {
  129. return m_overriddenFields.test( OVERRIDE_PRIORITY );
  130. }
  131. #endif // DYNAMICAUDIOEVENTINFO_H_INCLUDED