diff options
author | Chris Robinson <[email protected]> | 2013-10-29 20:08:03 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2013-10-29 20:13:42 -0700 |
commit | bc9c3de96963dc47df9a5851f3c500e8a6404966 (patch) | |
tree | d1bfa93bec516e4f7f9c5273537481aee898f6fe | |
parent | 9f0e49917d808b93e0c47ce4fa2cbf7050cfe65a (diff) |
Use a helper macro for making vtable thunks
-rw-r--r-- | Alc/backends/base.h | 51 | ||||
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 28 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 29 |
3 files changed, 54 insertions, 54 deletions
diff --git a/Alc/backends/base.h b/Alc/backends/base.h index 285d1ac9..59e01304 100644 --- a/Alc/backends/base.h +++ b/Alc/backends/base.h @@ -49,30 +49,18 @@ struct ALCbackendVtable { static const struct ALCbackendVtable T##_ALCbackend_vtable #define DEFINE_ALCBACKEND_VTABLE(T) \ -static void T##_ALCbackend_Destruct(ALCbackend *obj) \ -{ T##_Destruct(STATIC_UPCAST(T, ALCbackend, obj)); } \ -static ALCenum T##_ALCbackend_open(ALCbackend *obj, const ALCchar *p1) \ -{ return T##_open(STATIC_UPCAST(T, ALCbackend, obj), p1); } \ -static void T##_ALCbackend_close(ALCbackend *obj) \ -{ T##_close(STATIC_UPCAST(T, ALCbackend, obj)); } \ -static ALCboolean T##_ALCbackend_reset(ALCbackend *obj) \ -{ return T##_reset(STATIC_UPCAST(T, ALCbackend, obj)); } \ -static ALCboolean T##_ALCbackend_start(ALCbackend *obj) \ -{ return T##_start(STATIC_UPCAST(T, ALCbackend, obj)); } \ -static void T##_ALCbackend_stop(ALCbackend *obj) \ -{ T##_stop(STATIC_UPCAST(T, ALCbackend, obj)); } \ -static ALCenum T##_ALCbackend_captureSamples(ALCbackend *obj, void *a, ALCuint b) \ -{ return T##_captureSamples(STATIC_UPCAST(T, ALCbackend, obj), a, b); } \ -static ALCuint T##_ALCbackend_availableSamples(ALCbackend *obj) \ -{ return T##_availableSamples(STATIC_UPCAST(T, ALCbackend, obj)); } \ -static ALint64 T##_ALCbackend_getLatency(ALCbackend *obj) \ -{ return T##_getLatency(STATIC_UPCAST(T, ALCbackend, obj)); } \ -static void T##_ALCbackend_lock(ALCbackend *obj) \ -{ T##_lock(STATIC_UPCAST(T, ALCbackend, obj)); } \ -static void T##_ALCbackend_unlock(ALCbackend *obj) \ -{ T##_unlock(STATIC_UPCAST(T, ALCbackend, obj)); } \ -static void T##_ALCbackend_Delete(ALCbackend *obj) \ -{ T##_Delete(STATIC_UPCAST(T, ALCbackend, obj)); } \ +DECLARE_THUNK(T, ALCbackend, void, Destruct) \ +DECLARE_THUNK1(T, ALCbackend, ALCenum, open, const ALCchar*) \ +DECLARE_THUNK(T, ALCbackend, void, close) \ +DECLARE_THUNK(T, ALCbackend, ALCboolean, reset) \ +DECLARE_THUNK(T, ALCbackend, ALCboolean, start) \ +DECLARE_THUNK(T, ALCbackend, void, stop) \ +DECLARE_THUNK2(T, ALCbackend, ALCenum, captureSamples, void*, ALCuint) \ +DECLARE_THUNK(T, ALCbackend, ALCuint, availableSamples) \ +DECLARE_THUNK(T, ALCbackend, ALint64, getLatency) \ +DECLARE_THUNK(T, ALCbackend, void, lock) \ +DECLARE_THUNK(T, ALCbackend, void, unlock) \ +DECLARE_THUNK(T, ALCbackend, void, Delete) \ \ DECLARE_ALCBACKEND_VTABLE(T) = { \ T##_ALCbackend_Destruct, \ @@ -116,16 +104,11 @@ struct ALCbackendFactoryVtable { }; #define DEFINE_ALCBACKENDFACTORY_VTABLE(T) \ -static ALCboolean T##_ALCbackendFactory_init(ALCbackendFactory *obj) \ -{ return T##_init(STATIC_UPCAST(T, ALCbackendFactory, obj)); } \ -static void T##_ALCbackendFactory_deinit(ALCbackendFactory *obj) \ -{ T##_deinit(STATIC_UPCAST(T, ALCbackendFactory, obj)); } \ -static ALCboolean T##_ALCbackendFactory_querySupport(ALCbackendFactory *obj, ALCbackend_Type a) \ -{ return T##_querySupport(STATIC_UPCAST(T, ALCbackendFactory, obj), a); } \ -static void T##_ALCbackendFactory_probe(ALCbackendFactory *obj, enum DevProbe a) \ -{ T##_probe(STATIC_UPCAST(T, ALCbackendFactory, obj), a); } \ -static ALCbackend* T##_ALCbackendFactory_createBackend(ALCbackendFactory *obj, ALCdevice *a, ALCbackend_Type b) \ -{ return T##_createBackend(STATIC_UPCAST(T, ALCbackendFactory, obj), a, b); } \ +DECLARE_THUNK(T, ALCbackendFactory, ALCboolean, init) \ +DECLARE_THUNK(T, ALCbackendFactory, void, deinit) \ +DECLARE_THUNK1(T, ALCbackendFactory, ALCboolean, querySupport, ALCbackend_Type) \ +DECLARE_THUNK1(T, ALCbackendFactory, void, probe, enum DevProbe) \ +DECLARE_THUNK2(T, ALCbackendFactory, ALCbackend*, createBackend, ALCdevice*, ALCbackend_Type) \ \ static const struct ALCbackendFactoryVtable T##_ALCbackendFactory_vtable = { \ T##_ALCbackendFactory_init, \ diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index 71898964..73b4b67b 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -16,26 +16,25 @@ typedef struct ALeffectState { } ALeffectState; struct ALeffectStateVtable { - ALvoid (*const Destruct)(ALeffectState *state); + void (*const Destruct)(ALeffectState *state); ALboolean (*const deviceUpdate)(ALeffectState *state, ALCdevice *device); - ALvoid (*const update)(ALeffectState *state, ALCdevice *device, const struct ALeffectslot *slot); - ALvoid (*const process)(ALeffectState *state, ALuint samplesToDo, const ALfloat *restrict samplesIn, ALfloat (*restrict samplesOut)[BUFFERSIZE]); + void (*const update)(ALeffectState *state, ALCdevice *device, const struct ALeffectslot *slot); + void (*const process)(ALeffectState *state, ALuint samplesToDo, const ALfloat *restrict samplesIn, ALfloat (*restrict samplesOut)[BUFFERSIZE]); void (*const Delete)(struct ALeffectState *state); }; +/* Small hack to use a pointer-to-array type as a normal argument type. + * Shouldn't be used directly. */ +typedef ALfloat ALfloatBUFFERSIZE[BUFFERSIZE]; + #define DEFINE_ALEFFECTSTATE_VTABLE(T) \ -static ALvoid T##_ALeffectState_Destruct(ALeffectState *state) \ -{ T##_Destruct(STATIC_UPCAST(T, ALeffectState, state)); } \ -static ALboolean T##_ALeffectState_deviceUpdate(ALeffectState *state, ALCdevice *device) \ -{ return T##_deviceUpdate(STATIC_UPCAST(T, ALeffectState, state), device); } \ -static ALvoid T##_ALeffectState_update(ALeffectState *state, ALCdevice *device, const ALeffectslot *slot) \ -{ T##_update(STATIC_UPCAST(T, ALeffectState, state), device, slot); } \ -static ALvoid T##_ALeffectState_process(ALeffectState *state, ALuint samplesToDo, const ALfloat *restrict samplesIn, ALfloat (*restrict samplesOut)[BUFFERSIZE]) \ -{ T##_process(STATIC_UPCAST(T, ALeffectState, state), samplesToDo, samplesIn, samplesOut); } \ -static ALvoid T##_ALeffectState_Delete(ALeffectState *state) \ -{ T##_Delete(STATIC_UPCAST(T, ALeffectState, state)); } \ +DECLARE_THUNK(T, ALeffectState, void, Destruct) \ +DECLARE_THUNK1(T, ALeffectState, ALboolean, deviceUpdate, ALCdevice*) \ +DECLARE_THUNK2(T, ALeffectState, void, update, ALCdevice*, const ALeffectslot*) \ +DECLARE_THUNK3(T, ALeffectState, void, process, ALuint, const ALfloat*restrict, ALfloatBUFFERSIZE*restrict) \ +DECLARE_THUNK(T, ALeffectState, void, Delete) \ \ static const struct ALeffectStateVtable T##_ALeffectState_vtable = { \ T##_ALeffectState_Destruct, \ @@ -59,8 +58,7 @@ struct ALeffectStateFactoryVtable { }; #define DEFINE_ALEFFECTSTATEFACTORY_VTABLE(T) \ -static ALeffectState* T##_ALeffectStateFactory_create(ALeffectStateFactory *factory) \ -{ return T##_create(STATIC_UPCAST(T, ALeffectStateFactory, factory)); } \ +DECLARE_THUNK(T, ALeffectStateFactory, ALeffectState*, create) \ \ static const struct ALeffectStateFactoryVtable T##_ALeffectStateFactory_vtable = { \ T##_ALeffectStateFactory_create, \ diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 370c20af..64678b38 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -96,11 +96,6 @@ static const union { #define STATIC_CAST(to, obj) (&(obj)->to##_parent) #define STATIC_UPCAST(to, from, obj) ((to*)((char*)(obj) - offsetof(to, from##_parent))) -#define GET_VTABLE1(T1) (&(T1##_vtable)) -#define GET_VTABLE2(T1, T2) (&(T1##_##T2##_vtable)) - -#define SET_VTABLE1(T1, obj) ((obj)->vtbl = GET_VTABLE1(T1)) -#define SET_VTABLE2(T1, T2, obj) (STATIC_CAST(T2, obj)->vtbl = GET_VTABLE2(T1, T2)) #define DECLARE_FORWARD(T1, T2, rettype, func) \ rettype T1##_##func(T1 *obj) \ @@ -110,6 +105,30 @@ rettype T1##_##func(T1 *obj) \ rettype T1##_##func(T1 *obj, argtype1 a, argtype2 b) \ { return T2##_##func(STATIC_CAST(T2, obj), a, b); } + +#define GET_VTABLE1(T1) (&(T1##_vtable)) +#define GET_VTABLE2(T1, T2) (&(T1##_##T2##_vtable)) + +#define SET_VTABLE1(T1, obj) ((obj)->vtbl = GET_VTABLE1(T1)) +#define SET_VTABLE2(T1, T2, obj) (STATIC_CAST(T2, obj)->vtbl = GET_VTABLE2(T1, T2)) + +#define DECLARE_THUNK(T1, T2, rettype, func) \ +static rettype T1##_##T2##_##func(T2 *obj) \ +{ return T1##_##func(STATIC_UPCAST(T1, T2, obj)); } + +#define DECLARE_THUNK1(T1, T2, rettype, func, argtype1) \ +static rettype T1##_##T2##_##func(T2 *obj, argtype1 a) \ +{ return T1##_##func(STATIC_UPCAST(T1, T2, obj), a); } + +#define DECLARE_THUNK2(T1, T2, rettype, func, argtype1, argtype2) \ +static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b) \ +{ return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b); } + +#define DECLARE_THUNK3(T1, T2, rettype, func, argtype1, argtype2, argtype3) \ +static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b, argtype3 c) \ +{ return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b, c); } + + /* Helper to extract an argument list for VCALL. Not used directly. */ #define EXTRACT_VCALL_ARGS(...) __VA_ARGS__)) |