changed signed handling

This commit is contained in:
Dave Schuyler 2005-04-21 00:28:46 +00:00
parent c0c9cb499e
commit d058dcfaff
2 changed files with 24 additions and 16 deletions

View File

@ -23,8 +23,9 @@ NetworkTimePrecision = 100.0
# These values are derived from the above.
NetworkTimeMask = (1 << NetworkTimeBits) - 1
NetworkTimeSignedMask = NetworkTimeMask >> 1 # the max absolute value bits.
NetworkTimeTopBits = 32 - NetworkTimeBits
MaxTimeDelta = (NetworkTimeMask / 2.0) / NetworkTimePrecision
MaxTimeDelta = NetworkTimeSignedMask / NetworkTimePrecision
# This is the maximum number of seconds by which we expect our clock
# (or the server's clock) to drift over an hour.
@ -310,6 +311,13 @@ class ClockDelta(DirectObject.DirectObject):
Preserves the lower NetworkTimeBits of the networkTime value,
and extends the sign bit all the way up.
"""
return ((networkTime & NetworkTimeMask) << NetworkTimeTopBits) >> NetworkTimeTopBits
if networkTime < 0:
# flip the sign, mask it as if it were positive, flip the sign back:
r = (networkTime * -1 & NetworkTimeSignedMask) * -1
else:
r = networkTime & NetworkTimeSignedMask
assert -32768 <= r <= 32767
return r
globalClockDelta = ClockDelta()

View File

@ -1098,7 +1098,7 @@ def randInt32(rng=random.random):
"""
i = int(rng() * 0x7FFFFFFF)
if rng() < .5:
i += 0x80000000
i *= -1
return i
class Enum: