Pyrogenesis  trunk
SoundGroup.h
Go to the documentation of this file.
1 /* Copyright (C) 2021 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_SOUNDGROUP_H
19 #define INCLUDED_SOUNDGROUP_H
20 
21 #include "lib/config2.h"
22 #include "lib/file/vfs/vfs_path.h"
23 #include "lib/types.h"
26 
27 #include <vector>
28 
29 class CVector3D;
30 
32 {
33  eRandOrder = 0x01,
34  eRandGain = 0x02,
35  eRandPitch = 0x04,
36  eLoop = 0x08,
37  eOmnipresent = 0x10,
38  eDistanceless = 0x20,
39  eOwnerOnly = 0x40
40 };
41 
42 // Loads up a group of sound files with shared properties,
43 // and provides a simple interface for playing them.
45 {
47 public:
48  CSoundGroup(const VfsPath& pathnameXML);
49  CSoundGroup();
50  ~CSoundGroup();
51 
52  // Play next sound in group
53  // @param position world position of the entity generating the sound
54  // (ignored if the eOmnipresent flag is set)
55  void PlayNext(const CVector3D& position, entity_id_t source);
56 
57  float RadiansOffCenter(const CVector3D& position, bool& onScreen, float& itemRollOff);
58 
59  // Load a group
60  bool LoadSoundGroup(const VfsPath& pathnameXML);
61 
62  void Reload();
63 
64  // Release all remaining loaded handles
65  void ReleaseGroup();
66 
67  // Update SoundGroup, remove dead sounds from intensity count
68  void Update(float TimeSinceLastFrame);
69 
70  // Set a flag using a value from eSndGrpFlags
71  inline void SetFlag(int flag) { m_Flags = (unsigned char)(m_Flags | flag); }
72 
73  // Test flag, returns true if flag is set.
74  inline bool TestFlag(int flag) { return (m_Flags & flag) != 0; }
75 
76 private:
77  void SetGain(float gain);
78 
79  void UploadPropertiesAndPlay(size_t theIndex, const CVector3D& position, entity_id_t source);
80 
81  void SetDefaultValues();
82 #if CONFIG2_AUDIO
83  // We store the handles so we can load now and play later
84  std::vector<CSoundData*> m_SoundGroups;
85 #endif
87  // We need the filenames so we can reload when necessary.
88  std::vector<std::wstring> m_Filenames;
89  // The file path for the list of sound file resources
95  // Time elapsed since soundgroup was created
96  float m_CurTime;
97  float m_Decay;
98  float m_Gain;
99  float m_GainUpper;
100  float m_GainLower;
101  // Distance attenuation settings
102  float m_MinDist;
103  float m_MaxDist;
104  // How much stereo separation to apply to sounds based on L-R position relative to the camera.
106  // The allowable intensity before a sound switch
108  float m_Pitch;
111  float m_Priority;
112  // Up to eight individual parameters, use with eSndGrpFlags.
114 };
115 
116 #endif //#ifndef INCLUDED_SOUNDGROUP_H
Definition: SoundGroup.h:39
float m_Gain
Definition: SoundGroup.h:98
Definition: SoundGroup.h:37
Definition: SoundGroup.h:35
float m_Pitch
Definition: SoundGroup.h:108
float m_MinDist
Definition: SoundGroup.h:102
CSoundGroup()
Definition: SoundGroup.cpp:119
u32 m_Seed
Definition: SoundGroup.h:86
float m_GainUpper
Definition: SoundGroup.h:99
void SetDefaultValues()
Definition: SoundGroup.cpp:88
void UploadPropertiesAndPlay(size_t theIndex, const CVector3D &position, entity_id_t source)
Definition: SoundGroup.cpp:190
void SetFlag(int flag)
Definition: SoundGroup.h:71
Definition: Vector3D.h:30
Definition: SoundGroup.h:33
void Update(float TimeSinceLastFrame)
Definition: SoundGroup.cpp:302
uint8_t u8
Definition: types.h:37
size_t m_CurrentSoundIndex
Definition: SoundGroup.h:91
float RadiansOffCenter(const CVector3D &position, bool &onScreen, float &itemRollOff)
Definition: SoundGroup.cpp:136
Definition: SoundGroup.h:38
bool LoadSoundGroup(const VfsPath &pathnameXML)
Definition: SoundGroup.cpp:306
float m_Priority
Definition: SoundGroup.h:111
float m_ConeInnerAngle
Definition: SoundGroup.h:92
u8 m_Flags
Definition: SoundGroup.h:113
float m_CurTime
Definition: SoundGroup.h:96
uint32_t u32
Definition: types.h:39
std::vector< CSoundData * > m_SoundGroups
Definition: SoundGroup.h:84
Definition: path.h:79
VfsPath m_Filepath
Definition: SoundGroup.h:90
float m_Decay
Definition: SoundGroup.h:97
float m_MaxStereoAngle
Definition: SoundGroup.h:105
float m_ConeOuterGain
Definition: SoundGroup.h:94
float m_ConeOuterAngle
Definition: SoundGroup.h:93
float m_MaxDist
Definition: SoundGroup.h:103
std::vector< std::wstring > m_Filenames
Definition: SoundGroup.h:88
void Reload()
Definition: SoundGroup.cpp:268
Definition: SoundGroup.h:44
float m_PitchUpper
Definition: SoundGroup.h:110
eSndGrpFlags
Definition: SoundGroup.h:31
void ReleaseGroup()
Definition: SoundGroup.cpp:292
float m_GainLower
Definition: SoundGroup.h:100
NONCOPYABLE(CSoundGroup)
void SetGain(float gain)
Definition: SoundGroup.cpp:83
~CSoundGroup()
Definition: SoundGroup.cpp:130
Definition: SoundGroup.h:36
float m_PitchLower
Definition: SoundGroup.h:109
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
bool TestFlag(int flag)
Definition: SoundGroup.h:74
Definition: SoundGroup.h:34
float m_IntensityThreshold
Definition: SoundGroup.h:107
void PlayNext(const CVector3D &position, entity_id_t source)
Definition: SoundGroup.cpp:259