Fix "no remove aqua speed" bug when player leaves the water
[ryzomcore.git] / nel / src / sound / sample_bank_manager.cpp
blobbb4f680b7c2aeb3fc02040f2d9a33e7e9414e998
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010-2019 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdsound.h"
21 #include "nel/sound/sample_bank_manager.h"
23 // STL includes
25 // NeL includes
26 #include "nel/misc/path.h"
27 #include "nel/misc/file.h"
29 // Project includes
30 #include "nel/sound/driver/sound_driver.h"
31 #include "nel/sound/driver/buffer.h"
32 #include "nel/sound/sample_bank.h"
33 #include "nel/sound/async_file_manager_sound.h"
34 #include "nel/sound/background_sound_manager.h"
35 #include "nel/sound/sound_bank.h"
37 using namespace std;
38 using namespace NLMISC;
40 namespace NLSOUND {
42 CSampleBankManager::CSampleBankManager(CAudioMixerUser *audioMixer) : m_AudioMixer(audioMixer), m_LoadedSize(0)
47 CSampleBankManager::~CSampleBankManager()
49 releaseAll();
53 void CSampleBankManager::init(NLGEORGES::UFormElm *mixerConfig)
55 if (mixerConfig == 0)
56 return;
58 NLGEORGES::UFormElm *virtualBanks;
59 mixerConfig->getNodeByName(&virtualBanks, ".VirtualBanks");
60 if (virtualBanks == 0)
61 return;
63 uint size;
64 virtualBanks->getArraySize(size);
66 for (uint i=0; i<size; ++i)
68 NLGEORGES::UFormElm *virtualBank;
69 virtualBanks->getArrayNode(&virtualBank, i);
71 if (virtualBank != 0)
73 std::vector<TFilteredBank> vfb;
74 std::string virtualName;
75 virtualBank->getValueByName(virtualName, ".VirtualName");
76 NLGEORGES::UFormElm *realBanks;
77 virtualBank->getNodeByName(&realBanks, ".FilteredBank");
78 if (realBanks != 0)
80 uint size2;
81 realBanks->getArraySize(size2);
83 for (uint j=0; j<size2; ++j)
85 TFilteredBank fb;
86 std::string bankName;
87 NLGEORGES::UFormElm *realBank = NULL;
88 realBanks->getArrayNode(&realBank, j);
89 if (realBank != 0)
91 realBank->getValueByName(bankName, ".SampleBank");
92 fb.BankName = CStringMapper::map(bankName);
93 realBank->getValueByName(fb.Filter, ".Filter");
94 vfb.push_back(fb);
99 if (!vfb.empty())
101 TStringId virtualNameId = CStringMapper::map(virtualName);
102 m_VirtualBanks.insert(std::make_pair(virtualNameId, vfb));
103 // create the sample bank
104 CSampleBank *sampleBank = new CSampleBank(virtualNameId, this);
110 void CSampleBankManager::releaseAll()
112 // nldebug("SampleBanks: Releasing...");
113 while (!m_Banks.empty())
115 delete m_Banks.begin()->second;
117 // nldebug("SampleBanks: Released");
120 CSampleBank *CSampleBankManager::findSampleBank(const NLMISC::TStringId &filename)
122 TSampleBankContainer::iterator it(m_Banks.find(filename));
124 if (it != m_Banks.end())
125 return it->second;
127 return NULL;
130 IBuffer *CSampleBankManager::get(const NLMISC::TStringId &name)
132 IBuffer* buffer;
133 TSampleBankContainer::iterator iter;
135 for (iter = m_Banks.begin(); iter != m_Banks.end(); ++iter)
137 buffer = iter->second->getSample(name);
138 if (buffer != 0)
140 return buffer;
144 //nlwarning ("Try to get an unknown sample '%s'", name);
145 return 0;
148 void CSampleBankManager::reload(bool async)
150 TSampleBankContainer::iterator first(m_Banks.begin()), last(m_Banks.end());
152 for (; first != last; ++first)
154 first->second->unload();
155 first->second->load(async);
160 void CSampleBankManager::getLoadedSampleBankInfo(std::vector<std::pair<std::string, uint> > &result)
162 result.clear();
164 TSampleBankContainer::iterator first(m_Banks.begin()), last(m_Banks.end());
165 for (; first != last; ++first)
167 std::pair<std::string, uint> p;
168 if (first->second->isLoaded())
170 p.first = NLMISC::CStringMapper::unmap(first->first);
171 p.second = first->second->getSize();
172 result.push_back(p);
177 } /* namespace NLSOUND */
179 /* end of file */