Browse Source

*** empty log message ***

Darren Ranalli 25 years ago
parent
commit
e2a3d907e5
2 changed files with 64 additions and 43 deletions
  1. 15 13
      direct/src/showbase/ShowBase.py
  2. 49 30
      direct/src/task/Task.py

+ 15 - 13
direct/src/showbase/ShowBase.py

@@ -36,6 +36,8 @@ class ShowBase:
         self.wantDIRECT = self.config.GetBool('want-directtools', 0)
         self.wantDIRECT = self.config.GetBool('want-directtools', 0)
         self.wantStats = self.config.GetBool('want-stats', 0)
         self.wantStats = self.config.GetBool('want-stats', 0)
 
 
+        taskMgr.taskTimerVerbose = self.config.GetBool('task-timer-verbose', 0)
+
         self.initialState = NodeAttributes()
         self.initialState = NodeAttributes()
         # Set a default "off color" (i.e. use poly color) for color transitions
         # Set a default "off color" (i.e. use poly color) for color transitions
         self.initialState.setAttribute(ColorTransition.getClassType(),
         self.initialState.setAttribute(ColorTransition.getClassType(),
@@ -61,7 +63,7 @@ class ShowBase:
         # stores a CollisionTraverser pointer here, we'll traverse it
         # stores a CollisionTraverser pointer here, we'll traverse it
         # in the igloop task.
         # in the igloop task.
         self.cTrav = 0
         self.cTrav = 0
-        
+
         # This is a list of cams associated with the display region's cameras
         # This is a list of cams associated with the display region's cameras
         self.camList = []
         self.camList = []
         for camera in self.cameraList:
         for camera in self.cameraList:
@@ -131,7 +133,7 @@ class ShowBase:
 	# Particle manager
 	# Particle manager
 	self.particleMgr = particleMgr
 	self.particleMgr = particleMgr
 	self.particleMgr.setFrameStepping(1)
 	self.particleMgr.setFrameStepping(1)
-	self.particleMgrEnabled = 0 
+	self.particleMgrEnabled = 0
 
 
 	# Physics manager
 	# Physics manager
 	self.physicsMgr = physicsMgr
 	self.physicsMgr = physicsMgr
@@ -166,8 +168,8 @@ class ShowBase:
 
 
     def disableParticles(self):
     def disableParticles(self):
 	"""enableParticles(self)"""
 	"""enableParticles(self)"""
-	self.particleMgrEnabled = 0 
-	self.physicsMgrEnabled = 0 
+	self.particleMgrEnabled = 0
+	self.physicsMgrEnabled = 0
 	self.taskMgr.removeTasksNamed('manager-update')
 	self.taskMgr.removeTasksNamed('manager-update')
 
 
     def toggleParticles(self):
     def toggleParticles(self):
@@ -188,7 +190,7 @@ class ShowBase:
 	if (self.particleMgrEnabled == 1):
 	if (self.particleMgrEnabled == 1):
 	    self.particleMgr.doParticles(dt)
 	    self.particleMgr.doParticles(dt)
 	if (self.physicsMgrEnabled == 1):
 	if (self.physicsMgrEnabled == 1):
-	    self.physicsMgr.doPhysics(dt)	
+	    self.physicsMgr.doPhysics(dt)
 	return Task.cont
 	return Task.cont
 
 
     def createStats(self):
     def createStats(self):
@@ -200,7 +202,7 @@ class ShowBase:
     def createAudioManager(self):
     def createAudioManager(self):
         if self.wantSound:
         if self.wantSound:
             AudioManager.spawnUpdate()
             AudioManager.spawnUpdate()
-            
+
     def createRootPanel(self):
     def createRootPanel(self):
         if self.wantTk:
         if self.wantTk:
             from TkGlobal import *
             from TkGlobal import *
@@ -224,9 +226,9 @@ class ShowBase:
 
 
         # Finally, render the frame.
         # Finally, render the frame.
         self.win.update()
         self.win.update()
-        
+
         return Task.cont
         return Task.cont
-    
+
     def restart(self):
     def restart(self):
         self.shutdown()
         self.shutdown()
         # give the igloop task a reasonably "late" priority,
         # give the igloop task a reasonably "late" priority,
@@ -330,7 +332,7 @@ class ShowBase:
 
 
         # If oobeMode was never set, set it to false and create the
         # If oobeMode was never set, set it to false and create the
         # structures we need to implement OOBE.
         # structures we need to implement OOBE.
-        
+
         try:
         try:
             self.oobeMode
             self.oobeMode
         except:
         except:
@@ -388,14 +390,14 @@ class ShowBase:
             mat = Mat4.translateMat(0, -10, 3) * base.camera.getMat(cameraParent)
             mat = Mat4.translateMat(0, -10, 3) * base.camera.getMat(cameraParent)
             mat.invertInPlace()
             mat.invertInPlace()
             self.oobeTrackball.node().setMat(mat)
             self.oobeTrackball.node().setMat(mat)
-            
+
             self.cam.reparentTo(self.oobeCameraTrackball)
             self.cam.reparentTo(self.oobeCameraTrackball)
             if not self.oobeVis.isEmpty():
             if not self.oobeVis.isEmpty():
                 self.oobeVis.reparentTo(self.camera)
                 self.oobeVis.reparentTo(self.camera)
             self.oobeMode = 1
             self.oobeMode = 1
-            
-        
-        
+
+
+
     def run(self):
     def run(self):
         self.taskMgr.run()
         self.taskMgr.run()
 
 

+ 49 - 30
direct/src/task/Task.py

@@ -96,7 +96,7 @@ def make_sequence(taskList):
             return done
             return done
         else:
         else:
             task = self.taskList[self.index]
             task = self.taskList[self.index]
-            # If this is a new task, set it's start time and frame
+            # If this is a new task, set its start time and frame
             if (self.index > self.prevIndex):
             if (self.index > self.prevIndex):
                 task.setStartTimeFrame(self.time, self.frame)
                 task.setStartTimeFrame(self.time, self.frame)
             self.prevIndex = self.index
             self.prevIndex = self.index
@@ -258,6 +258,7 @@ class TaskManager:
         if (TaskManager.notify == None):
         if (TaskManager.notify == None):
             TaskManager.notify = directNotify.newCategory("TaskManager")
             TaskManager.notify = directNotify.newCategory("TaskManager")
         # TaskManager.notify.setDebug(1)
         # TaskManager.notify.setDebug(1)
+        self.taskTimerVerbose = 0
 
 
     def stepping(value):
     def stepping(value):
         self.stepping = value
         self.stepping = value
@@ -347,25 +348,29 @@ class TaskManager:
         for task in self.taskList:
         for task in self.taskList:
             task.setCurrentTimeFrame(self.currentTime, self.currentFrame)
             task.setCurrentTimeFrame(self.currentTime, self.currentFrame)
 
 
-            # Run the task and check the return value
-            startTime = time.clock()
-            ret = task(task)
-            endTime = time.clock()
-
-            # Record the dt
-            dt = endTime - startTime
-            task.dt = dt
-            
-            # See if this is the new max
-            if dt > task.maxDt:
-                task.maxDt = dt
-            
-            # Record the running total of all dts so we can compute an average
-            task.runningTotal = task.runningTotal + dt
-            if (task.frame > 0):
-                task.avgDt = (task.runningTotal / task.frame)
+            if (self.taskTimerVerbose == 0):
+                # don't record timing info
+                ret = task(task)
             else:
             else:
-                task.avgDt = 0
+                # Run the task and check the return value
+                startTime = time.clock()
+                ret = task(task)
+                endTime = time.clock()
+
+                # Record the dt
+                dt = endTime - startTime
+                task.dt = dt
+
+                # See if this is the new max
+                if dt > task.maxDt:
+                    task.maxDt = dt
+
+                # Record the running total of all dts so we can compute an average
+                task.runningTotal = task.runningTotal + dt
+                if (task.frame > 0):
+                    task.avgDt = (task.runningTotal / task.frame)
+                else:
+                    task.avgDt = 0
 
 
             # See if the task is done
             # See if the task is done
             if (ret == cont):
             if (ret == cont):
@@ -416,7 +421,7 @@ class TaskManager:
                                                method.im_self,
                                                method.im_self,
                                                method.im_class)
                                                method.im_class)
                 task.__call__ = newMethod
                 task.__call__ = newMethod
-                # Found it retrun true
+                # Found it return true
                 return 1
                 return 1
         return 0
         return 0
 
 
@@ -437,17 +442,31 @@ class TaskManager:
         for task in self.taskList:
         for task in self.taskList:
             totalDt = totalDt + task.dt
             totalDt = totalDt + task.dt
             totalAvgDt = totalAvgDt + task.avgDt
             totalAvgDt = totalAvgDt + task.avgDt
-            str = str + (task.name.ljust(taskNameWidth)
-                         + fpformat.fix(task.dt*1000, 2).rjust(dtWidth)
-                         + fpformat.fix(task.avgDt*1000, 2).rjust(dtWidth)
-                         + fpformat.fix(task.maxDt*1000, 2).rjust(dtWidth)
-                         + `task.getPriority()`.rjust(priorityWidth)
-                         + '\n')
+            if (self.taskTimerVerbose):
+                str = str + (task.name.ljust(taskNameWidth)
+                             + fpformat.fix(task.dt*1000, 2).rjust(dtWidth)
+                             + fpformat.fix(task.avgDt*1000, 2).rjust(dtWidth)
+                             + fpformat.fix(task.maxDt*1000, 2).rjust(dtWidth)
+                             + `task.getPriority()`.rjust(priorityWidth)
+                             + '\n')
+            else:
+                str = str + (task.name.ljust(taskNameWidth)
+                             + '----'.rjust(dtWidth)
+                             + '----'.rjust(dtWidth)
+                             + '----'.rjust(dtWidth)
+                             + `task.getPriority()`.rjust(priorityWidth)
+                             + '\n')
         str = str + '---------------------------------------------------------------\n'
         str = str + '---------------------------------------------------------------\n'
-        str = str + ('total'.ljust(taskNameWidth)
-                     + fpformat.fix(totalDt*1000, 2).rjust(dtWidth)
-                     + fpformat.fix(totalAvgDt*1000, 2).rjust(dtWidth)
-                     + '\n')
+        if (self.taskTimerVerbose):
+            str = str + ('total'.ljust(taskNameWidth)
+                         + fpformat.fix(totalDt*1000, 2).rjust(dtWidth)
+                         + fpformat.fix(totalAvgDt*1000, 2).rjust(dtWidth)
+                         + '\n')
+        else:
+            str = str + ('total'.ljust(taskNameWidth)
+                         + '----'.rjust(dtWidth)
+                         + '----'.rjust(dtWidth)
+                         + '\n')
         return str
         return str