sfxProvider.cpp
Engine/source/sfx/sfxProvider.cpp
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "core/strings/stringFunctions.h" 25#include "sfx/sfxProvider.h" 26 27SFXProvider* SFXProvider::smProviders = NULL; 28Vector<SFXProvider*> SFXProvider::sAllProviders( __FILE__, __LINE__ ); 29 30SFXProvider* SFXProvider::findProvider( String providerName ) 31{ 32 if( providerName.isEmpty() ) 33 return NULL; 34 35 SFXProvider* curr = smProviders; 36 for ( ; curr != NULL; curr = curr->mNextProvider ) 37 { 38 if( curr->getName().equal( providerName, String::NoCase ) ) 39 return curr; 40 } 41 42 return NULL; 43} 44 45void SFXProvider::regProvider( SFXProvider* provider ) 46{ 47 AssertFatal( provider, "Got null provider!" ); 48 AssertFatal( findProvider( provider->getName() ) == NULL, "Can't register provider twice!" ); 49 AssertFatal( provider->mNextProvider == NULL, "Can't register provider twice!" ); 50 51 SFXProvider* oldHead = smProviders; 52 smProviders = provider; 53 provider->mNextProvider = oldHead; 54} 55 56SFXProvider::SFXProvider( const String& name ) 57 : mNextProvider( NULL ), 58 mName( name ) 59{ 60 VECTOR_SET_ASSOCIATION( mDeviceInfo ); 61 62 sAllProviders.push_back( this ); 63} 64 65void SFXProvider::initializeAllProviders() 66{ 67 68 for (U32 i = 0; i < sAllProviders.size(); i++) 69 sAllProviders[i]->init(); 70 71} 72 73SFXProvider::~SFXProvider() 74{ 75 SFXDeviceInfoVector::iterator iter = mDeviceInfo.begin(); 76 for ( ; iter != mDeviceInfo.end(); iter++ ) 77 delete *iter; 78} 79 80SFXDeviceInfo* SFXProvider::_findDeviceInfo( const String& deviceName ) 81{ 82 SFXDeviceInfoVector::iterator iter = mDeviceInfo.begin(); 83 for ( ; iter != mDeviceInfo.end(); iter++ ) 84 { 85 if( deviceName.equal( ( *iter )->name, String::NoCase ) ) 86 return *iter; 87 } 88 89 // If not found and deviceName is empty, 90 // return first (default) device. 91 92 if( deviceName.isEmpty() && mDeviceInfo.size() > 0 ) 93 return mDeviceInfo[ 0 ]; 94 95 return NULL; 96} 97