00001 00002 // 00003 // Copyright (c) 2006 Audiokinetic Inc. / All Rights Reserved 00004 // 00006 00007 #ifndef _AK_MIXERINPUTMAP_H_ 00008 #define _AK_MIXERINPUTMAP_H_ 00009 00010 #include <AK/SoundEngine/Common/AkTypes.h> 00011 #include <AK/SoundEngine/Common/IAkPlugin.h> 00012 #include <AK/SoundEngine/Common/IAkPluginMemAlloc.h> 00013 #include <AK/Tools/Common/AkArray.h> 00014 00038 00040 template <class USER_DATA> 00041 struct AkInputMapSlot 00042 { 00043 AK::IAkMixerInputContext * pContext; 00044 USER_DATA * pUserData; 00045 00046 AkInputMapSlot() : pContext( NULL ), pUserData( NULL ) {} 00047 bool operator ==(const AkInputMapSlot& in_Op) const { return ( pContext == in_Op.pContext ); } 00048 }; 00049 00052 class AkPluginArrayAllocator 00053 { 00054 public: 00055 AkForceInline AkPluginArrayAllocator() : m_pAllocator( NULL ) {} 00056 AkForceInline void Init( AK::IAkPluginMemAlloc * in_pAllocator ) { m_pAllocator = in_pAllocator; } 00057 protected: 00058 AkForceInline void * Alloc( size_t in_uSize ) { AKASSERT( m_pAllocator || !"Allocator not set. Did you forget to call AkMixerInputMap::Init()?" ); return AK_PLUGIN_ALLOC( m_pAllocator, in_uSize ); } 00059 AkForceInline void Free( void * in_pAddress ) { AKASSERT( m_pAllocator || !"Allocator not set. Did you forget to call AkMixerInputMap::Init()?" ); AK_PLUGIN_FREE( m_pAllocator, in_pAddress ); } 00060 AkForceInline AK::IAkPluginMemAlloc * GetAllocator() { return m_pAllocator; } 00061 private: 00062 AK::IAkPluginMemAlloc * m_pAllocator; 00063 }; 00064 00066 template <class USER_DATA> 00067 class AkMixerInputMap : public AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1> 00068 { 00069 public: 00070 typedef AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1> BaseClass; 00071 00073 USER_DATA * Exists( AK::IAkMixerInputContext * in_pInput ) 00074 { 00075 typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = FindEx( in_pInput ); 00076 return ( it != BaseClass::End() ) ? (*it).pUserData : NULL; 00077 } 00078 00080 USER_DATA * AddInput( AK::IAkMixerInputContext * in_pInput ) 00081 { 00082 typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = FindEx( in_pInput ); 00083 if ( it != BaseClass::End() ) 00084 return (*it).pUserData; 00085 else 00086 { 00087 AkInputMapSlot<USER_DATA> * pSlot = AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::AddLast(); 00088 if ( pSlot ) 00089 { 00090 pSlot->pUserData = AK_PLUGIN_NEW( AkPluginArrayAllocator::GetAllocator(), USER_DATA ); 00091 if ( pSlot->pUserData ) 00092 { 00093 pSlot->pContext = in_pInput; 00094 return pSlot->pUserData; 00095 } 00096 BaseClass::RemoveLast(); 00097 } 00098 } 00099 return NULL; 00100 } 00101 00103 bool RemoveInput( AK::IAkMixerInputContext * in_pInput ) 00104 { 00105 typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = FindEx( in_pInput ); 00106 if ( it != BaseClass::End() ) 00107 { 00108 AKASSERT( (*it).pUserData ); 00109 AK_PLUGIN_DELETE( AkPluginArrayAllocator::GetAllocator(), (*it).pUserData ); 00110 BaseClass::EraseSwap( it ); 00111 return true; 00112 } 00113 return false; 00114 } 00115 00117 void Term() 00118 { 00119 if ( BaseClass::m_pItems ) 00120 { 00121 RemoveAll(); 00122 AkPluginArrayAllocator::Free( BaseClass::m_pItems ); 00123 BaseClass::m_pItems = 0; 00124 BaseClass::m_ulReserved = 0; 00125 } 00126 } 00127 00129 typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator FindEx( AK::IAkMixerInputContext * in_pInput ) const 00130 { 00131 AkInputMapSlot<USER_DATA> mapSlot; 00132 mapSlot.pContext = in_pInput; 00133 return BaseClass::FindEx( mapSlot ); 00134 } 00135 00137 void RemoveAll() 00138 { 00139 for ( typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = BaseClass::Begin(), itEnd = BaseClass::End(); it != itEnd; ++it ) 00140 { 00141 AKASSERT( (*it).pUserData ); 00142 AK_PLUGIN_DELETE( AkPluginArrayAllocator::GetAllocator(), (*it).pUserData ); 00143 (*it).~AkInputMapSlot(); 00144 } 00145 BaseClass::m_uLength = 0; 00146 } 00147 }; 00148 00149 #endif // _AK_MIXERINPUTMAP_H_
프로젝트를 등록하세요. 아무런 조건이나 의무 사항 없이 빠른 시작을 도와드리겠습니다.
Wwise를 시작해 보세요