1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 10:09:43 +01:00
VVVVVV/desktop_version/src/DeferCallbacks.h
Misa c8537beac1 Add deferred callbacks to game loop
Sometimes, there needs to be code that gets ran at the end of the game
loop, otherwise rendering issues might occur. Currently, we do this by
special-casing each deferred routine (e.g. shouldreturntoeditor), but it
would be better if we could generalize this deference instead.

Deferred callbacks can be added using the DEFER_CALLBACK macro. It takes
in one argument, which is the name of a function, and that function must
be a void function that takes in no arguments. Also, due to annoying C++
quirks, void functions taking no arguments cannot be attributes of
objects (because they have an implicit `this` parameter), so it's
recommended to create each callback separately before using the
DEFER_CALLBACK macro.
2021-03-21 02:55:42 -04:00

31 lines
528 B
C

#ifndef DEFERCALLBACKS_H
#define DEFERCALLBACKS_H
#ifdef __cplusplus
extern "C"
{
#endif
struct DEFER_Callback
{
void (*func)(void);
struct DEFER_Callback* next;
};
void DEFER_add_callback(struct DEFER_Callback* callback);
void DEFER_execute_callbacks(void);
#define DEFER_CALLBACK(FUNC) \
do \
{ \
static struct DEFER_Callback callback = {FUNC, NULL}; \
\
DEFER_add_callback(&callback); \
} while (0)
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* DEFERCALLBACKS_H */