mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 11:06:44 +01:00
fix pausing timers in timeline manager
This commit is contained in:
parent
0eacf9a67d
commit
4ec5686aac
3 changed files with 51 additions and 25 deletions
|
@ -230,11 +230,17 @@ void Level_Logic(struct Game *game) {
|
|||
void Level_Resume(struct Game *game) {
|
||||
al_set_sample_instance_position(game->level.music, game->level.music_pos);
|
||||
al_set_sample_instance_playing(game->level.music, true);
|
||||
if (game->level.current_level==1) {
|
||||
TM_Resume();
|
||||
}
|
||||
}
|
||||
|
||||
void Level_Pause(struct Game *game) {
|
||||
game->level.music_pos = al_get_sample_instance_position(game->level.music);
|
||||
al_set_sample_instance_playing(game->level.music, false);
|
||||
if (game->level.current_level==1) {
|
||||
TM_Pause();
|
||||
}
|
||||
}
|
||||
|
||||
void Level_Draw(struct Game *game) {
|
||||
|
|
|
@ -108,7 +108,26 @@ void TM_Process() {
|
|||
}
|
||||
}
|
||||
|
||||
void TM_Draw() {
|
||||
void PauseTimers(bool pause) {
|
||||
if (queue) {
|
||||
if (queue->timer) {
|
||||
if (pause) {
|
||||
al_stop_timer(queue->timer);
|
||||
} else if (!queue->active) al_start_timer(queue->timer);
|
||||
}
|
||||
}
|
||||
struct TM_Action* tmp = background;
|
||||
while (tmp) {
|
||||
if (tmp->timer) {
|
||||
if (pause) {
|
||||
al_stop_timer(tmp->timer);
|
||||
} else if (!tmp->active) al_start_timer(tmp->timer);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
}
|
||||
|
||||
void Propagate(enum TM_ActionState action) {
|
||||
if (!game) return;
|
||||
if (queue) {
|
||||
if ((*queue->function) && (queue->active)) {
|
||||
|
@ -127,6 +146,24 @@ void TM_Draw() {
|
|||
}
|
||||
}
|
||||
|
||||
void TM_Draw() {
|
||||
Propagate(TM_ACTIONSTATE_DRAW);
|
||||
}
|
||||
|
||||
void TM_Pause() {
|
||||
PrintConsole(game, "Timeline Manager: Pause.");
|
||||
paused = true;
|
||||
PauseTimers(true);
|
||||
Propagate(TM_ACTIONSTATE_PAUSE);
|
||||
}
|
||||
|
||||
void TM_Resume() {
|
||||
PrintConsole(game, "Timeline Manager: Resume.");
|
||||
paused = false;
|
||||
Propagate(TM_ACTIONSTATE_RESUME);
|
||||
PauseTimers(false);
|
||||
}
|
||||
|
||||
void TM_HandleEvent(ALLEGRO_EVENT *ev) {
|
||||
if (ev->type != ALLEGRO_EVENT_TIMER) return;
|
||||
if (!game) return;
|
||||
|
@ -252,27 +289,6 @@ void TM_AddDelay(float delay) {
|
|||
al_register_event_source(game->event_queue, al_get_timer_event_source(tmp->timer));
|
||||
}
|
||||
|
||||
void TM_Pause(bool pause) {
|
||||
paused = pause;
|
||||
PrintConsole(game, "Timeline Manager: pause %d", pause);
|
||||
if (queue) {
|
||||
if (queue->timer) {
|
||||
if (pause) {
|
||||
al_stop_timer(queue->timer);
|
||||
} else if (!queue->active) al_start_timer(queue->timer);
|
||||
}
|
||||
}
|
||||
struct TM_Action* tmp = background;
|
||||
while (tmp) {
|
||||
if (tmp->timer) {
|
||||
if (pause) {
|
||||
al_stop_timer(tmp->timer);
|
||||
} else if (!tmp->active) al_start_timer(tmp->timer);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
}
|
||||
|
||||
void TM_Destroy() {
|
||||
if (!game) return;
|
||||
PrintConsole(game, "Timeline Manager: destroy");
|
||||
|
|
|
@ -28,7 +28,9 @@ enum TM_ActionState {
|
|||
TM_ACTIONSTATE_INIT,
|
||||
TM_ACTIONSTATE_RUNNING,
|
||||
TM_ACTIONSTATE_DRAW,
|
||||
TM_ACTIONSTATE_DESTROY
|
||||
TM_ACTIONSTATE_DESTROY,
|
||||
TM_ACTIONSTATE_PAUSE,
|
||||
TM_ACTIONSTATE_RESUME
|
||||
};
|
||||
|
||||
/*! \brief Arguments for TM_Action. */
|
||||
|
@ -55,6 +57,10 @@ void TM_Init(struct Game* game);
|
|||
void TM_Process();
|
||||
/*! \brief Ask current timeline actions to draw. */
|
||||
void TM_Draw();
|
||||
/*! \brief Pauses timeline. */
|
||||
void TM_Pause();
|
||||
/*! \brief Resumes timeline. */
|
||||
void TM_Resume();
|
||||
/*! \brief Handle timer events. */
|
||||
void TM_HandleEvent(ALLEGRO_EVENT *ev);
|
||||
/*! \brief Add new action to main queue. */
|
||||
|
@ -65,8 +71,6 @@ struct TM_Action* TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Ac
|
|||
struct TM_Action* TM_AddQueuedBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, float delay, char* name);
|
||||
/*! \brief Add delay to main queue. */
|
||||
void TM_AddDelay(float delay);
|
||||
/*! \brief Pause timers. */
|
||||
void TM_Pause(bool pause);
|
||||
/*! \brief Destroy timeline. */
|
||||
void TM_Destroy();
|
||||
/*! \brief Add data to TM_Arguments queue. */
|
||||
|
|
Loading…
Reference in a new issue