Table of Contents

Wwise SDK 2019.2.0
AkMixerInputMap.h
Go to the documentation of this file.
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Version: <VERSION> Build: <BUILDNUMBER>
25  Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
26 *******************************************************************************/
27 
28 #ifndef _AK_MIXERINPUTMAP_H_
29 #define _AK_MIXERINPUTMAP_H_
30 
32 
34 #include <AK/Tools/Common/AkArray.h>
36 
37 /// Collection class to manage inputs in mixer plugins.
38 /// The inputs are identified by their context AK::IAkMixerInputContext. The type of data attached to it is the template argument USER_DATA.
39 /// The collection performs allocation/deallocation of user data via AK_PLUGIN_NEW/DELETE().
40 /// Usage
41 ///
42 /// // Init
43 /// AkMixerInputMap<MyStruct> m_mapInputs;
44 /// m_mapInputs.Init( in_pAllocator ); // in_pAllocator passed at plugin init.
45 ///
46 /// // Add an input.
47 /// m_mapInputs.AddInput( in_pInput ); // AK::IAkMixerInputContext * in_pInput passed to OnInputConnected()
48 ///
49 /// // Find an input
50 /// MyStruct * pInput = m_mapInputs.Exists( in_pInputContext ); // AK::IAkMixerInputContext * in_pInputContext passed to ConsumeInput()
51 ///
52 /// // Iterate through inputs.
53 /// AkMixerInputMap<MyStruct>::Iterator it = m_mapInputs.End();
54 /// while ( it != m_mapInputs.End() )
55 /// {
56 /// MyStruct * pInput = (*it).pUserData;
57 /// ...
58 /// ++it;
59 /// }
60 
61 /// Structure of an entry in the AkMixerInputMap map.
62 template <class USER_DATA>
64 {
66  USER_DATA * pUserData; /// User data. Here we have a buffer. Other relevant info would be the game object position and input parameters of the previous frame.
67 
69  bool operator ==(const AkInputMapSlot& in_Op) const { return ( pContext == in_Op.pContext ); }
70 };
71 
72 /// Allocator for plugin-friendly arrays.
73 /// TODO Replace by a sorted array.
75 {
76 public:
77  AkForceInline AkPluginArrayAllocator() : m_pAllocator( NULL ) {}
78  AkForceInline void Init( AK::IAkPluginMemAlloc * in_pAllocator ) { m_pAllocator = in_pAllocator; }
79 protected:
80  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 ); }
81  AkForceInline void * ReAlloc(void * in_pCurrent, size_t in_uOldSize, size_t in_uNewSize)
82  {
83  void* pNew = Alloc(in_uNewSize);
84  if (pNew && in_pCurrent)
85  {
86  AKPLATFORM::AkMemCpy(pNew, in_pCurrent, (AkUInt32)in_uOldSize);
87  Free(in_pCurrent);
88  }
89  return pNew;
90 
91  }
92  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 ); }
93  AkForceInline AK::IAkPluginMemAlloc * GetAllocator() { return m_pAllocator; }
94 private:
95  AK::IAkPluginMemAlloc * m_pAllocator;
96 };
97 
98 /// AkMixerInputMap: Map of inputs (identified with AK::IAkMixerInputContext *) to user-defined blocks of data.
99 template <class USER_DATA>
100 class AkMixerInputMap : public AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator>
101 {
102 public:
104 
105  /// Returns the user data associated with given input context. Returns NULL if none found.
106  USER_DATA * Exists( AK::IAkMixerInputContext * in_pInput )
107  {
108  typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator>::Iterator it = FindEx( in_pInput );
109  return ( it != BaseClass::End() ) ? (*it).pUserData : NULL;
110  }
111 
112  /// Adds an input with new user data.
113  USER_DATA * AddInput( AK::IAkMixerInputContext * in_pInput )
114  {
115  typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator>::Iterator it = FindEx( in_pInput );
116  if ( it != BaseClass::End() )
117  return (*it).pUserData;
118  else
119  {
121  if ( pSlot )
122  {
123  pSlot->pUserData = AK_PLUGIN_NEW( AkPluginArrayAllocator::GetAllocator(), USER_DATA );
124  if ( pSlot->pUserData )
125  {
126  pSlot->pContext = in_pInput;
127  return pSlot->pUserData;
128  }
130  }
131  }
132  return NULL;
133  }
134 
135  /// Removes an input and destroys its associated user data.
137  {
138  typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator>::Iterator it = FindEx( in_pInput );
139  if ( it != BaseClass::End() )
140  {
141  AKASSERT( (*it).pUserData );
143  BaseClass::EraseSwap( it );
144  return true;
145  }
146  return false;
147  }
148 
149  /// Terminate array.
150  void Term()
151  {
152  if ( BaseClass::m_pItems )
153  {
154  RemoveAll();
155  AkPluginArrayAllocator::Free( BaseClass::m_pItems );
156  BaseClass::m_pItems = 0;
157  BaseClass::m_ulReserved = 0;
158  }
159  }
160 
161  /// Finds an item in the array.
163  {
165  mapSlot.pContext = in_pInput;
166  return BaseClass::FindEx( mapSlot );
167  }
168 
169  /// Removes and destroys all items in the array.
170  void RemoveAll()
171  {
172  for ( typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator>::Iterator it = BaseClass::Begin(), itEnd = BaseClass::End(); it != itEnd; ++it )
173  {
174  AKASSERT( (*it).pUserData );
176  (*it).~AkInputMapSlot();
177  }
178  BaseClass::m_uLength = 0;
179  }
180 };
181 
182 #endif // _AK_MIXERINPUTMAP_H_
#define AK_PLUGIN_NEW(_allocator, _what)
bool RemoveInput(AK::IAkMixerInputContext *in_pInput)
Removes an input and destroys its associated user data.
Definition: AkMixerInputMap.h:136
USER_DATA * Exists(AK::IAkMixerInputContext *in_pInput)
Returns the user data associated with given input context. Returns NULL if none found.
Definition: AkMixerInputMap.h:106
AkForceInline void AkMemCpy(void *pDest, const void *pSrc, AkUInt32 uSize)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:333
USER_DATA * AddInput(AK::IAkMixerInputContext *in_pInput)
Adds an input with new user data.
Definition: AkMixerInputMap.h:113
Specific implementation of array.
Definition: AkArray.h:201
#define AK_PLUGIN_ALLOC(_allocator, _size)
#define AKASSERT(Condition)
Definition: AkAssert.h:76
#define AkForceInline
Force inlining.
Definition: AkTypes.h:66
Iterator End() const
Returns the iterator to the end of the array.
Definition: AkArray.h:290
AK::IAkMixerInputContext * pContext
Definition: AkMixerInputMap.h:65
void Term()
Terminate array.
Definition: AkMixerInputMap.h:150
Structure of an entry in the AkMixerInputMap map.
Definition: AkMixerInputMap.h:63
Interface to retrieve information about an input of a mixer.
Definition: IAkPlugin.h:745
AkForceInline AkPluginArrayAllocator()
Definition: AkMixerInputMap.h:77
AkForceInline void Init(AK::IAkPluginMemAlloc *in_pAllocator)
Definition: AkMixerInputMap.h:78
AkArray< AkInputMapSlot< USER_DATA >, const AkInputMapSlot< USER_DATA > &, AkPluginArrayAllocator >::Iterator FindEx(AK::IAkMixerInputContext *in_pInput) const
Finds an item in the array.
Definition: AkMixerInputMap.h:162
#define AK_PLUGIN_FREE(_allocator, _pvmem)
#define NULL
Definition: AkTypes.h:49
void RemoveAll()
Removes and destroys all items in the array.
Definition: AkMixerInputMap.h:170
bool operator==(const AkInputMapSlot &in_Op) const
Definition: AkMixerInputMap.h:69
AkArray< AkInputMapSlot< USER_DATA >, const AkInputMapSlot< USER_DATA > &, AkPluginArrayAllocator > BaseClass
Definition: AkMixerInputMap.h:103
AkForceInline void * Alloc(size_t in_uSize)
Definition: AkMixerInputMap.h:80
AkMixerInputMap: Map of inputs (identified with AK::IAkMixerInputContext *) to user-defined blocks of...
Definition: AkMixerInputMap.h:100
AkForceInline AK::IAkPluginMemAlloc * GetAllocator()
Definition: AkMixerInputMap.h:93
AkForceInline void * ReAlloc(void *in_pCurrent, size_t in_uOldSize, size_t in_uNewSize)
Definition: AkMixerInputMap.h:81
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:86
AkInputMapSlot()
User data. Here we have a buffer. Other relevant info would be the game object position and input par...
Definition: AkMixerInputMap.h:68
USER_DATA * pUserData
Definition: AkMixerInputMap.h:66
AkForceInline void Free(void *in_pAddress)
Definition: AkMixerInputMap.h:92
AkForceInline void AK_PLUGIN_DELETE(AK::IAkPluginMemAlloc *in_pAllocator, T *in_pObject)