]> git.lizzy.rs Git - dungeon_game.git/commitdiff
Add globalsteps
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 13 Jun 2021 18:34:58 +0000 (20:34 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 13 Jun 2021 18:34:58 +0000 (20:34 +0200)
plugins/game/game.c
plugins/game/game.h

index 9fcf7ea6c0191237fec9683d19161f2edd6a6cf6..5d5c31ae6f98fa8f210a163e5c0f7164a43405d0 100644 (file)
@@ -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;
 
index cdca0b4e6eb12cb44aa06ba60933aba5d29b4a43..7ae93448e743513429deacb41663579db029b510 100644 (file)
@@ -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