Exemplo n.º 1
0
 def run(self):
     if self.isReady():
         buffer = blender_cave.buffer.Buffer()
         buffer.command(self.SYNCHRONIZER)
         buffer.subBuffer(self._synchronizer.getBuffer())
         self._send(buffer)
     self._select.run(False)
Exemplo n.º 2
0
    def getCreationBuffer(self, parent_id):

        buffer = blender_cave.buffer.Buffer()
        item_id = self.getItemID()

        if not self._created:
            buffer.command(self.getParent().CREATE_ITEM)
            buffer.itemID(parent_id)
            buffer.itemID(item_id)
            item_name = self.getItemName()
            buffer.string(item_name)
            try:
                if self._item.parent is not None:
                    parent_name = str(self._item.parent)
                else:
                    parent_name = item_name
            except AttributeError:
                parent_name = item_name
            buffer.string(parent_name)
            self._created = True
            if not self.getParent()._firstCreation:
                self.activate(True, True)

        for item in self._getSubItems():
            item = self.getParent().getItem(item)
            buffer += item.getCreationBuffer(item_id)
        return buffer
Exemplo n.º 3
0
 def run(self):
     if self.isReady():
         buffer = blender_cave.buffer.Buffer()
         buffer.command(self.SYNCHRONIZER)
         buffer.subBuffer(self._synchronizer.getBuffer())
         self._send(buffer)
     self._select.run(False)
Exemplo n.º 4
0
    def getCreationBuffer(self, parent_id):

        buffer = blender_cave.buffer.Buffer()
        item_id = self.getItemID()

        if not self._created:
            buffer.command(self.getParent().CREATE_ITEM)
            buffer.itemID(parent_id)
            buffer.itemID(item_id)
            item_name = self.getItemName()
            buffer.string(item_name)
            try:
                if self._item.parent is not None:
                    parent_name = str(self._item.parent)
                else:
                    parent_name = item_name
            except AttributeError:
                parent_name = item_name
            buffer.string(parent_name)
            self._created = True
            if not self.getParent()._firstCreation:
                self.activate(True, True)

        for item in self._getSubItems():
            item = self.getParent().getItem(item)
            buffer += item.getCreationBuffer(item_id)
        return buffer
Exemplo n.º 5
0
    def getBuffer(self):
        buffer = blender_cave.buffer.Buffer()

        # Create new objects affectations ...
        newObjects = blender_cave.buffer.Buffer()
        while len(self._synchronizedObjectsToAdd) > 0:
            object = self._synchronizedObjectsToAdd.pop()
            objects_id = id(object)
            self._synchronizedObjects[objects_id] = object
            newObjects.itemID(objects_id)
            newObjects.string(object._synchronize_object_name)
        if not newObjects.isEmpty():
            buffer.command(self.NEW_OBJECT)
            buffer.subBuffer(newObjects)

        # Then update objects attributs
        for objects_id, object in self._synchronizedObjects.items():
            object_data_buffer = object.getSynchronizerBuffer()
            if (object_data_buffer
                    is not None) and (not object_data_buffer.isEmpty()):
                buffer.command(self.OBJECT)
                buffer.itemID(objects_id)
                buffer.subBuffer(object_data_buffer)

        return buffer
Exemplo n.º 6
0
 def quit(self, reason):
     if not hasattr(self, '_is_quitting'):
         self._is_quitting = True
         buffer = blender_cave.buffer.Buffer()
         buffer.command(self.QUIT)
         buffer.string(reason)
         self._send(buffer)
         while len(self._clients) > 0:
             self._select.run(True)
         super(Master, self).quit(reason)
Exemplo n.º 7
0
 def quit(self, reason):
     if not hasattr(self,'_is_quitting'): 
         self._is_quitting = True
         buffer = blender_cave.buffer.Buffer()
         buffer.command(self.QUIT)
         buffer.string(reason)
         self._send(buffer)
         while len(self._clients) > 0:
             self._select.run(True)
         super(Master, self).quit(reason)
Exemplo n.º 8
0
    def getSynchronizerBuffer(self):
        buffer = blender_cave.buffer.Buffer()

        if (self._previous['user_position'] != self.getPosition()):
            self._previous['user_position'] = self.getPosition()
            buffer.command(self.SYNCHRONIZER_COMMAND_USER_POSITION)
            buffer.matrix_4x4(self.getPosition())

        if (self._previous['vehicle_position'] != self.getVehiclePosition()):
            self._previous['vehicle_position'] = self.getVehiclePosition()
            buffer.command(self.SYNCHRONIZER_COMMAND_VEHICLE_POSITION)
            buffer.matrix_4x4(self.getVehiclePosition())

        return buffer
Exemplo n.º 9
0
    def processSynchronizerBuffer(self, buffer):
        while not buffer.isEmpty():
            command = buffer.command()

            if (command == self.SYNCHRONIZER_COMMAND_USER_POSITION):
                self.setPosition(buffer.matrix_4x4())

            elif (command == self.SYNCHRONIZER_COMMAND_VEHICLE_POSITION):
                self.setVehiclePosition(buffer.matrix_4x4())
Exemplo n.º 10
0
 def _processMessageFromClient(self, peer): 
     buffer = self._receiveFrom(peer)
     if buffer is None:
         self._delClient(peer)
         return
     while not buffer.isEmpty():
         command = buffer.command()
         if command == self.QUIT:
             reason = buffer.string()
             self.quit(reason)
         else:
             raise blender_cave.exceptions.Controller("Unattended command (" + str(command) + ") from " + self._clients[peer]['address'])
Exemplo n.º 11
0
 def _processMessageFromClient(self, peer):
     buffer = self._receiveFrom(peer)
     if buffer is None:
         self._delClient(peer)
         return
     while not buffer.isEmpty():
         command = buffer.command()
         if command == self.QUIT:
             reason = buffer.string()
             self.quit(reason)
         else:
             raise blender_cave.exceptions.Controller(
                 "Unattended command (" + str(command) + ") from " +
                 self._clients[peer]['address'])
Exemplo n.º 12
0
    def getBuffer(self):
        buffer = blender_cave.buffer.Buffer()

        # Create new objects affectations ...
        newObjects = blender_cave.buffer.Buffer()
        while len(self._synchronizedObjectsToAdd) > 0:
            object = self._synchronizedObjectsToAdd.pop()
            objects_id = id(object)
            self._synchronizedObjects[objects_id] = object
            newObjects.itemID(objects_id)
            newObjects.string(object._synchronize_object_name)
        if not newObjects.isEmpty():
            buffer.command(self.NEW_OBJECT)
            buffer.subBuffer(newObjects)

        # Then update objects attributs
        for objects_id, object in self._synchronizedObjects.items():
            object_data_buffer = object.getSynchronizerBuffer()
            if (object_data_buffer is not None) and (not object_data_buffer.isEmpty()):
                buffer.command(self.OBJECT)
                buffer.itemID(objects_id)
                buffer.subBuffer(object_data_buffer)

        return buffer
Exemplo n.º 13
0
 def _processMessageFromMaster(self, peer):
     buffer = self._receiveFrom(peer)
     if buffer is None:
         self.quit("Lose connection from the master !")
         return
     while not buffer.isEmpty():
         command = buffer.command()
         if command == self.EVERYBODY_HERE:
             self._switchToReady()
         elif command == self.QUIT:
             self._shutdown()
             self.quit(buffer.string())
         elif command == self.SYNCHRONIZER:
             self._synchronizer.process(buffer.subBuffer())
         else:
             raise blender_cave.exceptions.Controller("Unattended command (" + str(command) + ") from " + str(peer))
Exemplo n.º 14
0
 def _processMessageFromMaster(self, peer):
     buffer = self._receiveFrom(peer)
     if buffer is None:
         self.quit("Lose connection from the master !")
         return
     while not buffer.isEmpty():
         command = buffer.command()
         if command == self.EVERYBODY_HERE:
             self._switchToReady()
         elif command == self.QUIT:
             self._shutdown()
             self.quit(buffer.string())
         elif command == self.SYNCHRONIZER:
             self._synchronizer.process(buffer.subBuffer())
         else:
             raise blender_cave.exceptions.Controller(
                 "Unattended command (" + str(command) + ") from " +
                 str(peer))
Exemplo n.º 15
0
    def process(self, buffer):
        while not buffer.isEmpty():
            command = buffer.command()

            if command == self.NEW_OBJECT:
                new_objects_buffer = buffer.subBuffer()
                while not new_objects_buffer.isEmpty():
                    objects_id   = new_objects_buffer.itemID()
                    objects_name = new_objects_buffer.string()
                    for i in range(len(self._synchronizedObjectsToAdd)):
                        if self._synchronizedObjectsToAdd[i]._synchronize_object_name == objects_name:
                            object = self._synchronizedObjectsToAdd.pop(i)
                            self._synchronizedObjects[objects_id] = object
                            break

            elif command == self.OBJECT:
                objects_id   = buffer.itemID()
                objectBuffer = buffer.subBuffer()
                if objects_id in self._synchronizedObjects:
                    self._synchronizedObjects[objects_id].processSynchronizerBuffer(objectBuffer)
Exemplo n.º 16
0
    def process(self, buffer):
        while not buffer.isEmpty():
            command = buffer.command()

            if command == self.NEW_OBJECT:
                new_objects_buffer = buffer.subBuffer()
                while not new_objects_buffer.isEmpty():
                    objects_id = new_objects_buffer.itemID()
                    objects_name = new_objects_buffer.string()
                    for i in range(len(self._synchronizedObjectsToAdd)):
                        if self._synchronizedObjectsToAdd[
                                i]._synchronize_object_name == objects_name:
                            object = self._synchronizedObjectsToAdd.pop(i)
                            self._synchronizedObjects[objects_id] = object
                            break

            elif command == self.OBJECT:
                objects_id = buffer.itemID()
                objectBuffer = buffer.subBuffer()
                if objects_id in self._synchronizedObjects:
                    self._synchronizedObjects[
                        objects_id].processSynchronizerBuffer(objectBuffer)
Exemplo n.º 17
0
 def _sendCommand(self, command):
     buffer = blender_cave.buffer.Buffer()
     buffer.command(command)
     self._send(buffer)
Exemplo n.º 18
0
 def _sendCommand(self, command):
     buffer = blender_cave.buffer.Buffer()
     buffer.command(command)
     self._send(buffer)