1 /* Copyright (C) 2017 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
18 #ifndef INCLUDED_SOUNDMANAGER_H
19 #define INCLUDED_SOUNDMANAGER_H
21 #include "lib/config2.h"
25 #include "ISoundManager.h"
26 #include "data/SoundData.h"
27 #include "items/ISoundItem.h"
28 #include "scripting/SoundGroup.h"
30 #include "lib/external_libraries/openal.h"
31 #include "lib/file/vfs/vfs_path.h"
32 #include "ps/Profiler2.h"
33 #include "simulation2/system/Entity.h"
38 #define AL_CHECK CSoundManager::al_check(__func__, __LINE__)
42 /// Title of the column
44 ISoundItem
* SourceItem
;
47 typedef std::vector
<VfsPath
> PlayList
;
48 typedef std::vector
<ISoundItem
*> ItemsList
;
49 typedef std::map
<entity_id_t
, ISoundItem
*> ItemsMap
;
50 typedef std::map
<std::wstring
, CSoundGroup
*> SoundGroupMap
;
52 class CSoundManagerWorker
;
55 class CSoundManager
: public ISoundManager
57 NONCOPYABLE(CSoundManager
);
61 ALCcontext
* m_Context
;
63 ALSourceHolder
* m_ALSourceBuffer
;
64 ISoundItem
* m_CurrentTune
;
65 ISoundItem
* m_CurrentEnvirons
;
66 CSoundManagerWorker
* m_Worker
;
67 CMutex m_DistressMutex
;
68 PlayList
* m_PlayListItems
;
69 SoundGroupMap m_SoundGroups
;
85 bool m_RunningPlaylist
;
86 bool m_PlayingPlaylist
;
87 bool m_LoopingPlaylist
;
90 long m_DistressErrCount
;
96 virtual ~CSoundManager();
100 ISoundItem
* LoadItem(const VfsPath
& itemPath
);
101 ISoundItem
* ItemForData(CSoundData
* itemData
);
102 ISoundItem
* ItemForEntity(entity_id_t source
, CSoundData
* sndData
);
104 Status
ReloadChangedFiles(const VfsPath
& path
);
106 void ClearPlayListItems();
107 void StartPlayList(bool doLoop
);
108 void AddPlayListItem(const VfsPath
& itemPath
);
110 static void CreateSoundManager();
111 static void SetEnabled(bool doEnable
);
112 static Status
ReloadChangedFileCB(void* param
, const VfsPath
& path
);
114 static void CloseGame();
116 static void al_ReportError(ALenum err
, const char* caller
, int line
);
117 static void al_check(const char* caller
, int line
);
119 void SetMusicEnabled(bool isEnabled
);
120 void SetSoundEnabled(bool enabled
);
122 ALuint
GetALSource(ISoundItem
* anItem
);
123 void ReleaseALSource(ALuint theSource
);
124 ISoundItem
* ItemFromData(CSoundData
* itemData
);
126 ISoundItem
* ItemFromWAV(VfsPath
& fname
);
127 ISoundItem
* ItemFromOgg(VfsPath
& fname
);
129 ISoundItem
* GetSoundItem(unsigned long itemRow
);
130 unsigned long Count();
133 void SetMemoryUsage(long bufferSize
, int bufferCount
);
134 long GetBufferCount();
135 long GetBufferSize();
137 void PlayAsMusic(const VfsPath
& itemPath
, bool looping
);
138 void PlayAsAmbient(const VfsPath
& itemPath
, bool looping
);
139 void PlayAsUI(const VfsPath
& itemPath
, bool looping
);
140 void PlayAsGroup(const VfsPath
& groupPath
, const CVector3D
& sourcePos
, entity_id_t source
, bool ownedSound
);
142 void PlayGroupItem(ISoundItem
* anItem
, ALfloat groupGain
);
145 void SetDistressThroughShortage();
146 void SetDistressThroughError();
148 void Pause(bool pauseIt
);
149 void PauseMusic(bool pauseIt
);
150 void PauseAmbient(bool pauseIt
);
151 void PauseAction(bool pauseIt
);
152 void SetAmbientItem(ISoundItem
* anItem
);
154 void SetMasterGain(float gain
);
155 void SetMusicGain(float gain
);
156 void SetAmbientGain(float gain
);
157 void SetActionGain(float gain
);
158 void SetUIGain(float gain
);
163 void SetMusicItem(ISoundItem
* anItem
);
166 CSoundManager(CSoundManager
* UNUSED(other
)){};
169 #else // !CONFIG2_AUDIO
173 #endif // !CONFIG2_AUDIO
175 #endif // INCLUDED_SOUNDMANAGER_H