バージョン
menu_open
link
Wwise SDK 2018.1.11
AkMixerInputMap.h
[詳解]
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 Free( void * in_pAddress ) { AKASSERT( m_pAllocator || !"Allocator not set. Did you forget to call AkMixerInputMap::Init()?" ); AK_PLUGIN_FREE( m_pAllocator, in_pAddress ); }
82  AkForceInline AK::IAkPluginMemAlloc * GetAllocator() { return m_pAllocator; }
83 private:
84  AK::IAkPluginMemAlloc * m_pAllocator;
85 };
86 
87 /// AkMixerInputMap: Map of inputs (identified with AK::IAkMixerInputContext *) to user-defined blocks of data.
88 template <class USER_DATA>
89 class AkMixerInputMap : public AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>
90 {
91 public:
93 
94  /// Returns the user data associated with given input context. Returns NULL if none found.
95  USER_DATA * Exists( AK::IAkMixerInputContext * in_pInput )
96  {
97  typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = FindEx( in_pInput );
98  return ( it != BaseClass::End() ) ? (*it).pUserData : NULL;
99  }
100 
101  /// Adds an input with new user data.
102  USER_DATA * AddInput( AK::IAkMixerInputContext * in_pInput )
103  {
104  typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = FindEx( in_pInput );
105  if ( it != BaseClass::End() )
106  return (*it).pUserData;
107  else
108  {
110  if ( pSlot )
111  {
112  pSlot->pUserData = AK_PLUGIN_NEW( AkPluginArrayAllocator::GetAllocator(), USER_DATA );
113  if ( pSlot->pUserData )
114  {
115  pSlot->pContext = in_pInput;
116  return pSlot->pUserData;
117  }
119  }
120  }
121  return NULL;
122  }
123 
124  /// Removes an input and destroys its associated user data.
126  {
127  typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = FindEx( in_pInput );
128  if ( it != BaseClass::End() )
129  {
130  AKASSERT( (*it).pUserData );
132  BaseClass::EraseSwap( it );
133  return true;
134  }
135  return false;
136  }
137 
138  /// Terminate array.
139  void Term()
140  {
141  if ( BaseClass::m_pItems )
142  {
143  RemoveAll();
144  AkPluginArrayAllocator::Free( BaseClass::m_pItems );
145  BaseClass::m_pItems = 0;
146  BaseClass::m_ulReserved = 0;
147  }
148  }
149 
150  /// Finds an item in the array.
152  {
154  mapSlot.pContext = in_pInput;
155  return BaseClass::FindEx( mapSlot );
156  }
157 
158  /// Removes and destroys all items in the array.
159  void RemoveAll()
160  {
161  for ( typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = BaseClass::Begin(), itEnd = BaseClass::End(); it != itEnd; ++it )
162  {
163  AKASSERT( (*it).pUserData );
165  (*it).~AkInputMapSlot();
166  }
167  BaseClass::m_uLength = 0;
168  }
169 };
170 
171 #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:125
USER_DATA * Exists(AK::IAkMixerInputContext *in_pInput)
Returns the user data associated with given input context. Returns NULL if none found.
Definition: AkMixerInputMap.h:95
USER_DATA * AddInput(AK::IAkMixerInputContext *in_pInput)
Adds an input with new user data.
Definition: AkMixerInputMap.h:102
Specific implementation of array
Definition: AkArray.h:152
#define AK_PLUGIN_ALLOC(_allocator, _size)
#define AKASSERT(Condition)
Definition: AkAssert.h:69
#define AkForceInline
Force inlining
Definition: AkTypes.h:63
Iterator End() const
Returns the iterator to the end of the array
Definition: AkArray.h:241
AK::IAkMixerInputContext * pContext
Definition: AkMixerInputMap.h:65
void Term()
Terminate array.
Definition: AkMixerInputMap.h:139
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, 1 >::Iterator FindEx(AK::IAkMixerInputContext *in_pInput) const
Finds an item in the array.
Definition: AkMixerInputMap.h:151
#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:159
bool operator==(const AkInputMapSlot &in_Op) const
Definition: AkMixerInputMap.h:69
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:89
AkForceInline AK::IAkPluginMemAlloc * GetAllocator()
Definition: AkMixerInputMap.h:82
AkArray< AkInputMapSlot< USER_DATA >, const AkInputMapSlot< USER_DATA > &, AkPluginArrayAllocator, 1 > BaseClass
Definition: AkMixerInputMap.h:92
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:81
AkForceInline void AK_PLUGIN_DELETE(AK::IAkPluginMemAlloc *in_pAllocator, T *in_pObject)

このページはお役に立ちましたか?

サポートは必要ですか?

ご質問や問題、ご不明点はございますか?お気軽にお問い合わせください。

サポートページをご確認ください

あなたのプロジェクトについて教えてください。ご不明な点はありませんか。

プロジェクトを登録していただくことで、ご利用開始のサポートをいたします。

Wwiseからはじめよう