void MetavoxelSession::sendDelta() { // wait until we have a valid lod if (!_lod.isValid()) { return; } Bitstream& out = _sequencer.startPacket(); out << QVariant::fromValue(MetavoxelDeltaMessage()); _server->getData().writeDelta(_sendRecords.first().data, _sendRecords.first().lod, out, _lod); _sequencer.endPacket(); // record the send SendRecord record = { _sequencer.getOutgoingPacketNumber(), _server->getData(), _lod }; _sendRecords.append(record); }
void MetavoxelSession::update() { // wait until we have a valid lod before sending if (!_lod.isValid()) { return; } // if we're sending a reliable delta, wait until it's acknowledged if (_reliableDeltaChannel) { sendPacketGroup(); return; } Bitstream& out = _sequencer.startPacket(); int start = _sequencer.getOutputStream().getUnderlying().device()->pos(); out << QVariant::fromValue(MetavoxelDeltaMessage()); PacketRecord* sendRecord = getLastAcknowledgedSendRecord(); _server->getData().writeDelta(sendRecord->getData(), sendRecord->getLOD(), out, _lod); out.flush(); int end = _sequencer.getOutputStream().getUnderlying().device()->pos(); if (end > _sequencer.getMaxPacketSize()) { // we need to send the delta on the reliable channel _reliableDeltaChannel = _sequencer.getReliableOutputChannel(RELIABLE_DELTA_CHANNEL_INDEX); _reliableDeltaChannel->startMessage(); _reliableDeltaChannel->getBuffer().write(_sequencer.getOutgoingPacketData().constData() + start, end - start); _reliableDeltaChannel->endMessage(); _reliableDeltaWriteMappings = out.getAndResetWriteMappings(); _reliableDeltaReceivedOffset = _reliableDeltaChannel->getBytesWritten(); _reliableDeltaData = _server->getData(); _reliableDeltaLOD = _lod; // go back to the beginning with the current packet and note that there's a delta pending _sequencer.getOutputStream().getUnderlying().device()->seek(start); MetavoxelDeltaPendingMessage msg = { ++_reliableDeltaID }; out << QVariant::fromValue(msg); _sequencer.endPacket(); } else { _sequencer.endPacket(); } // perhaps send additional packets to fill out the group sendPacketGroup(1); }