forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniTask.py
More file actions
executable file
·68 lines (53 loc) · 1.73 KB
/
MiniTask.py
File metadata and controls
executable file
·68 lines (53 loc) · 1.73 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
"""This module implements a minimum task manager. It is similar in
principle to the full-featured task manager implemented in Task.py,
but it has a sharply reduced feature set--completely bare-bones, in
fact--and it is designed to be a pure-python implementation that does
not require any C++ Panda support, so that it can be loaded before
Panda has been fully downloaded. """
__all__ = ['MiniTask', 'MiniTaskManager']
class MiniTask:
done = 0
cont = 1
def __init__(self, callback):
self.__call__ = callback
class MiniTaskManager:
def __init__(self):
self.taskList = []
self.running = 0
def add(self, task, name):
assert isinstance(task, MiniTask)
task.name = name
self.taskList.append(task)
def remove(self, task):
try:
self.taskList.remove(task)
except ValueError:
pass
def __executeTask(self, task):
return task(task)
def step(self):
i = 0
while (i < len(self.taskList)):
task = self.taskList[i]
ret = task(task)
# See if the task is done
if (ret == task.cont):
# Leave it for next frame, its not done yet
pass
else:
# Remove the task
try:
self.taskList.remove(task)
except ValueError:
pass
# Do not increment the iterator
continue
# Move to the next element
i += 1
def run(self):
self.running = 1
while self.running:
self.step()
def stop(self):
# Set a flag so we will stop before beginning next frame
self.running = 0