Version

menu_open
Wwise SDK 2024.1.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  Copyright (c) 2024 Audiokinetic Inc.
25 *******************************************************************************/
26 
27 #ifndef _AK_MIXERINPUTMAP_H_
28 #define _AK_MIXERINPUTMAP_H_
29 
31 
35 
36 /// Collection class to manage inputs in mixer plugins.
37 /// The inputs are identified by their context. The type of data attached to it is the template argument USER_DATA.
38 /// The collection performs allocation/deallocation of user data via AK_PLUGIN_NEW/DELETE().
39 /// Usage
40 ///
41 /// // Init
42 /// AkMixerInputMap<void*, MyStruct> m_mapInputs;
43 /// m_mapInputs.Init( in_pAllocator ); // in_pAllocator passed at plugin init.
44 ///
45 /// // Add an input.
46 /// m_mapInputs.AddInput( in_pInput ); // void * in_pInput
47 ///
48 /// // Find an input
49 /// MyStruct * pInput = m_mapInputs.Exists( in_pInputContext ); // void * in_pInputContext passed to ConsumeInput()
50 ///
51 /// // Iterate through inputs.
52 /// AkMixerInputMap<MyStruct>::Iterator it = m_mapInputs.End();
53 /// while ( it != m_mapInputs.End() )
54 /// {
55 /// MyStruct * pInput = (*it).pUserData;
56 /// ...
57 /// ++it;
58 /// }
59 
60 /// Structure of an entry in the AkMixerInputMap map.
61 template <class KEY, class USER_DATA>
63 {
64  KEY key; /// Key.
65  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.
66 
68  bool operator ==(const AkInputMapSlot& in_Op) const { return (key == in_Op.key); }
69 };
70 
71 /// AkMixerInputMap: Map of inputs (identified with AK::IAkMixerInputContext *) to user-defined blocks of data.
72 template <class KEY, class USER_DATA>
73 class AkMixerInputMap : public AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>
74 {
75 public:
77 
78  /// Returns the user data associated with given input context. Returns NULL if none found.
79  USER_DATA * Exists( KEY in_key )
80  {
82  return ( it != BaseClass::End() ) ? (*it).pUserData : NULL;
83  }
84 
85  /// Adds an input with new user data.
86  USER_DATA * AddInput(KEY in_key)
87  {
89  if ( it != BaseClass::End() )
90  return (*it).pUserData;
91  else
92  {
94  if ( pSlot )
95  {
96  pSlot->pUserData = AK_PLUGIN_NEW( AkPluginArrayAllocator::GetAllocator(), USER_DATA );
97  if ( pSlot->pUserData )
98  {
99  pSlot->key = in_key;
100  return pSlot->pUserData;
101  }
103  }
104  }
105  return NULL;
106  }
107 
108  /// Removes an input and destroys its associated user data.
109  bool RemoveInput(KEY in_key)
110  {
111  typename AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::Iterator it = FindEx( in_key );
112  if ( it != BaseClass::End() )
113  {
114  AKASSERT( (*it).pUserData );
116  BaseClass::EraseSwap( it );
117  return true;
118  }
119  return false;
120  }
121 
122  /// Erase the specified iterator in the array. but it does not guarantee the ordering in the array.
124  {
125  if ((*in_rIter).pUserData)
126  {
127  AK_PLUGIN_DELETE(AkPluginArrayAllocator::GetAllocator(), (*in_rIter).pUserData);
128  }
129  return BaseClass::EraseSwap(in_rIter);
130  }
131 
132  /// Terminate array.
133  void Term()
134  {
135  if ( BaseClass::m_pItems )
136  {
137  RemoveAll();
138  AkPluginArrayAllocator::Free( BaseClass::m_pItems );
139  BaseClass::m_pItems = 0;
140  BaseClass::m_ulReserved = 0;
141  }
142  }
143 
144  /// Finds an item in the array.
146  {
148  mapSlot.key = in_key;
149  return BaseClass::FindEx( mapSlot );
150  }
151 
152  /// Removes and destroys all items in the array.
153  void RemoveAll()
154  {
155  for ( typename AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::Iterator it = BaseClass::Begin(), itEnd = BaseClass::End(); it != itEnd; ++it )
156  {
157  AKASSERT( (*it).pUserData );
159  (*it).~AkInputMapSlot();
160  }
161  BaseClass::m_uLength = 0;
162  }
163 };
164 
165 #endif // _AK_MIXERINPUTMAP_H_
AkForceInline void AK_PLUGIN_DELETE(AK::IAkPluginMemAlloc *in_pAllocator, T *in_pObject)
AkForceInline AK::IAkPluginMemAlloc * GetAllocator()
void Term()
Terminate array.
void RemoveAll()
Removes and destroys all items in the array.
bool RemoveInput(KEY in_key)
Removes an input and destroys its associated user data.
#define AK_PLUGIN_NEW(_allocator, _what)
Specific implementation of array.
Definition: AkArray.h:259
#define NULL
Definition: AkTypes.h:46
AkArray< AkInputMapSlot< KEY, USER_DATA >, const AkInputMapSlot< KEY, USER_DATA > &, AkPluginArrayAllocator > BaseClass
USER_DATA * Exists(KEY in_key)
Returns the user data associated with given input context. Returns NULL if none found.
USER_DATA * AddInput(KEY in_key)
Adds an input with new user data.
Structure of an entry in the AkMixerInputMap map.
#define AKASSERT(Condition)
Definition: AkAssert.h:67
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.
AkInputMapSlot()
User data. Here we have a buffer. Other relevant info would be the game object position and input par...
USER_DATA * pUserData
Key.
AkMixerInputMap: Map of inputs (identified with AK::IAkMixerInputContext *) to user-defined blocks of...
AkArray< AkInputMapSlot< KEY, USER_DATA >, const AkInputMapSlot< KEY, USER_DATA > &, AkPluginArrayAllocator >::Iterator FindEx(KEY in_key) const
Finds an item in the array.
AkForceInline void Free(void *in_pAddress)
bool operator==(const AkInputMapSlot &in_Op) const

Cette page a-t-elle été utile ?

Besoin d'aide ?

Des questions ? Des problèmes ? Besoin de plus d'informations ? Contactez-nous, nous pouvons vous aider !

Visitez notre page d'Aide

Décrivez-nous de votre projet. Nous sommes là pour vous aider.

Enregistrez votre projet et nous vous aiderons à démarrer sans aucune obligation !

Partir du bon pied avec Wwise