AudioEventRTS.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: AudioEventRTS.h ///////////////////////////////////////////////////////////////////////////////
  24. // AudioEventRTS structure
  25. // Author: John K. McDonald, March 2002
  26. #pragma once
  27. #ifndef _H_AUDIOEVENTRTS_
  28. #define _H_AUDIOEVENTRTS_
  29. #include "Common/AsciiString.h"
  30. #include "Common/GameAudio.h"
  31. #include "Common/GameMemory.h"
  32. #include "Common/GameType.h"
  33. // forward declarations ///////////////////////////////////////////////////////////////////////////
  34. struct AudioEventInfo;
  35. enum OwnerType
  36. {
  37. OT_Positional,
  38. OT_Drawable,
  39. OT_Object,
  40. OT_Dead,
  41. OT_INVALID
  42. };
  43. enum PortionToPlay
  44. {
  45. PP_Attack,
  46. PP_Sound,
  47. PP_Decay,
  48. PP_Done
  49. };
  50. enum AudioPriority;
  51. // This is called AudioEventRTS because AudioEvent is a typedef in ww3d
  52. // You might want this to be memory pooled (I personally do), but it can't
  53. // because we allocate them on the stack frequently.
  54. class AudioEventRTS
  55. {
  56. public:
  57. AudioEventRTS( );
  58. AudioEventRTS( const AsciiString& eventName );
  59. AudioEventRTS( const AsciiString& eventName, ObjectID ownerID );
  60. AudioEventRTS( const AsciiString& eventName, DrawableID drawableID ); // Pass 0 for unused if attaching to drawable
  61. AudioEventRTS( const AsciiString& eventName, const Coord3D *positionOfAudio );
  62. virtual ~AudioEventRTS( );
  63. AudioEventRTS( const AudioEventRTS& right );
  64. AudioEventRTS& operator=( const AudioEventRTS& right );
  65. void setEventName( AsciiString name );
  66. const AsciiString& getEventName( void ) const { return m_eventName; }
  67. // generateFilename is separate from generatePlayInfo because generatePlayInfo should only be called once
  68. // per triggered event. generateFilename will be called once per loop, or once to get each filename if 'all' is
  69. // specified.
  70. void generateFilename( void );
  71. AsciiString getFilename( void );
  72. // The attack and decay sounds are generated in generatePlayInfo, because they will never be played more
  73. // than once during a given sound event.
  74. void generatePlayInfo( void );
  75. Real getPitchShift( void ) const;
  76. Real getVolumeShift( void ) const;
  77. AsciiString getAttackFilename( void ) const;
  78. AsciiString getDecayFilename( void ) const;
  79. Real getDelay( void ) const;
  80. void decrementDelay( Real timeToDecrement );
  81. PortionToPlay getNextPlayPortion( void ) const;
  82. void advanceNextPlayPortion( void );
  83. void setNextPlayPortion( PortionToPlay ptp );
  84. void decreaseLoopCount( void );
  85. Bool hasMoreLoops( void ) const;
  86. void setAudioEventInfo( const AudioEventInfo *eventInfo ) const;
  87. const AudioEventInfo *getAudioEventInfo( void ) const;
  88. void setPlayingHandle( AudioHandle handle ); // for ID of this audio piece.
  89. AudioHandle getPlayingHandle( void ); // for ID of this audio piece
  90. void setPosition( const Coord3D *pos );
  91. const Coord3D* getPosition( void );
  92. void setObjectID( ObjectID objID );
  93. ObjectID getObjectID( void );
  94. Bool isDead() const { return m_ownerType == OT_Dead; }
  95. OwnerType getOwnerType() const { return m_ownerType; }
  96. void setDrawableID( DrawableID drawID );
  97. DrawableID getDrawableID( void );
  98. void setTimeOfDay( TimeOfDay tod );
  99. TimeOfDay getTimeOfDay( void ) const;
  100. void setHandleToKill( AudioHandle handleToKill );
  101. AudioHandle getHandleToKill( void ) const;
  102. void setShouldFade( Bool shouldFade );
  103. Bool getShouldFade( void ) const;
  104. void setIsLogicalAudio( Bool isLogicalAudio );
  105. Bool getIsLogicalAudio( void ) const;
  106. Bool isPositionalAudio( void ) const;
  107. Bool isCurrentlyPlaying( void ) const;
  108. AudioPriority getAudioPriority( void ) const;
  109. void setAudioPriority( AudioPriority newPriority );
  110. Real getVolume( void ) const;
  111. void setVolume( Real vol );
  112. Int getPlayerIndex( void ) const;
  113. void setPlayerIndex( Int playerNdx );
  114. Int getPlayingAudioIndex( void ) { return m_playingAudioIndex; };
  115. void setPlayingAudioIndex( Int pai ) { m_playingAudioIndex = pai; };
  116. Bool getUninterruptable( ) const { return m_uninterruptable; }
  117. void setUninterruptable( Bool uninterruptable ) { m_uninterruptable = uninterruptable; }
  118. // This will retrieve the appropriate position based on type.
  119. const Coord3D *getCurrentPosition( void );
  120. // This will return the directory leading up to the appropriate type, including the trailing '\\'
  121. // If localized is true, we'll append a language specifc directory to the end of the path.
  122. AsciiString generateFilenamePrefix( AudioType audioTypeToPlay, Bool localized );
  123. AsciiString generateFilenameExtension( AudioType audioTypeToPlay );
  124. protected:
  125. void adjustForLocalization( AsciiString &strToAdjust );
  126. protected:
  127. AsciiString m_filenameToLoad;
  128. mutable const AudioEventInfo *m_eventInfo; // Mutable so that it can be modified even on const objects
  129. AudioHandle m_playingHandle;
  130. AudioHandle m_killThisHandle; ///< Sometimes sounds will canabilize other sounds in order to take their handle away.
  131. ///< This is one of those instances.
  132. AsciiString m_eventName; ///< This should correspond with an entry in Dialog.ini, Speech.ini, or Audio.ini
  133. AsciiString m_attackName; ///< This is the filename that should be used during the attack.
  134. AsciiString m_decayName; ///< This is the filename that should be used during the decay.
  135. AudioPriority m_priority; ///< This should be the priority as given by the event info, or the overrided priority.
  136. Real m_volume; ///< This is the override for the volume. It will either be the normal
  137. TimeOfDay m_timeOfDay; ///< This should be the current Time Of Day.
  138. Coord3D m_positionOfAudio; ///< Position of the sound if no further positional updates are necessary
  139. union // These are now unioned.
  140. {
  141. ObjectID m_objectID; ///< ObjectID of the object that this sound is tied to. Position can be automatically updated from this.
  142. DrawableID m_drawableID; ///< DrawableID of the drawable that owns this sound
  143. };
  144. OwnerType m_ownerType;
  145. Bool m_shouldFade; ///< This should fade in or out (if it is starting or stopping)
  146. Bool m_isLogicalAudio; ///< Should probably only be true for scripted sounds
  147. Bool m_uninterruptable;
  148. // Playing attributes
  149. Real m_pitchShift; ///< Pitch shift that should occur on this piece of audio
  150. Real m_volumeShift; ///< Volume shift that should occur on this piece of audio
  151. Real m_delay; ///< Amount to delay before playing this sound
  152. Int m_loopCount; ///< The current loop count value. Only valid if this is a looping type event or the override has been set.
  153. Int m_playingAudioIndex; ///< The sound index we are currently playing. In the case of non-random, we increment this to move to the next sound
  154. Int m_allCount; ///< If this sound is an ALL type, then this is how many sounds we have played so far.
  155. Int m_playerIndex; ///< The index of the player who owns this sound. Used for sounds that should have an owner, but don't have an object, etc.
  156. PortionToPlay m_portionToPlayNext; ///< Which portion (attack, sound, decay) should be played next?
  157. };
  158. class DynamicAudioEventRTS : public MemoryPoolObject
  159. {
  160. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(DynamicAudioEventRTS, "DynamicAudioEventRTS" )
  161. public:
  162. DynamicAudioEventRTS() { }
  163. DynamicAudioEventRTS(const AudioEventRTS& a) : m_event(a) { }
  164. AudioEventRTS m_event;
  165. };
  166. EMPTY_DTOR(DynamicAudioEventRTS)
  167. #endif /* _H_AUDIOEVENTRTS_ */