Merge branch 'atp' of https://github.com/birarda/hifi into protocol

This commit is contained in:
Atlante45 2015-07-15 11:53:11 -07:00
commit edc14ec6eb
38 changed files with 174 additions and 112 deletions

View file

@ -65,9 +65,9 @@ void Agent::handleOctreePacket(QSharedPointer<NLPacket> packet, SharedNodePointe
if (packetType == PacketType::OctreeStats) {
int statsMessageLength = OctreeHeadlessViewer::parseOctreeStats(packet, senderNode);
if (packet->getSizeUsed() > statsMessageLength) {
if (packet->getPayloadSize() > statsMessageLength) {
// pull out the piggybacked packet and create a new QSharedPointer<NLPacket> for it
int piggyBackedSizeWithHeader = packet->getSizeUsed() - statsMessageLength;
int piggyBackedSizeWithHeader = packet->getPayloadSize() - statsMessageLength;
std::unique_ptr<char> buffer = std::unique_ptr<char>(new char[piggyBackedSizeWithHeader]);
memcpy(buffer.get(), packet->getPayload() + statsMessageLength, piggyBackedSizeWithHeader);

View file

@ -552,9 +552,9 @@ void AudioMixer::handleMuteEnvironmentPacket(QSharedPointer<NLPacket> packet, Sh
auto nodeList = DependencyManager::get<NodeList>();
if (sendingNode->getCanAdjustLocks()) {
auto newPacket = NLPacket::create(PacketType::MuteEnvironment, packet->getSizeUsed());
auto newPacket = NLPacket::create(PacketType::MuteEnvironment, packet->getPayloadSize());
// Copy payload
newPacket->write(packet->getPayload(), packet->getSizeUsed());
newPacket->write(packet->getPayload(), packet->getPayloadSize());
nodeList->eachNode([&](const SharedNodePointer& node){
if (node->getType() == NodeType::Agent && node->getActiveSocket() &&

View file

@ -15,7 +15,7 @@
int AvatarMixerClientData::parseData(NLPacket& packet) {
// compute the offset to the data payload
return _avatar.parseDataFromBuffer(QByteArray::fromRawData(packet.getPayload(), packet.getSizeUsed()));
return _avatar.parseDataFromBuffer(QByteArray::fromRawData(packet.getPayload(), packet.getPayloadSize()));
}
bool AvatarMixerClientData::checkAndSetHasReceivedFirstPackets() {

View file

@ -108,7 +108,7 @@ int EntityServer::sendSpecialPackets(const SharedNodePointer& node, OctreeQueryN
queryNode->packetSent(*specialPacket);
totalBytes += specialPacket->getSizeWithHeader();
totalBytes += specialPacket->getDataSize();
packetsSent++;
DependencyManager::get<NodeList>()->sendPacket(std::move(specialPacket), *node);

View file

@ -85,7 +85,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
if (debugProcessPacket) {
qDebug("OctreeInboundPacketProcessor::processPacket() payload=%p payloadLength=%lld",
packet->getPayload(),
packet->getSizeUsed());
packet->getPayloadSize());
}
// Ask our tree subclass if it can handle the incoming packet...
@ -117,7 +117,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
if (debugProcessPacket || _myServer->wantsDebugReceiving()) {
qDebug() << "PROCESSING THREAD: got '" << packetType << "' packet - " << _receivedPacketCount << " command from client";
qDebug() << " receivedBytes=" << packet->getSizeWithHeader();
qDebug() << " receivedBytes=" << packet->getDataSize();
qDebug() << " sequence=" << sequence;
qDebug() << " sentAt=" << sentAt << " usecs";
qDebug() << " arrivedAt=" << arrivedAt << " usecs";
@ -135,26 +135,27 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
if (debugProcessPacket) {
qDebug() << " atByte (in payload)=" << packet->pos();
qDebug() << " payload size=" << packet->getSizeUsed();
if (!packet->bytesAvailable()) {
qDebug() << " payload size=" << packet->getPayloadSize();
if (!packet->bytesLeftToRead()) {
qDebug() << " ----- UNEXPECTED ---- got a packet without any edit details!!!! --------";
}
}
const unsigned char* editData = nullptr;
while (packet->bytesAvailable() > 0) {
while (packet->bytesLeftToRead() > 0) {
editData = reinterpret_cast<const unsigned char*>(packet->getPayload() + packet->pos());
int maxSize = packet->bytesAvailable();
int maxSize = packet->bytesLeftToRead();
if (debugProcessPacket) {
qDebug() << " --- inside while loop ---";
qDebug() << " maxSize=" << maxSize;
qDebug("OctreeInboundPacketProcessor::processPacket() %c "
"payload=%p payloadLength=%lld editData=%p payloadPosition=%lld maxSize=%d",
packetType, packet->getPayload(), packet->getSizeUsed(), editData,
packetType, packet->getPayload(), packet->getPayloadSize(), editData,
packet->pos(), maxSize);
}
@ -184,7 +185,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
if (debugProcessPacket) {
qDebug() << " editDataBytesRead=" << editDataBytesRead;
qDebug() << " AFTER processEditPacketData payload position=" << packet->pos();
qDebug() << " AFTER processEditPacketData payload size=" << packet->getSizeUsed();
qDebug() << " AFTER processEditPacketData payload size=" << packet->getPayloadSize();
}
}
@ -192,7 +193,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer<NLPacket> packet
if (debugProcessPacket) {
qDebug("OctreeInboundPacketProcessor::processPacket() DONE LOOPING FOR %c "
"payload=%p payloadLength=%lld editData=%p payloadPosition=%lld",
packetType, packet->getPayload(), packet->getSizeUsed(), editData, packet->pos());
packetType, packet->getPayload(), packet->getPayloadSize(), editData, packet->pos());
}
// Make sure our Node and NodeList knows we've heard from this node.

View file

@ -108,10 +108,10 @@ bool OctreeQueryNode::packetIsDuplicate() const {
// since our packets now include header information, like sequence number, and createTime, we can't just do a memcmp
// of the entire packet, we need to compare only the packet content...
if (_lastOctreePacketLength == _octreePacket->getSizeUsed()) {
if (_lastOctreePacketLength == _octreePacket->getPayloadSize()) {
if (memcmp(_lastOctreePayload + OCTREE_PACKET_EXTRA_HEADERS_SIZE,
_octreePacket->getPayload() + OCTREE_PACKET_EXTRA_HEADERS_SIZE,
_octreePacket->getSizeUsed() - OCTREE_PACKET_EXTRA_HEADERS_SIZE) == 0) {
_octreePacket->getPayloadSize() - OCTREE_PACKET_EXTRA_HEADERS_SIZE) == 0) {
return true;
}
}
@ -176,7 +176,7 @@ void OctreeQueryNode::resetOctreePacket() {
// changed since we last reset it. Since we know that no two packets can ever be identical without being the same
// scene information, (e.g. the root node packet of a static scene), we can use this as a strategy for reducing
// packet send rate.
_lastOctreePacketLength = _octreePacket->getSizeUsed();
_lastOctreePacketLength = _octreePacket->getPayloadSize();
memcpy(_lastOctreePayload, _octreePacket->getPayload(), _lastOctreePacketLength);
// If we're moving, and the client asked for low res, then we force monochrome, otherwise, use

View file

@ -147,16 +147,16 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
NLPacket& statsPacket = nodeData->stats.getStatsMessage();
// If the size of the stats message and the octree message will fit in a packet, then piggyback them
if (nodeData->getPacket().getSizeWithHeader() <= statsPacket.bytesAvailableForWrite()) {
if (nodeData->getPacket().getDataSize() <= statsPacket.bytesAvailableForWrite()) {
// copy octree message to back of stats message
statsPacket.write(nodeData->getPacket().getData(), nodeData->getPacket().getSizeWithHeader());
statsPacket.write(nodeData->getPacket().getData(), nodeData->getPacket().getDataSize());
// since a stats message is only included on end of scene, don't consider any of these bytes "wasted", since
// there was nothing else to send.
int thisWastedBytes = 0;
_totalWastedBytes += thisWastedBytes;
_totalBytes += statsPacket.getSizeWithHeader();
_totalBytes += statsPacket.getDataSize();
_totalPackets++;
if (debug) {
@ -172,8 +172,8 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
qDebug() << "Adding stats to packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
" timestamp: " << timestamp <<
" statsMessageLength: " << statsPacket.getSizeWithHeader() <<
" original size: " << nodeData->getPacket().getSizeWithHeader() << " [" << _totalBytes <<
" statsMessageLength: " << statsPacket.getDataSize() <<
" original size: " << nodeData->getPacket().getDataSize() << " [" << _totalBytes <<
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
}
@ -190,7 +190,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
// there was nothing else to send.
int thisWastedBytes = 0;
_totalWastedBytes += thisWastedBytes;
_totalBytes += statsPacket.getSizeWithHeader();
_totalBytes += statsPacket.getDataSize();
_totalPackets++;
if (debug) {
@ -206,11 +206,11 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
qDebug() << "Sending separate stats packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
" timestamp: " << timestamp <<
" size: " << statsPacket.getSizeWithHeader() << " [" << _totalBytes <<
" size: " << statsPacket.getDataSize() << " [" << _totalBytes <<
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
}
trueBytesSent += statsPacket.getSizeWithHeader();
trueBytesSent += statsPacket.getDataSize();
truePacketsSent++;
packetsSent++;
@ -218,10 +218,10 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
DependencyManager::get<NodeList>()->sendUnreliablePacket(nodeData->getPacket(), *_node);
packetSent = true;
int packetSizeWithHeader = nodeData->getPacket().getSizeWithHeader();
int packetSizeWithHeader = nodeData->getPacket().getDataSize();
thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader;
_totalWastedBytes += thisWastedBytes;
_totalBytes += nodeData->getPacket().getSizeWithHeader();
_totalBytes += nodeData->getPacket().getDataSize();
_totalPackets++;
if (debug) {
@ -237,7 +237,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
qDebug() << "Sending packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
" timestamp: " << timestamp <<
" size: " << nodeData->getPacket().getSizeWithHeader() << " [" << _totalBytes <<
" size: " << nodeData->getPacket().getDataSize() << " [" << _totalBytes <<
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
}
}
@ -250,7 +250,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
DependencyManager::get<NodeList>()->sendUnreliablePacket(nodeData->getPacket(), *_node);
packetSent = true;
int packetSizeWithHeader = nodeData->getPacket().getSizeWithHeader();
int packetSizeWithHeader = nodeData->getPacket().getDataSize();
int thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader;
_totalWastedBytes += thisWastedBytes;
_totalBytes += packetSizeWithHeader;
@ -277,8 +277,8 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
// remember to track our stats
if (packetSent) {
nodeData->stats.packetSent(nodeData->getPacket().getSizeUsed());
trueBytesSent += nodeData->getPacket().getSizeUsed();
nodeData->stats.packetSent(nodeData->getPacket().getPayloadSize());
trueBytesSent += nodeData->getPacket().getPayloadSize();
truePacketsSent++;
packetsSent++;
nodeData->octreePacketSent();
@ -596,9 +596,9 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
truePacketsSent++;
packetsSentThisInterval++;
_totalBytes += packet->getSizeWithHeader();
_totalBytes += packet->getDataSize();
_totalPackets++;
_totalWastedBytes += MAX_PACKET_SIZE - packet->getSizeWithHeader();
_totalWastedBytes += MAX_PACKET_SIZE - packet->getDataSize();
}
}

View file

@ -579,7 +579,7 @@ void DomainServer::processConnectRequestPacket(QSharedPointer<NLPacket> packet)
NodeType_t nodeType;
HifiSockAddr publicSockAddr, localSockAddr;
if (packet->getSizeUsed() == 0) {
if (packet->getPayloadSize() == 0) {
// TODO: We know what size the connect packet should be (minimally) - check for that here
return;
}
@ -2190,7 +2190,7 @@ void DomainServer::processPathQueryPacket(QSharedPointer<NLPacket> packet) {
quint16 numPathBytes;
packet->readPrimitive(&numPathBytes);
if (numPathBytes <= packet->bytesAvailable()) {
if (numPathBytes <= packet->bytesLeftToRead()) {
// the number of path bytes makes sense for the sent packet - pull out the path
QString pathQuery = QString::fromUtf8(packet->getPayload() + packet->pos(), numPathBytes);
@ -2223,7 +2223,7 @@ void DomainServer::processPathQueryPacket(QSharedPointer<NLPacket> packet) {
// are we going to be able to fit this response viewpoint in a packet?
if (numPathBytes + numViewpointBytes + sizeof(numViewpointBytes) + sizeof(numPathBytes)
< (unsigned long) pathResponsePacket->bytesAvailable()) {
< (unsigned long) pathResponsePacket->bytesLeftToRead()) {
// append the number of bytes this path is
pathResponsePacket->writePrimitive(numPathBytes);

View file

@ -134,7 +134,7 @@ void IceServer::sendPeerInformationPacket(const NetworkPeer& peer, const HifiSoc
peerPacket->write(peer.toByteArray());
// write the current packet
_serverSocket.writeDatagram(peerPacket->getData(), peerPacket->getSizeWithHeader(),
_serverSocket.writeDatagram(peerPacket->getData(), peerPacket->getDataSize(),
destinationSockAddr->getAddress(), destinationSockAddr->getPort());
}

View file

@ -105,10 +105,10 @@ if (APPLE)
# set where in the bundle to put the resources file
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/icon/${ICON_FILENAME} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set(DISCOVERED_RESOURCES "")
set(DISCOVERED_RESOURCES "")
# use the add_resources_to_os_x_bundle macro to recurse into resources
add_resources_to_os_x_bundle("${CMAKE_CURRENT_SOURCE_DIR}/resources")
add_resources_to_os_x_bundle("${CMAKE_CURRENT_SOURCE_DIR}/resources")
# append the discovered resources to our list of interface sources
list(APPEND INTERFACE_SRCS ${DISCOVERED_RESOURCES})
@ -136,12 +136,19 @@ target_include_directories(${TARGET_NAME} PRIVATE ${LIBOVR_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES})
find_package(Bullet REQUIRED)
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
# perform the system include hack for OS X to ignore warnings
if (APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${BULLET_INCLUDE_DIRS}")
else()
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
endif()
target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES})
# link required hifi libraries
link_hifi_libraries(shared octree environment gpu model render fbx networking entities avatars
audio audio-client animation script-engine physics
link_hifi_libraries(shared octree environment gpu model render fbx networking entities avatars
audio audio-client animation script-engine physics
render-utils entities-renderer ui auto-updater)
add_dependency_external_projects(sdl2)
@ -185,7 +192,7 @@ foreach(EXTERNAL ${OPTIONAL_EXTERNALS})
endforeach()
# special OS X modifications for RtMidi library
if (RTMIDI_FOUND AND NOT DISABLE_RTMIDI AND APPLE)
if (RTMIDI_FOUND AND NOT DISABLE_RTMIDI AND APPLE)
find_library(CoreMIDI CoreMIDI)
add_definitions(-D__MACOSX_CORE__)
target_link_libraries(${TARGET_NAME} ${CoreMIDI})

View file

@ -2899,7 +2899,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType::Value packetTyp
// encode the query data
int packetSize = _octreeQuery.getBroadcastData(reinterpret_cast<unsigned char*>(queryPacket->getPayload()));
queryPacket->setSizeUsed(packetSize);
queryPacket->setPayloadSize(packetSize);
// make sure we still have an active socket
nodeList->sendUnreliablePacket(*queryPacket, *node);

View file

@ -57,7 +57,7 @@ void OctreePacketProcessor::processPacket(QSharedPointer<NLPacket> packet, Share
int statsMessageLength = app->processOctreeStats(*packet, sendingNode);
wasStatsPacket = true;
int piggybackBytes = packet->getSizeUsed() - statsMessageLength;
int piggybackBytes = packet->getPayloadSize() - statsMessageLength;
if (piggybackBytes) {
// construct a new packet from the piggybacked one

View file

@ -38,14 +38,14 @@
**
****************************************************************************/
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdouble-promotion"
#endif
#include <QtWidgets>
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

View file

@ -937,7 +937,7 @@ void AudioClient::handleAudioInput() {
if (_audioPacket->getType() != PacketType::SilentAudioFrame) {
// audio samples have already been packed (written to networkAudioSamples)
_audioPacket->setSizeUsed(_audioPacket->getSizeUsed() + numNetworkBytes);
_audioPacket->setPayloadSize(_audioPacket->getPayloadSize() + numNetworkBytes);
}
_stats.sentPacket();

View file

@ -232,7 +232,7 @@ void AudioInjector::injectToMixer() {
audioPacket->write(_audioData.data() + _currentSendPosition, bytesToCopy);
// set the correct size used for this packet
audioPacket->setSizeUsed(audioPacket->pos());
audioPacket->setPayloadSize(audioPacket->pos());
// grab our audio mixer from the NodeList, if it exists
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);

View file

@ -56,7 +56,7 @@ void AvatarHashMap::processAvatarDataPacket(QSharedPointer<NLPacket> packet, Sha
// enumerate over all of the avatars in this packet
// only add them if mixerWeakPointer points to something (meaning that mixer is still around)
while (packet->bytesAvailable()) {
while (packet->bytesLeftToRead()) {
QUuid sessionUUID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID));
if (sessionUUID != _lastOwnerSessionUUID) {
@ -121,7 +121,7 @@ void AvatarHashMap::processAvatarBillboardPacket(QSharedPointer<NLPacket> packet
avatar = addAvatar(sessionUUID, sendingNode);
}
QByteArray billboard = packet->read(packet->bytesAvailable());
QByteArray billboard = packet->read(packet->bytesLeftToRead());
if (avatar->getBillboard() != billboard) {
avatar->setBillboard(billboard);
}

View file

@ -9,7 +9,14 @@ target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS})
add_dependency_external_projects(bullet)
find_package(Bullet REQUIRED)
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
# perform the system include hack for OS X to ignore warnings
if (APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${BULLET_INCLUDE_DIRS}")
else()
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
endif()
target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES})
add_dependency_external_projects(polyvox)

View file

@ -10,7 +10,14 @@ target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS})
add_dependency_external_projects(bullet)
find_package(Bullet REQUIRED)
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
# perform the system include hack for OS X to ignore warnings
if (APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${BULLET_INCLUDE_DIRS}")
else()
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
endif()
target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES})
link_hifi_libraries(avatars shared octree gpu model fbx networking animation environment)

View file

@ -24,7 +24,7 @@ EntityEditPacketSender::EntityEditPacketSender() {
void EntityEditPacketSender::processEntityEditNackPacket(QSharedPointer<NLPacket> packet) {
if (_shouldNack) {
processNackPacket(QByteArray::fromRawData(packet->getData(), packet->getSizeWithHeader()));
processNackPacket(QByteArray::fromRawData(packet->getData(), packet->getDataSize()));
}
}

View file

@ -907,7 +907,7 @@ bool EntityItemProperties::decodeEntityEditPacket(NLPacket& packet, int& process
const unsigned char* data = reinterpret_cast<const unsigned char*>(packet.getPayload());
const unsigned char* dataAt = data;
int bytesToRead = packet.getSizeUsed();
int bytesToRead = packet.getPayloadSize();
processedBytes = 0;
// the first part of the data is an octcode, this is a required element of the edit packet format, but we don't

View file

@ -867,7 +867,7 @@ int EntityTree::processEraseMessage(NLPacket& packet, const SharedNodePointer& s
for (size_t i = 0; i < numberOfIDs; i++) {
if (NUM_BYTES_RFC4122_UUID > packet.bytesAvailable()) {
if (NUM_BYTES_RFC4122_UUID > packet.bytesLeftToRead()) {
qCDebug(entities) << "EntityTree::processEraseMessage().... bailing because not enough bytes in buffer";
break; // bail to prevent buffer overflow
}

View file

@ -222,7 +222,7 @@ qint64 LimitedNodeList::writeDatagram(const NLPacket& packet, const HifiSockAddr
if (!connectionSecret.isNull() && !NON_VERIFIED_PACKETS.contains(packet.getType())) {
const_cast<NLPacket&>(packet).writeVerificationHash(packet.payloadHashWithConnectionUUID(connectionSecret));
}
return writeDatagram({packet.getData(), static_cast<int>(packet.getSizeWithHeader())}, destinationSockAddr);
return writeDatagram({ packet.getData(), (int)packet.getDataSize() }, destinationSockAddr);
}
qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr) {
@ -286,7 +286,7 @@ qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& des
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr,
const QUuid& connectionSecret) {
qint64 bytesSent{ 0 };
qint64 bytesSent = 0;
// close the last packet in the list
packetList.closeCurrentPacket();
@ -612,7 +612,7 @@ bool LimitedNodeList::processSTUNResponse(QSharedPointer<NLPacket> packet) {
sizeof(RFC_5389_MAGIC_COOKIE_NETWORK_ORDER)) == 0) {
// enumerate the attributes to find XOR_MAPPED_ADDRESS_TYPE
while (attributeStartIndex < packet->getSizeWithHeader()) {
while (attributeStartIndex < packet->getDataSize()) {
if (memcmp(packet->getData() + attributeStartIndex, &XOR_MAPPED_ADDRESS_TYPE, sizeof(XOR_MAPPED_ADDRESS_TYPE)) == 0) {
const int NUM_BYTES_STUN_ATTR_TYPE_AND_LENGTH = 4;
const int NUM_BYTES_FAMILY_ALIGN = 1;

View file

@ -80,7 +80,7 @@ NLPacket::NLPacket(PacketType::Value type, qint64 size) :
qint64 headerSize = localHeaderSize(type);
_payloadStart += headerSize;
_capacity -= headerSize;
_payloadCapacity -= headerSize;
}
NLPacket::NLPacket(PacketType::Value type) :
@ -88,7 +88,7 @@ NLPacket::NLPacket(PacketType::Value type) :
{
qint64 headerSize = localHeaderSize(type);
_payloadStart += headerSize;
_capacity -= headerSize;
_payloadCapacity -= headerSize;
}
NLPacket::NLPacket(const NLPacket& other) : Packet(other) {
@ -137,7 +137,7 @@ QByteArray NLPacket::payloadHashWithConnectionUUID(const QUuid& connectionUUID)
QCryptographicHash hash(QCryptographicHash::Md5);
// add the packet payload and the connection UUID
hash.addData(_payloadStart, _sizeUsed);
hash.addData(_payloadStart, _payloadSize);
hash.addData(connectionUUID.toRfc4122());
// return the hash

View file

@ -475,7 +475,7 @@ void NodeList::processDomainServerList(QSharedPointer<NLPacket> packet) {
setThisNodeCanRez((bool) thisNodeCanRez);
// pull each node in the packet
while (packetStream.device()->pos() < packet->getSizeUsed()) {
while (packetStream.device()->pos() < packet->getPayloadSize()) {
parseNodeFromPacketStream(packetStream);
}
}

View file

@ -236,7 +236,7 @@ void PacketReceiver::processDatagrams() {
matchingNode->setLastSequenceNumberForPacketType(packet->readSequenceNumber(), packet->getType());
}
emit dataReceived(matchingNode->getType(), packet->getSizeWithHeader());
emit dataReceived(matchingNode->getType(), packet->getDataSize());
QMetaMethod metaMethod = listener.second;
static const QByteArray QSHAREDPOINTER_NODE_NORMALIZED = QMetaObject::normalizedType("QSharedPointer<Node>");
@ -257,7 +257,7 @@ void PacketReceiver::processDatagrams() {
Q_ARG(QSharedPointer<NLPacket>, QSharedPointer<NLPacket>(packet.release())));
}
} else {
emit dataReceived(NodeType::Unassigned, packet->getSizeWithHeader());
emit dataReceived(NodeType::Unassigned, packet->getDataSize());
success = listener.second.invoke(listener.first,
Q_ARG(QSharedPointer<NLPacket>, QSharedPointer<NLPacket>(packet.release())));

View file

@ -54,7 +54,7 @@ void PacketSender::queuePacketForSending(const SharedNodePointer& destinationNod
unlock();
_totalPacketsQueued++;
_totalBytesQueued += packet->getSizeWithHeader();
_totalBytesQueued += packet->getDataSize();
// Make sure to wake our actual processing thread because we now have packets for it to process.
_hasPackets.wakeAll();
@ -278,7 +278,7 @@ bool PacketSender::nonThreadedProcess() {
_packetsOverCheckInterval++;
_totalPacketsSent++;
int packetSize = packetPair.second->getSizeWithHeader();
int packetSize = packetPair.second->getDataSize();
_totalBytesSent += packetSize;
emit packetSent(packetSize);

View file

@ -71,8 +71,8 @@ Packet::Packet(PacketType::Value type, qint64 size) :
_packetSize = localHeaderSize(type) + size;
_packet.reset(new char[_packetSize]);
_capacity = size;
_payloadStart = _packet.get() + (_packetSize - _capacity);
_payloadCapacity = size;
_payloadStart = _packet.get() + (_packetSize - _payloadCapacity);
// Sanity check
Q_ASSERT(size >= 0 || size < maxPayload);
@ -93,9 +93,9 @@ Packet::Packet(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& send
{
_type = readType();
_version = readVersion();
_capacity = _packetSize - localHeaderSize(_type);
_sizeUsed = _capacity;
_payloadStart = _packet.get() + (_packetSize - _capacity);
_payloadCapacity = _packetSize - localHeaderSize(_type);
_payloadSize = _payloadCapacity;
_payloadStart = _packet.get() + (_packetSize - _payloadCapacity);
}
Packet::Packet(const Packet& other) {
@ -110,9 +110,9 @@ Packet& Packet::operator=(const Packet& other) {
memcpy(_packet.get(), other._packet.get(), _packetSize);
_payloadStart = _packet.get() + (other._payloadStart - other._packet.get());
_capacity = other._capacity;
_payloadCapacity = other._payloadCapacity;
_sizeUsed = other._sizeUsed;
_payloadSize = other._payloadSize;
return *this;
}
@ -128,13 +128,31 @@ Packet& Packet::operator=(Packet&& other) {
_packet = std::move(other._packet);
_payloadStart = other._payloadStart;
_capacity = other._capacity;
_payloadCapacity = other._payloadCapacity;
_sizeUsed = other._sizeUsed;
_payloadSize = other._payloadSize;
return *this;
}
void Packet::setPayloadSize(qint64 payloadSize) {
if (isWritable()) {
Q_ASSERT(payloadSize <= _payloadCapacity);
_payloadSize = std::max(payloadSize, _payloadCapacity);
} else {
qDebug() << "You can not call setPayloadSize for a non-writeable Packet.";
Q_ASSERT(false);
}
}
bool Packet::reset() {
if (isWritable()) {
setPayloadSize(0);
}
return QIODevice::reset();
}
void Packet::setType(PacketType::Value type) {
auto currentHeaderSize = totalHeadersSize();
_type = type;
@ -197,13 +215,13 @@ qint64 Packet::writeData(const char* data, qint64 maxSize) {
if (maxSize <= bytesAvailableForWrite()) {
qint64 currentPos = pos();
Q_ASSERT(currentPos < _capacity);
Q_ASSERT(currentPos < _payloadCapacity);
// good to go - write the data
memcpy(_payloadStart + currentPos, data, maxSize);
// keep track of _sizeUsed so we can just write the actual data when packet is about to be sent
_sizeUsed = std::max(currentPos + maxSize, _sizeUsed);
// keep track of _payloadSize so we can just write the actual data when packet is about to be sent
_payloadSize = std::max(currentPos + maxSize, _payloadSize);
// return the number of bytes written
return maxSize;
@ -215,7 +233,7 @@ qint64 Packet::writeData(const char* data, qint64 maxSize) {
qint64 Packet::readData(char* dest, qint64 maxSize) {
// we're either reading what is left from the current position or what was asked to be read
qint64 numBytesToRead = std::min(bytesAvailable(), maxSize);
qint64 numBytesToRead = std::min(bytesLeftToRead(), maxSize);
if (numBytesToRead > 0) {
int currentPosition = pos();

View file

@ -49,11 +49,20 @@ public:
PacketVersion getVersion() const { return _version; }
qint64 getSizeWithHeader() const { return totalHeadersSize() + getSizeUsed(); }
qint64 getSizeUsed() const { return _sizeUsed; }
void setSizeUsed(qint64 sizeUsed) { _sizeUsed = sizeUsed; }
// Returns the size of the packet, including the header
qint64 getDataSize() const { return totalHeadersSize() + getPayloadSize(); }
// Returns the size of the payload only
qint64 getPayloadSize() const { return _payloadSize; }
// Allows a writer to change the size of the payload used when writing directly
void setPayloadSize(qint64 payloadSize);
// Returns the number of bytes allocated for the payload
qint64 getPayloadCapacity() const { return _payloadCapacity; }
qint64 bytesAvailableForWrite() const { return _capacity - _sizeUsed; }
qint64 bytesLeftToRead() const { return _payloadCapacity - pos(); }
qint64 bytesAvailableForWrite() const { return _payloadCapacity - pos(); }
HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; }
const HifiSockAddr& getSenderSockAddr() const { return _senderSockAddr; }
@ -64,8 +73,8 @@ public:
// QIODevice virtual functions
// WARNING: Those methods all refer to the payload ONLY and NOT the entire packet
virtual bool isSequential() const { return false; }
virtual bool reset() { setSizeUsed(0); return QIODevice::reset(); }
virtual qint64 size() const { return _capacity; }
virtual bool reset();
virtual qint64 size() const { return _payloadCapacity; }
template<typename T> qint64 peekPrimitive(T* data);
template<typename T> qint64 readPrimitive(T* data);
@ -98,9 +107,9 @@ protected:
std::unique_ptr<char> _packet; // Allocated memory
char* _payloadStart = nullptr; // Start of the payload
qint64 _capacity = 0; // Total capacity of the payload
qint64 _payloadCapacity = 0; // Total capacity of the payload
qint64 _sizeUsed = 0; // How much of the payload is actually used
qint64 _payloadSize = 0; // How much of the payload is actually used
HifiSockAddr _senderSockAddr; // sender address for packet (only used on receiving end)
};

View file

@ -90,7 +90,7 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) {
_segmentStartIndex = 0;
// shrink the current payload to the actual size of the packet
_currentPacket->setSizeUsed(_segmentStartIndex);
_currentPacket->setPayloadSize(_segmentStartIndex);
}
// move the current packet to our list of packets

View file

@ -322,7 +322,7 @@ int JurisdictionMap::unpackFromPacket(NLPacket& packet) {
int bytes = 0;
packet.readPrimitive(&bytes);
if (bytes > 0 && bytes <= packet.bytesAvailable()) {
if (bytes > 0 && bytes <= packet.bytesLeftToRead()) {
_rootOctalCode = new unsigned char[bytes];
packet.read(reinterpret_cast<char*>(_rootOctalCode), bytes);
@ -334,7 +334,7 @@ int JurisdictionMap::unpackFromPacket(NLPacket& packet) {
int bytes = 0;
packet.readPrimitive(&bytes);
if (bytes <= packet.bytesAvailable()) {
if (bytes <= packet.bytesLeftToRead()) {
unsigned char* endNodeCode = new unsigned char[bytes];
packet.read(reinterpret_cast<char*>(endNodeCode), bytes);

View file

@ -103,7 +103,7 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, std::uniqu
quint64 transitTime = queuedAt - createdAt;
qCDebug(octree) << "OctreeEditPacketSender::queuePacketToNode() queued " << packet->getType()
<< " - command to node bytes=" << packet->getSizeWithHeader()
<< " - command to node bytes=" << packet->getDataSize()
<< " sequence=" << sequence << " transitTimeSoFar=" << transitTime << " usecs";
}
@ -254,7 +254,7 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType::Value type, QByt
bufferedPacket = NLPacket::create(type);
} else {
// If we're switching type, then we send the last one and start over
if ((type != bufferedPacket->getType() && bufferedPacket->getSizeUsed() > 0) ||
if ((type != bufferedPacket->getType() && bufferedPacket->getPayloadSize() > 0) ||
(editMessage.size() >= bufferedPacket->bytesAvailableForWrite())) {
// create the new packet and swap it with the packet in _pendingEditPackets
@ -307,7 +307,7 @@ void OctreeEditPacketSender::releaseQueuedMessages() {
void OctreeEditPacketSender::releaseQueuedPacket(const QUuid& nodeID, std::unique_ptr<NLPacket> packet) {
_releaseQueuedPacketMutex.lock();
if (packet->getSizeUsed() > 0 && packet->getType() != PacketType::Unknown) {
if (packet->getPayloadSize() > 0 && packet->getType() != PacketType::Unknown) {
queuePacketToNode(nodeID, std::move(packet));
}
_releaseQueuedPacketMutex.unlock();

View file

@ -90,7 +90,7 @@ void OctreeRenderer::processDatagram(NLPacket& packet, SharedNodePointer sourceN
qCDebug(octree, "OctreeRenderer::processDatagram() ... Got Packet Section"
" color:%s compressed:%s sequence: %u flight:%d usec size:%lld data:%lld",
debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed),
sequence, flightTime, packet.getSizeWithHeader(), packet.bytesAvailable());
sequence, flightTime, packet.getDataSize(), packet.bytesLeftToRead());
}
_packetsInLastWindow++;
@ -108,16 +108,16 @@ void OctreeRenderer::processDatagram(NLPacket& packet, SharedNodePointer sourceN
bool error = false;
while (packet.bytesAvailable() > 0 && !error) {
while (packet.bytesLeftToRead() > 0 && !error) {
if (packetIsCompressed) {
if (packet.bytesAvailable() > (qint64) sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE)) {
if (packet.bytesLeftToRead() > (qint64) sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE)) {
packet.readPrimitive(&sectionLength);
} else {
sectionLength = 0;
error = true;
}
} else {
sectionLength = packet.bytesAvailable();
sectionLength = packet.bytesLeftToRead();
}
if (sectionLength) {
@ -139,7 +139,7 @@ void OctreeRenderer::processDatagram(NLPacket& packet, SharedNodePointer sourceN
" color:%s compressed:%s sequence: %u flight:%d usec size:%lld data:%lld"
" subsection:%d sectionLength:%d uncompressed:%d",
debug::valueOf(packetIsColored), debug::valueOf(packetIsCompressed),
sequence, flightTime, packet.getSizeWithHeader(), packet.bytesAvailable(), subsection, sectionLength,
sequence, flightTime, packet.getDataSize(), packet.bytesLeftToRead(), subsection, sectionLength,
packetData.getUncompressedSize());
}

View file

@ -439,7 +439,7 @@ int OctreeSceneStats::packIntoPacket() {
_statsPacket->writePrimitive(bytes);
}
return _statsPacket->getSizeUsed();
return _statsPacket->getPayloadSize();
}
int OctreeSceneStats::unpackFromPacket(NLPacket& packet) {
@ -789,8 +789,8 @@ void OctreeSceneStats::trackIncomingOctreePacket(NLPacket& packet, bool wasStats
// track packets here...
_incomingPacket++;
_incomingBytes += packet.getSizeWithHeader();
_incomingBytes += packet.getDataSize();
if (!wasStatsPacket) {
_incomingWastedBytes += (MAX_PACKET_SIZE - packet.getSizeWithHeader());
_incomingWastedBytes += (MAX_PACKET_SIZE - packet.getDataSize());
}
}

View file

@ -10,7 +10,14 @@ target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS})
add_dependency_external_projects(bullet)
find_package(Bullet REQUIRED)
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
# perform the system include hack for OS X to ignore warnings
if (APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${BULLET_INCLUDE_DIRS}")
else()
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
endif()
target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES})
link_hifi_libraries(shared fbx entities)

View file

@ -205,9 +205,9 @@ int Environment::processPacket(NLPacket& packet) {
EnvironmentData newData;
while (packet.bytesAvailable() > 0) {
while (packet.bytesLeftToRead() > 0) {
int dataLength = newData.parseData(reinterpret_cast<const unsigned char*>(packet.getPayload() + packet.pos()),
packet.bytesAvailable());
packet.bytesLeftToRead());
packet.seek(packet.pos() + dataLength);
// update the mapping by address/ID

View file

@ -18,7 +18,7 @@
#include <QBuffer>
#include <QFile>
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdouble-promotion"
#endif
@ -29,7 +29,7 @@
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

View file

@ -109,7 +109,7 @@ void testPropertyFlags(uint32_t value) {
}
QByteArray encoded = original.encode();
#ifndef QT_NO_DEBUG
auto originalSize = encoded.size();
int originalSize = encoded.size();
#endif
for (size_t i = 0; i < enumSize; ++i) {
encoded.append(qrand());
@ -123,7 +123,7 @@ void testPropertyFlags(uint32_t value) {
{
#ifndef QT_NO_DEBUG
auto decodeSize = decodeNew.decode((const uint8_t*)encoded.data(), encoded.size());
int decodeSize = decodeNew.decode((const uint8_t*)encoded.data(), encoded.size());
#endif
Q_ASSERT(originalSize == decodeSize);
Q_ASSERT(decodeNew == original);

View file

@ -8,11 +8,17 @@ macro (SETUP_TESTCASE_DEPENDENCIES)
add_dependency_external_projects(bullet)
find_package(Bullet REQUIRED)
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES})
# perform the system include hack for OS X to ignore warnings
if (APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${BULLET_INCLUDE_DIRS}")
else()
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
endif()
link_hifi_libraries(shared physics)
copy_dlls_beside_windows_executable()
endmacro ()
setup_hifi_testcase(Script)
setup_hifi_testcase(Script)