Browse Source

split serverTime into serverTimeSec and serverTimeUSec

David Rose 22 years ago
parent
commit
8f02530c64
1 changed files with 38 additions and 13 deletions
  1. 38 13
      direct/src/distributed/DistributedSmoothNode.py

+ 38 - 13
direct/src/distributed/DistributedSmoothNode.py

@@ -11,6 +11,9 @@ import Task
 # avatar and suggest a resync for both.
 # avatar and suggest a resync for both.
 MaxFuture = base.config.GetFloat("smooth-max-future", 0.2)
 MaxFuture = base.config.GetFloat("smooth-max-future", 0.2)
 
 
+# How frequently can we suggest a resynchronize with another client?
+MinSuggestResync = base.config.GetFloat("smooth-min-suggest-resync", 15)
+
 # These flags indicate whether global smoothing and/or prediction is
 # These flags indicate whether global smoothing and/or prediction is
 # allowed or disallowed.
 # allowed or disallowed.
 EnableSmoothing = base.config.GetBool("smooth-enable-smoothing", 1)
 EnableSmoothing = base.config.GetBool("smooth-enable-smoothing", 1)
@@ -81,6 +84,7 @@ class DistributedSmoothNode(DistributedNode.DistributedNode):
 
 
             self.smoother = SmoothMover()
             self.smoother = SmoothMover()
             self.smoothStarted = 0
             self.smoothStarted = 0
+            self.lastSuggestResync = 0
 
 
     ### Methods to handle computing and updating of the smoothed
     ### Methods to handle computing and updating of the smoothed
     ### position.
     ### position.
@@ -283,8 +287,8 @@ class DistributedSmoothNode(DistributedNode.DistributedNode):
         
         
         now = globalClock.getFrameTime()
         now = globalClock.getFrameTime()
         local = globalClockDelta.networkToLocalTime(timestamp, now)
         local = globalClockDelta.networkToLocalTime(timestamp, now)
-        real = globalClock.getRealTime()
-        chug = real - now
+        realTime = globalClock.getRealTime()
+        chug = realTime - now
 
 
         # Sanity check the timestamp from the other avatar.  It should
         # Sanity check the timestamp from the other avatar.  It should
         # be just slightly in the past, but it might be off by as much
         # be just slightly in the past, but it might be off by as much
@@ -292,10 +296,16 @@ class DistributedSmoothNode(DistributedNode.DistributedNode):
         howFarFuture = local - now
         howFarFuture = local - now
         if howFarFuture - chug >= MaxFuture:
         if howFarFuture - chug >= MaxFuture:
             # Too far off; advise the other client of our clock information.
             # Too far off; advise the other client of our clock information.
-            if globalClockDelta.getUncertainty() != None:
+            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.localToonDoId, timestamp,
                 self.d_suggestResync(self.cr.localToonDoId, timestamp,
-                                     globalClockDelta.getRealNetworkTime(),
-                                     real - globalClockDelta.getDelta(),
+                                     timestampB, serverTime,
                                      globalClockDelta.getUncertainty())
                                      globalClockDelta.getUncertainty())
         
         
         self.smoother.setTimestamp(local)
         self.smoother.setTimestamp(local)
@@ -337,39 +347,54 @@ class DistributedSmoothNode(DistributedNode.DistributedNode):
 
 
     ### Monitor clock sync ###
     ### Monitor clock sync ###
 
 
-    def d_suggestResync(self, avId, timestampA, timestampB, serverTime, uncertainty):
-        self.sendUpdate("suggestResync", [avId, timestampA, timestampB, serverTime, uncertainty])
+    def d_suggestResync(self, avId, timestampA, timestampB,
+                        serverTime, uncertainty):
+        serverTimeSec = math.floor(serverTime)
+        serverTimeUSec = (serverTime - serverTimeSec) * 10000.0
+        self.sendUpdate("suggestResync", [avId, timestampA, timestampB,
+                                          serverTimeSec, serverTimeUSec,
+                                          uncertainty])
         
         
-    def suggestResync(self, avId, timestampA, timestampB, serverTime, uncertainty):
-        """suggestResync(self, avId)
+    def suggestResync(self, avId, timestampA, timestampB,
+                      serverTimeSec, serverTimeUSec, uncertainty):
+        """suggestResync(self, avId, ....)
 
 
         This message is sent from one client to another when the other
         This message is sent from one client to another when the other
         client receives a timestamp from this client that is so far
         client receives a timestamp from this client that is so far
         out of date as to suggest that one or both clients needs to
         out of date as to suggest that one or both clients needs to
         resynchronize their clock information.
         resynchronize their clock information.
         """
         """
+        serverTime = float(serverTimeSec) + float(serverTimeUSec) / 10000.0
         result = \
         result = \
                self.peerToPeerResync(avId, timestampA, serverTime, uncertainty)
                self.peerToPeerResync(avId, timestampA, serverTime, uncertainty)
         if result >= 0 and \
         if result >= 0 and \
            globalClockDelta.getUncertainty() != None:
            globalClockDelta.getUncertainty() != None:
             other = self.cr.doId2do.get(avId)
             other = self.cr.doId2do.get(avId)
             if other and hasattr(other, "d_returnResync"):
             if other and hasattr(other, "d_returnResync"):
-                real = globalClock.getRealTime()
+                realTime = globalClock.getRealTime()
+                serverTime = realTime - globalClockDelta.getDelta()
+                self.notify.info("Returning resync for %s; local time is %s and server time is %s." % (
+                    self.doId, realTime, serverTime))
                 other.d_returnResync(self.cr.localToonDoId, timestampB,
                 other.d_returnResync(self.cr.localToonDoId, timestampB,
-                                     real - globalClockDelta.getDelta(),
+                                     serverTime,
                                      globalClockDelta.getUncertainty())
                                      globalClockDelta.getUncertainty())
         
         
 
 
     def d_returnResync(self, avId, timestampB, serverTime, uncertainty):
     def d_returnResync(self, avId, timestampB, serverTime, uncertainty):
-        self.sendUpdate("returnResync", [avId, timestampB, serverTime, uncertainty])
+        serverTimeSec = math.floor(serverTime)
+        serverTimeUSec = (serverTime - serverTimeSec) * 10000.0
+        self.sendUpdate("returnResync", [avId, timestampB,
+                                         serverTimeSec, serverTimeUSec,
+                                         uncertainty])
         
         
-    def returnResync(self, avId, timestampB, serverTime, uncertainty):
+    def returnResync(self, avId, timestampB, serverTimeSec, serverTimeUSec, uncertainty):
         """returnResync(self, avId)
         """returnResync(self, avId)
 
 
         A reply sent by a client whom we recently sent suggestResync
         A reply sent by a client whom we recently sent suggestResync
         to, this reports the client's new delta information so we can
         to, this reports the client's new delta information so we can
         adjust our clock as well.
         adjust our clock as well.
         """
         """
+        serverTime = float(serverTimeSec) + float(serverTimeUSec) / 10000.0
         self.peerToPeerResync(avId, timestampB, serverTime, uncertainty)
         self.peerToPeerResync(avId, timestampB, serverTime, uncertainty)
 
 
     def peerToPeerResync(self, avId, timestamp, serverTime, uncertainty):
     def peerToPeerResync(self, avId, timestamp, serverTime, uncertainty):