From ab17bd8050ebdfccb3b30b4d31f2165afb8cb7b6 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 5 Jul 2018 22:31:18 +0200 Subject: [PATCH] timeline: add TM_AddActionAfter --- src/timeline.c | 32 ++++++++++++++++++++++---------- src/timeline.h | 6 ++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/timeline.c b/src/timeline.c index 4f39660..0ac1867 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -183,17 +183,8 @@ SYMBOL_EXPORT void TM_Process(struct Timeline* timeline, double delta) { } } -SYMBOL_EXPORT struct TM_Action* TM_AddNamedAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, char* name) { +static struct TM_Action* CreateAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, char* name) { struct TM_Action* action = malloc(sizeof(struct TM_Action)); - if (timeline->queue) { - struct TM_Action* pom = timeline->queue; - while (pom->next != NULL) { - pom = pom->next; - } - pom->next = action; - } else { - timeline->queue = action; - } action->next = NULL; action->function = func; action->arguments = args; @@ -211,6 +202,27 @@ SYMBOL_EXPORT struct TM_Action* TM_AddNamedAction(struct Timeline* timeline, TM_ return action; } +SYMBOL_EXPORT struct TM_Action* TM_AddNamedAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, char* name) { + struct TM_Action* action = CreateAction(timeline, func, args, name); + if (timeline->queue) { + struct TM_Action* pom = timeline->queue; + while (pom->next != NULL) { + pom = pom->next; + } + pom->next = action; + } else { + timeline->queue = action; + } + return action; +} + +SYMBOL_EXPORT struct TM_Action* TM_AddNamedActionAfter(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, struct TM_Action* after, char* name) { + struct TM_Action* action = CreateAction(timeline, func, args, name); + action->next = after->next; + after->next = action; + return action; +} + SYMBOL_EXPORT struct TM_Action* TM_AddNamedBackgroundAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, int delay, char* name) { struct TM_Action* action = malloc(sizeof(struct TM_Action)); if (timeline->background) { diff --git a/src/timeline.h b/src/timeline.h index 4eb8796..f7b62a8 100644 --- a/src/timeline.h +++ b/src/timeline.h @@ -75,6 +75,9 @@ void TM_Process(struct Timeline*, double delta); /*! \brief Add new action to main queue, with specified name. */ struct TM_Action* TM_AddNamedAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, char* name); +/*! \brief Add new action to main queue, with specified name, placed after specified action. */ +struct TM_Action* TM_AddNamedActionAfter(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, struct TM_Action* after, char* name); + /*! \brief Add new action to background queue, with specified name. */ struct TM_Action* TM_AddNamedBackgroundAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, int delay, char* name); @@ -84,6 +87,9 @@ struct TM_Action* TM_AddQueuedNamedBackgroundAction(struct Timeline* timeline, T /*! \brief Add new action to main queue. */ #define TM_AddAction(timeline, func, args) TM_AddNamedAction(timeline, func, args, #func) +/*! \brief Add new action to main queue placed after specified action.. */ +#define TM_AddActionAfter(timeline, func, args, after) TM_AddNamedAction(timeline, func, args, after, #func) + /*! \brief Add new action to background queue. */ #define TM_AddBackgroundAction(timeline, func, args, delay) TM_AddNamedBackgroundAction(timeline, func, args, delay, #func)