diff --git a/Messages.py b/Messages.py index c672ff5..bc0e76e 100644 --- a/Messages.py +++ b/Messages.py @@ -143,6 +143,7 @@ class PoseMsg(IMessage): self.networkId = networkId self.thingId = thing.id + poseType = 0x0F # unity server currently requires position and orientation self.poseType = poseType self.position = Spherical.zero self.orientation = Quaternion.identity diff --git a/SiteServer.py b/SiteServer.py new file mode 100644 index 0000000..1211e9f --- /dev/null +++ b/SiteServer.py @@ -0,0 +1,23 @@ +from .Participant import Participant +from .Thing import Thing +from . import Messages + +import select + +class SiteServer(Participant): + def __init__(self, ipAddress, port): + super().__init__(ipAddress, port) + self.udpSocket.setblocking(0) + + def Update(self, currentTime): + ready_to_read, _, _ = select.select([self.udpSocket], [], [], 0.1) # Timeout of 0.1 seconds + if ready_to_read: + data, addr = self.udpSocket.recvfrom(1024) + self.ReceiveData(data) + + return super().Update(currentTime) + + def ProcessNetworkIdMsg(self, msg): + self.networkId = msg.networkId + msg = Messages.ThingMsg(self.networkId, next(iter(Thing.allThings))) + msg.SendTo(self) \ No newline at end of file diff --git a/Thing.py b/Thing.py index 0b36e0a..1346703 100644 --- a/Thing.py +++ b/Thing.py @@ -9,7 +9,7 @@ class Thing: self.modelUrl = None Thing.Add(self) - def Update(self, currentTime): + def update(self, currentTime): pass @staticmethod @@ -19,4 +19,4 @@ class Thing: def UpdateAll(currentTime): for thing in Thing.allThings: - thing.Update(currentTime) + thing.update(currentTime) diff --git a/__init__.py b/__init__.py index 446fb62..69ea4cb 100644 --- a/__init__.py +++ b/__init__.py @@ -1,6 +1,7 @@ -__all__ = ['Direction', 'Spherical', 'Thing', 'Participant', 'Messages'] +__all__ = ['Direction', 'Spherical', 'Thing', 'Participant', 'Messages', 'SiteServer'] from .Direction import Direction from .Participant import Participant from .Thing import Thing -from .Spherical import Spherical \ No newline at end of file +from .Spherical import Spherical +from .SiteServer import SiteServer \ No newline at end of file