mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
support 32-bit timestamps
This commit is contained in:
parent
5e82884821
commit
a54fb260f1
@ -68,7 +68,7 @@ class ClockDelta(DirectObject.DirectObject):
|
|||||||
|
|
||||||
### Primary interface functions ###
|
### Primary interface functions ###
|
||||||
|
|
||||||
def networkToLocalTime(self, networkTime, now = None):
|
def networkToLocalTime(self, networkTime, now = None, bits = 16):
|
||||||
"""networkToLocalTime(self, int networkTime)
|
"""networkToLocalTime(self, int networkTime)
|
||||||
|
|
||||||
Converts the indicated networkTime to the corresponding
|
Converts the indicated networkTime to the corresponding
|
||||||
@ -89,18 +89,33 @@ class ClockDelta(DirectObject.DirectObject):
|
|||||||
# The signed difference between these is the number of units
|
# The signed difference between these is the number of units
|
||||||
# of NetworkTimePrecision by which the network time differs
|
# of NetworkTimePrecision by which the network time differs
|
||||||
# from 'now'.
|
# from 'now'.
|
||||||
diff = self.__signExtend(networkTime - ntime)
|
if bits == 16:
|
||||||
|
diff = self.__signExtend(networkTime - ntime)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Assume the bits is either 16 or 32. If it's 32, no need
|
||||||
|
# to sign-extend. 32 bits gives us about 227 days of
|
||||||
|
# continuous timestamp.
|
||||||
|
|
||||||
|
diff = networkTime - ntime
|
||||||
|
|
||||||
return now + float(diff) / NetworkTimePrecision
|
return now + float(diff) / NetworkTimePrecision
|
||||||
|
|
||||||
def localToNetworkTime(self, localTime):
|
def localToNetworkTime(self, localTime, bits = 16):
|
||||||
"""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) * NetworkTimePrecision + 0.5))
|
||||||
return self.__signExtend(ntime)
|
if bits == 16:
|
||||||
|
return self.__signExtend(ntime)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Assume the bits is either 16 or 32. If it's 32, no need
|
||||||
|
# to sign-extend. 32 bits gives us about 227 days of
|
||||||
|
# continuous timestamp.
|
||||||
|
return ntime
|
||||||
|
|
||||||
|
|
||||||
### Convenience functions ###
|
### Convenience functions ###
|
||||||
|
Loading…
x
Reference in New Issue
Block a user