From 67dc975a29da3abed0834f0fefbeb7c905c16316 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sun, 13 Jun 2021 20:34:58 +0200 Subject: [PATCH] Add globalsteps --- plugins/game/game.c | 13 +++++++++++++ plugins/game/game.h | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/plugins/game/game.c b/plugins/game/game.c index 9fcf7ea..5d5c31a 100644 --- a/plugins/game/game.c +++ b/plugins/game/game.c @@ -38,6 +38,7 @@ static struct list *air_functions = NULL; static struct input_handler *input_handlers[256] = {NULL}; static struct entity *render_entities[LIGHT * 2 + 1][LIGHT * 2 + 1]; static struct list *render_components = NULL; +static struct list *globalsteps = NULL; /* Helper functions */ @@ -239,6 +240,11 @@ void register_render_component(void (*callback)(struct winsize ws)) render_components = add_element(render_components, callback); }; +void register_globalstep(struct globalstep step) +{ + globalsteps = add_element(globalsteps, make_buffer(&step, sizeof(struct globalstep))); +} + /* Player */ static void player_death(struct entity *self) @@ -516,6 +522,13 @@ void game() bool dead = player_dead(); + for (struct list *ptr = globalsteps; ptr != NULL; ptr = ptr->next) { + struct globalstep *step = ptr->element; + + if (step->run_if_dead || ! dead) + step->callback(dtime); + } + if (! dead && damage_overlay > 0.0) { damage_overlay -= dtime; diff --git a/plugins/game/game.h b/plugins/game/game.h index cdca0b4..7ae9344 100644 --- a/plugins/game/game.h +++ b/plugins/game/game.h @@ -74,6 +74,12 @@ struct input_handler void (*callback)(); }; +struct globalstep +{ + bool run_if_dead; + void (*callback)(double dtime); +}; + enum direction { UP, @@ -120,5 +126,6 @@ void add_health(struct entity *entity, int health); void register_air_function(struct generator_function func); void register_input_handler(unsigned char c, struct input_handler handler); void register_render_component(void (*callback)(struct winsize ws)); +void register_globalstep(struct globalstep step); #endif -- 2.44.0