mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
timeline: use macros to get action name by default
This commit is contained in:
parent
d5faec85ac
commit
c7fac39b79
3 changed files with 38 additions and 11 deletions
|
@ -465,7 +465,7 @@ static void DrawQueue(struct Game* game, struct TM_Action* queue, int clipX, int
|
|||
al_draw_textf(game->_priv.font_console, al_map_rgb(255, 255, 255), pos, clipY - (50 / 1800.0) * al_get_display_height(game->display), ALLEGRO_ALIGN_LEFT, "%d", (int)(pom->delay * 1000));
|
||||
}
|
||||
|
||||
if (strncmp(pom->name, "TM_BackgroundAction", 19) == 0) {
|
||||
if (strncmp(pom->name, "TM_RunInBackground", 18) == 0) { // FIXME: this is crappy way to detect queued background actions
|
||||
al_draw_textf(game->_priv.font_console, al_map_rgb(255, 255, 255), pos, clipY - (50 / 1800.0) * al_get_display_height(game->display), ALLEGRO_ALIGN_LEFT, "%s", (char*)pom->arguments->next->next->value);
|
||||
}
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ SYMBOL_EXPORT void TM_Process(struct Timeline* timeline, double delta) {
|
|||
}
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT struct TM_Action* TM_AddAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, char* name) {
|
||||
SYMBOL_EXPORT struct TM_Action* TM_AddNamedAction(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;
|
||||
|
@ -211,7 +211,7 @@ SYMBOL_EXPORT struct TM_Action* TM_AddAction(struct Timeline* timeline, TM_Actio
|
|||
return action;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT struct TM_Action* TM_AddBackgroundAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, int delay, char* name) {
|
||||
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) {
|
||||
struct TM_Action* pom = timeline->background;
|
||||
|
@ -238,13 +238,13 @@ SYMBOL_EXPORT struct TM_Action* TM_AddBackgroundAction(struct Timeline* timeline
|
|||
}
|
||||
|
||||
/*! \brief Predefined action used by TM_AddQueuedBackgroundAction */
|
||||
static TM_Action(RunInBackground) {
|
||||
static TM_Action(TM_RunInBackground) {
|
||||
int* delay = TM_Arg(1);
|
||||
char* name = TM_Arg(2);
|
||||
struct TM_Arguments* arguments = TM_Arg(3);
|
||||
bool* used = TM_Arg(4);
|
||||
if (action->state == TM_ACTIONSTATE_START) {
|
||||
TM_AddBackgroundAction(action->timeline, TM_Arg(0), arguments, *delay, name);
|
||||
TM_AddNamedBackgroundAction(action->timeline, TM_Arg(0), arguments, *delay, name);
|
||||
*used = true;
|
||||
}
|
||||
if (action->state == TM_ACTIONSTATE_DESTROY) {
|
||||
|
@ -258,15 +258,15 @@ static TM_Action(RunInBackground) {
|
|||
return true;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT struct TM_Action* TM_AddQueuedBackgroundAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, int delay, char* name) {
|
||||
SYMBOL_EXPORT struct TM_Action* TM_AddQueuedNamedBackgroundAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, int delay, char* name) {
|
||||
TM_WrapArg(int, del, delay);
|
||||
TM_WrapArg(bool, used, false);
|
||||
struct TM_Arguments* arguments = TM_Args(func, del, strdup(name), args, used);
|
||||
return TM_AddAction(timeline, RunInBackground, arguments, "TM_BackgroundAction");
|
||||
return TM_AddAction(timeline, TM_RunInBackground, arguments);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void TM_AddDelay(struct Timeline* timeline, int delay) {
|
||||
struct TM_Action* tmp = TM_AddAction(timeline, NULL, NULL, "TM_Delay");
|
||||
struct TM_Action* tmp = TM_AddNamedAction(timeline, NULL, NULL, "TM_Delay");
|
||||
PrintConsole(timeline->game, "Timeline Manager[%s]: queue: adding delay %d ms (%d)", timeline->name, delay, tmp->id);
|
||||
tmp->delay = delay / 1000.0;
|
||||
}
|
||||
|
|
|
@ -68,43 +68,70 @@ struct TM_Action {
|
|||
|
||||
/*! \brief Init timeline. */
|
||||
struct Timeline* TM_Init(struct Game* game, struct GamestateResources* data, char* name);
|
||||
|
||||
/*! \brief Process current timeline actions. */
|
||||
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 background queue, with specified name. */
|
||||
struct TM_Action* TM_AddNamedBackgroundAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, int delay, char* name);
|
||||
|
||||
/*! \brief Add new action to main queue, which adds specified action into background queue, with specified name. */
|
||||
struct TM_Action* TM_AddQueuedNamedBackgroundAction(struct Timeline* timeline, TM_ActionCallback* func, struct TM_Arguments* args, int delay, char* name);
|
||||
|
||||
/*! \brief Add new action to main queue. */
|
||||
struct TM_Action* TM_AddAction(struct Timeline*, TM_ActionCallback* func, struct TM_Arguments* args, char* name);
|
||||
#define TM_AddAction(timeline, func, args) TM_AddNamedAction(timeline, func, args, #func)
|
||||
|
||||
/*! \brief Add new action to background queue. */
|
||||
struct TM_Action* TM_AddBackgroundAction(struct Timeline*, TM_ActionCallback* func, struct TM_Arguments* args, int delay, char* name);
|
||||
#define TM_AddBackgroundAction(timeline, func, args, delay) TM_AddNamedBackgroundAction(timeline, func, args, delay, #func)
|
||||
|
||||
/*! \brief Add new action to main queue, which adds specified action into background queue. */
|
||||
struct TM_Action* TM_AddQueuedBackgroundAction(struct Timeline*, TM_ActionCallback* func, struct TM_Arguments* args, int delay, char* name);
|
||||
#define TM_AddQueuedBackgroundAction(timeline, func, args, delay) TM_AddQueuedNamedBackgroundAction(timeline, func, args, delay, #func)
|
||||
|
||||
/*! \brief Add delay to main queue. */
|
||||
void TM_AddDelay(struct Timeline*, int delay);
|
||||
|
||||
/*! \brief Remove all actions from main queue. */
|
||||
void TM_CleanQueue(struct Timeline*);
|
||||
|
||||
/*! \brief Remove all actions from background queue. */
|
||||
void TM_CleanBackgroundQueue(struct Timeline*);
|
||||
|
||||
/*! \brief Destroy given timeline. */
|
||||
void TM_Destroy(struct Timeline*);
|
||||
|
||||
/*! \brief Add data to TM_Arguments queue (or create if NULL). */
|
||||
struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, int num, ...);
|
||||
|
||||
/*! \brief Get nth argument from TM_Arguments queue (counted from 0). */
|
||||
void* TM_GetArg(struct TM_Arguments* args, int num);
|
||||
|
||||
/*! \brief Skip delay of the first action in the queue */
|
||||
void TM_SkipDelay(struct Timeline*);
|
||||
|
||||
/*! \brief Checks if the main queue is empty */
|
||||
bool TM_IsEmpty(struct Timeline* timeline);
|
||||
|
||||
/*! \brief Checks if the background queue is empty */
|
||||
bool TM_IsBackgroundEmpty(struct Timeline* timeline);
|
||||
|
||||
/*! \brief Allocates memory and sets given value. */
|
||||
#define TM_WrapArg(type, result, val) \
|
||||
type* result = malloc(sizeof(type)); \
|
||||
*result = val;
|
||||
|
||||
/*! \brief Indicates that the action handles only TM_ACTIONSTATE_RUNNING state. */
|
||||
#define TM_RunningOnly \
|
||||
if (action->state != TM_ACTIONSTATE_RUNNING) return false;
|
||||
|
||||
/*! \brief Shorthand for creating list of arguments for action. */
|
||||
#define TM_Args(...) TM_AddToArgs(NULL, TM_NUMARGS(__VA_ARGS__), __VA_ARGS__)
|
||||
|
||||
/*! \brief Shorthand for accessing the nth argument of current action. */
|
||||
#define TM_Arg(n) TM_GetArg(action->arguments, n)
|
||||
|
||||
/*! \brief Macro for easy timeline action definition. */
|
||||
#define TM_Action(name) bool name(struct Game* game, struct GamestateResources* data, struct TM_Action* action)
|
||||
|
||||
|
|
Loading…
Reference in a new issue