mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
support for arbitrary timescales for network timestamps
This commit is contained in:
parent
ab6449b623
commit
b0731772c1
@ -218,7 +218,8 @@ class ClockDelta(DirectObject.DirectObject):
|
|||||||
|
|
||||||
### Primary interface functions ###
|
### Primary interface functions ###
|
||||||
|
|
||||||
def networkToLocalTime(self, networkTime, now = None, bits = 16):
|
def networkToLocalTime(self, networkTime, now = None, bits = 16,
|
||||||
|
ticksPerSec=NetworkTimePrecision):
|
||||||
"""networkToLocalTime(self, int networkTime)
|
"""networkToLocalTime(self, int networkTime)
|
||||||
|
|
||||||
Converts the indicated networkTime to the corresponding
|
Converts the indicated networkTime to the corresponding
|
||||||
@ -234,11 +235,10 @@ class ClockDelta(DirectObject.DirectObject):
|
|||||||
return now
|
return now
|
||||||
|
|
||||||
# First, determine what network time we have for 'now'.
|
# First, determine what network time we have for 'now'.
|
||||||
ntime = int(math.floor((now - self.delta) * NetworkTimePrecision + 0.5))
|
ntime = int(math.floor(((now - self.delta) * ticksPerSec) + 0.5))
|
||||||
|
|
||||||
# The signed difference between these is the number of units
|
# The signed difference between these is the number of ticks
|
||||||
# of NetworkTimePrecision by which the network time differs
|
# by which the network time differs from 'now'.
|
||||||
# from 'now'.
|
|
||||||
if bits == 16:
|
if bits == 16:
|
||||||
diff = self.__signExtend(networkTime - ntime)
|
diff = self.__signExtend(networkTime - ntime)
|
||||||
|
|
||||||
@ -249,15 +249,16 @@ class ClockDelta(DirectObject.DirectObject):
|
|||||||
|
|
||||||
diff = networkTime - ntime
|
diff = networkTime - ntime
|
||||||
|
|
||||||
return now + float(diff) / NetworkTimePrecision
|
return now + float(diff) / ticksPerSec
|
||||||
|
|
||||||
def localToNetworkTime(self, localTime, bits = 16):
|
def localToNetworkTime(self, localTime, bits = 16,
|
||||||
|
ticksPerSec=NetworkTimePrecision):
|
||||||
"""localToNetworkTime(self, float localTime)
|
"""localToNetworkTime(self, float localTime)
|
||||||
|
|
||||||
Converts the indicated localTime to the corresponding
|
Converts the indicated localTime to the corresponding
|
||||||
networkTime value.
|
networkTime value.
|
||||||
"""
|
"""
|
||||||
ntime = int(math.floor((localTime - self.delta) * NetworkTimePrecision + 0.5))
|
ntime = int(math.floor(((localTime - self.delta) * ticksPerSec) + 0.5))
|
||||||
if bits == 16:
|
if bits == 16:
|
||||||
return self.__signExtend(ntime)
|
return self.__signExtend(ntime)
|
||||||
|
|
||||||
@ -270,23 +271,28 @@ class ClockDelta(DirectObject.DirectObject):
|
|||||||
|
|
||||||
### Convenience functions ###
|
### Convenience functions ###
|
||||||
|
|
||||||
def getRealNetworkTime(self, bits=16):
|
def getRealNetworkTime(self, bits=16,
|
||||||
|
ticksPerSec=NetworkTimePrecision):
|
||||||
"""getRealNetworkTime(self)
|
"""getRealNetworkTime(self)
|
||||||
|
|
||||||
Returns the current getRealTime() expressed as a network time.
|
Returns the current getRealTime() expressed as a network time.
|
||||||
"""
|
"""
|
||||||
return self.localToNetworkTime(self.globalClock.getRealTime(),
|
return self.localToNetworkTime(self.globalClock.getRealTime(),
|
||||||
bits=bits)
|
bits=bits,
|
||||||
|
ticksPerSec=ticksPerSec)
|
||||||
|
|
||||||
def getFrameNetworkTime(self, bits=16):
|
def getFrameNetworkTime(self, bits=16,
|
||||||
|
ticksPerSec=NetworkTimePrecision):
|
||||||
"""getFrameNetworkTime(self)
|
"""getFrameNetworkTime(self)
|
||||||
|
|
||||||
Returns the current getFrameTime() expressed as a network time.
|
Returns the current getFrameTime() expressed as a network time.
|
||||||
"""
|
"""
|
||||||
return self.localToNetworkTime(self.globalClock.getFrameTime(),
|
return self.localToNetworkTime(self.globalClock.getFrameTime(),
|
||||||
bits=bits)
|
bits=bits,
|
||||||
|
ticksPerSec=ticksPerSec)
|
||||||
|
|
||||||
def localElapsedTime(self, networkTime, bits=16):
|
def localElapsedTime(self, networkTime, bits=16,
|
||||||
|
ticksPerSec=NetworkTimePrecision):
|
||||||
"""localElapsedTime(self, int networkTime)
|
"""localElapsedTime(self, int networkTime)
|
||||||
|
|
||||||
Returns the amount of time elapsed (in seconds) on the client
|
Returns the amount of time elapsed (in seconds) on the client
|
||||||
@ -295,7 +301,8 @@ class ClockDelta(DirectObject.DirectObject):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
now = self.globalClock.getFrameTime()
|
now = self.globalClock.getFrameTime()
|
||||||
dt = now - self.networkToLocalTime(networkTime, now, bits=bits)
|
dt = now - self.networkToLocalTime(networkTime, now, bits=bits,
|
||||||
|
ticksPerSec=ticksPerSec)
|
||||||
|
|
||||||
return max(dt, 0.0)
|
return max(dt, 0.0)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user