Sunset old state system finally.

This commit is contained in:
2023-11-02 12:36:14 -05:00
parent 79b7e235ab
commit b4c7953c93
32 changed files with 212 additions and 420 deletions

View File

@ -6,7 +6,7 @@
#pragma once
#include "util/flag.hpp"
#include "display/Color.hpp"
#include "event/Event.hpp"
#include "state/StateEvent.hpp"
#define RENDER_TARGET_CLEAR_FLAG_COLOR FLAG_DEFINE(0)
#define RENDER_TARGET_CLEAR_FLAG_DEPTH FLAG_DEFINE(1)
@ -14,7 +14,7 @@
namespace Dawn {
class RenderTarget {
public:
Event<RenderTarget*, float_t, float_t> eventRenderTargetResized;
StateEvent<RenderTarget*, float_t, float_t> eventRenderTargetResized;
/**
* Return the width of the render target.

View File

@ -7,7 +7,6 @@
#include "dawnlibs.hpp"
#include "assert/assert.hpp"
#include "util/flag.hpp"
#include "event/Event.hpp"
#include "state/StateEvent.hpp"
namespace Dawn {

View File

@ -5,8 +5,6 @@
#pragma once
#include "state/StateEvent.hpp"
#include "Easing.hpp"
#include "util/mathutils.hpp"
namespace Dawn {
struct Animation {
@ -15,8 +13,7 @@ namespace Dawn {
bool_t finished = false;
float_t time = 0;
float_t duration = 0;
Event<> eventAnimationEnd;
StateEvent<> event2AnimationEnd;
StateEvent<> eventAnimationEnd;
/**
* Ticks the animation along. Delta is whatever you want to update the
@ -26,7 +23,7 @@ namespace Dawn {
*
* @param delta Time delta (in seconds) to tick the animaiton by.
*/
virtual void tick(float_t delta) = 0;
virtual void tick(const float_t delta) = 0;
/**
* Restart a running animation.

View File

@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME}
PRIVATE
Animation.cpp
TiledSpriteAnimation.cpp
easing.cpp
)

View File

@ -1,78 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dawnlibs.hpp"
typedef float_t easefunction_t(float_t t);
/**
* Returns the ease time for a given real time duration span.
* @param start At what point in time the animation started
* @param current The current point in time the animation is at.
* @param duration The total duration on the animation.
* @returns The easing time (0-1 time) that the animation is at.
*/
static inline float_t easeTimeToEase(
float_t start,
float_t current,
float_t duration
) {
return (current - start) / duration;
}
static inline float_t easeLinear(float_t t) {
return t;
}
static inline float_t easeInQuad(float_t t) {
return t * t;
}
static inline float_t easeOutQuad(float_t t) {
return t * (2 - t);
}
static inline float_t easeOutCubic(float_t t) {
return 1 - powf(1 - t, 3);
}
static inline float_t easeInOutQuad(float_t t) {
return t < .5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
}
static inline float_t easeInCubic(float_t t) {
return t * t * t;
}
static inline float_t easeInOutCubic(float_t t) {
return t < .5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
}
static inline float_t easeInQuart(float_t t) {
return t * t * t * t;
}
static inline float_t easeOutQuart(float_t t) {
return 1 - (t-1)*(t-1)*(t-1)*(t-1);
}
static inline float_t easeInOutQuart(float_t t) {
return t < .5 ? 8*t*t*t*t : 1-8*(t-1)*(t-1)*(t-1)*(t-1);
}
static inline float_t easeInQuint(float_t t) {
return t*t*t*t*t;
}
static inline float_t easeOutQuint(float_t t) {
return 1 + (t-1)*(t-1)*(t-1)*(t-1)*(t-1);
}
static inline float_t easeInOutQuint(float_t t) {
return t<.5 ? 16*t*t*t*t*t : 1+16*(t-1)*(t-1)*(t-1)*(t-1)*(t-1);
}

View File

@ -5,6 +5,8 @@
#pragma once
#include "Animation.hpp"
#include "easing.hpp"
#include "util/mathutils.hpp"
namespace Dawn {
template<typename T>
@ -195,7 +197,6 @@ namespace Dawn {
// Animation end.
this->finished = true;
this->eventAnimationEnd.invoke();
this->event2AnimationEnd.invoke();
}
void clear() override {

View File

@ -13,7 +13,7 @@ TiledSpriteAnimation::TiledSpriteAnimation(TiledSprite *sprite) :
{
}
void TiledSpriteAnimation::tick(float_t delta) {
void TiledSpriteAnimation::tick(const float_t delta) {
SimpleAnimation::tick(delta);
this->sprite->tile = frame;
}

View File

@ -20,6 +20,6 @@ namespace Dawn {
*/
TiledSpriteAnimation(TiledSprite *sprite);
void tick(float_t delta) override;
void tick(const float_t delta) override;
};
}

View File

@ -0,0 +1,66 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "easing.hpp"
float_t easeTimeToEase(
const float_t start,
const float_t current,
const float_t duration
) {
return (current - start) / duration;
}
float_t easeLinear(const float_t t) {
return t;
}
float_t easeInQuad(const float_t t) {
return t * t;
}
float_t easeOutQuad(const float_t t) {
return t * (2 - t);
}
float_t easeOutCubic(const float_t t) {
return 1 - powf(1 - t, 3);
}
float_t easeInOutQuad(const float_t t) {
return t < .5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
}
float_t easeInCubic(const float_t t) {
return t * t * t;
}
float_t easeInOutCubic(const float_t t) {
return t < .5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
}
float_t easeInQuart(const float_t t) {
return t * t * t * t;
}
float_t easeOutQuart(const float_t t) {
return 1 - (t-1)*(t-1)*(t-1)*(t-1);
}
float_t easeInOutQuart(const float_t t) {
return t < .5 ? 8*t*t*t*t : 1-8*(t-1)*(t-1)*(t-1)*(t-1);
}
float_t easeInQuint(const float_t t) {
return t*t*t*t*t;
}
float_t easeOutQuint(const float_t t) {
return 1 + (t-1)*(t-1)*(t-1)*(t-1)*(t-1);
}
float_t easeInOutQuint(const float_t t) {
return t<.5 ? 16*t*t*t*t*t : 1+16*(t-1)*(t-1)*(t-1)*(t-1)*(t-1);
}

View File

@ -0,0 +1,37 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dawnlibs.hpp"
typedef float_t easefunction_t(const float_t t);
/**
* Returns the ease time for a given real time duration span.
* @param start At what point in time the animation started
* @param current The current point in time the animation is at.
* @param duration The total duration on the animation.
* @returns The easing time (0-1 time) that the animation is at.
*/
float_t easeTimeToEase(
const float_t start,
const float_t current,
const float_t duration
);
float_t easeLinear(const float_t t);
float_t easeInQuad(const float_t t);
float_t easeOutQuad(const float_t t);
float_t easeOutCubic(const float_t t);
float_t easeInOutQuad(const float_t t);
float_t easeInCubic(const float_t t);
float_t easeInOutCubic(const float_t t);
float_t easeInQuart(const float_t t);
float_t easeOutQuart(const float_t t);
float_t easeInOutQuart(const float_t t);
float_t easeInQuint(const float_t t);
float_t easeOutQuint(const float_t t);
float_t easeInOutQuint(const float_t t);