Пример #1
0
	def stepClient(self, updateDue):
		assert network.mode == network.MODE_CLIENT
		timeStamp = network.getTime()
		localControl = self.control.getControl()
		
		if updateDue:
			# add client timestamp, client input sample to list, then send to server
			controlData = (timeStamp, localControl)
			self.connection.writeQueue.append(network.Packet(self.connection.serverUser, network.CL_UPDATE, controlData)) #self.controlList))

		network.sendReceive()

		# Use packets to determine visible objects and their state
		while self.connection.readQueue:
			packet = self.connection.readQueue.popleft()
			assert packet.opCode == network.SV_UPDATE
			assert packet.sender == self.connection.serverUser
			NetEnt.addGlobalState(packet.sentTime, packet.data)
		
		localChar = self.connection.localUser.char
		
		# update all non-local characters
		NetEnt.takeGlobalStateSample(network.getTime(), skipList=[localChar.id])
		
		# apply input to local char speculatively, #todo: consider collisions?
		localChar.applyControl(globalClock.getDt(), localControl, True, timeStamp=timeStamp)
		
		Character.collisionTraverser.traverse(render)
		localChar.postCollide()
		
		localChar.applyCorrection(timeStamp)
Пример #2
0
    def stepServer(self, updateDue):
        assert network.mode == network.MODE_SERVER
        network.sendReceive()

        # handle received client input
        while self.connection.readQueue:
            packet = self.connection.readQueue.popleft()
            assert packet.opCode == network.CL_UPDATE
            #print 'saw client update, from time', packet.data[0]
            packet.sender.addControlState(packet.data[0], packet.data[1])

        # Simulate characters attempting to move
        for control in ([self.control] + self.ai):
            control.char.applyControl(globalClock.getDt(),
                                      control.getControl(),
                                      control == self.control)
        timeStamp = time.clock()
        for user in UserPool.values():
            if user != self.connection.localUser:
                user.char.applyControl(globalClock.getDt(),
                                       user.takeControlStateSample(timeStamp),
                                       False)

        Character.collisionTraverser.traverse(render)

        # handle collide case
        for c in CharacterPool.values():
            c.postCollide()
        # process explosions, then projectiles
        for e in EffectPool.values():
            if not e.movePostCollide(globalClock.getDt()):
                EffectPool.remove(e)
                del NetEnt.entities[e.id]
                del e
        for p in ProjectilePool.values():
            if not p.movePostCollide(globalClock.getDt()):
                Effect(parentNode=p.node)
                ProjectilePool.remove(p)
                del NetEnt.entities[p.id]
                del p
        # For each connected client, package up visible objects/world state and send to client
        if updateDue:
            entstate = NetEnt.getState()
            for user in UserPool.values():
                if user == self.connection.localUser:
                    continue
                self.connection.writeQueue.append(
                    network.Packet(user, network.SV_UPDATE, entstate))
        network.sendReceive()
Пример #3
0
	def stepServer(self, updateDue):
		assert network.mode == network.MODE_SERVER
		network.sendReceive()

		# handle received client input
		while self.connection.readQueue:
			packet = self.connection.readQueue.popleft()
			assert packet.opCode == network.CL_UPDATE
			#print 'saw client update, from time', packet.data[0]
			packet.sender.addControlState(packet.data[0],packet.data[1])

		# Simulate characters attempting to move
		for control in ([self.control]+self.ai):
			control.char.applyControl(globalClock.getDt(), control.getControl(), control==self.control)
		timeStamp = time.clock()
		for user in UserPool.values():
			if user != self.connection.localUser:
				user.char.applyControl(globalClock.getDt(), user.takeControlStateSample(timeStamp), False)

		Character.collisionTraverser.traverse(render)

		# handle collide case
		for c in CharacterPool.values():
			c.postCollide()
		# process explosions, then projectiles
		for e in EffectPool.values():
			if not e.movePostCollide(globalClock.getDt()):
				EffectPool.remove(e)
				del NetEnt.entities[e.id]
				del e
		for p in ProjectilePool.values():
			if not p.movePostCollide(globalClock.getDt()):
				Effect(parentNode=p.node)
				ProjectilePool.remove(p)
				del NetEnt.entities[p.id]
				del p
		# For each connected client, package up visible objects/world state and send to client
		if updateDue:
			entstate = NetEnt.getState()
			for user in UserPool.values():
				if user == self.connection.localUser:
					continue
				self.connection.writeQueue.append(network.Packet(user, network.SV_UPDATE, entstate))
		network.sendReceive()
Пример #4
0
    def stepClient(self, updateDue):
        assert network.mode == network.MODE_CLIENT
        timeStamp = network.getTime()
        localControl = self.control.getControl()

        if updateDue:
            # add client timestamp, client input sample to list, then send to server
            controlData = (timeStamp, localControl)
            self.connection.writeQueue.append(
                network.Packet(self.connection.serverUser, network.CL_UPDATE,
                               controlData))  #self.controlList))

        network.sendReceive()

        # Use packets to determine visible objects and their state
        while self.connection.readQueue:
            packet = self.connection.readQueue.popleft()
            assert packet.opCode == network.SV_UPDATE
            assert packet.sender == self.connection.serverUser
            NetEnt.addGlobalState(packet.sentTime, packet.data)

        localChar = self.connection.localUser.char

        # update all non-local characters
        NetEnt.takeGlobalStateSample(network.getTime(),
                                     skipList=[localChar.id])

        # apply input to local char speculatively, #todo: consider collisions?
        localChar.applyControl(globalClock.getDt(),
                               localControl,
                               True,
                               timeStamp=timeStamp)

        Character.collisionTraverser.traverse(render)
        localChar.postCollide()

        localChar.applyCorrection(timeStamp)