forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasyncTask.I
More file actions
213 lines (192 loc) · 4.97 KB
/
asyncTask.I
File metadata and controls
213 lines (192 loc) · 4.97 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file asyncTask.I
* @author drose
* @date 2006-08-23
*/
/**
* Returns the current state of the task.
*/
INLINE AsyncTask::State AsyncTask::
get_state() const {
return _state;
}
/**
* Returns true if the task is currently active or sleeping on some task
* chain, meaning that it will be executed in its turn, or false if it is not
* active. If the task has recently been removed while it is in the middle of
* execution, this will return false, because the task will not run again once
* it finishes.
*/
INLINE bool AsyncTask::
is_alive() const {
switch (_state) {
case S_active:
case S_servicing:
case S_sleeping:
case S_active_nested:
case S_awaiting:
return true;
case S_inactive:
case S_servicing_removed:
return false;
}
// Shouldn't get here.
return false;
}
/**
* Returns the AsyncTaskManager that this task is active on. This will be
* NULL if the state is S_inactive.
*/
INLINE AsyncTaskManager *AsyncTask::
get_manager() const {
return _manager;
}
/**
* Specifies the amount of time, in seconds, by which this task will be
* delayed after it has been added to the AsyncTaskManager. At least the
* specified amount of time (and possibly more) will elapse before the task
* begins.
*
* You may specify a delay of 0.0 to guarantee that the task will run in the
* next epoch following the one in which it is added.
*
* Setting this value after the task has already been added will not affect
* the task's wake time; it will only affect the task if it is re-added to the
* queue in the future, for instance if the task returns DS_again. However,
* see recalc_wake_time() if you wish to apply the delay effect immediately.
*/
INLINE void AsyncTask::
set_delay(double delay) {
_delay = delay;
_has_delay = true;
}
/**
* Removes any delay specified for the task. The next time the task is added
* to the queue, it will run immediately. This does not affect the task's
* wake time if it has already been added to the queue.
*/
INLINE void AsyncTask::
clear_delay() {
_delay = 0.0;
_has_delay = false;
}
/**
* Returns true if a delay has been set for this task via set_delay(), or
* false otherwise.
*/
INLINE bool AsyncTask::
has_delay() const {
return _has_delay;
}
/**
* Returns the delay value that has been set via set_delay, if any.
*/
INLINE double AsyncTask::
get_delay() const {
return _delay;
}
/**
* Returns the time at which the task was started, according to the task
* manager's clock.
*
* It is only valid to call this if the task's status is not S_inactive.
*/
INLINE double AsyncTask::
get_start_time() const {
nassertr(_state != S_inactive, 0.0);
return _start_time;
}
/**
* Returns the frame number at which the task was started, according to the
* task manager's clock.
*
* It is only valid to call this if the task's status is not S_inactive.
*/
INLINE int AsyncTask::
get_start_frame() const {
nassertr(_state != S_inactive, 0);
return _start_frame;
}
/**
* Resets the task's name to empty.
*/
INLINE void AsyncTask::
clear_name() {
set_name(std::string());
}
/**
* Returns a number guaranteed to be unique for each different AsyncTask
* object in the universe.
*/
INLINE AtomicAdjust::Integer AsyncTask::
get_task_id() const {
return _task_id;
}
/**
* Returns the AsyncTaskChain on which this task will be running. Each task
* chain runs tasks independently of the others.
*/
INLINE const std::string &AsyncTask::
get_task_chain() const {
return _chain_name;
}
/**
* Returns the task's current sort value. See set_sort().
*/
INLINE int AsyncTask::
get_sort() const {
return _sort;
}
/**
* Returns the task's current priority value. See set_priority().
*/
INLINE int AsyncTask::
get_priority() const {
return _priority;
}
/**
* Sets the event name that will be triggered when the task finishes. This
* should only be called before the task has been started, or after it has
* finished and before it is about to be restarted (i.e. when get_state()
* returns S_inactive).
*/
INLINE void AsyncTask::
set_done_event(const std::string &done_event) {
nassertv(_state == S_inactive);
_done_event = done_event;
}
/**
* Returns the amount of time elapsed during the task's previous run cycle, in
* seconds.
*/
INLINE double AsyncTask::
get_dt() const {
return _dt;
}
/**
* Returns the maximum amount of time elapsed during any one of the task's
* previous run cycles, in seconds.
*/
INLINE double AsyncTask::
get_max_dt() const {
return _max_dt;
}
/**
* Returns the average amount of time elapsed during each of the task's
* previous run cycles, in seconds.
*/
INLINE double AsyncTask::
get_average_dt() const {
if (_num_frames == 0) {
return 0.0;
} else {
return _total_dt / _num_frames;
}
}