blob: 2045fc0c4ddf84776c1b51eb85cc3b0db323cd34 (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#include "anim/task.hpp"
#include "base/assert.hpp"
#include "std/algorithm.hpp"
namespace anim
{
Task::Task()
: m_State(EReady)
{}
Task::~Task()
{}
Task::EState Task::State() const
{
return m_State;
}
void Task::Lock()
{
m_mutex.Lock();
}
void Task::Unlock()
{
m_mutex.Unlock();
}
void Task::SetState(EState State)
{
m_State = State;
}
void Task::PerformCallbacks(EState state)
{
list<TCallback> const & cb = m_Callbacks[state];
for_each(cb.begin(), cb.end(), [] (TCallback const & el) { el(); });
}
void Task::OnStart(double ts)
{
PerformCallbacks(EReady);
}
void Task::OnStep(double ts)
{
PerformCallbacks(EInProgress);
}
void Task::OnCancel(double ts)
{
PerformCallbacks(ECancelled);
}
void Task::OnEnd(double ts)
{
PerformCallbacks(EEnded);
}
void Task::Start()
{
ASSERT(IsReady(), ());
SetState(EInProgress);
}
void Task::Cancel()
{
ASSERT(IsRunning() || IsReady(), ());
SetState(ECancelled);
}
void Task::End()
{
ASSERT(IsRunning() || IsReady(), ());
SetState(EEnded);
}
bool Task::IsEnded() const
{
return State() == EEnded;
}
bool Task::IsCancelled() const
{
return State() == ECancelled;
}
bool Task::IsRunning() const
{
return State() == EInProgress;
}
bool Task::IsReady() const
{
return State() == EReady;
}
bool Task::IsVisual() const
{
return false;
}
void Task::AddCallback(EState state, TCallback const & cb)
{
m_Callbacks[state].push_back(cb);
}
void Task::SetController(Controller * controller)
{
m_controller = controller;
}
Controller * Task::GetController() const
{
return m_controller;
}
}
|