summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-03-31 02:32:32 +0200
committerkdx <kikoodx@paranoici.org>2023-03-31 02:32:32 +0200
commit3fb3d12d6a984c660c3fd18bc74216fceab8467f (patch)
tree7457f67a75eebc662283c249b28a32a99f25ca7d
parent69375e8cf07e0e5b1f812ac6147c83152fd3c48f (diff)
download006-3fb3d12d6a984c660c3fd18bc74216fceab8467f.tar.gz
draw begin+end & update begin+end
-rw-r--r--src/entity.h4
-rw-r--r--src/entityimpl.h8
-rw-r--r--src/game.c20
3 files changed, 32 insertions, 0 deletions
diff --git a/src/entity.h b/src/entity.h
index 6b8d2e7..bf246d0 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -6,8 +6,12 @@ struct Game;
typedef struct Entity Entity;
struct Entity {
unsigned long uuid;
+ void (*update_begin)(Entity *this, struct Game *g);
void (*update)(Entity *this, struct Game *g);
+ void (*update_end)(Entity *this, struct Game *g);
+ void (*draw_begin)(Entity *this, struct Game *g);
void (*draw)(Entity *this, struct Game *g);
+ void (*draw_end)(Entity *this, struct Game *g);
unsigned int type;
const char *name;
int pos[2];
diff --git a/src/entityimpl.h b/src/entityimpl.h
index 397e58b..87eeb4c 100644
--- a/src/entityimpl.h
+++ b/src/entityimpl.h
@@ -5,8 +5,12 @@
#include "entitytag.h"
#include <string.h>
+[[maybe_unused]] static void *_draw_begin;
[[maybe_unused]] static void *_draw;
+[[maybe_unused]] static void *_draw_end;
+[[maybe_unused]] static void *_update_begin;
[[maybe_unused]] static void *_update;
+[[maybe_unused]] static void *_update_end;
#define IMPL(X) static void X(Entity *this, Game *g); \
__attribute__((constructor)) static void init_##X() { _##X = X; } \
@@ -22,8 +26,12 @@ __attribute__((constructor)) static void init_tag(void) { \
static void _init(Entity *this); \
static void init(Entity *this, const char *name, int x, int y, int w, int h) { \
memset(this, 0, sizeof(*this)); \
+ this->update_begin = _update_begin; \
this->update = _update; \
+ this->update_end = _update_end; \
+ this->draw_begin = _draw_begin; \
this->draw = _draw; \
+ this->draw_end = _draw_end; \
this->name = name; \
this->pos[0] = x; \
this->pos[1] = y; \
diff --git a/src/game.c b/src/game.c
index ea98bec..13b4432 100644
--- a/src/game.c
+++ b/src/game.c
@@ -39,9 +39,19 @@ game_update(Game *this)
}
for (__auto_type i = 0; i < MAX_ENTITIES; i++) {
const __auto_type e = &this->entities[i];
+ if (e->type != 0 && e->update_begin != NULL)
+ e->update_begin(e, this);
+ }
+ for (__auto_type i = 0; i < MAX_ENTITIES; i++) {
+ const __auto_type e = &this->entities[i];
if (e->type != 0 && e->update != NULL)
e->update(e, this);
}
+ for (__auto_type i = 0; i < MAX_ENTITIES; i++) {
+ const __auto_type e = &this->entities[i];
+ if (e->type != 0 && e->update_end != NULL)
+ e->update_end(e, this);
+ }
}
void
@@ -50,9 +60,19 @@ game_draw(Game *this)
map_draw();
for (int i = 0; i < MAX_ENTITIES; i++) {
const __auto_type e = &this->entities[i];
+ if (e->type != 0 && e->draw_begin != NULL)
+ e->draw_begin(e, this);
+ }
+ for (int i = 0; i < MAX_ENTITIES; i++) {
+ const __auto_type e = &this->entities[i];
if (e->type != 0 && e->draw != NULL)
e->draw(e, this);
}
+ for (int i = 0; i < MAX_ENTITIES; i++) {
+ const __auto_type e = &this->entities[i];
+ if (e->type != 0 && e->draw_end != NULL)
+ e->draw_end(e, this);
+ }
}
void