diff --git a/src/level.c b/src/level.c index 5c80d25..0c220e0 100644 --- a/src/level.c +++ b/src/level.c @@ -51,11 +51,8 @@ void Level_Draw(struct Game *game) { bool FadeIn(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (!action->arguments) { - action->arguments = malloc(sizeof(struct TM_Arguments)); - action->arguments->value = malloc(sizeof(float)); - action->arguments->next = malloc(sizeof(struct TM_Arguments)); - action->arguments->next->value = (void*)al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)); - action->arguments->next->next = NULL; + action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(float))); + action->arguments = TM_AddToArgs(action->arguments, (void*)al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display))); } float* fadeloop; ALLEGRO_BITMAP* fade_bitmap; @@ -81,11 +78,8 @@ bool FadeIn(struct Game *game, struct TM_Action *action, enum TM_ActionState sta bool FadeOut(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (!action->arguments) { - action->arguments = malloc(sizeof(struct TM_Arguments)); - action->arguments->value = malloc(sizeof(float)); - action->arguments->next = malloc(sizeof(struct TM_Arguments)); - action->arguments->next->value = (void*)al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display)); - action->arguments->next->next = NULL; + action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(float))); + action->arguments = TM_AddToArgs(action->arguments, (void*)al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display))); } float* fadeloop; ALLEGRO_BITMAP* fade_bitmap; @@ -114,9 +108,7 @@ bool FadeOut(struct Game *game, struct TM_Action *action, enum TM_ActionState st bool napis2(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (!action->arguments) { - action->arguments = malloc(sizeof(struct TM_Arguments)); - action->arguments->value = malloc(sizeof(int)); - action->arguments->next = NULL; + action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(int))); } int* tmp; tmp = (int*)action->arguments->value; @@ -135,9 +127,7 @@ bool napis2(struct Game *game, struct TM_Action *action, enum TM_ActionState sta bool napis(struct Game *game, struct TM_Action *action, enum TM_ActionState state) { if (!action->arguments) { - action->arguments = malloc(sizeof(struct TM_Arguments)); - action->arguments->value = malloc(sizeof(int)); - action->arguments->next = NULL; + action->arguments = TM_AddToArgs(action->arguments, malloc(sizeof(int))); } int* tmp; tmp = (int*)action->arguments->value; diff --git a/src/timeline.c b/src/timeline.c index d827b65..ffbec0a 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -128,9 +128,13 @@ void TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum T action->function = func; action->arguments = args; action->timer = NULL; // TODO - action->active = true; // TODO: false here, true when delay action->delay = delay; - (*action->function)(game, action, TM_ACTIONSTATE_INIT); // TODO: move to TM_HandleEvent + if (delay) { + action->active = false; + } else { + action->active = true; + (*action->function)(game, action, TM_ACTIONSTATE_INIT); + } } void TM_AddDelay(int delay) { @@ -195,8 +199,20 @@ void TM_Destroy() { } struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, void* arg) { - // TODO - return NULL; + struct TM_Arguments* tmp; + if (!args) { + tmp = malloc(sizeof(struct TM_Arguments)); + tmp->value = arg; + tmp->next = NULL; + return tmp; + } + while (tmp->next) { + tmp = tmp->next; + } + tmp->next = malloc(sizeof(struct TM_Arguments)); + tmp->next->value = arg; + tmp->next->next = NULL; + return args; } void TM_DestroyArgs(struct TM_Arguments* args) {