diff options
-rw-r--r-- | Alc/ALc.c | 68 | ||||
-rw-r--r-- | Alc/ALu.c | 37 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 4 |
3 files changed, 53 insertions, 56 deletions
@@ -1019,11 +1019,12 @@ static ALCboolean IsContext(ALCcontext *context) tmp_dev = g_pDeviceList; while(tmp_dev) { - ALuint i; - for(i = 0;i < tmp_dev->NumContexts;i++) + ALCcontext *tmp_ctx = tmp_dev->ContextList; + while(tmp_ctx) { - if(tmp_dev->Contexts[i] == context) + if(tmp_ctx == context) return ALC_TRUE; + tmp_ctx = tmp_ctx->next; } tmp_dev = tmp_dev->next; } @@ -1054,6 +1055,7 @@ ALCvoid alcSetError(ALCdevice *device, ALenum errorCode) */ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) { + ALCcontext *context; ALuint i; // Check for attributes @@ -1229,9 +1231,9 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) } TRACE("Stereo duplication %s\n", (device->Flags&DEVICE_DUPLICATE_STEREO)?"enabled":"disabled"); - for(i = 0;i < device->NumContexts;i++) + context = device->ContextList; + while(context) { - ALCcontext *context = device->Contexts[i]; ALsizei pos; context->UpdateSources = AL_FALSE; @@ -1266,6 +1268,8 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) source->NeedsUpdate = AL_FALSE; ALsource_Update(source, context); } + + context = context->next; } UnlockDevice(device); @@ -2029,7 +2033,6 @@ ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *e ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList) { ALCcontext *ALContext; - void *temp; LockLists(); if(!IsDevice(device) || device->IsCaptureDevice || !device->Connected) @@ -2050,28 +2053,19 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin return NULL; } - LockDevice(device); - ALContext = NULL; - temp = realloc(device->Contexts, (device->NumContexts+1) * sizeof(*device->Contexts)); - if(temp) + ALContext = calloc(1, sizeof(ALCcontext)); + if(ALContext) { - device->Contexts = temp; - - ALContext = calloc(1, sizeof(ALCcontext)); - if(ALContext) - { - ALContext->ref = 1; + ALContext->ref = 1; - ALContext->MaxActiveSources = 256; - ALContext->ActiveSources = malloc(sizeof(ALContext->ActiveSources[0]) * - ALContext->MaxActiveSources); - } + ALContext->MaxActiveSources = 256; + ALContext->ActiveSources = malloc(sizeof(ALContext->ActiveSources[0]) * + ALContext->MaxActiveSources); } if(!ALContext || !ALContext->ActiveSources) { free(ALContext); alcSetError(device, ALC_OUT_OF_MEMORY); - UnlockDevice(device); if(device->NumContexts == 0) { ALCdevice_StopPlayback(device); @@ -2080,14 +2074,17 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin UnlockLists(); return NULL; } - - device->Contexts[device->NumContexts++] = ALContext; ALContext->Device = device; - InitContext(ALContext); + LockDevice(device); + UnlockLists(); + + ALContext->next = device->ContextList; + device->ContextList = ALContext; + device->NumContexts++; + InitContext(ALContext); UnlockDevice(device); - UnlockLists(); return ALContext; } @@ -2101,7 +2098,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) { ALCdevice *Device; - ALuint i; + ALCcontext **tmp_ctx; LockLists(); Device = alcGetContextsDevice(context); @@ -2112,14 +2109,16 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) } LockDevice(Device); - for(i = 0;i < Device->NumContexts;i++) + tmp_ctx = &Device->ContextList; + while(*tmp_ctx) { - if(Device->Contexts[i] == context) + if(*tmp_ctx == context) { - Device->Contexts[i] = Device->Contexts[Device->NumContexts-1]; + *tmp_ctx = (*tmp_ctx)->next; Device->NumContexts--; break; } + tmp_ctx = &(*tmp_ctx)->next; } UnlockDevice(Device); @@ -2411,7 +2410,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) device->Bs2b = NULL; device->szDeviceName = NULL; - device->Contexts = NULL; + device->ContextList = NULL; device->NumContexts = 0; InitUIntMap(&device->BufferMap); @@ -2506,8 +2505,8 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice) if(pDevice->NumContexts > 0) { WARN("alcCloseDevice(): destroying %u Context(s)\n", pDevice->NumContexts); - while(pDevice->NumContexts > 0) - alcDestroyContext(pDevice->Contexts[0]); + while(pDevice->ContextList) + alcDestroyContext(pDevice->ContextList); } ALCdevice_ClosePlayback(pDevice); @@ -2538,9 +2537,6 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice) free(pDevice->szDeviceName); pDevice->szDeviceName = NULL; - free(pDevice->Contexts); - pDevice->Contexts = NULL; - DeleteCriticalSection(&pDevice->Mutex); //Release device structure @@ -2576,7 +2572,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(void) device->Bs2b = NULL; device->szDeviceName = NULL; - device->Contexts = NULL; + device->ContextList = NULL; device->NumContexts = 0; InitUIntMap(&device->BufferMap); @@ -950,8 +950,8 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) { ALuint SamplesToDo; ALeffectslot *ALEffectSlot; - ALCcontext **ctx, **ctx_end; ALsource **src, **src_end; + ALCcontext *ctx; int fpuState; ALuint i, c; ALsizei e; @@ -975,26 +975,25 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) memset(device->DryBuffer, 0, SamplesToDo*MAXCHANNELS*sizeof(ALfloat)); LockDevice(device); - ctx = device->Contexts; - ctx_end = ctx + device->NumContexts; - while(ctx != ctx_end) + ctx = device->ContextList; + while(ctx) { - ALboolean DeferUpdates = (*ctx)->DeferUpdates; + ALboolean DeferUpdates = ctx->DeferUpdates; ALboolean UpdateSources = AL_FALSE; if(!DeferUpdates) { - UpdateSources = (*ctx)->UpdateSources; - (*ctx)->UpdateSources = AL_FALSE; + UpdateSources = ctx->UpdateSources; + ctx->UpdateSources = AL_FALSE; } - src = (*ctx)->ActiveSources; - src_end = src + (*ctx)->ActiveSourceCount; + src = ctx->ActiveSources; + src_end = src + ctx->ActiveSourceCount; while(src != src_end) { if((*src)->state != AL_PLAYING) { - --((*ctx)->ActiveSourceCount); + --(ctx->ActiveSourceCount); *src = *(--src_end); continue; } @@ -1002,7 +1001,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) if(!DeferUpdates && ((*src)->NeedsUpdate || UpdateSources)) { (*src)->NeedsUpdate = AL_FALSE; - ALsource_Update(*src, *ctx); + ALsource_Update(*src, ctx); } MixSource(*src, device, SamplesToDo); @@ -1010,9 +1009,9 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) } /* effect slot processing */ - for(e = 0;e < (*ctx)->EffectSlotMap.size;e++) + for(e = 0;e < ctx->EffectSlotMap.size;e++) { - ALEffectSlot = (*ctx)->EffectSlotMap.array[e].value; + ALEffectSlot = ctx->EffectSlotMap.array[e].value; for(i = 0;i < SamplesToDo;i++) { @@ -1028,7 +1027,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) if(!DeferUpdates && ALEffectSlot->NeedsUpdate) { ALEffectSlot->NeedsUpdate = AL_FALSE; - ALEffect_Update(ALEffectSlot->EffectState, *ctx, ALEffectSlot); + ALEffect_Update(ALEffectSlot->EffectState, ctx, ALEffectSlot); } ALEffect_Process(ALEffectSlot->EffectState, ALEffectSlot, @@ -1039,7 +1038,7 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) ALEffectSlot->WetBuffer[i] = 0.0f; } - ctx++; + ctx = ctx->next; } UnlockDevice(device); @@ -1123,12 +1122,12 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) ALvoid aluHandleDisconnect(ALCdevice *device) { - ALuint i; + ALCcontext *Context; LockDevice(device); - for(i = 0;i < device->NumContexts;i++) + Context = device->ContextList; + while(Context) { - ALCcontext *Context = device->Contexts[i]; ALsource *source; ALsizei pos; @@ -1143,6 +1142,8 @@ ALvoid aluHandleDisconnect(ALCdevice *device) source->position_fraction = 0; } } + + Context = Context->next; } device->Connected = ALC_FALSE; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 357090a6..75dd7ec8 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -471,8 +471,8 @@ struct ALCdevice_struct ALfloat PendingClicks[MAXCHANNELS]; // Contexts created on this device - ALCcontext **Contexts; - ALuint NumContexts; + ALCcontext *ContextList; + ALuint NumContexts; BackendFuncs *Funcs; void *ExtraData; // For the backend's use |