diff options
Diffstat (limited to 'src/entityimpl.h')
-rw-r--r-- | src/entityimpl.h | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/entityimpl.h b/src/entityimpl.h index 3d62172..1fd65ba 100644 --- a/src/entityimpl.h +++ b/src/entityimpl.h @@ -5,22 +5,26 @@ #include "entitytag.h" #include <string.h> -#define IMPL(X) static void \ -X([[maybe_unused]] Entity *this, [[maybe_unused]] Game *g) +[[maybe_unused]] static void *_draw; +[[maybe_unused]] static void *_update; -#define IMPL_INIT(X) static Entity *init(Entity *this, int x, int y); \ +#define IMPL(X) static void X(Entity *this, Game *g); \ +__attribute__((constructor)) static void init_##X() { _##X = X; } \ +static void X([[maybe_unused]] Entity *this, [[maybe_unused]] Game *g) + +#define IMPL_INIT(X) static void init(Entity *this, int x, int y); \ __attribute__((constructor)) static void init_tag() { \ entitytags[num_entitytags].init = init; \ entitytags[num_entitytags++].name = #X; \ } \ -static Entity * \ -init(Entity *this, int x, int y) { do { \ +static void _init(Entity *this); \ +static void init(Entity *this, int x, int y) { \ memset(this, 0, sizeof(*this)); \ - this->update = update; \ - this->draw = draw; \ + this->update = _update; \ + this->draw = _draw; \ this->pos[0] = x; \ this->pos[1] = y; \ this->type = entity_type(#X); \ -} while(0); - -#define IMPL_END return this; } + _init(this); \ +} \ +static void _init([[maybe_unused]] Entity *this) |