]> git.lizzy.rs Git - dungeon_game.git/blobdiff - plugins/game/game.c
Add globalsteps
[dungeon_game.git] / plugins / game / game.c
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;