mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-08 06:06:43 +01:00
implement timeline destroying
This commit is contained in:
parent
4674c298bb
commit
cff6de73c3
2 changed files with 75 additions and 9 deletions
|
@ -73,6 +73,7 @@ bool FadeIn(struct Game *game, struct TM_Action *action, enum TM_ActionState sta
|
||||||
} else {
|
} else {
|
||||||
al_destroy_bitmap(fade_bitmap);
|
al_destroy_bitmap(fade_bitmap);
|
||||||
free(fadeloop);
|
free(fadeloop);
|
||||||
|
TM_DestroyArgs(action->arguments);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -104,6 +105,7 @@ bool FadeOut(struct Game *game, struct TM_Action *action, enum TM_ActionState st
|
||||||
Level_Unload(game);
|
Level_Unload(game);
|
||||||
game->gamestate = GAMESTATE_LOADING;
|
game->gamestate = GAMESTATE_LOADING;
|
||||||
game->loadstate = GAMESTATE_MAP;
|
game->loadstate = GAMESTATE_MAP;
|
||||||
|
TM_DestroyArgs(action->arguments);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -122,6 +124,8 @@ bool napis2(struct Game *game, struct TM_Action *action, enum TM_ActionState sta
|
||||||
al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), *tmp, 100, 0, "lol");
|
al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), *tmp, 100, 0, "lol");
|
||||||
*tmp+=5;
|
*tmp+=5;
|
||||||
if (*tmp>=al_get_display_width(game->display)) { *tmp=0; return true; }
|
if (*tmp>=al_get_display_width(game->display)) { *tmp=0; return true; }
|
||||||
|
} else {
|
||||||
|
TM_DestroyArgs(action->arguments);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -142,6 +146,7 @@ bool napis(struct Game *game, struct TM_Action *action, enum TM_ActionState stat
|
||||||
if (*tmp>=al_get_display_width(game->display)) { *tmp=0; return true; }
|
if (*tmp>=al_get_display_width(game->display)) { *tmp=0; return true; }
|
||||||
} else {
|
} else {
|
||||||
TM_AddBackgroundAction(&napis2, NULL, 0);
|
TM_AddBackgroundAction(&napis2, NULL, 0);
|
||||||
|
TM_DestroyArgs(action->arguments);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,12 @@ void TM_Process() {
|
||||||
// if returns true, then delete it
|
// if returns true, then delete it
|
||||||
if (queue) {
|
if (queue) {
|
||||||
if (*queue->function) {
|
if (*queue->function) {
|
||||||
|
queue->active = true;
|
||||||
if ((*queue->function)(game, queue, TM_ACTIONSTATE_RUNNING)) {
|
if ((*queue->function)(game, queue, TM_ACTIONSTATE_RUNNING)) {
|
||||||
|
queue->active=false;
|
||||||
(*queue->function)(game, queue, TM_ACTIONSTATE_DESTROY);
|
(*queue->function)(game, queue, TM_ACTIONSTATE_DESTROY);
|
||||||
struct TM_Action *tmp = queue;
|
struct TM_Action *tmp = queue;
|
||||||
queue = queue->next;
|
queue = queue->next;
|
||||||
if (tmp->arguments) free(tmp->arguments); // TODO: cascade destroy
|
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -60,6 +61,7 @@ void TM_Process() {
|
||||||
if (pom->active) {
|
if (pom->active) {
|
||||||
if (*pom->function) {
|
if (*pom->function) {
|
||||||
if ((*pom->function)(game, pom, TM_ACTIONSTATE_RUNNING)) {
|
if ((*pom->function)(game, pom, TM_ACTIONSTATE_RUNNING)) {
|
||||||
|
pom->active=false;
|
||||||
(*pom->function)(game, pom, TM_ACTIONSTATE_DESTROY);
|
(*pom->function)(game, pom, TM_ACTIONSTATE_DESTROY);
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
tmp->next = pom->next;
|
tmp->next = pom->next;
|
||||||
|
@ -75,7 +77,6 @@ void TM_Process() {
|
||||||
tmp = pom;
|
tmp = pom;
|
||||||
pom = pom->next;
|
pom = pom->next;
|
||||||
} else {
|
} else {
|
||||||
if (pom->arguments) free(pom->arguments); // TODO: cascade destroy
|
|
||||||
free(pom);
|
free(pom);
|
||||||
tmp2 = tmp;
|
tmp2 = tmp;
|
||||||
if (!tmp) pom=background->next;
|
if (!tmp) pom=background->next;
|
||||||
|
@ -88,7 +89,7 @@ void TM_Process() {
|
||||||
void TM_HandleEvent(ALLEGRO_EVENT *ev) {
|
void TM_HandleEvent(ALLEGRO_EVENT *ev) {
|
||||||
if (!game) return;
|
if (!game) return;
|
||||||
if (paused) return;
|
if (paused) return;
|
||||||
// TODO: mark action as active
|
// TODO: find proper action and mark it as active
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,10 +127,10 @@ void TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum T
|
||||||
action->next = NULL;
|
action->next = NULL;
|
||||||
action->function = func;
|
action->function = func;
|
||||||
action->arguments = args;
|
action->arguments = args;
|
||||||
action->timer = NULL;
|
action->timer = NULL; // TODO
|
||||||
action->active = true;
|
action->active = true; // TODO: false here, true when delay
|
||||||
action->delay = 0;
|
action->delay = delay;
|
||||||
(*action->function)(game, action, TM_ACTIONSTATE_INIT);
|
(*action->function)(game, action, TM_ACTIONSTATE_INIT); // TODO: move to TM_HandleEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM_AddDelay(int delay) {
|
void TM_AddDelay(int delay) {
|
||||||
|
@ -142,15 +143,75 @@ void TM_Pause(bool pause) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM_Destroy() {
|
void TM_Destroy() {
|
||||||
|
if (!game) return;
|
||||||
// TODO: delete everything from queues
|
// TODO: delete everything from queues
|
||||||
// maybe delete all args too?
|
// maybe delete all args too?
|
||||||
|
struct TM_Action *tmp, *tmp2, *pom = queue;
|
||||||
|
tmp = NULL;
|
||||||
|
while (pom!=NULL) {
|
||||||
|
if (pom->active) {
|
||||||
|
if (*pom->function) {
|
||||||
|
(*pom->function)(game, pom, TM_ACTIONSTATE_DESTROY);
|
||||||
|
if (tmp) {
|
||||||
|
tmp->next = pom->next;
|
||||||
|
} else {
|
||||||
|
background = pom->next;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: handle delay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((!tmp) || (tmp->next==pom)) {
|
||||||
|
tmp = pom;
|
||||||
|
pom = pom->next;
|
||||||
|
} else {
|
||||||
|
free(pom);
|
||||||
|
tmp2 = tmp;
|
||||||
|
if (!tmp) pom=background->next;
|
||||||
|
else pom=tmp->next;
|
||||||
|
tmp = tmp2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tmp = NULL;
|
||||||
|
pom=background;
|
||||||
|
while (pom!=NULL) {
|
||||||
|
if (pom->active) {
|
||||||
|
if (*pom->function) {
|
||||||
|
(*pom->function)(game, pom, TM_ACTIONSTATE_DESTROY);
|
||||||
|
if (tmp) {
|
||||||
|
tmp->next = pom->next;
|
||||||
|
} else {
|
||||||
|
background = pom->next;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: handle delay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((!tmp) || (tmp->next==pom)) {
|
||||||
|
tmp = pom;
|
||||||
|
pom = pom->next;
|
||||||
|
} else {
|
||||||
|
free(pom);
|
||||||
|
tmp2 = tmp;
|
||||||
|
if (!tmp) pom=background->next;
|
||||||
|
else pom=tmp->next;
|
||||||
|
tmp = tmp2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
game = NULL;
|
game = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, void* arg) {
|
struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, void* arg) {
|
||||||
|
// TODO
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM_DestroyArgs(struct TM_Arguments* args) {
|
void TM_DestroyArgs(struct TM_Arguments* args) {
|
||||||
|
struct TM_Arguments *pom;
|
||||||
|
while (args) {
|
||||||
|
pom = args->next;
|
||||||
|
free(args);
|
||||||
|
args = pom;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue