mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 19:16:44 +01:00
support action names in timeline manager
This commit is contained in:
parent
6e27c1e3b5
commit
cd6e5a0ff9
3 changed files with 46 additions and 30 deletions
20
src/level.c
20
src/level.c
|
@ -259,7 +259,7 @@ bool Welcome(struct Game *game, struct TM_Action *action, enum TM_ActionState st
|
||||||
bool PassLevel(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
bool PassLevel(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||||
if (state == TM_ACTIONSTATE_DESTROY) {
|
if (state == TM_ACTIONSTATE_DESTROY) {
|
||||||
Level_Passed(game);
|
Level_Passed(game);
|
||||||
TM_AddBackgroundAction(&FadeOut, NULL, 0);
|
TM_AddBackgroundAction(&FadeOut, NULL, 0, "fadeout");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -282,18 +282,18 @@ void Level_Load(struct Game *game) {
|
||||||
if (game->level.current_level!=1) Moonwalk_Load(game);
|
if (game->level.current_level!=1) Moonwalk_Load(game);
|
||||||
else {
|
else {
|
||||||
TM_Init(game);
|
TM_Init(game);
|
||||||
TM_AddBackgroundAction(&FadeIn, NULL, 0);
|
TM_AddBackgroundAction(&FadeIn, NULL, 0, "fadein");
|
||||||
TM_AddDelay(1000);
|
TM_AddDelay(1000);
|
||||||
TM_AddQueuedBackgroundAction(&Welcome, NULL, 0);
|
TM_AddQueuedBackgroundAction(&Welcome, NULL, 0, "welcome");
|
||||||
TM_AddDelay(1000);
|
TM_AddDelay(1000);
|
||||||
TM_AddAction(&Walk, NULL);
|
TM_AddAction(&Walk, NULL, "walk");
|
||||||
TM_AddAction(&Move, NULL);
|
TM_AddAction(&Move, NULL, "move");
|
||||||
TM_AddAction(&Stop, NULL);
|
TM_AddAction(&Stop, NULL, "stop");
|
||||||
TM_AddDelay(1000);
|
TM_AddDelay(1000);
|
||||||
TM_AddAction(&Letter, NULL);
|
TM_AddAction(&Letter, NULL, "letter");
|
||||||
TM_AddDelay(500);
|
TM_AddDelay(500);
|
||||||
TM_AddQueuedBackgroundAction(&Accelerate, NULL, 0);
|
TM_AddQueuedBackgroundAction(&Accelerate, NULL, 0, "accelerate");
|
||||||
TM_AddAction(&Fly, NULL);
|
TM_AddAction(&Fly, NULL, "fly");
|
||||||
// Derpy walks in... (background - owl)
|
// Derpy walks in... (background - owl)
|
||||||
// Derpy reads a letter
|
// Derpy reads a letter
|
||||||
// Letter on screen
|
// Letter on screen
|
||||||
|
@ -312,7 +312,7 @@ void Level_Load(struct Game *game) {
|
||||||
// cutscene goes here
|
// cutscene goes here
|
||||||
//
|
//
|
||||||
|
|
||||||
TM_AddAction(&PassLevel, NULL);
|
TM_AddAction(&PassLevel, NULL, "passlevel");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,19 +45,23 @@ void TM_Process() {
|
||||||
if (*queue->function) {
|
if (*queue->function) {
|
||||||
queue->active = true;
|
queue->active = true;
|
||||||
if ((*queue->function)(game, queue, TM_ACTIONSTATE_RUNNING)) {
|
if ((*queue->function)(game, queue, TM_ACTIONSTATE_RUNNING)) {
|
||||||
PrintConsole(game, "Timeline Manager: destroy action (queue) %d", queue->id);
|
PrintConsole(game, "Timeline Manager: queue: destroy action (%d - %s)", queue->id, queue->name);
|
||||||
queue->active=false;
|
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;
|
||||||
|
free(tmp->name);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
if (queue) PrintConsole(game, "Timeline Manager: queue: run action (%d - %s)", queue->id, queue->name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// delay
|
// delay
|
||||||
if (queue->active) {
|
if (queue->active) {
|
||||||
struct TM_Action *tmp = queue;
|
struct TM_Action *tmp = queue;
|
||||||
queue = queue->next;
|
queue = queue->next;
|
||||||
|
free(tmp->name);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
if (queue) PrintConsole(game, "Timeline Manager: queue: run action (%d - %s)", queue->id, queue->name);
|
||||||
} else {
|
} else {
|
||||||
al_start_timer(queue->timer);
|
al_start_timer(queue->timer);
|
||||||
}
|
}
|
||||||
|
@ -71,7 +75,7 @@ void TM_Process() {
|
||||||
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->active=false;
|
||||||
PrintConsole(game, "Timeline Manager: destroy action (background) %d", pom->id);
|
PrintConsole(game, "Timeline Manager: background: destroy action (%d - %s)", pom->id, pom->name);
|
||||||
(*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;
|
||||||
|
@ -92,6 +96,7 @@ void TM_Process() {
|
||||||
tmp = pom;
|
tmp = pom;
|
||||||
pom = pom->next;
|
pom = pom->next;
|
||||||
} else {
|
} else {
|
||||||
|
free(pom->name);
|
||||||
free(pom);
|
free(pom);
|
||||||
tmp2 = tmp;
|
tmp2 = tmp;
|
||||||
if (!tmp) pom=background->next;
|
if (!tmp) pom=background->next;
|
||||||
|
@ -107,15 +112,14 @@ void TM_HandleEvent(ALLEGRO_EVENT *ev) {
|
||||||
if (paused) return;
|
if (paused) return;
|
||||||
if (queue) {
|
if (queue) {
|
||||||
if (ev->timer.source == queue->timer) {
|
if (ev->timer.source == queue->timer) {
|
||||||
PrintConsole(game, "Timeline Manager: event matched (queue) %d", queue->id);
|
|
||||||
queue->active=true;
|
queue->active=true;
|
||||||
al_destroy_timer(queue->timer);
|
al_destroy_timer(queue->timer);
|
||||||
queue->timer = NULL;
|
queue->timer = NULL;
|
||||||
if (queue->function) {
|
if (queue->function) {
|
||||||
PrintConsole(game, "Timeline Manager: init action (queue) %d", queue->id);
|
PrintConsole(game, "Timeline Manager: queue: init action (%d - %s)", queue->id, queue->name);
|
||||||
(*queue->function)(game, queue, TM_ACTIONSTATE_INIT);
|
(*queue->function)(game, queue, TM_ACTIONSTATE_INIT);
|
||||||
} else {
|
} else {
|
||||||
PrintConsole(game, "Timeline Manager: delay reached (queue) %d", queue->id);
|
PrintConsole(game, "Timeline Manager: queue: delay reached (%d - %s)", queue->id, queue->name);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -123,11 +127,10 @@ void TM_HandleEvent(ALLEGRO_EVENT *ev) {
|
||||||
struct TM_Action *pom = background;
|
struct TM_Action *pom = background;
|
||||||
while (pom) {
|
while (pom) {
|
||||||
if (ev->timer.source == pom->timer) {
|
if (ev->timer.source == pom->timer) {
|
||||||
PrintConsole(game, "Timeline Manager: event matched (background) %d", pom->id);
|
PrintConsole(game, "Timeline Manager: background: delay reached, init and run action (%d - %s)", pom->id, pom->name);
|
||||||
pom->active=true;
|
pom->active=true;
|
||||||
al_destroy_timer(pom->timer);
|
al_destroy_timer(pom->timer);
|
||||||
pom->timer = NULL;
|
pom->timer = NULL;
|
||||||
PrintConsole(game, "Timeline Manager: delay reached, init action (background) %d", pom->id);
|
|
||||||
(*pom->function)(game, pom, TM_ACTIONSTATE_INIT);
|
(*pom->function)(game, pom, TM_ACTIONSTATE_INIT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +138,7 @@ void TM_HandleEvent(ALLEGRO_EVENT *ev) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TM_Action* TM_AddAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args) {
|
struct TM_Action* TM_AddAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, char* name) {
|
||||||
struct TM_Action *action = malloc(sizeof(struct TM_Action));
|
struct TM_Action *action = malloc(sizeof(struct TM_Action));
|
||||||
if (queue) {
|
if (queue) {
|
||||||
struct TM_Action *pom = queue;
|
struct TM_Action *pom = queue;
|
||||||
|
@ -149,18 +152,20 @@ struct TM_Action* TM_AddAction(bool (*func)(struct Game*, struct TM_Action*, enu
|
||||||
action->next = NULL;
|
action->next = NULL;
|
||||||
action->function = func;
|
action->function = func;
|
||||||
action->arguments = args;
|
action->arguments = args;
|
||||||
|
action->name = malloc((strlen(name)+1)*sizeof(char));
|
||||||
|
strcpy(action->name, name);
|
||||||
action->timer = NULL;
|
action->timer = NULL;
|
||||||
action->active = false;
|
action->active = false;
|
||||||
action->delay = 0;
|
action->delay = 0;
|
||||||
action->id = ++lastid;
|
action->id = ++lastid;
|
||||||
if (action->function) {
|
if (action->function) {
|
||||||
PrintConsole(game, "Timeline Manager: init action (queue) %d", action->id);
|
PrintConsole(game, "Timeline Manager: queue: init action (%d - %s)", action->id, action->name);
|
||||||
(*action->function)(game, action, TM_ACTIONSTATE_INIT);
|
(*action->function)(game, action, TM_ACTIONSTATE_INIT);
|
||||||
}
|
}
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TM_Action* TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay) {
|
struct TM_Action* TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay, char* name) {
|
||||||
struct TM_Action *action = malloc(sizeof(struct TM_Action));
|
struct TM_Action *action = malloc(sizeof(struct TM_Action));
|
||||||
if (background) {
|
if (background) {
|
||||||
struct TM_Action *pom = background;
|
struct TM_Action *pom = background;
|
||||||
|
@ -174,6 +179,8 @@ struct TM_Action* TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Ac
|
||||||
action->next = NULL;
|
action->next = NULL;
|
||||||
action->function = func;
|
action->function = func;
|
||||||
action->arguments = args;
|
action->arguments = args;
|
||||||
|
action->name = malloc((strlen(name)+1)*sizeof(char));
|
||||||
|
strcpy(action->name, name);
|
||||||
action->delay = delay;
|
action->delay = delay;
|
||||||
action->id = ++lastid;
|
action->id = ++lastid;
|
||||||
if (delay) {
|
if (delay) {
|
||||||
|
@ -184,7 +191,7 @@ struct TM_Action* TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Ac
|
||||||
} else {
|
} else {
|
||||||
action->timer = NULL;
|
action->timer = NULL;
|
||||||
action->active = true;
|
action->active = true;
|
||||||
PrintConsole(game, "Timeline Manager: init action (background) %d", action->id);
|
PrintConsole(game, "Timeline Manager: background: init and run action (%d - %s)", action->id, action->name);
|
||||||
(*action->function)(game, action, TM_ACTIONSTATE_INIT);
|
(*action->function)(game, action, TM_ACTIONSTATE_INIT);
|
||||||
}
|
}
|
||||||
return action;
|
return action;
|
||||||
|
@ -193,16 +200,22 @@ struct TM_Action* TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Ac
|
||||||
bool runinbackground(struct Game* game, struct TM_Action* action, enum TM_ActionState state) {
|
bool runinbackground(struct Game* game, struct TM_Action* action, enum TM_ActionState state) {
|
||||||
if (state != TM_ACTIONSTATE_RUNNING) return false;
|
if (state != TM_ACTIONSTATE_RUNNING) return false;
|
||||||
float* delay = (float*) action->arguments->next->value;
|
float* delay = (float*) action->arguments->next->value;
|
||||||
TM_AddBackgroundAction(action->arguments->value, action->arguments->next->next, *delay);
|
char* name = (char*) action->arguments->next->next->value;
|
||||||
|
TM_AddBackgroundAction(action->arguments->value, action->arguments->next->next->next, *delay, name);
|
||||||
|
free(name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TM_Action* TM_AddQueuedBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay) {
|
struct TM_Action* TM_AddQueuedBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay, char* name) {
|
||||||
struct TM_Arguments* arguments = TM_AddToArgs(NULL, (void*) func);
|
struct TM_Arguments* arguments = TM_AddToArgs(NULL, (void*) func);
|
||||||
arguments = TM_AddToArgs(arguments, malloc(sizeof(float)));
|
arguments = TM_AddToArgs(arguments, malloc(sizeof(float)));
|
||||||
|
arguments = TM_AddToArgs(arguments, NULL);
|
||||||
*(float*)(arguments->next->value) = delay;
|
*(float*)(arguments->next->value) = delay;
|
||||||
arguments->next->next = args;
|
arguments->next->next->value = malloc((strlen(name)+1)*sizeof(char));
|
||||||
return TM_AddAction(*runinbackground, arguments);
|
strcpy(arguments->next->next->value, name);
|
||||||
|
|
||||||
|
arguments->next->next->next = args;
|
||||||
|
return TM_AddAction(*runinbackground, arguments, "TM_BackgroundAction");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM_AddDelay(float delay) {
|
void TM_AddDelay(float delay) {
|
||||||
|
@ -210,8 +223,8 @@ void TM_AddDelay(float delay) {
|
||||||
tmp = malloc(sizeof(int));
|
tmp = malloc(sizeof(int));
|
||||||
*tmp = delay;
|
*tmp = delay;
|
||||||
TM_AddAction(NULL, TM_AddToArgs(NULL, tmp));*/
|
TM_AddAction(NULL, TM_AddToArgs(NULL, tmp));*/
|
||||||
struct TM_Action* tmp = TM_AddAction(NULL, NULL);
|
struct TM_Action* tmp = TM_AddAction(NULL, NULL, "Delay");
|
||||||
PrintConsole(game, "Timeline Manager: adding delay %f ms %d", delay, tmp->id);
|
PrintConsole(game, "Timeline Manager: queue: adding delay %f ms (%d)", delay, tmp->id);
|
||||||
tmp->delay = delay;
|
tmp->delay = delay;
|
||||||
tmp->timer = al_create_timer(delay/1000.0);
|
tmp->timer = al_create_timer(delay/1000.0);
|
||||||
al_register_event_source(game->event_queue, al_get_timer_event_source(tmp->timer));
|
al_register_event_source(game->event_queue, al_get_timer_event_source(tmp->timer));
|
||||||
|
@ -257,6 +270,7 @@ void TM_Destroy() {
|
||||||
tmp = pom;
|
tmp = pom;
|
||||||
pom = pom->next;
|
pom = pom->next;
|
||||||
} else {
|
} else {
|
||||||
|
free(pom->name);
|
||||||
free(pom);
|
free(pom);
|
||||||
tmp2 = tmp;
|
tmp2 = tmp;
|
||||||
if (!tmp) pom=background->next;
|
if (!tmp) pom=background->next;
|
||||||
|
@ -280,6 +294,7 @@ void TM_Destroy() {
|
||||||
tmp = pom;
|
tmp = pom;
|
||||||
pom = pom->next;
|
pom = pom->next;
|
||||||
} else {
|
} else {
|
||||||
|
free(pom->name);
|
||||||
free(pom);
|
free(pom);
|
||||||
tmp2 = tmp;
|
tmp2 = tmp;
|
||||||
if (!tmp) pom=background->next;
|
if (!tmp) pom=background->next;
|
||||||
|
|
|
@ -41,18 +41,19 @@ struct TM_Action {
|
||||||
int delay;
|
int delay;
|
||||||
struct TM_Action *next;
|
struct TM_Action *next;
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
|
char* name;
|
||||||
//*prev;
|
//*prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
void TM_Init(struct Game* game);
|
void TM_Init(struct Game* game);
|
||||||
void TM_Process();
|
void TM_Process();
|
||||||
void TM_HandleEvent(ALLEGRO_EVENT *ev);
|
void TM_HandleEvent(ALLEGRO_EVENT *ev);
|
||||||
struct TM_Action* TM_AddAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args);
|
struct TM_Action* TM_AddAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, char* name);
|
||||||
struct TM_Action* TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay);
|
struct TM_Action* TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay, char* name);
|
||||||
|
struct TM_Action* TM_AddQueuedBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay, char* name);
|
||||||
void TM_AddDelay(float delay);
|
void TM_AddDelay(float delay);
|
||||||
void TM_Pause(bool pause);
|
void TM_Pause(bool pause);
|
||||||
void TM_Destroy();
|
void TM_Destroy();
|
||||||
struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, void* arg);
|
struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, void* arg);
|
||||||
void TM_DestroyArgs(struct TM_Arguments* args);
|
void TM_DestroyArgs(struct TM_Arguments* args);
|
||||||
bool TM_Initialized();
|
bool TM_Initialized();
|
||||||
struct TM_Action* TM_AddQueuedBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay);
|
|
||||||
|
|
Loading…
Reference in a new issue