Browse Source

Non scaled 2d nodes

Zachary Pavlov 15 years ago
parent
commit
128097e19d
2 changed files with 190 additions and 2 deletions
  1. 163 2
      direct/src/showbase/PythonUtil.py
  2. 27 0
      direct/src/showbase/ShowBase.py

+ 163 - 2
direct/src/showbase/PythonUtil.py

@@ -1,3 +1,4 @@
+
 """Undocumented Module"""
 """Undocumented Module"""
 
 
 __all__ = ['enumerate', 'unique', 'indent', 'nonRepeatingRandomList',
 __all__ = ['enumerate', 'unique', 'indent', 'nonRepeatingRandomList',
@@ -54,6 +55,8 @@ import marshal
 import ElementTree as ET
 import ElementTree as ET
 from HTMLParser import HTMLParser
 from HTMLParser import HTMLParser
 
 
+__report_indent = 3
+
 from direct.directutil import Verify
 from direct.directutil import Verify
 # Don't import libpandaexpressModules, which doesn't get built until
 # Don't import libpandaexpressModules, which doesn't get built until
 # genPyCode.
 # genPyCode.
@@ -2580,6 +2583,159 @@ def fastRepr(obj, maxLen=200, strFactor=10, _visitedIds=None):
     except:
     except:
         return '<** FAILED REPR OF %s **>' % obj.__class__.__name__
         return '<** FAILED REPR OF %s **>' % obj.__class__.__name__
 
 
+baseLine = {}
+
+def baseLineCheck():
+    global baseLine
+    import gc
+    obj = gc.get_objects()
+    baseLine = {}
+    for i in obj:
+        baseLine[str(itype(i))] = 0
+    for i in obj:
+        baseLine[str(itype(i))] += 1
+
+def diffSinceBaseLine():
+    import copy
+    import gc
+    obj = gc.get_objects()    
+    since = copy.deepcopy(baseLine)
+    for i in obj:
+        since.setdefault(str(itype(i)), 0)
+    for i in obj:
+        since[str(itype(i))] -= 1
+    for i in since.keys():
+        if not since[i]:
+            del since[i]
+        else:
+            since[i] = abs(since[i])
+
+    final = [(since[x],x) for x in since]
+    final.sort()
+    final.reverse()
+    for i in final:
+        print i
+
+    final = []
+    since = []
+
+
+# Recursively expand slist's objects
+# into olist, using seen to track
+# already processed objects.
+def _getr(slist, olist, seen):
+  for e in slist:
+    if id(e) in seen:
+      continue
+    seen[id(e)] = None
+    olist.append(e)
+    tl = gc.get_referents(e)
+    if tl:
+      _getr(tl, olist, seen)
+
+# The public function.
+def get_all_objects():
+  """Return a list of all live Python
+  objects, not including the list itself."""
+  gcl = gc.get_objects()
+  olist = []
+  seen = {}
+  # Just in case:
+  seen[id(gcl)] = None
+  seen[id(olist)] = None
+  seen[id(seen)] = None
+  # _getr does the real work.
+  _getr(gcl, olist, seen)
+  return olist    
+
+def getIdList():
+    baseList = get_all_objects()
+    idList = {}
+    for i in baseList:
+        idList[id(i)] = i
+
+    return idList
+
+
+ftype = None
+
+def getTree(obj):
+    global ftype
+    if not ftype:
+        ftype = itype(sys._getframe())
+    objId = id(obj)
+    obj = None
+    idList = getIdList()
+    objList = [objId]
+    objTree = {objId:{}}
+    r_add_chain(objId, objList, objTree[objId], idList, 0 )
+    
+    return convertTree(objTree, idList)
+
+def convertTree(objTree, idList):
+    newTree = {}
+    for key in objTree.keys():
+        obj = (idList[key],)
+        newTree[obj] = {}
+        r_convertTree(objTree[key], newTree[obj], idList)
+    return newTree
+
+def r_convertTree(oldTree, newTree, idList):
+    for key in oldTree.keys():
+        
+        obj = idList.get(key)
+        if(not obj):
+            continue
+        obj = str(obj)[:100]
+        
+        newTree[obj] = {}
+        r_convertTree(oldTree[key], newTree[obj], idList)        
+
+
+def pretty_print(tree):
+    for name in tree.keys():
+        print name
+        r_pretty_print(tree[name], 0)
+        
+            
+
+def r_pretty_print(tree, num):
+    num+=1
+    for name in tree.keys():
+        print "  "*num,name
+        r_pretty_print(tree[name],num)
+        
+def r_add_chain(objId, objList, objTree, idList, num):
+    num+=1
+    obj = idList.get(objId)
+    if(not obj):
+        return
+    
+    refList = gc.get_referrers(obj)
+    for ref in refList:
+        refId = id(ref)
+        if ref == __builtins__:
+            continue
+        if ref == objList:
+            continue
+        if refId in objList:
+            continue
+        if(ref == idList):
+            continue
+        if(itype(ref) == ftype):
+            continue
+        if(itype(ref) == itype(sys)):
+            continue
+
+        objList.append(refId)
+        
+        objTree[refId] = {}
+    refList = None
+    for refId in objTree:
+        r_add_chain(refId, objList, objTree[refId], idList, num)
+                    
+        
+    
 def tagRepr(obj, tag):
 def tagRepr(obj, tag):
     """adds a string onto the repr output of an instance"""
     """adds a string onto the repr output of an instance"""
     def reprWithTag(oldRepr, tag, self):
     def reprWithTag(oldRepr, tag, self):
@@ -3969,11 +4125,16 @@ def startSuperLog(customFunction = None):
                     del vars['__builtins__']
                     del vars['__builtins__']
                 for i in vars:
                 for i in vars:
                     vars[i] = safeReprTypeOnFail(vars[i]) 
                     vars[i] = safeReprTypeOnFail(vars[i]) 
+
                 if customFunction:
                 if customFunction:
-                    superLogFile.write( "before = %s"%customFunction())
+                    superLogFile.write( "before = %s\n"%customFunction())
+
                 superLogFile.write( "%s(%s):%s:%s\n"%(a.f_code.co_filename.split("\\")[-1],a.f_code.co_firstlineno, a.f_code.co_name, vars))
                 superLogFile.write( "%s(%s):%s:%s\n"%(a.f_code.co_filename.split("\\")[-1],a.f_code.co_firstlineno, a.f_code.co_name, vars))
+
                 if customFunction:
                 if customFunction:
-                    superLogFile.write( "after = %s"%customFunction())
+                    superLogFile.write( "after = %s\n"%customFunction())
+
+
                 return trace_dispatch
                 return trace_dispatch
         sys.settrace(trace_dispatch)
         sys.settrace(trace_dispatch)
       
       

+ 27 - 0
direct/src/showbase/ShowBase.py

@@ -948,25 +948,41 @@ class ShowBase(DirectObject.DirectObject):
         self.a2dRight = aspectRatio
         self.a2dRight = aspectRatio
 
 
         self.a2dTopCenter = self.aspect2d.attachNewNode("a2dTopCenter")
         self.a2dTopCenter = self.aspect2d.attachNewNode("a2dTopCenter")
+        self.a2dTopCenterNs = self.aspect2d.attachNewNode("a2dTopCenterNS")
         self.a2dBottomCenter = self.aspect2d.attachNewNode("a2dBottomCenter")
         self.a2dBottomCenter = self.aspect2d.attachNewNode("a2dBottomCenter")
+        self.a2dBottomCenterNs = self.aspect2d.attachNewNode("a2dBottomCenterNS")
         self.a2dLeftCenter = self.aspect2d.attachNewNode("a2dLeftCenter")
         self.a2dLeftCenter = self.aspect2d.attachNewNode("a2dLeftCenter")
+        self.a2dLeftCenterNs = self.aspect2d.attachNewNode("a2dLeftCenterNS")
         self.a2dRightCenter = self.aspect2d.attachNewNode("a2dRightCenter")
         self.a2dRightCenter = self.aspect2d.attachNewNode("a2dRightCenter")
+        self.a2dRightCenterNs = self.aspect2d.attachNewNode("a2dRightCenterNS")
 
 
         self.a2dTopLeft = self.aspect2d.attachNewNode("a2dTopLeft")
         self.a2dTopLeft = self.aspect2d.attachNewNode("a2dTopLeft")
+        self.a2dTopLeftNs = self.aspect2d.attachNewNode("a2dTopLeftNS")
         self.a2dTopRight = self.aspect2d.attachNewNode("a2dTopRight")
         self.a2dTopRight = self.aspect2d.attachNewNode("a2dTopRight")
+        self.a2dTopRightNs = self.aspect2d.attachNewNode("a2dTopRightNS")
         self.a2dBottomLeft = self.aspect2d.attachNewNode("a2dBottomLeft")
         self.a2dBottomLeft = self.aspect2d.attachNewNode("a2dBottomLeft")
+        self.a2dBottomLeftNs = self.aspect2d.attachNewNode("a2dBottomLeftNS")
         self.a2dBottomRight = self.aspect2d.attachNewNode("a2dBottomRight")
         self.a2dBottomRight = self.aspect2d.attachNewNode("a2dBottomRight")
+        self.a2dBottomRightNs = self.aspect2d.attachNewNode("a2dBottomRightNS")
 
 
         # Put the nodes in their places
         # Put the nodes in their places
         self.a2dTopCenter.setPos(0, 0, self.a2dTop)
         self.a2dTopCenter.setPos(0, 0, self.a2dTop)
+        self.a2dTopCenterNs.setPos(0, 0, self.a2dTop)
         self.a2dBottomCenter.setPos(0, 0, self.a2dBottom)
         self.a2dBottomCenter.setPos(0, 0, self.a2dBottom)
+        self.a2dBottomCenterNs.setPos(0, 0, self.a2dBottom)
         self.a2dLeftCenter.setPos(self.a2dLeft, 0, 0)
         self.a2dLeftCenter.setPos(self.a2dLeft, 0, 0)
+        self.a2dLeftCenterNs.setPos(self.a2dLeft, 0, 0)
         self.a2dRightCenter.setPos(self.a2dRight, 0, 0)
         self.a2dRightCenter.setPos(self.a2dRight, 0, 0)
+        self.a2dRightCenterNs.setPos(self.a2dRight, 0, 0)
 
 
         self.a2dTopLeft.setPos(self.a2dLeft, 0, self.a2dTop)
         self.a2dTopLeft.setPos(self.a2dLeft, 0, self.a2dTop)
+        self.a2dTopLeftNs.setPos(self.a2dLeft, 0, self.a2dTop)
         self.a2dTopRight.setPos(self.a2dRight, 0, self.a2dTop)
         self.a2dTopRight.setPos(self.a2dRight, 0, self.a2dTop)
+        self.a2dTopRightNs.setPos(self.a2dRight, 0, self.a2dTop)
         self.a2dBottomLeft.setPos(self.a2dLeft, 0, self.a2dBottom)
         self.a2dBottomLeft.setPos(self.a2dLeft, 0, self.a2dBottom)
+        self.a2dBottomLeftNs.setPos(self.a2dLeft, 0, self.a2dBottom)
         self.a2dBottomRight.setPos(self.a2dRight, 0, self.a2dBottom)
         self.a2dBottomRight.setPos(self.a2dRight, 0, self.a2dBottom)
+        self.a2dBottomRightNs.setPos(self.a2dRight, 0, self.a2dBottom)
         
         
         # This special root, pixel2d, uses units in pixels that are relative
         # This special root, pixel2d, uses units in pixels that are relative
         # to the window. The upperleft corner of the window is (0, 0),
         # to the window. The upperleft corner of the window is (0, 0),
@@ -2440,6 +2456,7 @@ class ShowBase(DirectObject.DirectObject):
                         self.a2dpLeft = -aspectRatio
                         self.a2dpLeft = -aspectRatio
                         self.a2dpRight = aspectRatio                        
                         self.a2dpRight = aspectRatio                        
 
 
+
                     # Reposition the aspect2d marker nodes
                     # Reposition the aspect2d marker nodes
                     self.a2dTopCenter.setPos(0, 0, self.a2dTop)
                     self.a2dTopCenter.setPos(0, 0, self.a2dTop)
                     self.a2dBottomCenter.setPos(0, 0, self.a2dBottom)
                     self.a2dBottomCenter.setPos(0, 0, self.a2dBottom)
@@ -2450,6 +2467,16 @@ class ShowBase(DirectObject.DirectObject):
                     self.a2dBottomLeft.setPos(self.a2dLeft, 0, self.a2dBottom)
                     self.a2dBottomLeft.setPos(self.a2dLeft, 0, self.a2dBottom)
                     self.a2dBottomRight.setPos(self.a2dRight, 0, self.a2dBottom)
                     self.a2dBottomRight.setPos(self.a2dRight, 0, self.a2dBottom)
 
 
+                    # Reposition the aspect2d marker nodes
+                    self.a2dTopCenterNs.setPos(0, 0, self.a2dTop)
+                    self.a2dBottomCenterNs.setPos(0, 0, self.a2dBottom)
+                    self.a2dLeftCenterNs.setPos(self.a2dLeft, 0, 0)
+                    self.a2dRightCenterNs.setPos(self.a2dRight, 0, 0)                    
+                    self.a2dTopLeftNs.setPos(self.a2dLeft, 0, self.a2dTop)
+                    self.a2dTopRightNs.setPos(self.a2dRight, 0, self.a2dTop)
+                    self.a2dBottomLeftNs.setPos(self.a2dLeft, 0, self.a2dBottom)
+                    self.a2dBottomRightNs.setPos(self.a2dRight, 0, self.a2dBottom)                    
+
                     # Reposition the aspect2dp marker nodes
                     # Reposition the aspect2dp marker nodes
                     self.a2dpTopCenter.setPos(0, 0, self.a2dpTop)
                     self.a2dpTopCenter.setPos(0, 0, self.a2dpTop)
                     self.a2dpBottomCenter.setPos(0, 0, self.a2dpBottom)
                     self.a2dpBottomCenter.setPos(0, 0, self.a2dpBottom)