mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
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.
This commit is contained in:
31
desktop_version/src/DeferCallbacks.h
Normal file
31
desktop_version/src/DeferCallbacks.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#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 */
|
||||
Reference in New Issue
Block a user