Added timeline

This commit is contained in:
2021-07-15 09:22:38 -07:00
parent 81a79e136d
commit 9e40d8f576
8 changed files with 189 additions and 10 deletions

View File

@ -0,0 +1,79 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "timeline.h"
void onDone(timeline_t *test) {
}
void timelineInit(timeline_t *timeline) {
timeline->current = 0;
timeline->diff = 0;
timeline->previous = 0;
timeline->user = 0;
timeline->actionCount = 0;
timeline->actions[0].onStart = &onDone;
}
void timelineUpdate(timeline_t *timeline, float delta) {
uint8_t i;
timelineaction_t *action;
float full;
timeline->diff = delta;
timeline->previous = timeline->current;
timeline->current = timeline->current + delta;
// Find all actions that would have started or ended in this timespan.
for(i = 0; i < timeline->actionCount; i++) {
action = timeline->actions +i;
// Has the action started yet?
if(action->start > timeline->current) continue;
// Did we start this frame?
if(action->start > timeline->previous && action->onStart != NULL) {
action->onStart(timeline);
}
// Durations of 0 only fire starts, never ends or durations.
if(action->duration == 0) continue;
// Is the end still in the future? Durations in negatives go forever
full = action->start+action->duration;
if(action->duration < 0 || full > timeline->current) {
if(action->onDuration != NULL) action->onDuration(timeline);
} else if(full > timeline->previous) {// Did we end this frame?
if(action->onEnd != NULL) action->onEnd(timeline);
}
}
}
bool timelineIsFinished(timeline_t *timeline) {
uint8_t i;
timelineaction_t *action;
for(i = 0; i < timeline->actionCount; i++) {
action = timeline->actions +i;
if(action->start > timeline->current) return false;
if(action->duration < 0) return false;
if(action->duration == 0) continue;
if(action->start+action->duration > timeline->current) return false;
}
return true;
}
timelineaction_t * timelineAddAction(timeline_t *timeline, float start,
float duration
) {
timelineaction_t *action = timeline->actions + (timeline->actionCount++);
action->start = start, action->duration = duration;
action->onStart = action->onEnd = action->onDuration = NULL;
return action;
}

View File

@ -0,0 +1,15 @@
// Copyright (c) 2021 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
void timelineInit(timeline_t *timeline);
void timelineUpdate(timeline_t *timeline, float delta);
bool timelineIsFinished(timeline_t *timeline);
timelineaction_t * timelineAddAction(timeline_t *timeline, float start,
float duration
);

View File

@ -7,15 +7,35 @@
#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;
}
@ -25,7 +45,14 @@ bool gameUpdate(game_t *game, float platformDelta) {
engineUpdateStart(&game->engine, game, platformDelta);
// Hand off to the poker logic
pokerUpdate(&game->poker, &game->engine);
// pokerUpdate(&game->poker, &game->engine);
timelineUpdate(&TIMELINE_TEST, platformDelta);
if(timelineIsFinished(&TIMELINE_TEST)) {
printf("Timeline finished\n");
} else {
printf("Timeline not finished\n");
}
// Hand back to the engine.
return engineUpdateEnd(&game->engine, game);

View File

@ -9,7 +9,7 @@
#include "../poker/poker.h"
#include "../poker/card.h"
#include "../util/array.h"
#include "../display/animation/timeline.h"
/**
* Initialize the game context.

View File

@ -27,8 +27,13 @@ void pokerMatchInit(poker_t *poker, engine_t *engine) {
}
void pokerMatchUpdate(poker_t *poker, engine_t *engine) {
// Ease into the game.
float t = easeTimeToEase(poker->roundMatch.time, engine->time.current, 5);
pokerLookAtPlayer(
&poker->cameraWorld, POKER_SEAT_PLAYER0, 1 - easeOutQuint(t)
);
pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_PLAYER0, (
t < 1 ? 1 - easeOutQuart(t) : 0
));
if(t > 0.75) {
pokerTalk(poker, "Hello World");
}
}