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:
Misa
2020-12-23 23:24:31 -08:00
committed by Ethan Lee
parent c8958de537
commit c8537beac1
4 changed files with 120 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
#include <SDL.h>
#include <stdio.h>
#include "DeferCallbacks.h"
#include "editor.h"
#include "Enums.h"
#include "Entity.h"
@@ -226,6 +227,9 @@ static enum IndexCode increment_gamestate_func_index(void)
&num_gamestate_funcs
);
/* Also run callbacks that were deferred to end of func sequence. */
DEFER_execute_callbacks();
gamestate_func_index = 0;
return Index_end;