diff --git a/cloud.py b/cloud.py index a452c6f..79daf83 100644 --- a/cloud.py +++ b/cloud.py @@ -6,11 +6,10 @@ HI_P_CLOUD_DELAY = 10 MED_P_CLOUD_DELAY = 5 LOW_P_CLOUD_DELAY = 3 -NUM_PLAYERS = 10 -ks + class Cloud(object): - def __init__(self, gameTraffic, location, timeout): + def __init__(self, gameTraffic, location, timeout, num_players): self.requestList = Queue.Queue() @@ -21,29 +20,29 @@ def __init__(self, gameTraffic, location, timeout): else: self.timeToProcess = HIGH_P_CLOUD_DELAY + self.num_players = num_players self.location = location self.timeMS = 0 self.timeout = timeout def updateTime(self, time): # is this how it works? self.timeMS = time - return processResponse(self) - - def processResponse(self): + return self.processResponse(time) - if self.timeMS % timeToProcess == 0 and not self.requestList.empty() : + def processResponse(self, time): + if self.timeMS % self.timeToProcess == 0 and not self.requestList.empty() : headPacket = self.requestList.get(); - if (time - headPacket.timestamp) > timeout: + if (time - headPacket.timestamp) > self.timeout: return None else: - responsePackets[] - for i in range(1,NUM_PLAYERS): + responsePackets = [] + for i in range(1,self.num_players): newPacket = headPacket # update packet newPacket.sendAddress = 0 newPacket.receiveAddress = i - responsePackets[i].append(newPacket) + responsePackets.append(newPacket) return responsePackets else: return None diff --git a/device.py b/device.py index 07033aa..b5e0a43 100644 --- a/device.py +++ b/device.py @@ -1,5 +1,6 @@ from game import Game from packet import Packet +import Cloud class Device(object): @@ -8,42 +9,47 @@ def __init__(self, deviceID, hwTier, eventsPerSec, location): self.hwTier = hwTier self.eventsPerSec = eventsPerSec self.location = location + self.position = (deviceID * 10, ) + self.timeMS = 0 - def getSpecsForGame(game): - pass + def updateTime(self, time): + self.timeMS = time + + return processResponse(self) - def sendPacket(): - packet = Packet((5,50), , deviceID) + def processResponse(): + if self.timeMS % eventsPerSec == 0: + packet = Packet(self.position, self.timeMS, 0, self.deviceID) + return packet + return None - def run(): - sendPacket() + def movePlayer(): - class OculusRift(Device): - def __init__(self, deviceID, hwTier, eventsPerSec, location): - super(OculusRift, self).__init__(deviceID, 90, eventsPerSec, location) + def __init__(self, deviceID, location): + super(OculusRift, self).__init__(deviceID, 90, 5, location) class HTCVive(Device): - def __init__(self, deviceID, hwTier, eventsPerSec, location): - super(HTCVive, self).__init__(deviceID, 90, eventsPerSec, location) + def __init__(self, deviceID, location): + super(HTCVive, self).__init__(deviceID, 90, 5, location) class PlayStationVR(Device): - def __init__(self, deviceID, hwTier, eventsPerSec, location): - super(PlayStationVR, self).__init__(deviceID, 120, eventsPerSec, location) + def __init__(self, deviceID, location): + super(PlayStationVR, self).__init__(deviceID, 120, 5, location) class LG360VR(Device): - def __init__(self, deviceID, hwTier, eventsPerSec, location): - super(LG360VR, self).__init__(deviceID, 120, eventsPerSec, location) + def __init__(self, deviceID, location): + super(LG360VR, self).__init__(deviceID, 120, 5, location) class GearVR(Device): - def __init__(self, deviceID, hwTier, eventsPerSec, location): - super(GearVR, self).__init__(deviceID, 60, eventsPerSec, location) + def __init__(self, deviceID, location): + super(GearVR, self).__init__(deviceID, 60, 5, location) class VisusVR(Device): - def __init__(self, deviceID, hwTier, eventsPerSec, location): - super(VisusVR, self).__init__(deviceID, 60, eventsPerSec, location) + def __init__(self, deviceID, location): + super(VisusVR, self).__init__(deviceID, 60, 5, location) devices = { "OculusRift" : OculusRift(), diff --git a/packet.py b/packet.py index 23d8048..cbf4c0d 100644 --- a/packet.py +++ b/packet.py @@ -2,7 +2,7 @@ class Packet(object): - def __init__(self, position, timestamp, receiverAddress, senderAddress): + def __init__(self, timestamp, position, receiverAddress, senderAddress): self._init_packet_id() self.timestamp = timestamp self.position = position diff --git a/testCloud.py b/testCloud.py index d6f7140..37e951b 100644 --- a/testCloud.py +++ b/testCloud.py @@ -1,28 +1,22 @@ import cloud - +import packet if __name__ == "__main__": - packet1.id = 0 - packet1.sendAddress = 1 - packet1.receiveAddress = 0 - packet1.timestamp = 100 - packet2.id = 1 - packet2.sendAddress = 2 - packet2.receiveAddress = 0 - packet2.timestamp = 0 - - cloud = Cloud(0, 0, 10) + + packet1 = packet.Packet(0, 100, 0, 0, 1) + packet2 = packet.Packet(0, 0, 0, 0, 2) + cloud = cloud.Cloud(0, 0, 10, 10) + cloud.receiveRequest(packet1) - cloud.receiveRequest(packet1) - cloud.receiveRequest(packet2) + cloud.receiveRequest(packet2) - time = 90 + time = 90 - for i in range(0,10): + for i in range(0,10): time = time + 1 packetList = cloud.updateTime(time) if packetList != None: - print packetList[0].id + print packetList[0].packet_id