Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
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"
23#include "lib/types.h"
26
27#include <vector>
28
29class CVector3D;
30
32{
33 eRandOrder = 0x01,
34 eRandGain = 0x02,
35 eRandPitch = 0x04,
36 eLoop = 0x08,
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{
47public:
48 CSoundGroup(const VfsPath& pathnameXML);
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
76private:
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;
101 // Distance attenuation settings
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;
112 // Up to eight individual parameters, use with eSndGrpFlags.
114};
115
116#endif //#ifndef INCLUDED_SOUNDGROUP_H
eSndGrpFlags
Definition: SoundGroup.h:32
@ eRandPitch
Definition: SoundGroup.h:35
@ eLoop
Definition: SoundGroup.h:36
@ eOmnipresent
Definition: SoundGroup.h:37
@ eDistanceless
Definition: SoundGroup.h:38
@ eOwnerOnly
Definition: SoundGroup.h:39
@ eRandOrder
Definition: SoundGroup.h:33
@ eRandGain
Definition: SoundGroup.h:34
Definition: SoundGroup.h:45
u32 m_Seed
Definition: SoundGroup.h:86
float m_Decay
Definition: SoundGroup.h:97
float m_GainUpper
Definition: SoundGroup.h:99
void UploadPropertiesAndPlay(size_t theIndex, const CVector3D &position, entity_id_t source)
Definition: SoundGroup.cpp:190
float m_MinDist
Definition: SoundGroup.h:102
bool LoadSoundGroup(const VfsPath &pathnameXML)
Definition: SoundGroup.cpp:306
CSoundGroup()
Definition: SoundGroup.cpp:119
float m_PitchUpper
Definition: SoundGroup.h:110
void Reload()
Definition: SoundGroup.cpp:268
void SetGain(float gain)
Definition: SoundGroup.cpp:83
void ReleaseGroup()
Definition: SoundGroup.cpp:292
float m_MaxStereoAngle
Definition: SoundGroup.h:105
void SetFlag(int flag)
Definition: SoundGroup.h:71
bool TestFlag(int flag)
Definition: SoundGroup.h:74
float m_Pitch
Definition: SoundGroup.h:108
std::vector< std::wstring > m_Filenames
Definition: SoundGroup.h:88
NONCOPYABLE(CSoundGroup)
void PlayNext(const CVector3D &position, entity_id_t source)
Definition: SoundGroup.cpp:259
std::vector< CSoundData * > m_SoundGroups
Definition: SoundGroup.h:84
float m_Priority
Definition: SoundGroup.h:111
void Update(float TimeSinceLastFrame)
Definition: SoundGroup.cpp:302
float m_CurTime
Definition: SoundGroup.h:96
VfsPath m_Filepath
Definition: SoundGroup.h:90
float m_IntensityThreshold
Definition: SoundGroup.h:107
float RadiansOffCenter(const CVector3D &position, bool &onScreen, float &itemRollOff)
Definition: SoundGroup.cpp:136
float m_MaxDist
Definition: SoundGroup.h:103
float m_PitchLower
Definition: SoundGroup.h:109
void SetDefaultValues()
Definition: SoundGroup.cpp:88
float m_Gain
Definition: SoundGroup.h:98
float m_ConeOuterAngle
Definition: SoundGroup.h:93
~CSoundGroup()
Definition: SoundGroup.cpp:130
float m_ConeInnerAngle
Definition: SoundGroup.h:92
size_t m_CurrentSoundIndex
Definition: SoundGroup.h:91
float m_ConeOuterGain
Definition: SoundGroup.h:94
u8 m_Flags
Definition: SoundGroup.h:113
float m_GainLower
Definition: SoundGroup.h:100
Definition: Vector3D.h:31
Definition: path.h:80
u32 entity_id_t
Entity ID type.
Definition: Entity.h:29
uint8_t u8
Definition: types.h:37
uint32_t u32
Definition: types.h:39