Cleaned the timeline code up nicely.
This commit is contained in:
@ -8,6 +8,8 @@
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
|
||||
#define TIMELINE_ACTION_COUNT_MAX 128
|
||||
|
||||
/** Type forwarder for timeline_t */
|
||||
typedef struct _timeline_t timeline_t;
|
||||
|
||||
@ -50,6 +52,6 @@ typedef struct _timeline_t {
|
||||
void *user;
|
||||
|
||||
/** Actions within the timeline */
|
||||
timelineaction_t actions[128];
|
||||
timelineaction_t actions[TIMELINE_ACTION_COUNT_MAX];
|
||||
uint8_t actionCount;
|
||||
} timeline_t;
|
@ -72,6 +72,7 @@ bool timelineIsFinished(timeline_t *timeline) {
|
||||
timelineaction_t * timelineAddAction(timeline_t *timeline, float start,
|
||||
float duration
|
||||
) {
|
||||
if(timeline->actionCount == TIMELINE_ACTION_COUNT_MAX) return NULL;
|
||||
timelineaction_t *action = timeline->actions + (timeline->actionCount++);
|
||||
action->start = start, action->duration = duration;
|
||||
action->onStart = action->onEnd = action->onDuration = NULL;
|
||||
|
@ -6,10 +6,38 @@
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Initializes a timeline back to its default state.
|
||||
*
|
||||
* @param timeline Timeline to initialize.
|
||||
*/
|
||||
void timelineInit(timeline_t *timeline);
|
||||
|
||||
/**
|
||||
* Ticks the timeline. This can be done using any delta.
|
||||
*
|
||||
* @param timeline Timeline to tick
|
||||
* @param delta Delta to tick.
|
||||
*/
|
||||
void timelineUpdate(timeline_t *timeline, float delta);
|
||||
|
||||
/**
|
||||
* Returns true if every action in the timeline has finished.
|
||||
*
|
||||
* @param timeline Timeline to check
|
||||
* @return True if finished, otherwise false.
|
||||
*/
|
||||
bool timelineIsFinished(timeline_t *timeline);
|
||||
|
||||
/**
|
||||
* Adds an action to the timeline. This will initialize the action callbacks to
|
||||
* NULL, you will need to initialize your own callbacks.
|
||||
*
|
||||
* @param timeline Timeline to add to.
|
||||
* @param start Start time.
|
||||
* @param duration Duration time
|
||||
* @return Pointer to the timeline action or NULL if the list is full.
|
||||
*/
|
||||
timelineaction_t * timelineAddAction(timeline_t *timeline, float start,
|
||||
float duration
|
||||
);
|
@ -7,35 +7,15 @@
|
||||
|
||||
#include "game.h"
|
||||
|
||||
timeline_t TIMELINE_TEST;
|
||||
|
||||
void onStart(timeline_t *tl) {
|
||||
printf("Action started %f\n", tl->current);
|
||||
}
|
||||
|
||||
void onDuration(timeline_t *tl) {
|
||||
printf("Action duration %f\n", tl->current);
|
||||
}
|
||||
|
||||
void onEnd(timeline_t *tl) {
|
||||
printf("Action ended %f\n", tl->current);
|
||||
}
|
||||
|
||||
bool gameInit(game_t *game) {
|
||||
// Init the game
|
||||
game->name = GAME_NAME;
|
||||
|
||||
// Init the engine and the rendering pipeline
|
||||
engineInit(&game->engine, game);
|
||||
|
||||
timelineInit(&TIMELINE_TEST);
|
||||
timelineaction_t *action = timelineAddAction(&TIMELINE_TEST, 1, 1);
|
||||
action->onStart = &onStart;
|
||||
action->onDuration = &onDuration;
|
||||
action->onEnd = &onEnd;
|
||||
|
||||
// Hand off to the poker logic.
|
||||
// pokerInit(&game->poker, &game->engine);
|
||||
pokerInit(&game->poker, &game->engine);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -45,15 +25,8 @@ bool gameUpdate(game_t *game, float platformDelta) {
|
||||
engineUpdateStart(&game->engine, game, platformDelta);
|
||||
|
||||
// Hand off to the poker logic
|
||||
// pokerUpdate(&game->poker, &game->engine);
|
||||
|
||||
timelineUpdate(&TIMELINE_TEST, platformDelta);
|
||||
if(timelineIsFinished(&TIMELINE_TEST)) {
|
||||
printf("Timeline finished\n");
|
||||
} else {
|
||||
printf("Timeline not finished\n");
|
||||
}
|
||||
|
||||
pokerUpdate(&game->poker, &game->engine);
|
||||
|
||||
// Hand back to the engine.
|
||||
return engineUpdateEnd(&game->engine, game);
|
||||
}
|
||||
|
Reference in New Issue
Block a user