diff options
author | Chris Robinson <[email protected]> | 2010-05-01 19:59:41 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-05-01 19:59:41 -0700 |
commit | 0378422fcb4badba0a0dcdce503dcbe9d253f9a8 (patch) | |
tree | b7bf68507f0b8fa7716c821db445c88df060af29 /OpenAL32/Include/alMain.h | |
parent | 0760415d08031eea36abf193537c8c8a120cb2e6 (diff) |
Use a map to store sources and buffers
And do a lookup using a binary search instead of linear
Diffstat (limited to 'OpenAL32/Include/alMain.h')
-rw-r--r-- | OpenAL32/Include/alMain.h | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 27c1f981..5f40bcc7 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -226,6 +226,41 @@ void alc_pulse_deinit(void); void alc_pulse_probe(int type); +typedef struct UIntMap { + struct { + ALuint key; + ALvoid *value; + } *array; + ALsizei size; + ALsizei maxsize; +} UIntMap; + +void InitUIntMap(UIntMap *map); +void ResetUIntMap(UIntMap *map); +ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value); +void RemoveUIntMapKey(UIntMap *map, ALuint key); + +static inline ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key) +{ + if(map->size > 0) + { + ALsizei low = 0; + ALsizei high = map->size - 1; + while(low < high) + { + ALsizei mid = low + (high-low)/2; + if(map->array[mid].key < key) + low = mid + 1; + else + high = mid; + } + if(map->array[low].key == key) + return map->array[low].value; + } + return NULL; +} + + struct ALCdevice_struct { ALCboolean Connected; @@ -249,9 +284,8 @@ struct ALCdevice_struct ALCuint NumStereoSources; ALuint NumAuxSends; - // Linked List of Buffers for this device - struct ALbuffer *BufferList; - ALuint BufferCount; + // Map of Buffers for this device + UIntMap BufferMap; // Linked List of Effects for this device struct ALeffect *EffectList; @@ -311,8 +345,7 @@ struct ALCcontext_struct { ALlistener Listener; - struct ALsource *SourceList; - ALuint SourceCount; + UIntMap SourceMap; struct ALeffectslot *EffectSlotList; ALuint EffectSlotCount; |