def pick_world(self, time): pos = len(self.snapshots) while pos > 0 and self.snapshots[pos - 1]['time'] > time: pos -= 1 self.snapshots = self.snapshots[:pos] if pos == 0: return World(self.start_time) return World.from_snapshot(self.snapshots[pos - 1])
def mainloop(self): new_messages = self.receive() if len(new_messages): last_message = new_messages[-1] self.world = World.from_snapshot(last_message['data']) if self.world: self.send({ 'keys': self.keys, 'client_time': self.world.time })