mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
formatting
This commit is contained in:
parent
0574017d72
commit
fc7fc09140
@ -21,7 +21,7 @@ class DirectNodePath(NodePath):
|
||||
self.mCoa2Dnp = Mat4(Mat4.identMat())
|
||||
if direct.coaMode == COA_CENTER:
|
||||
self.mCoa2Dnp.setRow(3, Vec4(center[0], center[1], center[2], 1))
|
||||
|
||||
|
||||
# Transform from nodePath to widget
|
||||
self.tDnp2Widget = TransformState.makeIdentity()
|
||||
|
||||
@ -80,7 +80,7 @@ class SelectedNodePaths(DirectObject):
|
||||
if nodePath.hasNetTag(tag):
|
||||
nodePath = nodePath.findNetTag(tag)
|
||||
break
|
||||
|
||||
|
||||
# Get this pointer
|
||||
id = nodePath.id()
|
||||
# First see if its already in the selected dictionary
|
||||
@ -136,7 +136,7 @@ class SelectedNodePaths(DirectObject):
|
||||
"""
|
||||
return self.selectedDict.values()[:]
|
||||
|
||||
def __getitem__(self,index):
|
||||
def __getitem__(self, index):
|
||||
return self.getSelectedAsList()[index]
|
||||
|
||||
def getSelectedDict(self, id):
|
||||
@ -209,7 +209,7 @@ class SelectedNodePaths(DirectObject):
|
||||
if selected:
|
||||
selected.remove()
|
||||
__builtins__["last"] = self.last = None
|
||||
|
||||
|
||||
def removeAll(self):
|
||||
# Remove all selected nodePaths from the Scene Graph
|
||||
self.forEachSelectedNodePathDo(NodePath.remove)
|
||||
@ -266,14 +266,14 @@ class DirectBoundingBox:
|
||||
# Get bounds
|
||||
self.min = Point3(0)
|
||||
self.max = Point3(0)
|
||||
self.nodePath.calcTightBounds(self.min,self.max)
|
||||
self.nodePath.calcTightBounds(self.min, self.max)
|
||||
# Calc center and radius
|
||||
self.center = Point3((self.min + self.max)/2.0)
|
||||
self.radius = Vec3(self.max - self.min).length()
|
||||
# Restore transform
|
||||
self.nodePath.setMat(tMat)
|
||||
del tMat
|
||||
|
||||
|
||||
def computeBounds(self):
|
||||
self.bounds = self.getBounds()
|
||||
if self.bounds.isEmpty() or self.bounds.isInfinite():
|
||||
@ -284,7 +284,7 @@ class DirectBoundingBox:
|
||||
self.radius = self.bounds.getRadius()
|
||||
self.min = Point3(self.center - Point3(self.radius))
|
||||
self.max = Point3(self.center + Point3(self.radius))
|
||||
|
||||
|
||||
def createBBoxLines(self, bboxColor=None):
|
||||
# Create a line segments object for the bbox
|
||||
lines = LineNodePath(hidden)
|
||||
@ -301,7 +301,7 @@ class DirectBoundingBox:
|
||||
maxX = self.max[0]
|
||||
maxY = self.max[1]
|
||||
maxZ = self.max[2]
|
||||
|
||||
|
||||
# Bottom face
|
||||
lines.moveTo(minX, minY, minZ)
|
||||
lines.drawTo(maxX, minY, minZ)
|
||||
@ -326,29 +326,29 @@ class DirectBoundingBox:
|
||||
|
||||
# Create and return bbox lines
|
||||
lines.create()
|
||||
|
||||
|
||||
# Make sure bbox is never lit or drawn in wireframe
|
||||
useDirectRenderStyle(lines)
|
||||
|
||||
|
||||
return lines
|
||||
|
||||
def setBoxColorScale(self,r,g,b,a):
|
||||
def setBoxColorScale(self, r, g, b, a):
|
||||
if (self.lines):
|
||||
self.lines.reset()
|
||||
self.lines = None
|
||||
self.lines = self.createBBoxLines((r,g,b,a))
|
||||
self.lines = self.createBBoxLines((r, g, b, a))
|
||||
self.show()
|
||||
|
||||
def updateBBoxLines(self):
|
||||
ls = self.lines.lineSegs
|
||||
|
||||
|
||||
minX = self.min[0]
|
||||
minY = self.min[1]
|
||||
minZ = self.min[2]
|
||||
maxX = self.max[0]
|
||||
maxY = self.max[1]
|
||||
maxZ = self.max[2]
|
||||
|
||||
|
||||
# Bottom face
|
||||
ls.setVertex(0, minX, minY, minZ)
|
||||
ls.setVertex(1, maxX, minY, minZ)
|
||||
@ -384,7 +384,7 @@ class DirectBoundingBox:
|
||||
|
||||
def hide(self):
|
||||
self.lines.reparentTo(hidden)
|
||||
|
||||
|
||||
def getCenter(self):
|
||||
return self.center
|
||||
|
||||
@ -401,7 +401,7 @@ class DirectBoundingBox:
|
||||
return '%.2f %.2f %.2f' % (vec[0], vec[1], vec[2])
|
||||
|
||||
def __repr__(self):
|
||||
return (`self.__class__` +
|
||||
return (`self.__class__` +
|
||||
'\nNodePath:\t%s\n' % self.nodePath.getName() +
|
||||
'Min:\t\t%s\n' % self.vecAsString(self.min) +
|
||||
'Max:\t\t%s\n' % self.vecAsString(self.max) +
|
||||
@ -528,7 +528,7 @@ class SelectionQueue(CollisionHandlerQueue):
|
||||
self.setCurrentIndex(-1)
|
||||
self.setCurrentEntry(None)
|
||||
# Pick out the closest object that isn't a widget
|
||||
for i in range(startIndex,self.getNumEntries()):
|
||||
for i in range(startIndex, self.getNumEntries()):
|
||||
entry = self.getEntry(i)
|
||||
nodePath = entry.getIntoNodePath()
|
||||
if (skipFlags & SKIP_HIDDEN) and nodePath.isHidden():
|
||||
@ -557,7 +557,7 @@ class SelectionRay(SelectionQueue):
|
||||
# Initialize the superclass
|
||||
SelectionQueue.__init__(self, parentNP)
|
||||
self.addCollider(CollisionRay())
|
||||
|
||||
|
||||
def pick(self, targetNodePath, xy = None):
|
||||
# Determine ray direction based upon the mouse coordinates
|
||||
if xy:
|
||||
@ -604,9 +604,9 @@ class SelectionRay(SelectionQueue):
|
||||
self.collider.setDirection(dir)
|
||||
self.ct.traverse(targetNodePath)
|
||||
self.sortEntries()
|
||||
|
||||
|
||||
def pickGeom3D(self, targetNodePath = render,
|
||||
origin = Point3(0), dir = Vec3(0,0,-1),
|
||||
origin = Point3(0), dir = Vec3(0, 0, -1),
|
||||
skipFlags = SKIP_HIDDEN | SKIP_CAMERA):
|
||||
self.collideWithGeom()
|
||||
self.pick3D(targetNodePath, origin, dir)
|
||||
@ -615,7 +615,7 @@ class SelectionRay(SelectionQueue):
|
||||
|
||||
def pickBitMask3D(self, bitMask = BitMask32.allOff(),
|
||||
targetNodePath = render,
|
||||
origin = Point3(0), dir = Vec3(0,0,-1),
|
||||
origin = Point3(0), dir = Vec3(0, 0, -1),
|
||||
skipFlags = SKIP_ALL):
|
||||
self.collideWithBitMask(bitMask)
|
||||
self.pick3D(targetNodePath, origin, dir)
|
||||
@ -633,7 +633,7 @@ class SelectionSegment(SelectionQueue):
|
||||
self.numColliders = 0
|
||||
for i in range(numSegments):
|
||||
self.addCollider(CollisionSegment())
|
||||
|
||||
|
||||
def addCollider(self, collider):
|
||||
# Record new collision object
|
||||
self.colliders.append(collider)
|
||||
@ -676,30 +676,30 @@ class SelectionSphere(SelectionQueue):
|
||||
self.numColliders = 0
|
||||
for i in range(numSpheres):
|
||||
self.addCollider(CollisionSphere(Point3(0), 1))
|
||||
|
||||
|
||||
def addCollider(self, collider):
|
||||
# Record new collision object
|
||||
self.colliders.append(collider)
|
||||
# Add the collider to the collision Node
|
||||
self.collisionNode.addSolid(collider)
|
||||
self.numColliders += 1
|
||||
|
||||
|
||||
def setCenter(self, i, center):
|
||||
c = self.colliders[i]
|
||||
c.setCenter(center)
|
||||
|
||||
|
||||
def setRadius(self, i, radius):
|
||||
c = self.colliders[i]
|
||||
c.setRadius(radius)
|
||||
|
||||
|
||||
def setCenterRadius(self, i, center, radius):
|
||||
c = self.colliders[i]
|
||||
c.setCenter(center)
|
||||
c.setRadius(radius)
|
||||
|
||||
|
||||
def isEntryBackfacing(self, entry):
|
||||
# If dot product of collision point surface normal and
|
||||
# ray from sphere origin to collision point is positive,
|
||||
# ray from sphere origin to collision point is positive,
|
||||
# center is on the backside of the polygon
|
||||
fromNodePath = entry.getFromNodePath()
|
||||
v = Vec3(entry.getSurfacePoint(fromNodePath) -
|
||||
@ -722,7 +722,7 @@ class SelectionSphere(SelectionQueue):
|
||||
skipFlags = SKIP_HIDDEN | SKIP_CAMERA):
|
||||
self.collideWithGeom()
|
||||
return self.pick(targetNodePath, skipFlags)
|
||||
|
||||
|
||||
def pickBitMask(self, bitMask = BitMask32.allOff(),
|
||||
targetNodePath = render,
|
||||
skipFlags = SKIP_HIDDEN | SKIP_CAMERA):
|
||||
|
@ -65,7 +65,7 @@ class DirectSession(DirectObject):
|
||||
self.activeParent = None
|
||||
|
||||
self.selectedNPReadout = OnscreenText.OnscreenText(
|
||||
pos = (-1.0, -0.9), bg=Vec4(1,1,1,1),
|
||||
pos = (-1.0, -0.9), bg=Vec4(1, 1, 1, 1),
|
||||
scale = 0.05, align = TextNode.ALeft,
|
||||
mayChange = 1, font = self.font)
|
||||
# Make sure readout is never lit or drawn in wireframe
|
||||
@ -73,7 +73,7 @@ class DirectSession(DirectObject):
|
||||
self.selectedNPReadout.reparentTo(hidden)
|
||||
|
||||
self.activeParentReadout = OnscreenText.OnscreenText(
|
||||
pos = (-1.0, -0.975), bg=Vec4(1,1,1,1),
|
||||
pos = (-1.0, -0.975), bg=Vec4(1, 1, 1, 1),
|
||||
scale = 0.05, align = TextNode.ALeft,
|
||||
mayChange = 1, font = self.font)
|
||||
# Make sure readout is never lit or drawn in wireframe
|
||||
@ -81,7 +81,7 @@ class DirectSession(DirectObject):
|
||||
self.activeParentReadout.reparentTo(hidden)
|
||||
|
||||
self.directMessageReadout = OnscreenText.OnscreenText(
|
||||
pos = (-1.0, 0.9), bg=Vec4(1,1,1,1),
|
||||
pos = (-1.0, 0.9), bg=Vec4(1, 1, 1, 1),
|
||||
scale = 0.05, align = TextNode.ALeft,
|
||||
mayChange = 1, font = self.font)
|
||||
# Make sure readout is never lit or drawn in wireframe
|
||||
@ -112,8 +112,8 @@ class DirectSession(DirectObject):
|
||||
fastrak = string.split(fastrak)
|
||||
for i in range(len(fastrak))[1:]:
|
||||
self.fastrak.append(DirectFastrak.DirectFastrak(fastrak[0] + ':' + fastrak[i]))
|
||||
|
||||
|
||||
|
||||
|
||||
self.fControl = 0
|
||||
self.fAlt = 0
|
||||
self.fShift = 0
|
||||
@ -127,7 +127,7 @@ class DirectSession(DirectObject):
|
||||
# Lists for managing undo/redo operations
|
||||
self.undoList = []
|
||||
self.redoList = []
|
||||
|
||||
|
||||
# One run through the context task to init everything
|
||||
self.drList.updateContext()
|
||||
for dr in self.drList:
|
||||
@ -160,7 +160,7 @@ class DirectSession(DirectObject):
|
||||
'shift', 'shift-up',
|
||||
'alt', 'alt-up',
|
||||
]
|
||||
self.keyEvents = ['escape', 'delete', 'page_up', 'page_down',
|
||||
self.keyEvents = ['escape', 'delete', 'page_up', 'page_down',
|
||||
'[', '{', ']', '}',
|
||||
'shift-a', 'b', 'control-f',
|
||||
'l', 'shift-l', 'o', 'p', 'r',
|
||||
@ -197,7 +197,7 @@ class DirectSession(DirectObject):
|
||||
else:
|
||||
self.cluster = DummyClusterClient()
|
||||
__builtins__['cluster'] = self.cluster
|
||||
|
||||
|
||||
def enable(self):
|
||||
# don't enable DIRECT if someone has posted DIRECTdisablePost
|
||||
if bboard.has(DirectSession.DIRECTdisablePost):
|
||||
@ -303,7 +303,7 @@ class DirectSession(DirectObject):
|
||||
base.cam.reparentTo(self.oobeCamera)
|
||||
# Position a target point to lerp the oobe camera to
|
||||
direct.cameraControl.camManipRef.setPos(
|
||||
self.trueCamera, Vec3(-2,-20, 5))
|
||||
self.trueCamera, Vec3(-2, -20, 5))
|
||||
direct.cameraControl.camManipRef.lookAt(self.trueCamera)
|
||||
t = self.oobeCamera.lerpPosHpr(
|
||||
Point3(0), Vec3(0), 2.0,
|
||||
@ -447,8 +447,8 @@ class DirectSession(DirectObject):
|
||||
if self.clusterMode == 'client':
|
||||
if input in ('v','b','l','p', 'r', 'shift-r', 's', 't',
|
||||
'shift-a', 'w'):
|
||||
self.cluster('messenger.send("%s")' % input,0)
|
||||
|
||||
self.cluster('messenger.send("%s")' % input, 0)
|
||||
|
||||
def getModifiers(self, input, base):
|
||||
modifiers = DIRECT_NO_MOD
|
||||
modifierString = input[: input.find(base)]
|
||||
@ -493,7 +493,7 @@ class DirectSession(DirectObject):
|
||||
self.cameraControl.updateCoa(coa)
|
||||
# Adjust widgets size
|
||||
# This uses the additional scaling factor used to grow and
|
||||
# shrink the widget
|
||||
# shrink the widget
|
||||
self.widget.setScalingFactor(dnp.getRadius())
|
||||
# Spawn task to have object handles follow the selected object
|
||||
taskMgr.remove('followSelectedNodePath')
|
||||
@ -506,9 +506,9 @@ class DirectSession(DirectObject):
|
||||
def followSelectedNodePathTask(self, state):
|
||||
mCoa2Render = state.dnp.mCoa2Dnp * state.dnp.getMat(render)
|
||||
decomposeMatrix(mCoa2Render,
|
||||
self.scale,self.hpr,self.pos,
|
||||
self.scale, self.hpr, self.pos,
|
||||
CSDefault)
|
||||
self.widget.setPosHpr(self.pos,self.hpr)
|
||||
self.widget.setPosHpr(self.pos, self.hpr)
|
||||
return Task.cont
|
||||
|
||||
def deselect(self, nodePath):
|
||||
@ -540,7 +540,7 @@ class DirectSession(DirectObject):
|
||||
'Active Reparent Target:' + nodePath.getName())
|
||||
# Alert everyone else
|
||||
messenger.send('DIRECT_activeParent', [self.activeParent])
|
||||
|
||||
|
||||
def reparent(self, nodePath = None, fWrt = 0):
|
||||
if (nodePath and self.activeParent and
|
||||
self.isNotCycle(nodePath, self.activeParent)):
|
||||
@ -561,7 +561,7 @@ class DirectSession(DirectObject):
|
||||
return self.isNotCycle(nodePath, parent.getParent())
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
||||
def flash(self, nodePath = 'None Given'):
|
||||
""" Highlight an object by setting it red for a few seconds """
|
||||
# Clean up any existing task
|
||||
@ -577,7 +577,7 @@ class DirectSession(DirectObject):
|
||||
flashColor.setW(1)
|
||||
else:
|
||||
doneColor = None
|
||||
flashColor = VBase4(1,0,0,1)
|
||||
flashColor = VBase4(1, 0, 0, 1)
|
||||
# Temporarily set node path color
|
||||
nodePath.setColor(flashColor)
|
||||
# Clean up color in a few seconds
|
||||
@ -593,8 +593,8 @@ class DirectSession(DirectObject):
|
||||
def flashDummy(self, state):
|
||||
# Real work is done in upon death function
|
||||
return Task.done
|
||||
|
||||
def flashDone(self,state):
|
||||
|
||||
def flashDone(self, state):
|
||||
# Return node Path to original state
|
||||
if state.nodePath.isEmpty():
|
||||
# Node path doesn't exist anymore, bail
|
||||
@ -714,7 +714,7 @@ class DirectSession(DirectObject):
|
||||
messenger.send('DIRECT_undoListEmpty')
|
||||
# Return last item
|
||||
return undoGroup
|
||||
|
||||
|
||||
def pushRedo(self, nodePathList):
|
||||
# Assemble group of changes
|
||||
redoGroup = []
|
||||
@ -738,7 +738,7 @@ class DirectSession(DirectObject):
|
||||
messenger.send('DIRECT_redoListEmpty')
|
||||
# Return last item
|
||||
return redoGroup
|
||||
|
||||
|
||||
def undo(self):
|
||||
if self.undoList:
|
||||
# Get last item off of redo list
|
||||
@ -843,7 +843,7 @@ class DisplayRegionContext(DirectObject):
|
||||
self.setOrientation()
|
||||
self.camUpdate()
|
||||
|
||||
def __getitem__(self,key):
|
||||
def __getitem__(self, key):
|
||||
return self.__dict__[key]
|
||||
|
||||
def setOrientation(self):
|
||||
@ -869,19 +869,19 @@ class DisplayRegionContext(DirectObject):
|
||||
else:
|
||||
return self.camLens.getVfov()
|
||||
|
||||
def setHfov(self,hfov):
|
||||
def setHfov(self, hfov):
|
||||
if self.isSideways:
|
||||
self.camLens.setFov(self.camLens.getHfov(), hfov)
|
||||
else:
|
||||
self.camLens.setFov(hfov, self.camLens.getVfov())
|
||||
|
||||
def setVfov(self,vfov):
|
||||
def setVfov(self, vfov):
|
||||
if self.isSideways:
|
||||
self.camLens.setFov(vfov, self.camLens.getVfov())
|
||||
else:
|
||||
self.camLens.setFov(self.camLens.getHfov(), vfov)
|
||||
|
||||
def setFov(self,hfov,vfov):
|
||||
def setFov(self, hfov, vfov):
|
||||
if self.isSideways:
|
||||
self.camLens.setFov(vfov, hfov)
|
||||
else:
|
||||
@ -893,14 +893,14 @@ class DisplayRegionContext(DirectObject):
|
||||
return prop.getXSize()
|
||||
else:
|
||||
return 640
|
||||
|
||||
|
||||
def getHeight(self):
|
||||
prop = base.win.getProperties()
|
||||
if prop.hasSize():
|
||||
return prop.getYSize()
|
||||
else:
|
||||
return 480
|
||||
|
||||
|
||||
def camUpdate(self, lens = None):
|
||||
# Window Data
|
||||
self.near = self.camLens.getNear()
|
||||
@ -961,12 +961,12 @@ class DisplayRegionList(DirectObject):
|
||||
drc = DisplayRegionContext(cam)
|
||||
self.displayRegionList.append(drc)
|
||||
|
||||
self.accept("DIRECT-mouse1",self.mouseUpdate)
|
||||
self.accept("DIRECT-mouse2",self.mouseUpdate)
|
||||
self.accept("DIRECT-mouse3",self.mouseUpdate)
|
||||
self.accept("DIRECT-mouse1Up",self.mouseUpdate)
|
||||
self.accept("DIRECT-mouse2Up",self.mouseUpdate)
|
||||
self.accept("DIRECT-mouse3Up",self.mouseUpdate)
|
||||
self.accept("DIRECT-mouse1", self.mouseUpdate)
|
||||
self.accept("DIRECT-mouse2", self.mouseUpdate)
|
||||
self.accept("DIRECT-mouse3", self.mouseUpdate)
|
||||
self.accept("DIRECT-mouse1Up", self.mouseUpdate)
|
||||
self.accept("DIRECT-mouse2Up", self.mouseUpdate)
|
||||
self.accept("DIRECT-mouse3Up", self.mouseUpdate)
|
||||
|
||||
def __getitem__(self, index):
|
||||
return self.displayRegionList[index]
|
||||
@ -980,11 +980,11 @@ class DisplayRegionList(DirectObject):
|
||||
def setNearFar(self, near, far):
|
||||
for dr in self.displayRegionList:
|
||||
dr.camLens.setNearFar(near, far)
|
||||
|
||||
|
||||
def setNear(self, near):
|
||||
for dr in self.displayRegionList:
|
||||
dr.camLens.setNear(near)
|
||||
|
||||
|
||||
def setFar(self, far):
|
||||
for dr in self.displayRegionList:
|
||||
dr.camLens.setFar(far)
|
||||
|
@ -28,7 +28,7 @@ def getTkColorString(color):
|
||||
return "#" + r + g + b
|
||||
|
||||
## Background Color ##
|
||||
def lerpBackgroundColor(r,g,b,duration):
|
||||
def lerpBackgroundColor(r, g, b, duration):
|
||||
"""
|
||||
Function to lerp background color to a new value
|
||||
"""
|
||||
@ -43,14 +43,14 @@ def lerpBackgroundColor(r,g,b,duration):
|
||||
r = sf * state.ec[0] + (1 - sf) * state.sc[0]
|
||||
g = sf * state.ec[1] + (1 - sf) * state.sc[1]
|
||||
b = sf * state.ec[2] + (1 - sf) * state.sc[2]
|
||||
base.setBackgroundColor(r,g,b)
|
||||
base.setBackgroundColor(r, g, b)
|
||||
return Task.cont
|
||||
taskMgr.remove('lerpBackgroundColor')
|
||||
t = taskMgr.add(lerpColor, 'lerpBackgroundColor')
|
||||
t.time = 0.0
|
||||
t.duration = duration
|
||||
t.sc = base.getBackgroundColor()
|
||||
t.ec = VBase4(r,g,b,1)
|
||||
t.ec = VBase4(r, g, b, 1)
|
||||
|
||||
# Set direct drawing style for an object
|
||||
# Never light object or draw in wireframe
|
||||
|
@ -8,7 +8,7 @@ class DistributedLargeBlobSender(DistributedObject.DistributedObject):
|
||||
"""DistributedLargeBlobSender: for sending large chunks of data through
|
||||
the DC system"""
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory('DistributedLargeBlobSender')
|
||||
|
||||
|
||||
def __init__(self, cr):
|
||||
DistributedObject.DistributedObject.__init__(self, cr)
|
||||
|
||||
|
@ -59,7 +59,7 @@ class DistributedLargeBlobSenderAI(DistributedObjectAI.DistributedObjectAI):
|
||||
|
||||
def getMode(self):
|
||||
return self.mode
|
||||
|
||||
|
||||
def getTargetAvId(self):
|
||||
return self.targetAvId
|
||||
|
||||
|
@ -42,7 +42,7 @@ class Mopath(DirectObject):
|
||||
nodePath.removeNode()
|
||||
else:
|
||||
print 'Mopath: no data in file: %s' % filename
|
||||
|
||||
|
||||
|
||||
def reset(self):
|
||||
self.maxT = 0.0
|
||||
|
@ -24,20 +24,20 @@ verify() will also throw an AssertionError, but you can ignore that if you
|
||||
like (I don't suggest trying to catch it, it's just doing it so that it can
|
||||
replace assert more fully).
|
||||
|
||||
Please do not use assert() for things that you want run on release builds.
|
||||
That is a bad thing to do. One of the main reasons that assert exists
|
||||
is to stip out debug code from a release build. The fact that it throws
|
||||
an exception can get it mistaken for an error handler. If your code
|
||||
needs to handle an error or throw an exception, you should do that
|
||||
Please do not use assert() for things that you want run on release builds.
|
||||
That is a bad thing to do. One of the main reasons that assert exists
|
||||
is to stip out debug code from a release build. The fact that it throws
|
||||
an exception can get it mistaken for an error handler. If your code
|
||||
needs to handle an error or throw an exception, you should do that
|
||||
(and not just assert() for it).
|
||||
|
||||
If you want to be a super keen software engineer then avoid using verify().
|
||||
If you want to be, or already are, a super keen software engineer, but
|
||||
you don't always have the time to write proper error handling, go ahead
|
||||
If you want to be, or already are, a super keen software engineer, but
|
||||
you don't always have the time to write proper error handling, go ahead
|
||||
and use verify() -- that's what it's for.
|
||||
|
||||
Please use assert (properly) and do proper error handling; and use verify()
|
||||
only when debugging (i.e. when it won't be checked-in) or where it helps
|
||||
only when debugging (i.e. when it won't be checked-in) or where it helps
|
||||
you resist using assert for error handling.
|
||||
"""
|
||||
|
||||
|
@ -14,11 +14,11 @@ class WeightedChoice:
|
||||
self.total = t
|
||||
self.listOfLists = listOfLists
|
||||
self.weightIndex = weightIndex
|
||||
|
||||
|
||||
def choose(self, rng=random):
|
||||
roll = rng.randrange(self.total)
|
||||
weight = self.weightIndex
|
||||
for i in self.listOfLists:
|
||||
roll -= i[weight]
|
||||
if roll <= 0:
|
||||
return i
|
||||
return i
|
||||
|
@ -153,7 +153,7 @@ class AsyncRequest(DirectObject):
|
||||
context=self.air.allocateContext()
|
||||
self.air.contextToClassName[context]=dclassName
|
||||
self.acceptOnce(
|
||||
"doFieldResponse-%s"%(context,),
|
||||
"doFieldResponse-%s"%(context,),
|
||||
self._checkCompletion, [key])
|
||||
self.air.queryObjectField(dclassName, fieldName, doId, context)
|
||||
|
||||
@ -173,7 +173,7 @@ class AsyncRequest(DirectObject):
|
||||
if context is None:
|
||||
context=self.air.allocateContext()
|
||||
self.acceptOnce(
|
||||
"doRequestResponse-%s"%(context,),
|
||||
"doRequestResponse-%s"%(context,),
|
||||
self._checkCompletion, [None])
|
||||
self.air.queryObjectAll(doId, context)
|
||||
|
||||
@ -192,7 +192,7 @@ class AsyncRequest(DirectObject):
|
||||
# if context is None:
|
||||
# context=self.air.allocateContext()
|
||||
# self.accept(
|
||||
# "doRequestResponse-%s"%(context,),
|
||||
# "doRequestResponse-%s"%(context,),
|
||||
# self._checkCompletion, [None])
|
||||
# self.air.queryObject(doId, context)
|
||||
|
||||
@ -201,11 +201,11 @@ class AsyncRequest(DirectObject):
|
||||
"""
|
||||
Create a new database object. You can get the doId from within
|
||||
your self.finish() function.
|
||||
|
||||
|
||||
This functions is different from createObjectId in that it does
|
||||
generate the object when the response comes back. The object is
|
||||
added to the doId2do and so forth and treated as a full regular
|
||||
object (which it is). This is useful on the AI where we really
|
||||
object (which it is). This is useful on the AI where we really
|
||||
do want the object on the AI.
|
||||
"""
|
||||
assert self.notify.debugCall()
|
||||
@ -234,7 +234,7 @@ class AsyncRequest(DirectObject):
|
||||
"""
|
||||
Create a new database object. You can get the doId from within
|
||||
your self.finish() function.
|
||||
|
||||
|
||||
This functions is different from createObject in that it does not
|
||||
generate the object when the response comes back. It only tells you
|
||||
the doId. This is useful on the UD where we don't really want the
|
||||
@ -252,7 +252,7 @@ class AsyncRequest(DirectObject):
|
||||
self.air.getDatabaseGenerateResponseEvent(context),
|
||||
self._checkCompletion, [name, None])
|
||||
self.air.requestDatabaseGenerate(className, context, values=values)
|
||||
|
||||
|
||||
def _doCreateObject(self, name, className, values, doId):
|
||||
assert self.notify.debugCall()
|
||||
assert not self.__deleted
|
||||
@ -264,8 +264,8 @@ class AsyncRequest(DirectObject):
|
||||
|
||||
def finish(self):
|
||||
"""
|
||||
This is the function that gets called when all of the needed objects
|
||||
are in (i.e. all the askForObject and createObject requests have
|
||||
This is the function that gets called when all of the needed objects
|
||||
are in (i.e. all the askForObject and createObject requests have
|
||||
been satisfied).
|
||||
If the other requests timeout, finish will not be called.
|
||||
"""
|
||||
|
@ -39,11 +39,11 @@ class CRCache:
|
||||
else:
|
||||
# Call disable on the distObj
|
||||
distObj.disableAndAnnounce()
|
||||
|
||||
|
||||
# Put the distObj in the fifo and the dict
|
||||
self.fifo.append(distObj)
|
||||
self.dict[doId] = distObj
|
||||
|
||||
|
||||
if len(self.fifo) > self.maxCacheItems:
|
||||
# if the cache is full, pop the oldest item
|
||||
oldestDistObj = self.fifo.pop(0)
|
||||
@ -51,7 +51,7 @@ class CRCache:
|
||||
del(self.dict[oldestDistObj.getDoId()])
|
||||
# and delete it
|
||||
oldestDistObj.deleteOrDelay()
|
||||
|
||||
|
||||
# Make sure that the fifo and the dictionary are sane
|
||||
assert len(self.dict) == len(self.fifo)
|
||||
|
||||
@ -72,7 +72,7 @@ class CRCache:
|
||||
|
||||
def contains(self, doId):
|
||||
return self.dict.has_key(doId)
|
||||
|
||||
|
||||
def delete(self, doId):
|
||||
assert self.checkCache()
|
||||
assert self.dict.has_key(doId)
|
||||
@ -83,7 +83,7 @@ class CRCache:
|
||||
self.fifo.remove(distObj)
|
||||
# and delete it
|
||||
distObj.deleteOrDelay()
|
||||
|
||||
|
||||
def checkCache(self):
|
||||
# For debugging; this verifies that the cache is sensible and
|
||||
# returns true if so.
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
class CartesianGridBase:
|
||||
def isValidZone(self, zoneId):
|
||||
def checkBounds(self=self,zoneId=zoneId):
|
||||
def checkBounds(self=self, zoneId=zoneId):
|
||||
if ((zoneId < self.startingZone) or
|
||||
(zoneId > self.startingZone + self.gridSize * self.gridSize - 1)):
|
||||
return 0
|
||||
@ -17,7 +17,7 @@ class CartesianGridBase:
|
||||
return checkBounds()
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def getZoneFromXYZ(self, pos):
|
||||
# NOTE: pos should be relative to our own grid origin
|
||||
# Convert a 3d position to a zone
|
||||
@ -38,7 +38,7 @@ class CartesianGridBase:
|
||||
# on it.
|
||||
sphereRadius = max(sphereRadius, gridRadius*cellWidth)
|
||||
return 2 * (sphereRadius // cellWidth)
|
||||
|
||||
|
||||
def getZoneCellOrigin(self, zoneId):
|
||||
# It returns the origin of the zoneCell
|
||||
# Origin is the top-left corner of zoneCell
|
||||
@ -49,8 +49,8 @@ class CartesianGridBase:
|
||||
x = col * self.cellWidth - dx
|
||||
y = row * self.cellWidth - dx
|
||||
|
||||
return (x,y,0)
|
||||
|
||||
return (x, y, 0)
|
||||
|
||||
def getZoneCellOriginCenter(self, zoneId):
|
||||
# Variant of the getZoneCellOrigin. It
|
||||
# returns the center of the zoneCell
|
||||
@ -62,5 +62,5 @@ class CartesianGridBase:
|
||||
x = col * self.cellWidth - dx + center
|
||||
y = row * self.cellWidth - dx + center
|
||||
|
||||
return (x,y,0)
|
||||
|
||||
return (x, y, 0)
|
||||
|
||||
|
@ -31,7 +31,7 @@ class ClientRepository(ClientRepositoryBase):
|
||||
# When new clients join the zone of an object, they need to hear
|
||||
# about it, so we send out all of our information about objects in
|
||||
# that particular zone.
|
||||
|
||||
|
||||
assert self.DOIDnext < self.DOIDlast
|
||||
zone = di.getUint32()
|
||||
for obj in self.doId2do.values():
|
||||
@ -39,7 +39,7 @@ class ClientRepository(ClientRepositoryBase):
|
||||
id = obj.doId
|
||||
if (self.isLocalId(id)):
|
||||
self.send(obj.dclass.clientFormatGenerate(obj, id, zone, []))
|
||||
|
||||
|
||||
def createWithRequired(self, className, zoneId = 0, optionalFields=None):
|
||||
if self.DOIDnext >= self.DOIDlast:
|
||||
self.notify.error(
|
||||
@ -115,9 +115,9 @@ class ClientRepository(ClientRepositoryBase):
|
||||
datagram.addUint32(zone)
|
||||
|
||||
# send the message
|
||||
self.send(datagram)
|
||||
|
||||
def isLocalId(self,id):
|
||||
self.send(datagram)
|
||||
|
||||
def isLocalId(self, id):
|
||||
return ((id >= self.DOIDbase) and (id < self.DOIDlast))
|
||||
|
||||
def haveCreateAuthority(self):
|
||||
@ -204,4 +204,4 @@ dclass.getName()))
|
||||
distObj.generate()
|
||||
distObj.updateRequiredFields(dclass, di)
|
||||
# updateRequiredFields calls announceGenerate
|
||||
return distObj
|
||||
return distObj
|
||||
|
@ -62,7 +62,7 @@ class ClientRepositoryBase(ConnectionRepository):
|
||||
## # Create a message
|
||||
## datagram = PyDatagram()
|
||||
## datagram.addServerHeader(
|
||||
## doID, localAvatar.getDoId(), 2020)
|
||||
## doID, localAvatar.getDoId(), 2020)
|
||||
## # A context that can be used to index the response if needed
|
||||
## datagram.addUint32(context)
|
||||
## self.send(datagram)
|
||||
@ -499,7 +499,7 @@ class ClientRepositoryBase(ConnectionRepository):
|
||||
return doDict
|
||||
|
||||
|
||||
def sendSetLocation(self,doId,parentId,zoneId):
|
||||
def sendSetLocation(self, doId, parentId, zoneId):
|
||||
datagram = PyDatagram()
|
||||
datagram.addUint16(CLIENT_OBJECT_LOCATION)
|
||||
datagram.addUint32(doId)
|
||||
@ -565,7 +565,7 @@ class ClientRepositoryBase(ConnectionRepository):
|
||||
elif worldNP.isEmpty():
|
||||
return None
|
||||
return worldNP
|
||||
|
||||
|
||||
def isLocalId(self, id):
|
||||
# By default, no ID's are local. See also
|
||||
# ClientRepository.isLocalId().
|
||||
|
@ -81,7 +81,7 @@ class ConnectionRepository(
|
||||
packer.beginPack(field)
|
||||
packer.packDefaultValue()
|
||||
packer.endPack()
|
||||
|
||||
|
||||
unpacker = DCPacker()
|
||||
unpacker.setUnpackData(packer.getString())
|
||||
unpacker.beginUnpack(field)
|
||||
@ -94,7 +94,7 @@ class ConnectionRepository(
|
||||
else:
|
||||
self.notify.error("\n\n\nNot able to find %s.%s"%(
|
||||
distObj.__class__.__name__, field.getName()))
|
||||
|
||||
|
||||
# Look up the dclass
|
||||
dclass = self.dclassesByName.get(dcname+self.dcSuffix)
|
||||
if dclass is None:
|
||||
@ -162,7 +162,7 @@ class ConnectionRepository(
|
||||
names.append(td.getName())
|
||||
nameList = ', '.join(names)
|
||||
self.notify.error("Undefined types in DC file: " + nameList)
|
||||
|
||||
|
||||
self.hashVal = dcFile.getHash()
|
||||
|
||||
# Now import all of the modules required by the DC file.
|
||||
|
@ -35,11 +35,11 @@ class DistributedCartesianGrid(DistributedNode.DistributedNode,
|
||||
|
||||
def generate(self):
|
||||
DistributedNode.DistributedNode.generate(self)
|
||||
|
||||
|
||||
def disable(self):
|
||||
DistributedNode.DistributedNode.disable(self)
|
||||
self.stopProcessVisibility()
|
||||
|
||||
|
||||
def delete(self):
|
||||
DistributedNode.DistributedNode.delete(self)
|
||||
# TODO: when teleporting off an island...
|
||||
@ -48,7 +48,7 @@ class DistributedCartesianGrid(DistributedNode.DistributedNode,
|
||||
def isGridParent(self):
|
||||
# If this distributed object is a DistributedGrid return 1. 0 by default
|
||||
return 1
|
||||
|
||||
|
||||
def setParentingRules(self, style, rule):
|
||||
assert self.notify.debug("setParentingRules: style: %s, rule: %s" % (style, rule))
|
||||
rules = rule.split(self.RuleSeparator)
|
||||
@ -76,7 +76,7 @@ class DistributedCartesianGrid(DistributedNode.DistributedNode,
|
||||
self.gridVisContext = self.cr.addInterest(self.getDoId(), 0, self.uniqueName("visibility"))
|
||||
taskMgr.add(self.processVisibility, self.taskName("processVisibility"))
|
||||
|
||||
def stopProcessVisibility(self,clearAll=False):
|
||||
def stopProcessVisibility(self, clearAll=False):
|
||||
taskMgr.remove(self.taskName("processVisibility"))
|
||||
if self.gridVisContext is not None:
|
||||
self.cr.removeInterest(self.gridVisContext)
|
||||
@ -97,7 +97,7 @@ class DistributedCartesianGrid(DistributedNode.DistributedNode,
|
||||
y = pos[1] + dx
|
||||
col = x // self.cellWidth
|
||||
row = y // self.cellWidth
|
||||
assert self.notify.debug("processVisibility: %s: avatar pos: %s %s" % (self.doId, x,y))
|
||||
assert self.notify.debug("processVisibility: %s: avatar pos: %s %s" % (self.doId, x, y))
|
||||
if (row < 0) or (col < 0) or (row > self.gridSize) or (col > self.gridSize):
|
||||
assert self.notify.debug("processVisibility: %s: not on the grid" % (self.doId))
|
||||
# If we are viewingRadius away from this entire grid,
|
||||
@ -153,9 +153,9 @@ class DistributedCartesianGrid(DistributedNode.DistributedNode,
|
||||
if (av.getParent().compareTo(self) == 0):
|
||||
# only detach if object is directly parented
|
||||
av.detachNode()
|
||||
#av.b_setLocation(0,0)
|
||||
#av.b_setLocation(0, 0)
|
||||
|
||||
|
||||
|
||||
def handleAvatarZoneChange(self, av, zoneId):
|
||||
assert self.notify.debug("handleAvatarZoneChange(%s, %s)" % (av.doId, zoneId))
|
||||
# This method can be overridden by derived classes that
|
||||
@ -165,7 +165,7 @@ class DistributedCartesianGrid(DistributedNode.DistributedNode,
|
||||
if not self.isValidZone(zoneId):
|
||||
self.notify.warning("handleAvatarZoneChange: not a valid zone (%s)" % zoneId)
|
||||
return
|
||||
|
||||
|
||||
# Set the location on the server
|
||||
av.b_setLocation(self.doId, zoneId)
|
||||
|
||||
@ -185,7 +185,7 @@ class DistributedCartesianGrid(DistributedNode.DistributedNode,
|
||||
# A Dark version of the grid color
|
||||
color = self.gridColor * 0.5
|
||||
color.setW(1)
|
||||
|
||||
|
||||
self.lines = self.attachNewNode('gridLines')
|
||||
self.minorLines = LineNodePath(self.lines)
|
||||
self.minorLines.lineNode.setName('minorLines')
|
||||
@ -199,19 +199,19 @@ class DistributedCartesianGrid(DistributedNode.DistributedNode,
|
||||
|
||||
self.centerLines = LineNodePath(self.lines)
|
||||
self.centerLines.lineNode.setName('centerLines')
|
||||
self.centerLines.setColor(VBase4(1,0,0,0))
|
||||
self.centerLines.setColor(VBase4(1, 0, 0, 0))
|
||||
self.centerLines.setThickness(3)
|
||||
|
||||
# Load up grid parts to initialize grid object
|
||||
# Polygon used to mark grid plane
|
||||
# self.gridBack = loader.loadModel('models/misc/gridBack')
|
||||
# self.gridBack.reparentTo(self)
|
||||
# self.gridBack.setColor(0.2,0.2,0.2,0.5)
|
||||
# self.gridBack.setColor(0.2, 0.2, 0.2, 0.5)
|
||||
|
||||
self.cellLabelParent = None
|
||||
self.markerParent = None
|
||||
self.haveGridLines = 1
|
||||
|
||||
|
||||
def updateGrid(self):
|
||||
# Update grid lines based upon current grid spacing and grid size
|
||||
# First reset existing grid lines
|
||||
@ -275,7 +275,7 @@ class DistributedCartesianGrid(DistributedNode.DistributedNode,
|
||||
(j * cw - dx) + (cw * 0.5), # y
|
||||
3.0, # z
|
||||
# Lay them down flat
|
||||
0,-90,0, # hpr
|
||||
0, -90, 0, # hpr
|
||||
scale, scale, scale)
|
||||
self.cellLabelParent.flattenLight()
|
||||
|
||||
|
@ -42,7 +42,7 @@ class DistributedCartesianGridAI(DistributedNodeAI, CartesianGridBase):
|
||||
def addObjectToGrid(self, av, useZoneId=-1):
|
||||
self.notify.debug("setting parent to grid %s" % self)
|
||||
avId = av.doId
|
||||
|
||||
|
||||
# Create a grid parent
|
||||
#gridParent = self.attachNewNode("gridParent-%s" % avId)
|
||||
#self.gridParents[avId] = gridParent
|
||||
@ -120,7 +120,7 @@ class DistributedCartesianGridAI(DistributedNodeAI, CartesianGridBase):
|
||||
"%s handleAvatarZoneChange %s: not a valid zone (%s) for pos %s" %
|
||||
(self.doId, av.doId, zoneId, pos))
|
||||
return
|
||||
|
||||
|
||||
# Set the location on the server.
|
||||
# setLocation will update the gridParent
|
||||
av.b_setLocation(self.doId, zoneId)
|
||||
|
@ -20,7 +20,7 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath):
|
||||
|
||||
# initialize gridParent
|
||||
self.gridParent = None
|
||||
|
||||
|
||||
def disable(self):
|
||||
if self.activeState != DistributedObject.ESDisabled:
|
||||
self.reparentTo(hidden)
|
||||
@ -56,12 +56,12 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath):
|
||||
else:
|
||||
if self.gridParent:
|
||||
self.gridParent.delete()
|
||||
self.gridParent = None
|
||||
self.gridParent = None
|
||||
else:
|
||||
if self.gridParent:
|
||||
self.gridParent.delete()
|
||||
self.gridParent = None
|
||||
|
||||
|
||||
def __cmp__(self, other):
|
||||
# DistributedNode inherits from NodePath, which inherits a
|
||||
# definition of __cmp__ from FFIExternalObject that uses the
|
||||
@ -127,19 +127,19 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath):
|
||||
# setY provided by NodePath
|
||||
def d_setY(self, y):
|
||||
self.sendUpdate("setY", [y])
|
||||
|
||||
|
||||
# setZ provided by NodePath
|
||||
def d_setZ(self, z):
|
||||
self.sendUpdate("setZ", [z])
|
||||
|
||||
|
||||
# setH provided by NodePath
|
||||
def d_setH(self, h):
|
||||
self.sendUpdate("setH", [h])
|
||||
|
||||
|
||||
# setP provided by NodePath
|
||||
def d_setP(self, p):
|
||||
self.sendUpdate("setP", [p])
|
||||
|
||||
|
||||
# setR provided by NodePath
|
||||
def d_setR(self, r):
|
||||
self.sendUpdate("setR", [r])
|
||||
|
@ -78,19 +78,19 @@ class DistributedNodeAI(DistributedObjectAI.DistributedObjectAI, NodePath):
|
||||
# setY provided by NodePath
|
||||
def d_setY(self, y):
|
||||
self.sendUpdate("setY", [y])
|
||||
|
||||
|
||||
# setZ provided by NodePath
|
||||
def d_setZ(self, z):
|
||||
self.sendUpdate("setZ", [z])
|
||||
|
||||
|
||||
# setH provided by NodePath
|
||||
def d_setH(self, h):
|
||||
self.sendUpdate("setH", [h])
|
||||
|
||||
|
||||
# setP provided by NodePath
|
||||
def d_setP(self, p):
|
||||
self.sendUpdate("setP", [p])
|
||||
|
||||
|
||||
# setR provided by NodePath
|
||||
def d_setR(self, r):
|
||||
self.sendUpdate("setR", [r])
|
||||
@ -117,16 +117,16 @@ class DistributedNodeAI(DistributedObjectAI.DistributedObjectAI, NodePath):
|
||||
self.sendUpdate("setXYH", [x, y, h])
|
||||
|
||||
def b_setXYZH(self, x, y, z, h):
|
||||
self.setXYZH(x,y,z,h)
|
||||
self.d_setXYZH(x,y,z,h)
|
||||
self.setXYZH(x, y, z, h)
|
||||
self.d_setXYZH(x, y, z, h)
|
||||
def setXYZH(self, x, y, z, h):
|
||||
self.setPos(x, y, z)
|
||||
self.setH(h)
|
||||
def getXYZH(self):
|
||||
pos = self.getPos()
|
||||
h = self.getH()
|
||||
return pos[0],pos[1],pos[2],h
|
||||
|
||||
return pos[0], pos[1], pos[2], h
|
||||
|
||||
def d_setXYZH(self, x, y, z, h):
|
||||
self.sendUpdate("setXYZH", [x, y, z, h])
|
||||
|
||||
|
@ -45,19 +45,19 @@ class DistributedNodeUD(DistributedObjectUD):
|
||||
# setY provided by NodePath
|
||||
def d_setY(self, y):
|
||||
self.sendUpdate("setY", [y])
|
||||
|
||||
|
||||
# setZ provided by NodePath
|
||||
def d_setZ(self, z):
|
||||
self.sendUpdate("setZ", [z])
|
||||
|
||||
|
||||
# setH provided by NodePath
|
||||
def d_setH(self, h):
|
||||
self.sendUpdate("setH", [h])
|
||||
|
||||
|
||||
# setP provided by NodePath
|
||||
def d_setP(self, p):
|
||||
self.sendUpdate("setP", [p])
|
||||
|
||||
|
||||
# setR provided by NodePath
|
||||
def d_setR(self, r):
|
||||
self.sendUpdate("setR", [r])
|
||||
|
@ -70,7 +70,7 @@ class DistributedObject(DistributedObjectBase):
|
||||
if __debug__:
|
||||
def status(self, indent=0):
|
||||
"""
|
||||
print out "doId(parentId,zoneId) className
|
||||
print out "doId(parentId, zoneId) className
|
||||
and conditionally show generated, disabled, neverDisable,
|
||||
or cachable"
|
||||
"""
|
||||
@ -79,7 +79,7 @@ class DistributedObject(DistributedObjectBase):
|
||||
print "%s%s:"%(
|
||||
' '*indent, self.__class__.__name__)
|
||||
print "%sfrom DistributedObject doId:%s, parent:%s, zone:%s"%(
|
||||
spaces,
|
||||
spaces,
|
||||
self.doId, self.parentId, self.zoneId),
|
||||
flags=[]
|
||||
if self.activeState == ESGenerated:
|
||||
|
@ -47,11 +47,11 @@ class DistributedObjectAI(DistributedObjectBase):
|
||||
# For debugging purposes, this just prints out what got deleted
|
||||
# """
|
||||
# print ("Destructing: " + self.__class__.__name__)
|
||||
|
||||
|
||||
if __debug__:
|
||||
def status(self, indent=0):
|
||||
"""
|
||||
print out doId(parentId,zoneId) className
|
||||
print out doId(parentId, zoneId) className
|
||||
and conditionally show generated, disabled, neverDisable,
|
||||
or cachable
|
||||
"""
|
||||
@ -60,7 +60,7 @@ class DistributedObjectAI(DistributedObjectBase):
|
||||
print "%s%s:"%(
|
||||
' '*indent, self.__class__.__name__)
|
||||
print "%sfrom DistributedObject doId:%s, parent:%s, zone:%s"%(
|
||||
spaces,
|
||||
spaces,
|
||||
self.doId, self.parentId, self.zoneId),
|
||||
flags=[]
|
||||
if self.__generated:
|
||||
@ -369,7 +369,7 @@ class DistributedObjectAI(DistributedObjectBase):
|
||||
else:
|
||||
self.doId = doId
|
||||
# Put the new DO in the dictionaries
|
||||
self.air.addDOToTables(self, location=(parentId,zoneId))
|
||||
self.air.addDOToTables(self, location=(parentId, zoneId))
|
||||
# Send a generate message
|
||||
self.sendGenerateWithRequired(self.air, parentId, zoneId, optionalFields)
|
||||
|
||||
|
@ -20,14 +20,14 @@ class DistributedObjectBase(DirectObject):
|
||||
if __debug__:
|
||||
def status(self, indent=0):
|
||||
"""
|
||||
print out "doId(parentId,zoneId) className"
|
||||
print out "doId(parentId, zoneId) className"
|
||||
"""
|
||||
spaces=' '*(indent+2)
|
||||
try:
|
||||
print "%s%s:"%(
|
||||
' '*indent, self.__class__.__name__)
|
||||
print "%sfrom DistributedObject doId:%s, parent:%s, zone:%s"%(
|
||||
spaces,
|
||||
spaces,
|
||||
self.doId, self.parentId, self.zoneId),
|
||||
except Exception, e: print "%serror printing status"%(spaces,), e
|
||||
|
||||
|
@ -5,7 +5,7 @@ from direct.distributed.DistributedObject import DistributedObject
|
||||
|
||||
class DistributedObjectGlobal(DistributedObject):
|
||||
"""
|
||||
The Distributed Object Global class is the base class for global
|
||||
The Distributed Object Global class is the base class for global
|
||||
network based (i.e. distributed) objects.
|
||||
"""
|
||||
notify = directNotify.newCategory("DistributedObjectGlobal")
|
||||
|
@ -16,11 +16,11 @@ class DistributedObjectGlobalAI(DistributedObjectAI):
|
||||
|
||||
def __init__(self, air):
|
||||
DistributedObjectAI.__init__(self, air)
|
||||
|
||||
|
||||
def announceGenerate(self):
|
||||
self.air.registerForChannel(self.doId)
|
||||
DistributedObjectAI.announceGenerate(self)
|
||||
|
||||
|
||||
def delete(self):
|
||||
self.air.unregisterForChannel(self.doId)
|
||||
## self.air.removeDOFromTables(self)
|
||||
|
@ -17,7 +17,7 @@ ESGenerated = 6
|
||||
|
||||
class DistributedObjectOV(DistributedObjectBase):
|
||||
"""
|
||||
Implementation of the 'owner view' (OV) of a distributed object;
|
||||
Implementation of the 'owner view' (OV) of a distributed object;
|
||||
"""
|
||||
notify = directNotify.newCategory("DistributedObjectOV")
|
||||
|
||||
@ -44,7 +44,7 @@ class DistributedObjectOV(DistributedObjectBase):
|
||||
if __debug__:
|
||||
def status(self, indent=0):
|
||||
"""
|
||||
print out "doId(parentId,zoneId) className"
|
||||
print out "doId(parentId, zoneId) className"
|
||||
and conditionally show generated, disabled
|
||||
"""
|
||||
spaces=' '*(indent+2)
|
||||
@ -52,7 +52,7 @@ class DistributedObjectOV(DistributedObjectBase):
|
||||
print "%s%s:"%(
|
||||
' '*indent, self.__class__.__name__)
|
||||
print "%sfrom DistributedObjectOV doId:%s, parent:%s, zone:%s"%(
|
||||
spaces,
|
||||
spaces,
|
||||
self.doId, self.parentId, self.zoneId),
|
||||
flags=[]
|
||||
if self.activeState == ESGenerated:
|
||||
|
@ -47,11 +47,11 @@ class DistributedObjectUD(DistributedObjectBase):
|
||||
# For debugging purposes, this just prints out what got deleted
|
||||
# """
|
||||
# print ("Destructing: " + self.__class__.__name__)
|
||||
|
||||
|
||||
if __debug__:
|
||||
def status(self, indent=0):
|
||||
"""
|
||||
print out doId(parentId,zoneId) className
|
||||
print out doId(parentId, zoneId) className
|
||||
and conditionally show generated, disabled, neverDisable,
|
||||
or cachable"
|
||||
"""
|
||||
@ -60,7 +60,7 @@ class DistributedObjectUD(DistributedObjectBase):
|
||||
print "%s%s:"%(
|
||||
' '*indent, self.__class__.__name__)
|
||||
print "%sfrom DistributedObject doId:%s, parent:%s, zone:%s"%(
|
||||
spaces,
|
||||
spaces,
|
||||
self.doId, self.parentId, self.zoneId),
|
||||
flags=[]
|
||||
if self.__generated:
|
||||
@ -315,7 +315,7 @@ class DistributedObjectUD(DistributedObjectBase):
|
||||
else:
|
||||
self.doId = doId
|
||||
# Put the new DO in the dictionaries
|
||||
self.air.addDOToTables(self, location=(parentId,zoneId))
|
||||
self.air.addDOToTables(self, location=(parentId, zoneId))
|
||||
# Send a generate message
|
||||
self.sendGenerateWithRequired(self.air, parentId, zoneId, optionalFields)
|
||||
|
||||
|
@ -4,7 +4,7 @@ import DistributedSmoothNodeBase
|
||||
|
||||
class DistributedSmoothNodeAI(DistributedNodeAI.DistributedNodeAI,
|
||||
DistributedSmoothNodeBase.DistributedSmoothNodeBase):
|
||||
|
||||
|
||||
def __init__(self, air, name=None):
|
||||
DistributedNodeAI.DistributedNodeAI.__init__(self, air, name)
|
||||
DistributedSmoothNodeBase.DistributedSmoothNodeBase.__init__(self)
|
||||
@ -27,36 +27,36 @@ class DistributedSmoothNodeAI(DistributedNodeAI.DistributedNodeAI,
|
||||
|
||||
def setSmZ(self, z, t):
|
||||
self.setZ(z)
|
||||
|
||||
|
||||
def setSmXY(self, x, y, t):
|
||||
self.setX(x)
|
||||
self.setY(y)
|
||||
|
||||
|
||||
def setSmXZ(self, x, z, t):
|
||||
self.setX(x)
|
||||
self.setZ(z)
|
||||
|
||||
|
||||
def setSmPos(self, x, y, z, t):
|
||||
self.setPos(x,y,z)
|
||||
|
||||
self.setPos(x, y, z)
|
||||
|
||||
def setSmHpr(self, h, p, r, t):
|
||||
self.setHpr(h,p,r)
|
||||
|
||||
self.setHpr(h, p, r)
|
||||
|
||||
def setSmXYH(self, x, y, h, t):
|
||||
self.setX(x)
|
||||
self.setY(y)
|
||||
self.setH(h)
|
||||
|
||||
|
||||
def setSmXYZH(self, x, y, z, h, t):
|
||||
self.setPos(x,y,z)
|
||||
self.setPos(x, y, z)
|
||||
self.setH(h)
|
||||
|
||||
|
||||
def setSmPosHpr(self, x, y, z, h, p, r, t):
|
||||
self.setPosHpr(x,y,z,h,p,r)
|
||||
|
||||
self.setPosHpr(x, y, z, h, p, r)
|
||||
|
||||
def clearSmoothing(self, bogus = None):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
# Do we use these on the AIx?
|
||||
def setComponentX(self, x):
|
||||
|
@ -13,7 +13,7 @@ class DoCollectionManager:
|
||||
# for 'owner' views of objects
|
||||
self.doId2ownerView = {}
|
||||
# Dict of {
|
||||
# parent DistributedObject id:
|
||||
# parent DistributedObject id:
|
||||
# { zoneIds: [child DistributedObject ids] }}
|
||||
self.__doHierarchy = {}
|
||||
|
||||
@ -26,7 +26,7 @@ class DoCollectionManager:
|
||||
callback(do)
|
||||
else:
|
||||
relatedObjectMgr(doId, allCallback=callback)
|
||||
|
||||
|
||||
def getOwnerView(self, doId):
|
||||
assert self.hasOwnerView()
|
||||
return self.doId2ownerView.get(doId)
|
||||
@ -85,12 +85,12 @@ class DoCollectionManager:
|
||||
"""
|
||||
parentId is any distributed object id.
|
||||
zoneId is a uint32, defaults to None (all zones). Try zone 2 if
|
||||
you're not sure which zone to use (0 is a bad/null zone and
|
||||
you're not sure which zone to use (0 is a bad/null zone and
|
||||
1 has had reserved use in the past as a no messages zone, while
|
||||
2 has traditionally been a global, uber, misc stuff zone).
|
||||
dclassType is a distributed class type filter, defaults
|
||||
dclassType is a distributed class type filter, defaults
|
||||
to None (no filter).
|
||||
|
||||
|
||||
If dclassName is None then all objects in the zone are returned;
|
||||
otherwise the list is filtered to only include objects of that type.
|
||||
"""
|
||||
@ -101,12 +101,12 @@ class DoCollectionManager:
|
||||
"""
|
||||
parentId is any distributed object id.
|
||||
zoneId is a uint32, defaults to None (all zones). Try zone 2 if
|
||||
you're not sure which zone to use (0 is a bad/null zone and
|
||||
you're not sure which zone to use (0 is a bad/null zone and
|
||||
1 has had reserved use in the past as a no messages zone, while
|
||||
2 has traditionally been a global, uber, misc stuff zone).
|
||||
dclassType is a distributed class type filter, defaults
|
||||
dclassType is a distributed class type filter, defaults
|
||||
to None (no filter).
|
||||
|
||||
|
||||
If dclassName is None then all objects in the zone are returned;
|
||||
otherwise the list is filtered to only include objects of that type.
|
||||
"""
|
||||
@ -128,7 +128,7 @@ class DoCollectionManager:
|
||||
a.append(doId)
|
||||
r = a
|
||||
return r
|
||||
|
||||
|
||||
def getOwnerViewDoList(self, classType):
|
||||
assert self.hasOwnerView()
|
||||
l = []
|
||||
@ -236,11 +236,11 @@ class DoCollectionManager:
|
||||
parentZoneDict = self.__doHierarchy.setdefault(parentId, {})
|
||||
zoneDoSet = parentZoneDict.setdefault(zoneId, set())
|
||||
zoneDoSet.add(doId)
|
||||
|
||||
|
||||
# Set the new parent and zone on the object
|
||||
obj.parentId = parentId
|
||||
obj.zoneId = zoneId
|
||||
|
||||
|
||||
if 1:
|
||||
# Do we still need this
|
||||
if oldParentId != parentId:
|
||||
@ -257,7 +257,7 @@ class DoCollectionManager:
|
||||
return
|
||||
if 1:
|
||||
# Do we still need this
|
||||
|
||||
|
||||
# notify any existing parent that we're moving away
|
||||
oldParentObj = self.doId2do.get(parentId)
|
||||
obj = self.doId2do.get(doId)
|
||||
@ -281,7 +281,7 @@ class DoCollectionManager:
|
||||
else:
|
||||
self.notify.warning(
|
||||
"deleteObjectLocation: parentId: %s not found"%(parentId,))
|
||||
|
||||
|
||||
def addDOToTables(self, do, location=None, ownerView=False):
|
||||
assert self.notify.debugStateCall(self)
|
||||
#assert not hasattr(do, "isQueryAllResponse") or not do.isQueryAllResponse
|
||||
@ -306,7 +306,7 @@ class DoCollectionManager:
|
||||
if not ownerView:
|
||||
if self.isValidLocationTuple(location):
|
||||
self.storeObjectLocation(do.doId, location[0], location[1])
|
||||
##assert do.doId not in self.zoneId2doIds.get(location,{})
|
||||
##assert do.doId not in self.zoneId2doIds.get(location, {})
|
||||
##self.zoneId2doIds.setdefault(location, {})
|
||||
##self.zoneId2doIds[location][do.doId]=do
|
||||
|
||||
@ -346,7 +346,7 @@ class DoCollectionManager:
|
||||
## del self.zoneId2doIds[location]
|
||||
if do.doId in self.doId2do:
|
||||
del self.doId2do[do.doId]
|
||||
|
||||
|
||||
## def changeDOZoneInTables(self, do, newParentId, newZoneId, oldParentId, oldZoneId):
|
||||
## if 1:
|
||||
## self.storeObjectLocation(do.doId, newParentId, newZoneId)
|
||||
@ -354,13 +354,13 @@ class DoCollectionManager:
|
||||
## #assert not hasattr(do, "isQueryAllResponse") or not do.isQueryAllResponse
|
||||
## oldLocation = (oldParentId, oldZoneId)
|
||||
## newLocation = (newParentId, newZoneId)
|
||||
## # HACK: DistributedGuildMemberUD starts in -1,-1, which isnt ever put in the
|
||||
## # HACK: DistributedGuildMemberUD starts in -1, -1, which isnt ever put in the
|
||||
## # zoneId2doIds table
|
||||
## if self.isValidLocationTuple(oldLocation):
|
||||
## assert self.notify.debugStateCall(self)
|
||||
## assert oldLocation in self.zoneId2doIds
|
||||
## assert do.doId in self.zoneId2doIds[oldLocation]
|
||||
## assert do.doId not in self.zoneId2doIds.get(newLocation,{})
|
||||
## assert do.doId not in self.zoneId2doIds.get(newLocation, {})
|
||||
## # remove from old zone
|
||||
## del(self.zoneId2doIds[oldLocation][do.doId])
|
||||
## if len(self.zoneId2doIds[oldLocation]) == 0:
|
||||
|
@ -223,7 +223,7 @@ class DoInterestManager(DirectObject.DirectObject):
|
||||
datagram.addUint16(CLIENT_REMOVE_INTEREST)
|
||||
datagram.addUint16(handle)
|
||||
if scopeId != 0:
|
||||
datagram.addUint32(scopeId)
|
||||
datagram.addUint32(scopeId)
|
||||
self.send(datagram)
|
||||
|
||||
def handleInterestDoneMessage(self, di):
|
||||
|
@ -12,7 +12,7 @@ from pandac.PandaModules import *
|
||||
# it lies in.
|
||||
|
||||
class GridParent:
|
||||
|
||||
|
||||
def __init__(self, av):
|
||||
# The object on the grid will need to broadcast his position relative to
|
||||
# his current grid cell in order to use 16 bit
|
||||
@ -36,7 +36,7 @@ class GridParent:
|
||||
self.av = None
|
||||
# Remove the gridNodes
|
||||
self.cellOrigin.removeNode()
|
||||
|
||||
|
||||
def setGridParent(self, grid, zoneId, teleport=0):
|
||||
# If teleport=0, preserve the avatar's absolute position. If teleport=1
|
||||
# the avatars previous world position is invalid, so don't wrtReparent,
|
||||
@ -57,8 +57,8 @@ class GridParent:
|
||||
self.grid = grid
|
||||
# Reparent the gridNodes under this grid
|
||||
self.cellOrigin.reparentTo(grid)
|
||||
self.cellOrigin.setPosHpr(0,0,0,0,0,0)
|
||||
|
||||
self.cellOrigin.setPosHpr(0, 0, 0, 0, 0, 0)
|
||||
|
||||
# Get grid cell origin
|
||||
cellPos = self.grid.getZoneCellOrigin(zoneId)
|
||||
|
||||
@ -72,8 +72,8 @@ class GridParent:
|
||||
self.av.wrtReparentTo(self.cellOrigin)
|
||||
else:
|
||||
self.av.reparentTo(self.cellOrigin)
|
||||
|
||||
#print "gridParent: reparent to %s" % self.av
|
||||
#print "gridParent: pos = %s,%s" % (self.av.getPos(), self.av.getParent().getPos())
|
||||
|
||||
|
||||
#print "gridParent: reparent to %s" % self.av
|
||||
#print "gridParent: pos = %s, %s" % (self.av.getPos(), self.av.getParent().getPos())
|
||||
|
||||
|
||||
|
@ -14,7 +14,7 @@ class SampleObject(DistributedObject):
|
||||
# self.blue = 0
|
||||
|
||||
def setColor(self, red = 0, green = 0, blue = 0):
|
||||
self.red = red
|
||||
self.red = red
|
||||
self.green = green
|
||||
self.blue = blue
|
||||
self.announceGenerate()
|
||||
|
@ -21,7 +21,7 @@ class ServerRepository:
|
||||
self.qcm = QueuedConnectionManager()
|
||||
self.qcl = QueuedConnectionListener(self.qcm, 0)
|
||||
self.qcr = QueuedConnectionReader(self.qcm, 0)
|
||||
self.cw = ConnectionWriter(self.qcm,0)
|
||||
self.cw = ConnectionWriter(self.qcm, 0)
|
||||
self.tcpRendezvous = self.qcm.openTCPServerRendezvous(tcpPort, 10)
|
||||
print self.tcpRendezvous
|
||||
self.qcl.addConnection(self.tcpRendezvous)
|
||||
@ -326,7 +326,7 @@ class ServerRepository:
|
||||
datagram.addUint16(CLIENT_SET_DOID_RANGE)
|
||||
datagram.addUint32(id)
|
||||
datagram.addUint32(self.DOIDrange)
|
||||
print "Sending DOID range: ",id,self.DOIDrange
|
||||
print "Sending DOID range: ", id, self.DOIDrange
|
||||
self.cw.send(datagram, connection)
|
||||
|
||||
# a client disconnected from us, we need to update our data, also tell other clients to remove
|
||||
@ -370,7 +370,7 @@ class ServerRepository:
|
||||
datagram.addUint16(CLIENT_REQUEST_GENERATES)
|
||||
datagram.addUint32(ZoneID)
|
||||
self.sendToAll(datagram)
|
||||
print "SENDING REQUEST GENERATES (",ZoneID,") TO ALL"
|
||||
print "SENDING REQUEST GENERATES (", ZoneID, ") TO ALL"
|
||||
|
||||
# client has moved zones, need to update them
|
||||
def handleRemoveZone(self, dgi, connection):
|
||||
|
@ -48,7 +48,7 @@
|
||||
tl = Toplevel()
|
||||
tl.title('Interval Controls')
|
||||
outerFrame = Frame(tl)
|
||||
def entryScaleCommand(t,s=self):
|
||||
def entryScaleCommand(t, s=self):
|
||||
s.setT(t)
|
||||
s.pause()
|
||||
self.es = es = EntryScale.EntryScale(
|
||||
@ -70,7 +70,7 @@
|
||||
# Stop/play buttons
|
||||
def doPlay(s=self, es=es):
|
||||
s.resume(es.get())
|
||||
|
||||
|
||||
stop = Button(bf, text = 'Stop',
|
||||
command = lambda s=self: s.pause())
|
||||
play = Button(
|
||||
@ -84,7 +84,7 @@
|
||||
bf.pack(expand = 1, fill = X)
|
||||
outerFrame.pack(expand = 1, fill = X)
|
||||
# Add function to update slider during setT calls
|
||||
def update(t,es=es):
|
||||
def update(t, es=es):
|
||||
es.set(t, fCommand = 0)
|
||||
if not hasattr(self, "setTHooks"):
|
||||
self.setTHooks = []
|
||||
|
Loading…
x
Reference in New Issue
Block a user