123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- #pragma once
- #include <AK/SoundEngine/Common/AkHashTableTypes.h>
- #include <AK/SoundEngine/Common/AkHashTableFuncs.h>
- #include <AK/SoundEngine/Common/IAkPlugin.h>
- #include <AK/Tools/Common/AkMurMurHash.h>
- namespace AK
- {
- class IAkPluginServiceHashTable : public IAkPluginService
- {
- protected:
- virtual ~IAkPluginServiceHashTable() {}
- public:
-
-
-
-
-
- virtual AKRESULT InitBase(AK::AkHashTableBase<AkUInt64>* io_pHashTable, AK::IAkPluginMemAlloc* in_pAllocator, AkUInt32 in_uInitialReserveCount, AkUInt32
- in_uValueElementSize, AkUInt32 in_uValueElementAlign) = 0;
-
- template<typename ValueType>
- AkForceInline AKRESULT Init(AkHashTable<AkUInt64, ValueType>* io_pHashTable, AK::IAkPluginMemAlloc* in_pAllocator, AkUInt32 in_uInitialReserveCount)
- {
- return InitBase(io_pHashTable, in_pAllocator, in_uInitialReserveCount, sizeof(ValueType), alignof(ValueType));
- }
-
- virtual void Term(AK::AkHashTableBase<AkUInt64>* io_pHashTable, AK::IAkPluginMemAlloc* in_pAllocator) = 0;
-
- virtual void Reset(AK::AkHashTableBase<AkUInt64>* io_pHashTable) = 0;
-
-
-
-
- virtual void* AddKey(AK::AkHashTableBase<AkUInt64>* io_pHashTable, AK::IAkPluginMemAlloc* in_pAllocator, AkUInt64 in_uKey) = 0;
-
-
-
-
- template<typename ValueType>
- AkForceInline ValueType* AddKeyValue(AkHashTable<AkUInt64, ValueType>* io_pHashTable, AK::IAkPluginMemAlloc* in_pAllocator, AkUInt64 in_uKey, ValueType* in_pNewValue)
- {
- if (ValueType* pInsertedValue = (ValueType*)AddKey(io_pHashTable, in_pAllocator, in_uKey))
- {
- AKASSERT(sizeof(ValueType) == io_pHashTable->uValueElementSize);
- AKPLATFORM::AkMemCpy(pInsertedValue, in_pNewValue, sizeof(ValueType));
- return pInsertedValue;
- }
- return nullptr;
- }
-
-
-
- virtual bool RemoveSlot(AK::AkHashTableBase<AkUInt64>* io_pHashTable, AkInt32 in_iSlot) = 0;
-
-
- virtual void RemoveKey(AK::AkHashTableBase<AkUInt64>* io_pHashTable, AkUInt64 in_uKey) = 0;
-
-
-
- static AkInt32 GetFirstSlotByKey(AK::AkHashTableBase<AkUInt64>* in_pHashTable, AkUInt64 in_uKey) {
- return AK::HashTable::GetFirstSlotForKey(in_pHashTable, in_uKey);
- }
-
-
-
- static AkInt32 GetNextSlotByKey(AK::AkHashTableBase<AkUInt64>* in_pHashTable, AkUInt64 in_uKey, AkInt32 in_iPreviousSlot) {
- return AK::HashTable::GetNextSlotForKey(in_pHashTable, in_uKey, in_iPreviousSlot);
- }
-
-
-
- template<typename KeyType, typename FuncType>
- void RemoveIf(AkHashTableBase<KeyType>* in_pHashTable, FuncType in_func)
- {
- AkUInt32 uNumReservedEntries = in_pHashTable->uNumReservedEntries;
- bool* pbSlotOccupied = in_pHashTable->pbSlotOccupied;
- AkUInt32 uSlot = 0;
- while (uSlot < uNumReservedEntries)
- {
- if (pbSlotOccupied[uSlot] && in_func(uSlot))
- {
- // if slot is occupied, and the function confirmed removal, remove this slot, but don't advance uSlot
- RemoveSlot(in_pHashTable, (AkInt32)uSlot);
- }
- else
- {
- uSlot++;
- }
- }
- }
- };
- #define AK_GET_PLUGIN_SERVICE_HASHTABLE(plugin_ctx) static_cast<AK::IAkPluginServiceHashTable*>(plugin_ctx->GetPluginService(AK::PluginServiceType_HashTable))
- struct AkAudioObjectBuffer
- {
- AkAudioObjectBuffer() : pMetadata(nullptr) {}
- AkAudioBuffer pBuffer;
- AkAudioObject* pMetadata;
- };
- typedef AK::AkHashTable<AkAudioObjectID, AkAudioObjectBuffer> AkAudioObjectBufferMap;
- AkForceInline AkUInt64 GetObjectChannelHash(AkUInt64 in_uAudioObjectId, AkUInt32 in_uChannelIdx)
- {
- return AkHashMurMurMix64(((AkUInt64)in_uChannelIdx << AkAudioObject::kObjectKeyNumBits) | (in_uAudioObjectId & AkAudioObject::kObjectKeyMask));
- }
- } // namespace AK
|