Version
menu_open
link
Wwise SDK 2021.1.14
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: v2021.1.14 Build: 6590
25  Copyright (c) 2006-2023 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. 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<void*, 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 ); // void * in_pInput
48 ///
49 /// // Find an input
50 /// MyStruct * pInput = m_mapInputs.Exists( in_pInputContext ); // void * 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 KEY, class USER_DATA>
64 {
65  KEY key; /// Key.
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 (key == in_Op.key); }
70 };
71 
72 /// AkMixerInputMap: Map of inputs (identified with AK::IAkMixerInputContext *) to user-defined blocks of data.
73 template <class KEY, class USER_DATA>
74 class AkMixerInputMap : public AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>
75 {
76 public:
78 
79  /// Returns the user data associated with given input context. Returns NULL if none found.
80  USER_DATA * Exists( KEY in_key )
81  {
83  return ( it != BaseClass::End() ) ? (*it).pUserData : NULL;
84  }
85 
86  /// Adds an input with new user data.
87  USER_DATA * AddInput(KEY in_key)
88  {
90  if ( it != BaseClass::End() )
91  return (*it).pUserData;
92  else
93  {
95  if ( pSlot )
96  {
97  pSlot->pUserData = AK_PLUGIN_NEW( AkPluginArrayAllocator::GetAllocator(), USER_DATA );
98  if ( pSlot->pUserData )
99  {
100  pSlot->key = in_key;
101  return pSlot->pUserData;
102  }
104  }
105  }
106  return NULL;
107  }
108 
109  /// Removes an input and destroys its associated user data.
110  bool RemoveInput(KEY in_key)
111  {
112  typename AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::Iterator it = FindEx( in_key );
113  if ( it != BaseClass::End() )
114  {
115  AKASSERT( (*it).pUserData );
117  BaseClass::EraseSwap( it );
118  return true;
119  }
120  return false;
121  }
122 
123  /// Erase the specified iterator in the array. but it does not guarantee the ordering in the array.
125  {
126  if ((*in_rIter).pUserData)
127  {
128  AK_PLUGIN_DELETE(AkPluginArrayAllocator::GetAllocator(), (*in_rIter).pUserData);
129  }
130  return BaseClass::EraseSwap(in_rIter);
131  }
132 
133  /// Terminate array.
134  void Term()
135  {
136  if ( BaseClass::m_pItems )
137  {
138  RemoveAll();
139  AkPluginArrayAllocator::Free( BaseClass::m_pItems );
140  BaseClass::m_pItems = 0;
141  BaseClass::m_ulReserved = 0;
142  }
143  }
144 
145  /// Finds an item in the array.
147  {
149  mapSlot.key = in_key;
150  return BaseClass::FindEx( mapSlot );
151  }
152 
153  /// Removes and destroys all items in the array.
154  void RemoveAll()
155  {
156  for ( typename AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::Iterator it = BaseClass::Begin(), itEnd = BaseClass::End(); it != itEnd; ++it )
157  {
158  AKASSERT( (*it).pUserData );
160  (*it).~AkInputMapSlot();
161  }
162  BaseClass::m_uLength = 0;
163  }
164 };
165 
166 #endif // _AK_MIXERINPUTMAP_H_
AkForceInline void AK_PLUGIN_DELETE(AK::IAkPluginMemAlloc *in_pAllocator, T *in_pObject)
AkForceInline AK::IAkPluginMemAlloc * GetAllocator()
void Term()
Terminate array.
Definition: AkMixerInputMap.h:134
void RemoveAll()
Removes and destroys all items in the array.
Definition: AkMixerInputMap.h:154
bool RemoveInput(KEY in_key)
Removes an input and destroys its associated user data.
Definition: AkMixerInputMap.h:110
#define AK_PLUGIN_NEW(_allocator, _what)
Specific implementation of array.
Definition: AkArray.h:200
#define NULL
Definition: AkTypes.h:47
AkArray< AkInputMapSlot< KEY, USER_DATA >, const AkInputMapSlot< KEY, USER_DATA > &, AkPluginArrayAllocator > BaseClass
Definition: AkMixerInputMap.h:77
USER_DATA * Exists(KEY in_key)
Returns the user data associated with given input context. Returns NULL if none found.
Definition: AkMixerInputMap.h:80
USER_DATA * AddInput(KEY in_key)
Adds an input with new user data.
Definition: AkMixerInputMap.h:87
Structure of an entry in the AkMixerInputMap map.
Definition: AkMixerInputMap.h:64
#define AKASSERT(Condition)
Definition: AkAssert.h:76
AkArray< AkInputMapSlot< KEY, USER_DATA >, const AkInputMapSlot< KEY, USER_DATA > &, AkPluginArrayAllocator >::Iterator EraseSwap(typename AkArray< AkInputMapSlot< KEY, USER_DATA >, const AkInputMapSlot< KEY, USER_DATA > &, AkPluginArrayAllocator >::Iterator &in_rIter)
Erase the specified iterator in the array. but it does not guarantee the ordering in the array.
Definition: AkMixerInputMap.h:124
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
Key.
Definition: AkMixerInputMap.h:66
AkMixerInputMap: Map of inputs (identified with AK::IAkMixerInputContext *) to user-defined blocks of...
Definition: AkMixerInputMap.h:75
AkArray< AkInputMapSlot< KEY, USER_DATA >, const AkInputMapSlot< KEY, USER_DATA > &, AkPluginArrayAllocator >::Iterator FindEx(KEY in_key) const
Finds an item in the array.
Definition: AkMixerInputMap.h:146
AkForceInline void Free(void *in_pAddress)
bool operator==(const AkInputMapSlot &in_Op) const
Definition: AkMixerInputMap.h:69

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise