-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oghenefego Ahia
authored and
Oghenefego Ahia
committed
Dec 18, 2016
1 parent
38378dc
commit 0d8703a
Showing
1 changed file
with
40 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,73 @@ | ||
from game import Game | ||
from packet import Packet | ||
import Cloud | ||
from random import randint | ||
|
||
TICKS_PER_EVENT = 5 | ||
|
||
class Device(object): | ||
|
||
def __init__(self, deviceID, hwTier, eventsPerSec, location): | ||
def __init__(self, deviceID, fps, ticksPerEvent, location): | ||
self.deviceID = deviceID | ||
self.hwTier = hwTier | ||
self.eventsPerSec = eventsPerSec | ||
self.fps = fps | ||
self.ticksPerEvent = ticksPerEvent | ||
self.location = location | ||
self.position = (deviceID * 5, deviceID * 10) | ||
|
||
self.position = (randint(0, 10), randint(5, 20)) | ||
self.timeMS = 0 | ||
self.packetDict = {} | ||
|
||
def updateTime(self, time, packet=None): | ||
if packet is None: | ||
return sendPacket(time) | ||
else: | ||
receivePacket(time, packet) | ||
|
||
def updateTime(self, time): | ||
self.timeMS = time | ||
movePlayer(time) | ||
return processResponse(self) | ||
|
||
def processResponse(): | ||
if self.timeMS % self.eventsPerSec == 0: | ||
packet = Packet(self.position, self.timeMS, 0, self.deviceID) | ||
def sendPacket(self, time): | ||
if time % self.ticksPerEvent == 0: | ||
movePlayer(time) | ||
packet = Packet(time, self.position, 0, self.deviceID) | ||
id = packet.packet_id | ||
packetDict[id] = {'sendTime' : time, 'receiveTime' : -1} | ||
print 'Device %s. Packet sent: %s ' % (self.deviceID, packet.packet_id) | ||
return packet | ||
return None | ||
|
||
def receivePacket(time, packet): | ||
print 'Device %s. Packet received: %s ' % (self.deviceID, packet.packet_id) | ||
id = packet.packet_id | ||
if id in packetDict.keys(): | ||
packetDict[id]['receiveTime'] = time | ||
else: | ||
# stray packet received | ||
packetDict[id] = {'sendTime' : -1, 'receiveTime' : time} | ||
|
||
def movePlayer(time): | ||
|
||
self.position = ( randint(0, 10), randint(5, 50)) | ||
|
||
|
||
|
||
|
||
class OculusRift(Device): | ||
def __init__(self, deviceID, location): | ||
super(OculusRift, self).__init__(deviceID, 90, 5, location) | ||
super(OculusRift, self).__init__(deviceID, 90, TICKS_PER_EVENT, location) | ||
|
||
class HTCVive(Device): | ||
def __init__(self, deviceID, location): | ||
super(HTCVive, self).__init__(deviceID, 90, 5, location) | ||
super(HTCVive, self).__init__(deviceID, 90, TICKS_PER_EVENT, location) | ||
|
||
class PlayStationVR(Device): | ||
def __init__(self, deviceID, location): | ||
super(PlayStationVR, self).__init__(deviceID, 120, 5, location) | ||
super(PlayStationVR, self).__init__(deviceID, 120, TICKS_PER_EVENT, location) | ||
|
||
class LG360VR(Device): | ||
def __init__(self, deviceID, location): | ||
super(LG360VR, self).__init__(deviceID, 120, 5, location) | ||
super(LG360VR, self).__init__(deviceID, 120, TICKS_PER_EVENT, location) | ||
|
||
class GearVR(Device): | ||
def __init__(self, deviceID, location): | ||
super(GearVR, self).__init__(deviceID, 60, 5, location) | ||
super(GearVR, self).__init__(deviceID, 60, TICKS_PER_EVENT, location) | ||
|
||
class VisusVR(Device): | ||
def __init__(self, deviceID, location): | ||
super(VisusVR, self).__init__(deviceID, 60, 5, location) | ||
|
||
devices = { | ||
"OculusRift" : OculusRift(), | ||
"HTCVive" : HTCVive(), | ||
"PlayStationVR" : PlayStationVR(), | ||
"SamsungGearVR" : SamsungGearVR(), | ||
"LG360VR" : LG360VR(), | ||
"VisusVR" : VisusVR(), | ||
} | ||
super(VisusVR, self).__init__(deviceID, 60, TICKS_PER_EVENT, location) |