diff src/libmlk-core/core/action.c @ 369:1e06f871dc63

core: split action and action_stack
author David Demelier <markand@malikania.fr>
date Sun, 24 Oct 2021 17:33:12 +0200
parents 8f9937403749
children 460c78706989
line wrap: on
line diff
--- a/src/libmlk-core/core/action.c	Sun Oct 24 17:07:20 2021 +0200
+++ b/src/libmlk-core/core/action.c	Sun Oct 24 17:33:12 2021 +0200
@@ -17,14 +17,9 @@
  */
 
 #include <assert.h>
-#include <stddef.h>
-#include <string.h>
 
 #include "action.h"
 
-#define ACTION_FOREACH(st, iter) \
-	for (size_t i = 0; i < ACTION_STACK_MAX && ((iter) = (st)->actions[i], 1); ++i)
-
 void
 action_handle(struct action *act, const union event *ev)
 {
@@ -73,107 +68,3 @@
 	if (act->finish)
 		act->finish(act);
 }
-
-void
-action_stack_init(struct action_stack *st)
-{
-	assert(st);
-
-	memset(st, 0, sizeof (*st));
-}
-
-int
-action_stack_add(struct action_stack *st, struct action *act)
-{
-	assert(st);
-	assert(act);
-
-	for (size_t i = 0; i < ACTION_STACK_MAX; ++i) {
-		if (!st->actions[i]) {
-			st->actions[i] = act;
-			return 0;
-		}
-	}
-
-	return -1;
-}
-
-void
-action_stack_handle(struct action_stack *st, const union event *ev)
-{
-	assert(st);
-	assert(ev);
-
-	struct action *act;
-
-	ACTION_FOREACH(st, act)
-		if (act)
-			action_handle(act, ev);
-}
-
-int
-action_stack_update(struct action_stack *st, unsigned int ticks)
-{
-	assert(st);
-
-	struct action *act;
-
-	for (size_t i = 0; i < ACTION_STACK_MAX; ++i) {
-		act = st->actions[i];
-
-		if (act && action_update(act, ticks)) {
-			action_end(act);
-			action_finish(act);
-			st->actions[i] = NULL;
-		}
-	}
-
-	/*
-	 * We process all actions again in case the user modified the stack
-	 * within their update function.
-	 */
-	return action_stack_completed(st);
-}
-
-void
-action_stack_draw(const struct action_stack *st)
-{
-	assert(st);
-
-	struct action *act;
-
-	ACTION_FOREACH(st, act)
-		if (act)
-			action_draw(act);
-}
-
-int
-action_stack_completed(const struct action_stack *st)
-{
-	assert(st);
-
-	struct action *act;
-
-	ACTION_FOREACH(st, act)
-		if (act)
-			return 0;
-
-	return 1;
-}
-
-void
-action_stack_finish(struct action_stack *st)
-{
-	assert(st);
-	
-	struct action *act;
-
-	ACTION_FOREACH(st, act) {
-		if (act) {
-			action_end(act);
-			action_finish(act);
-		}
-	}
-
-	memset(st, 0, sizeof (*st));
-}