31 #include "util/log/logger.h"
32 #include "util/resource/resourcemanager.h"
33 #include "util/resource/resource.h"
35 #include "soundclipmanager.h"
38 static Logger _log(LM_RESMGR);
47 SoundClipHandleMapConstIterator it = m_sclipHandleMap.begin(),
48 itend = m_sclipHandleMap.end();
50 for ( ; it != itend; ++it) {
51 totalSize += it->second->getSize();
58 SoundClipHandleMapConstIterator it = m_sclipHandleMap.begin(),
59 itend = m_sclipHandleMap.end();
62 for ( ; it != itend; ++it) {
63 if ( it->second->getState() == IResource::RES_NOT_LOADED ) {
72 SoundClipHandleMapConstIterator it = m_sclipHandleMap.begin(),
73 itend = m_sclipHandleMap.end();
76 for ( ; it != itend; ++it) {
77 if ( it->second->getState() == IResource::RES_LOADED ) {
86 return m_sclipHandleMap.size();
96 FL_WARN(_log,
LMsg(
"SoundClipManager::create(std::string, IResourceLoader* loader) - ") <<
"Resource name " << name <<
" was previously created. Returning original SoundClip...");
105 SoundClipNameMapIterator nit = m_sclipNameMap.find(name);
107 if (nit != m_sclipNameMap.end()) {
108 if ( nit->second->getState() == IResource::RES_NOT_LOADED ) {
119 if (ptr->getState() == IResource::RES_NOT_LOADED){
120 FL_WARN(_log,
LMsg(
"SoundClipManager::load(std::string) - ") <<
"Resource name " << name <<
" was not found and could not be loaded.");
129 assert(!(
exists(res->getHandle()) ||
exists(res->getName())));
133 std::pair<SoundClipHandleMapIterator, bool> returnValue;
134 returnValue = m_sclipHandleMap.insert ( SoundClipHandleMapPair(res->getHandle(), resptr));
136 if (returnValue.second) {
137 m_sclipNameMap.insert ( SoundClipNameMapPair(returnValue.first->second->getName(), returnValue.first->second) );
140 FL_WARN(_log,
LMsg(
"SoundClipManager::add(IResource*) - ") <<
"Resource " << res->getName() <<
" already exists.... ignoring.");
143 return returnValue.first->second;
147 SoundClipNameMapIterator it = m_sclipNameMap.find(name);
148 if (it != m_sclipNameMap.end()) {
156 SoundClipHandleMapConstIterator it = m_sclipHandleMap.find(handle);
157 if (it != m_sclipHandleMap.end()) {
165 SoundClipNameMapIterator nit = m_sclipNameMap.find(name);
167 if (nit != m_sclipNameMap.end()) {
168 if ( nit->second->getState() == IResource::RES_LOADED) {
175 FL_WARN(_log,
LMsg(
"SoundClipManager::reload(std::string) - ") <<
"Resource name " << name <<
" not found.");
179 SoundClipHandleMapIterator it = m_sclipHandleMap.find(handle);
181 if ( it != m_sclipHandleMap.end()) {
182 if ( it->second->getState() == IResource::RES_LOADED) {
189 FL_WARN(_log,
LMsg(
"SoundClipManager::reload(ResourceHandle) - ") <<
"Resource handle " << handle <<
" not found.");
194 SoundClipHandleMapIterator it = m_sclipHandleMap.begin(),
195 itend = m_sclipHandleMap.end();
197 for ( ; it != itend; ++it) {
198 if ( it->second->getState() == IResource::RES_LOADED) {
206 SoundClipHandleMapIterator it = m_sclipHandleMap.begin(),
207 itend = m_sclipHandleMap.end();
210 for ( ; it != itend; ++it) {
211 if (it->second.useCount() == 2 && it->second->getState() != IResource::RES_LOADED){
216 FL_DBG(_log,
LMsg(
"SoundClipManager::loadUnreferenced() - ") <<
"Loaded " << count <<
" unreferenced resources.");
220 SoundClipNameMapIterator nit = m_sclipNameMap.find(name);
222 if (nit != m_sclipNameMap.end()) {
223 if ( nit->second->getState() == IResource::RES_LOADED) {
229 FL_WARN(_log,
LMsg(
"SoundClipManager::free(std::string) - ") <<
"Resource name " << name <<
" not found.");
233 SoundClipHandleMapConstIterator it = m_sclipHandleMap.find(handle);
234 if (it != m_sclipHandleMap.end()) {
235 if ( it->second->getState() == IResource::RES_LOADED) {
241 FL_WARN(_log,
LMsg(
"SoundClipManager::free(ResourceHandle) - ") <<
"Resource handle " << handle <<
" not found.");
245 SoundClipHandleMapIterator it = m_sclipHandleMap.begin(),
246 itend = m_sclipHandleMap.end();
250 for ( ; it != itend; ++it) {
251 if ( it->second->getState() == IResource::RES_LOADED) {
257 FL_DBG(_log,
LMsg(
"SoundClipManager::freeAll() - ") <<
"Freed all " << count <<
" resources.");
261 SoundClipHandleMapIterator it = m_sclipHandleMap.begin(),
262 itend = m_sclipHandleMap.end();
265 for ( ; it != itend; ++it) {
266 if (it->second.useCount() == 2 && it->second->getState() == IResource::RES_LOADED ){
272 FL_DBG(_log,
LMsg(
"SoundClipManager::freeUnreferenced() - ") <<
"Freed " << count <<
" unreferenced resources.");
276 SoundClipHandleMapIterator it = m_sclipHandleMap.find(resource->getHandle());
277 SoundClipNameMapIterator nit = m_sclipNameMap.find(resource->getName());
279 if (it != m_sclipHandleMap.end()) {
280 m_sclipHandleMap.erase(it);
282 if (nit != m_sclipNameMap.end()) {
283 m_sclipNameMap.erase(nit);
289 FL_WARN(_log,
LMsg(
"SoundClipManager::remove(ResourcePtr&) - ") <<
"Resource " << resource->getName() <<
" was not found.");
295 SoundClipNameMapIterator nit = m_sclipNameMap.find(name);
296 if (nit != m_sclipNameMap.end()) {
297 handle = nit->second->getHandle();
298 m_sclipNameMap.erase(nit);
301 FL_WARN(_log,
LMsg(
"SoundClipManager::remove(std::string) - ") <<
"Resource " << name <<
" was not found.");
305 SoundClipHandleMapIterator it = m_sclipHandleMap.find(handle);
306 if ( it != m_sclipHandleMap.end()) {
307 m_sclipHandleMap.erase(it);
317 SoundClipHandleMapIterator it = m_sclipHandleMap.find(handle);
319 if (it != m_sclipHandleMap.end()) {
320 name = it->second->getName();
321 m_sclipHandleMap.erase(it);
324 FL_WARN(_log,
LMsg(
"SoundClipManager::remove(ResourceHandle) - ") <<
"Resource handle " << handle <<
" was not found.");
328 SoundClipNameMapIterator nit = m_sclipNameMap.find(name);
329 if ( nit != m_sclipNameMap.end() ) {
330 m_sclipNameMap.erase(nit);
339 assert (m_sclipHandleMap.size() == m_sclipNameMap.size());
341 size_t count = m_sclipHandleMap.size();
343 m_sclipHandleMap.clear();
344 m_sclipNameMap.clear();
346 FL_DBG(_log,
LMsg(
"SoundClipManager::removeAll() - ") <<
"Removed all " << count <<
" resources.");
350 SoundClipHandleMapIterator it = m_sclipHandleMap.begin(),
351 itend = m_sclipHandleMap.end();
354 for ( ; it != itend; ++it) {
355 if ( it->second.useCount() == 2) {
356 remove(it->second->getHandle());
361 FL_DBG(_log,
LMsg(
"SoundClipManager::removeUnreferenced() - ") <<
"Removed " << count <<
" unreferenced resources.");
365 SoundClipNameMapIterator nit = m_sclipNameMap.find(name);
367 if (nit != m_sclipNameMap.end()) {
368 if (nit->second->getState() != IResource::RES_LOADED){
381 SoundClipHandleMapConstIterator it = m_sclipHandleMap.find(handle);
382 if (it != m_sclipHandleMap.end()) {
383 if (it->second->getState() != IResource::RES_LOADED){
390 FL_WARN(_log,
LMsg(
"SoundClipManager::get(ResourceHandle) - ") <<
"Resource handle " << handle <<
" is undefined.");
396 SoundClipNameMapIterator nit = m_sclipNameMap.find(name);
397 if (nit != m_sclipNameMap.end()) {
398 return nit->second->getHandle();
401 FL_WARN(_log,
LMsg(
"SoundClipManager::getResourceHandle(std::string) - ") <<
"Resource " << name <<
" is undefined.");