summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-03-27 07:41:06 +0200
committerkdx <kikoodx@paranoici.org>2023-03-27 07:41:06 +0200
commit98bc80608f4252fb36bd6d0865341f98b036640b (patch)
treee9b2f770142a12072bd3f242ab18dbdc12000f0e
parentc81626e8a4dafcbc7d396b91d15865c758571473 (diff)
download006-98bc80608f4252fb36bd6d0865341f98b036640b.tar.gz
init width and height
-rw-r--r--src/entity.c4
-rw-r--r--src/entity.h2
-rw-r--r--src/entityimpl.h16
-rw-r--r--src/entitytag.h2
-rw-r--r--src/game.c3
5 files changed, 15 insertions, 12 deletions
diff --git a/src/entity.c b/src/entity.c
index 75ad7ec..89769fd 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -93,8 +93,8 @@ entity_move(Entity *this, [[maybe_unused]] struct Game *g)
}
Entity *
-entity_init(Entity *this, unsigned int type, int x, int y)
+entity_init(Entity *this, unsigned int type, int x, int y, int w, int h)
{
- entitytags[type - 1].init(this, x, y);
+ entitytags[type - 1].init(this, x, y, w, h);
return this;
}
diff --git a/src/entity.h b/src/entity.h
index 01230d5..c444be8 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -22,4 +22,4 @@ bool entity_collide(Entity *this, int ox, int oy);
bool entity_meet(Entity *this, Entity *other);
Entity *entity_place_meeting(Entity *this, struct Game *g, unsigned int type);
void entity_move(Entity *this, struct Game *g);
-Entity *entity_init(Entity *this, unsigned int type, int x, int y);
+Entity *entity_init(Entity *this, unsigned int type, int x, int y, int w, int h);
diff --git a/src/entityimpl.h b/src/entityimpl.h
index bd88df4..5ed9dfa 100644
--- a/src/entityimpl.h
+++ b/src/entityimpl.h
@@ -5,25 +5,27 @@
#include "entitytag.h"
#include <string.h>
-//[[maybe_unused]] static void *_draw;
-//[[maybe_unused]] static void *_update;
+[[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)
-/*__attribute__((constructor)) static void init_##X() { _##X = X; } \ */
-#define IMPL_INIT(X) static void init(Entity *this, int x, int y); \
+#define IMPL_INIT(X) static void init(Entity *, int, int, int, int); \
__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) { \
+static void init(Entity *this, int x, int y, int w, int h) { \
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->width = w; \
+ this->height = h; \
this->type = entity_type(#X); \
_init(this); \
} \
diff --git a/src/entitytag.h b/src/entitytag.h
index 154023c..0578089 100644
--- a/src/entitytag.h
+++ b/src/entitytag.h
@@ -3,7 +3,7 @@
typedef struct {
const char *name;
- void (*init)(Entity *this, int x, int y);
+ void (*init)(Entity *this, int x, int y, int w, int h);
} EntityTag;
extern unsigned int num_entitytags;
diff --git a/src/game.c b/src/game.c
index 4cd9728..fb7994a 100644
--- a/src/game.c
+++ b/src/game.c
@@ -58,7 +58,8 @@ game_restart_scene(Game *this)
continue;
const __auto_type x = object->x + object->width / 2;
const __auto_type y = object->y + object->height / 2;
- entity_init(game_create_entity(this), type, x, y);
+ entity_init(game_create_entity(this), type, x, y,
+ object->width, object->height);
}
}