瀏覽代碼

support for manual or task-driven position broadcasts

Darren Ranalli 18 年之前
父節點
當前提交
334cf9f8e8
共有 1 個文件被更改,包括 13 次插入4 次删除
  1. 13 4
      direct/src/distributed/DistributedSmoothNodeBase.py

+ 13 - 4
direct/src/distributed/DistributedSmoothNodeBase.py

@@ -4,11 +4,13 @@ from ClockDelta import *
 from direct.task import Task
 from direct.showbase.PythonUtil import randFloat, Enum
 
+DummyTask = ScratchPad()
+    
 class DistributedSmoothNodeBase:
     """common base class for DistributedSmoothNode and DistributedSmoothNodeAI
     """
     BroadcastTypes = Enum('FULL, XYH, XY')
-    
+
     def __init__(self):
         pass
 
@@ -46,6 +48,12 @@ class DistributedSmoothNodeBase:
         # Delete this callback because it maintains a reference to self
         self.d_broadcastPosHpr = None
 
+    def posHprBroadcastStarted(self):
+        return self.d_broadcastPosHpr != None
+
+    def wantSmoothPosBroadcastTask(self):
+        return True
+
     def startPosHprBroadcast(self, period=.2, stagger=0, type=None):
         if self.cnode == None:
             self.initializeCnode()
@@ -83,10 +91,11 @@ class DistributedSmoothNodeBase:
         delay = 0.
         if stagger:
             delay = randFloat(period)
-        taskMgr.doMethodLater(self.__broadcastPeriod + delay,
-                              self._posHprBroadcast, taskName)
+        if self.wantSmoothPosBroadcastTask():
+            taskMgr.doMethodLater(self.__broadcastPeriod + delay,
+                                  self._posHprBroadcast, taskName)
 
-    def _posHprBroadcast(self, task):
+    def _posHprBroadcast(self, task=DummyTask):
         # TODO: we explicitly stagger the initial task timing in
         # startPosHprBroadcast; we should at least make an effort to keep
         # this task accurately aligned with its period and starting time.