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)
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
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
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)
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)
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
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())
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'])
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'])
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))
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))
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)
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)
def _sendCommand(self, command): buffer = blender_cave.buffer.Buffer() buffer.command(command) self._send(buffer)