Example #1
0
    def networkUpdate(self):
        self.network.update()
        while self.timeUntilNextNetworkUpdate <= 0.0:
            self.timeUntilNextNetworkUpdate += self.timeBetweenNetworkUpdates

        for client in self.network.clients:
            if client.timedOut():
                self.serverChat.sendMessage(client.player._name + " timed out, disconnecting")
                client.player.close()
                self.objects.remove(client.player)
                self.network.clients.remove(client)

        timer = encode.timer()
        timer.start()

        for client in self.network.clients:                
            client.send([[[o._name,
                           o.getAttributes(),
                           1 if o._name == client.player._name else 0,
                           o.type,
                           o.getEvents()] for o in self.objects if o.shouldSendToClients()],
                        time.time(), self.timeUntilNextEngineUpdate])
            #parameter above is whether or not the player is the current player
                            
            while client.hasMoreMessages():
                client.player.inputPresses(client.pop())

        timer.stop()
        self.debugNetworkTime = timer.time()

        for o in self.objects:
            o.clearEvents()
Example #2
0
    def frameEnded(self, frameTime):
        timer = encode.timer()
        timer.start()
        self.timeUntilNextEngineUpdate -= frameTime
        self.step()     
        self.debugFrameTime = frameTime

        for object in self.objects:
            object.frameEnded(frameTime)
        timer.stop()
        self.debugStepTime = timer.time()

        return True # Keep going
Example #3
0
    def frameEnded(self, frameTime, keyboard,  mouse, joystick):
        t = timer()

        self.updateGUI(frameTime)
        
        Engine.frameEnded(self, frameTime)

        t.start()
        self.updateChat(frameTime)
        t.stop()
        t.debugChatTime = t.time()
        
        keyboard = keyboard
        self.mouse = mouse
        self.joystick = joystick
        self.timeUntilNextNetworkUpdate -= frameTime
        t.start()

        if self.timeUntilNextNetworkUpdate <= 0.0:
            self.timeUntilNextNetworkUpdate = self.timeBetweenNetworkUpdates

            u = timer()
            u.start()
            self.network.update(frameTime)
            u.stop()

            for message in self.network._messages:
                if message[1] > self.lastServerUpdate:
                    self.timeUntilNextEngineUpdate = message[Engine.NET_TIME_UNTIL_UPDATE]
                    #print message[Engine.NET_TIME_UNTIL_UPDATE]
                    self.lastServerUpdate = message[Engine.NET_TIME]

                    for object in self.objects:
                        object.existsOnServer = False

                    for serverObject in message[Engine.NET_OBJECTS]:
                        hasObject = False
                        for object in self.objects:
                            if serverObject[Engine.NET_OBJECTS_NAME] == object._name:
                                hasObject = True
                                object.existsOnServer = True
                                object.setAttributes(serverObject[Engine.NET_OBJECTS_ATTRIBUTES])
                                object.setEvents(serverObject[Engine.NET_OBJECTS_EVENTS])
                        if not hasObject:
                            newObject = None
                            if serverObject[2] == True:
                                newObject = Player(self, serverObject[Engine.NET_OBJECTS_NAME], self.camera)
                                self.chat.setNickName(serverObject[Engine.NET_OBJECTS_NAME])
                                newObject.enable()
                                self.player = newObject
                            else:
                                if serverObject[Engine.NET_OBJECTS_TYPE] == objects.PERSON:
                                    newObject = Person(self, serverObject[Engine.NET_OBJECTS_NAME])
                                elif serverObject[Engine.NET_OBJECTS_TYPE] == objects.BULLET:
                                    newObject = BulletObject(self, serverObject[Engine.NET_OBJECTS_NAME])
                                elif serverObject[Engine.NET_OBJECTS_TYPE] == objects.GRENADE:
                                    newObject = GrenadeObject(self, serverObject[Engine.NET_OBJECTS_NAME])
                                elif serverObject[Engine.NET_OBJECTS_TYPE] == objects.SHRAPNEL:
                                    newObject = ShrapnelObject(self, serverObject[Engine.NET_OBJECTS_NAME])
                                elif serverObject[Engine.NET_OBJECTS_TYPE] == objects.LASER:
                                    newObject = LaserObject(self, serverObject[Engine.NET_OBJECTS_NAME])
                                else:
                                    print "Unknown object to create", serverObject[Engine.NET_OBJECTS_TYPE], objects.PERSON

                            if newObject:
                                newObject.existsOnServer = True        
                                newObject.setAttributes(serverObject[Engine.NET_OBJECTS_ATTRIBUTES])
                                newObject.setEvents(serverObject[Engine.NET_OBJECTS_EVENTS])
                                self.objects += [newObject]

                    for object in self.objects:
                        if not object.existsOnServer and object.type == objects.PERSON:
                            self.objects.remove(object)
                            object.close()
                            del object
                        
            self.network.clearMessages()
            
        if self.player != None:
            self.network.send(self.player.input(keyboard,  self.mouse, self.joystick))

        t.stop()
        self.debugNetworkTime = t.time()
        return True # Keep running