Пример #1
0
    def update(self, dt):
        # Add time to schedulers.
        SchedulerManager.update(self, dt)

        # Get buffered input from clients and process it.
        while not self.server.input.empty():
            (client, packet) = self.server.input.get_nowait()
            self.process_packet(client, packet)

        # Update the game state world.
        self.world.update(dt)

        # Send necessary ObjectUpdate packets.
        for object in self.world.objects:
            if object.type == "player":
                self._send_update(object)

        # Send necessary ObjectStatusUpdate packets.
        for object in self.status_updates:
            update = packets.ObjectStatusUpdate()
            update.object_id = object.object_id
            update.health, update.power = object.health, object.power
            self.server.output_broadcast.put_nowait((update, None))
        self.status_updates.clear()

        # Send buffered output to clients.
        reactor.callFromThread(self.server.send)

        # Sleep some if we're updating too fast.
        extra = 0.01 - dt
        if extra >= 0.001:
            time.sleep(extra)
Пример #2
0
    def update(self, dt):
        # Add time to schedulers.
        SchedulerManager.update(self, dt)

        # Get buffered input from clients and process it.
        while not self.server.input.empty():
            (client, packet) = self.server.input.get_nowait()
            self.process_packet(client, packet)

        # Update the game state world.
        self.world.update(dt)

        # Send necessary ObjectUpdate packets.
        for object in self.world.objects:
            if object.type == "player":
                self._send_update(object)

        # Send necessary ObjectStatusUpdate packets.
        for object in self.status_updates:
            update = packets.ObjectStatusUpdate()
            update.object_id = object.object_id
            update.health, update.power = object.health, object.power
            self.server.output_broadcast.put_nowait((update, None))
        self.status_updates.clear()

        # Send buffered output to clients.
        reactor.callFromThread(self.server.send)

        # Sleep some if we're updating too fast.
        extra = 0.01 - dt
        if extra >= 0.001:
            time.sleep(extra)
Пример #3
0
    def frameStarted(self, event):
        """ 
        Called before a frame is displayed, handles events
        (also those via callback functions, as you need to call capture()
        on the input objects)

        Returning False here exits the application (render loop stops)
        """
        
        dt = event.timeSinceLastFrame
        
        # Get buffered input from server and process it.
        while not self.client.input.empty():
            packet = self.client.input.get_nowait()
            self.process_packet(packet)
        
        # Add time to schedulers.
        SchedulerManager.update(self, dt)
        
        # Capture any buffered events (and fire any callbacks).
        self.inputHandler.capture()
        
        # Update our UI Elements
        self.gui.update(dt)
        
        # Update the game state world.
        self.world.update(dt)
        
        # Update the audio module so it can throw its events
        audio.update(dt)
        
        # Send an PlayerUpdate packet to the server if appropriate.
        self._send_update()
        
        # Send buffered output to server.
        reactor.callFromThread(self.client.send)
        
        # Add time to animations.
        for node in self.nodes:
            node.update(dt)

        # Neatly close our FrameListener if our renderWindow has been shut down
        # or we are quitting.
        if self.renderWindow.isClosed() or self.quit:
            return False
        
        return True