diff options
author | Chris Robinson <[email protected]> | 2013-05-21 04:18:02 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2013-05-21 04:18:02 -0700 |
commit | 5516d8df0b21722c96189b946a8a10e9cbb0c001 (patch) | |
tree | c35fb0bf09965f0d528d40e984e529f3b8f3bac8 /OpenAL32 | |
parent | fba9ac6db1d1d1bff066befe48f75c64aead3587 (diff) |
Use macros to help define vtables for effect states
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 45 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 48 |
2 files changed, 58 insertions, 35 deletions
diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index c19eb7b3..a891b52a 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -8,15 +8,36 @@ extern "C" { #endif -typedef struct ALeffectState { - ALvoid (*Destroy)(struct ALeffectState *State); - ALboolean (*DeviceUpdate)(struct ALeffectState *State, ALCdevice *Device); - ALvoid (*Update)(struct ALeffectState *State, ALCdevice *Device, const struct ALeffectslot *Slot); - ALvoid (*Process)(struct ALeffectState *State, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]); -} ALeffectState; +typedef struct ALeffectState ALeffectState; +typedef struct ALeffectslot ALeffectslot; + +struct ALeffectStateVtable { + ALvoid (*const Destroy)(ALeffectState *State); + ALboolean (*const DeviceUpdate)(ALeffectState *State, ALCdevice *Device); + ALvoid (*const Update)(ALeffectState *State, ALCdevice *Device, const ALeffectslot *Slot); + ALvoid (*const Process)(ALeffectState *State, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]); +}; + +struct ALeffectState { + const struct ALeffectStateVtable *vtbl; +}; + +#define DEFINE_ALEFFECTSTATE_VTABLE(T) \ +static const struct ALeffectStateVtable T##_ALeffectState_vtable = { \ + T##_Destroy, \ + T##_DeviceUpdate, \ + T##_Update, \ + T##_Process \ +} + +#define SET_VTABLE1(T1, obj) ((obj)->vtbl = &(T1##_vtable)) +#define SET_VTABLE2(T1, T2, obj) do { \ + STATIC_CAST(T2, (obj))->vtbl = &(T1##_##T2##_vtable); \ + /*SET_VTABLE1(T1, obj);*/ \ +} while(0) -typedef struct ALeffectslot +struct ALeffectslot { ALeffect effect; @@ -35,7 +56,7 @@ typedef struct ALeffectslot /* Self ID */ ALuint id; -} ALeffectslot; +}; ALenum InitEffectSlot(ALeffectslot *slot); @@ -51,10 +72,10 @@ ALeffectState *FlangerCreate(void); ALeffectState *EqualizerCreate(void); ALeffectState *DistortionCreate(void); -#define ALeffectState_Destroy(a) ((a)->Destroy((a))) -#define ALeffectState_DeviceUpdate(a,b) ((a)->DeviceUpdate((a),(b))) -#define ALeffectState_Update(a,b,c) ((a)->Update((a),(b),(c))) -#define ALeffectState_Process(a,b,c,d) ((a)->Process((a),(b),(c),(d))) +#define ALeffectState_Destroy(a) ((a)->vtbl->Destroy((a))) +#define ALeffectState_DeviceUpdate(a,b) ((a)->vtbl->DeviceUpdate((a),(b))) +#define ALeffectState_Update(a,b,c) ((a)->vtbl->Update((a),(b),(c))) +#define ALeffectState_Process(a,b,c,d) ((a)->vtbl->Process((a),(b),(c),(d))) ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect); diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index 7df6bca4..0932376d 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -393,41 +393,43 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum p } -static ALvoid NoneDestroy(ALeffectState *State) -{ free(State); } -static ALboolean NoneDeviceUpdate(ALeffectState *State, ALCdevice *Device) +typedef struct ALnoneState { + DERIVE_FROM_TYPE(ALeffectState); +} ALnoneState; + +static ALvoid ALnoneState_Destroy(ALeffectState *state) +{ free(state); } +static ALboolean ALnoneState_DeviceUpdate(ALeffectState *state, ALCdevice *device) { return AL_TRUE; - (void)State; - (void)Device; + (void)state; + (void)device; } -static ALvoid NoneUpdate(ALeffectState *State, ALCdevice *Device, const ALeffectslot *Slot) +static ALvoid ALnoneState_Update(ALeffectState *state, ALCdevice *device, const ALeffectslot *slot) { - (void)State; - (void)Device; - (void)Slot; + (void)state; + (void)device; + (void)slot; } -static ALvoid NoneProcess(ALeffectState *State, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE]) +static ALvoid ALnoneState_Process(ALeffectState *state, ALuint samplesToDo, const ALfloat *RESTRICT samplesIn, ALfloat (*RESTRICT samplesOut)[BUFFERSIZE]) { - (void)State; - (void)SamplesToDo; - (void)SamplesIn; - (void)SamplesOut; + (void)state; + (void)samplesToDo; + (void)samplesIn; + (void)samplesOut; } + +DEFINE_ALEFFECTSTATE_VTABLE(ALnoneState); + ALeffectState *NoneCreate(void) { - ALeffectState *state; + ALnoneState *state; state = calloc(1, sizeof(*state)); - if(!state) - return NULL; - - state->Destroy = NoneDestroy; - state->DeviceUpdate = NoneDeviceUpdate; - state->Update = NoneUpdate; - state->Process = NoneProcess; + if(!state) return NULL; + SET_VTABLE2(ALnoneState, ALeffectState, state); - return state; + return STATIC_CAST(ALeffectState, state); } void null_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val) |