first rev

This commit is contained in:
Darren Ranalli 2006-05-16 23:43:42 +00:00
parent 279904b28d
commit 53797841c5
1 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,32 @@
from direct.task import Task
class TaskThreaded:
""" derive from this if you need to do a bunch of CPU-intensive
processing and you don't want to hang up the show. Lets you break
up the processing over multiple frames """
_Serial = SerialNum()
def __init__(self, name, threaded=True):
self._name = name
self._threaded=threaded
self._taskNames = set()
def destroy(self):
for taskName in self._taskNames:
taskMgr.remove(taskName)
def scheduleNext(self, callback):
if not self._threaded:
callback()
else:
taskName = ('%s-ThreadedTask-%s' %
(self._name, TaskThreaded._Serial.next()))
assert taskName not in self._taskNames
self._taskNames.add(taskName)
taskMgr.add(Functor(self._doCallback, callback, taskName),
taskName)
def _doCallback(self, callback, taskName, task):
self._taskNames.remove(taskName)
callback()
return Task.done