11 enum class FlashState {
18 float interpolation_a = 0.0f;
19 std::map<FlashState, float> speeds;
21 FlashState currentSpeedIndex = FlashState::FLASH_OUT;
29 FlashAnimation(
int ix,
int iy,
size_t f,
float s,
const std::string _type,
30 const std::vector<float>& flashTimes,
Color flashC,
int _reps = 0) :
Animation(ix, iy, f, s, _type)
32 speeds[FlashState::FLASH_OUT] = flashTimes[0];
33 speeds[FlashState::EASE_IN] = flashTimes[1];
34 speeds[FlashState::FLASH_IN] = flashTimes[2];
35 speeds[FlashState::EASE_OUT] = flashTimes[3];
40 FlashAnimation(
int ix,
int iy,
size_t f,
float s,
const animType _type,
41 const std::vector<float>& flashTimes,
Color flashC,
int _reps = 0) :
Animation(ix, iy, f, s, _type)
43 speeds[FlashState::FLASH_OUT] = flashTimes[0];
44 speeds[FlashState::EASE_IN] = flashTimes[1];
45 speeds[FlashState::FLASH_IN] = flashTimes[2];
46 speeds[FlashState::EASE_OUT] = flashTimes[3];
51 void advanceFrame(
float deltaTime) {
52 unsigned short prev_frame_index = cur_frame_index;
54 speed = speeds[currentSpeedIndex];
55 switch (currentSpeedIndex) {
56 case FlashState::FLASH_OUT:
59 case FlashState::EASE_IN:
61 interpolation_a = cur_frame_index_f - (int)cur_frame_index_f;
63 case FlashState::FLASH_IN:
66 case FlashState::EASE_OUT:
68 interpolation_a = 1 - (cur_frame_index_f - (int)cur_frame_index_f);
72 case Animation::animType::ANIMTYPE_BACK_FORTH:
74 cur_frame_index_f += speed * deltaTime;
75 cur_frame_index =
static_cast<unsigned short>(cur_frame_index_f);
77 if (cur_frame_index >= NUM_BACK_FORTH_STATES) {
80 if (reps && times_played >= reps) {
85 if (prev_frame_index != cur_frame_index) {
86 frame_times_played = 1;
87 if ((
static_cast<int>(currentSpeedIndex) + 1) % NUM_BACK_FORTH_STATES < NUM_BACK_FORTH_STATES)
88 currentSpeedIndex =
static_cast<FlashState
>((
static_cast<int>(currentSpeedIndex) + 1) % speeds.size());
94 case Animation::animType::ANIMTYPE_LOOPED:
95 case Animation::animType::ANIMTYPE_PLAY_N_TIMES:
96 cur_frame_index_f += speed * deltaTime;
97 cur_frame_index =
static_cast<unsigned short>(cur_frame_index_f);
100 if (prev_frame_index != cur_frame_index) {
101 frame_times_played = 1;
102 if(
static_cast<int>(currentSpeedIndex) % NUM_LOOP_STATES < NUM_LOOP_STATES)
103 currentSpeedIndex =
static_cast<FlashState
>(
static_cast<int>(currentSpeedIndex) % NUM_LOOP_STATES);
106 frame_times_played++;
109 if (cur_frame_index >= NUM_LOOP_STATES)
113 if (reps && times_played >= reps) {
119 case Animation::animType::ANIMTYPE_NONE:
124 std::vector<float> getSpeedsAsVector()
const {
125 std::vector<float> speedsVector(4);
128 speedsVector[0] = speeds.at(FlashState::FLASH_OUT);
129 speedsVector[1] = speeds.at(FlashState::EASE_IN);
130 speedsVector[2] = speeds.at(FlashState::FLASH_IN);
131 speedsVector[3] = speeds.at(FlashState::EASE_OUT);