hyperultra/src/entityimpl.h

31 lines
910 B
C
Raw Permalink Normal View History

2023-03-18 21:54:01 +01:00
#pragma once
#include "game.h"
#include "cfg.h"
#include "lzy.h"
2023-03-23 16:16:22 +01:00
#include "entitytag.h"
2023-03-18 21:54:01 +01:00
#include <string.h>
2023-03-26 09:26:47 +02:00
[[maybe_unused]] static void *_draw;
[[maybe_unused]] static void *_update;
2023-03-26 07:45:46 +02:00
2023-03-26 09:26:47 +02:00
#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); \
2023-03-26 07:45:46 +02:00
__attribute__((constructor)) static void init_tag() { \
2023-03-26 09:11:55 +02:00
entitytags[num_entitytags].init = init; \
entitytags[num_entitytags++].name = #X; \
2023-03-23 16:16:22 +01:00
} \
2023-03-26 09:26:47 +02:00
static void _init(Entity *this); \
static void init(Entity *this, int x, int y) { \
2023-03-18 21:54:01 +01:00
memset(this, 0, sizeof(*this)); \
2023-03-26 09:26:47 +02:00
this->update = _update; \
this->draw = _draw; \
2023-03-18 21:54:01 +01:00
this->pos[0] = x; \
this->pos[1] = y; \
2023-03-23 16:16:22 +01:00
this->type = entity_type(#X); \
2023-03-26 09:26:47 +02:00
_init(this); \
} \
static void _init([[maybe_unused]] Entity *this)