support local calls to setSm*

This commit is contained in:
Darren Ranalli 2007-08-09 23:20:17 +00:00
parent 2d2f8d7100
commit 506cf473cf

View File

@ -139,6 +139,7 @@ class DistributedSmoothNode(DistributedNode.DistributedNode,
position. This may result in a pop as the node skips the last position. This may result in a pop as the node skips the last
of its lerp points. of its lerp points.
""" """
#printStack()
if (not self.isLocal()) and \ if (not self.isLocal()) and \
self.smoother.getLatestPosition(): self.smoother.getLatestPosition():
self.smoother.applySmoothMat(self) self.smoother.applySmoothMat(self)
@ -151,6 +152,7 @@ class DistributedSmoothNode(DistributedNode.DistributedNode,
used whenever show code bangs on the node position and expects used whenever show code bangs on the node position and expects
it to stick. it to stick.
""" """
#printStack()
self.smoother.clearPositions(0) self.smoother.clearPositions(0)
self.smoother.setMat(self.getMat()) self.smoother.setMat(self.getMat())
self.smoother.setPhonyTimestamp() self.smoother.setPhonyTimestamp()
@ -158,28 +160,28 @@ class DistributedSmoothNode(DistributedNode.DistributedNode,
# distributed set pos and hpr functions # distributed set pos and hpr functions
# 'send' versions are inherited from DistributedSmoothNodeBase # 'send' versions are inherited from DistributedSmoothNodeBase
def setSmStop(self, timestamp): def setSmStop(self, timestamp=None):
self.setComponentTLive(timestamp) self.setComponentTLive(timestamp)
def setSmH(self, h, timestamp): def setSmH(self, h, timestamp=None):
self.setComponentH(h) self.setComponentH(h)
self.setComponentTLive(timestamp) self.setComponentTLive(timestamp)
def setSmZ(self, z, timestamp): def setSmZ(self, z, timestamp=None):
self.setComponentZ(z) self.setComponentZ(z)
self.setComponentTLive(timestamp) self.setComponentTLive(timestamp)
def setSmXY(self, x, y, timestamp): def setSmXY(self, x, y, timestamp=None):
self.setComponentX(x) self.setComponentX(x)
self.setComponentY(y) self.setComponentY(y)
self.setComponentTLive(timestamp) self.setComponentTLive(timestamp)
def setSmXZ(self, x, z, timestamp): def setSmXZ(self, x, z, timestamp=None):
self.setComponentX(x) self.setComponentX(x)
self.setComponentZ(z) self.setComponentZ(z)
self.setComponentTLive(timestamp) self.setComponentTLive(timestamp)
def setSmPos(self, x, y, z, timestamp): def setSmPos(self, x, y, z, timestamp=None):
self.setComponentX(x) self.setComponentX(x)
self.setComponentY(y) self.setComponentY(y)
self.setComponentZ(z) self.setComponentZ(z)
self.setComponentTLive(timestamp) self.setComponentTLive(timestamp)
def setSmHpr(self, h, p, r, timestamp): def setSmHpr(self, h, p, r, timestamp=None):
self.setComponentH(h) self.setComponentH(h)
self.setComponentP(p) self.setComponentP(p)
self.setComponentR(r) self.setComponentR(r)
@ -189,13 +191,13 @@ class DistributedSmoothNode(DistributedNode.DistributedNode,
self.setComponentY(y) self.setComponentY(y)
self.setComponentH(h) self.setComponentH(h)
self.setComponentTLive(timestamp) self.setComponentTLive(timestamp)
def setSmXYZH(self, x, y, z, h, timestamp): def setSmXYZH(self, x, y, z, h, timestamp=None):
self.setComponentX(x) self.setComponentX(x)
self.setComponentY(y) self.setComponentY(y)
self.setComponentZ(z) self.setComponentZ(z)
self.setComponentH(h) self.setComponentH(h)
self.setComponentTLive(timestamp) self.setComponentTLive(timestamp)
def setSmPosHpr(self, x, y, z, h, p, r, timestamp): def setSmPosHpr(self, x, y, z, h, p, r, timestamp=None):
self.setComponentX(x) self.setComponentX(x)
self.setComponentY(y) self.setComponentY(y)
self.setComponentZ(z) self.setComponentZ(z)
@ -247,37 +249,50 @@ class DistributedSmoothNode(DistributedNode.DistributedNode,
# client. This is because the component functions, above, # client. This is because the component functions, above,
# call this function explicitly instead of setComponentT(). # call this function explicitly instead of setComponentT().
now = globalClock.getFrameTime() #print 'setComponentTLive: %s' % timestamp
local = globalClockDelta.networkToLocalTime(timestamp, now)
realTime = globalClock.getRealTime()
chug = realTime - now
# Sanity check the timestamp from the other avatar. It should if timestamp is None:
# be just slightly in the past, but it might be off by as much # if no timestamp, re-use the most recent timestamp to keep things
# as this frame's amount of time forward or back. # from getting out of order
howFarFuture = local - now if self.smoother.hasMostRecentTimestamp():
if howFarFuture - chug >= MaxFuture: self.smoother.setTimestamp(self.smoother.getMostRecentTimestamp())
# Too far off; advise the other client of our clock information. else:
if globalClockDelta.getUncertainty() != None and \ # no most-recent timestamp, use current time
realTime - self.lastSuggestResync >= MinSuggestResync: self.smoother.setPhonyTimestamp()
self.lastSuggestResync = realTime self.smoother.markPosition()
timestampB = globalClockDelta.localToNetworkTime(realTime) else:
serverTime = realTime - globalClockDelta.getDelta() now = globalClock.getFrameTime()
self.notify.info( local = globalClockDelta.networkToLocalTime(timestamp, now)
"Suggesting resync for %s, with discrepency %s; local time is %s and server time is %s." % ( realTime = globalClock.getRealTime()
self.doId, howFarFuture - chug, chug = realTime - now
realTime, serverTime))
self.d_suggestResync(
self.cr.localAvatarDoId, timestamp,
timestampB, serverTime,
globalClockDelta.getUncertainty())
self.smoother.setTimestamp(local) # Sanity check the timestamp from the other avatar. It should
self.smoother.markPosition() # be just slightly in the past, but it might be off by as much
# as this frame's amount of time forward or back.
howFarFuture = local - now
if howFarFuture - chug >= MaxFuture:
# Too far off; advise the other client of our clock information.
if globalClockDelta.getUncertainty() != None and \
realTime - self.lastSuggestResync >= MinSuggestResync:
self.lastSuggestResync = realTime
timestampB = globalClockDelta.localToNetworkTime(realTime)
serverTime = realTime - globalClockDelta.getDelta()
self.notify.info(
"Suggesting resync for %s, with discrepency %s; local time is %s and server time is %s." % (
self.doId, howFarFuture - chug,
realTime, serverTime))
self.d_suggestResync(
self.cr.localAvatarDoId, timestamp,
timestampB, serverTime,
globalClockDelta.getUncertainty())
self.smoother.setTimestamp(local)
self.smoother.markPosition()
def clearSmoothing(self, bogus = None): def clearSmoothing(self, bogus = None):
# Call this to invalidate all the old position reports # Call this to invalidate all the old position reports
# (e.g. just before popping to a new position). # (e.g. just before popping to a new position).
#printStack()
self.smoother.clearPositions(1) self.smoother.clearPositions(1)
@ -286,6 +301,7 @@ class DistributedSmoothNode(DistributedNode.DistributedNode,
# automatically reset the smoothing position when we call it. # automatically reset the smoothing position when we call it.
if self.smoothStarted: if self.smoothStarted:
if self._smoothWrtReparents: if self._smoothWrtReparents:
#print self.getParent(), parent, self.getParent().getPos(parent)
self.smoother.handleWrtReparent(self.getParent(), parent) self.smoother.handleWrtReparent(self.getParent(), parent)
NodePath.wrtReparentTo(self, parent) NodePath.wrtReparentTo(self, parent)
else: else: