-
Notifications
You must be signed in to change notification settings - Fork 0
/
Animation.h
40 lines (35 loc) · 912 Bytes
/
Animation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#include <deque>
#include <memory>
class Animation {
friend class AnimationManager;
private:
bool started = false;
bool finished = false;
bool interrupted = false;
double timeElapsed = 0;
bool operator ()(const double timeDelta);
public:
virtual void onStart();
// return true if finished
virtual bool stepFrame(const double timeElapsed, const double timeDelta) = 0;
virtual void onFinished();
virtual void onInterrupted();
bool isStarted() const;
bool isFinished() const;
bool isInterrupted() const;
void interrupt();
};
class AnimationManager {
private:
typedef std::deque<std::shared_ptr<Animation>> Queue;
size_t queueIndex = 0;
Queue queue[2];
Queue & getFrontQueue();
Queue & getBackQueue();
void swapQueue();
public:
AnimationManager & push(std::shared_ptr<Animation> animation);
void step(const double timeDelta, const bool interrupted = false);
void clear();
};