From 60a0c182738a87b68d4582c1262dc3c71adfc222 Mon Sep 17 00:00:00 2001 From: Samir Naik Date: Mon, 28 Mar 2005 22:31:19 +0000 Subject: [PATCH] adding teleport support --- direct/src/distributed/DistributedNode.py | 4 ++-- direct/src/distributed/DistributedNodeAI.py | 2 +- direct/src/distributed/GridParent.py | 19 ++++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/direct/src/distributed/DistributedNode.py b/direct/src/distributed/DistributedNode.py index b62e7e52ac..5224fae29c 100644 --- a/direct/src/distributed/DistributedNode.py +++ b/direct/src/distributed/DistributedNode.py @@ -41,7 +41,7 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath): DistributedObject.DistributedObject.generate(self) self.gotStringParentToken = 0 - def setLocation(self, parentId, zoneId): + def setLocation(self, parentId, zoneId, teleport=0): # Redefine DistributedObject setLocation, so that when # location is set to the ocean grid, we can update our parenting # under gridParent @@ -51,7 +51,7 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath): if parentObj.isGridParent(): if not self.gridParent: self.gridParent = GridParent.GridParent(self) - self.gridParent.setGridParent(parentObj, zoneId) + self.gridParent.setGridParent(parentObj, zoneId, teleport) else: if self.gridParent: self.gridParent.delete() diff --git a/direct/src/distributed/DistributedNodeAI.py b/direct/src/distributed/DistributedNodeAI.py index eaec23a2a4..1022760e0e 100644 --- a/direct/src/distributed/DistributedNodeAI.py +++ b/direct/src/distributed/DistributedNodeAI.py @@ -23,7 +23,7 @@ class DistributedNodeAI(DistributedObjectAI.DistributedObjectAI, NodePath): self.removeNode() DistributedObjectAI.DistributedObjectAI.delete(self) - def setLocation(self, parentId, zoneId): + def setLocation(self, parentId, zoneId, teleport=0): # Redefine DistributedObject setLocation, so that when # location is set to the ocean grid, we can update our parenting # under gridParent diff --git a/direct/src/distributed/GridParent.py b/direct/src/distributed/GridParent.py index dd27a173b8..f5490700c1 100755 --- a/direct/src/distributed/GridParent.py +++ b/direct/src/distributed/GridParent.py @@ -35,15 +35,16 @@ class GridParent: # Remove the gridNodes self.cellOrigin.removeNode() - def setGridParent(self, grid, zoneId): - # If the avatar has a parent, preserve his absolute position. Otherwise - # if he has no parent, assume this is the first time he's been parented - # to anything, and don't wrtReparent, just do a regular reparent. - firstParent = 0 - if self.av.getParent().isEmpty(): - firstParent = 1 + 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, + # just do a regular reparent, and let the cellOrigin give us our new position - if not firstParent: + # Also, if the avatar has no parent, then force teleport=1 + if self.av.getParent().isEmpty(): + teleport = 1 + + if not teleport: # Stick the avatar under hidden while we move the cellOrigin into # position so we do not lose the avatars absolute position. self.av.wrtReparentTo(hidden) @@ -63,7 +64,7 @@ class GridParent: self.cellOrigin.setPos(*cellPos) # Reparent our avatar to this node - if not firstParent: + if not teleport: self.av.wrtReparentTo(self.cellOrigin) else: self.av.reparentTo(self.cellOrigin)