summaryrefslogtreecommitdiff
path: root/src/entityimpl.h
blob: 1fd65ba7dd78c6a084b21132e6ee7bcd082d170f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once
#include "game.h"
#include "cfg.h"
#include "lzy.h"
#include "entitytag.h"
#include <string.h>

[[maybe_unused]] static void *_draw;
[[maybe_unused]] static void *_update;

#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 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->pos[0] = x; \
	this->pos[1] = y; \
	this->type = entity_type(#X); \
	_init(this); \
} \
static void _init([[maybe_unused]] Entity *this)