2
0

TimeManagerAI.py 1021 B

1234567891011121314151617181920212223
  1. from direct.directnotify import DirectNotifyGlobal
  2. from direct.distributed.ClockDelta import globalClockDelta
  3. from direct.distributed import DistributedObjectAI
  4. class TimeManagerAI(DistributedObjectAI.DistributedObjectAI):
  5. notify = DirectNotifyGlobal.directNotify.newCategory("TimeManagerAI")
  6. def __init__(self, air):
  7. DistributedObjectAI.DistributedObjectAI.__init__(self, air)
  8. def requestServerTime(self, context):
  9. """requestServerTime(self, int8 context)
  10. This message is sent from the client to the AI to initiate a
  11. synchronization phase. The AI should immediately report back
  12. with its current time. The client will then measure the round
  13. trip.
  14. """
  15. timestamp = globalClockDelta.getRealNetworkTime(bits=32)
  16. requesterId = self.air.getAvatarIdFromSender()
  17. print("requestServerTime from %s" % (requesterId))
  18. self.sendUpdateToAvatarId(requesterId, "serverTime",
  19. [context, timestamp])