mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 21:22:52 +02:00
Update OctreePacketProcessor to use packet callbacks
This commit is contained in:
parent
1b5d526444
commit
3b7ad982a4
2 changed files with 55 additions and 9 deletions
|
@ -16,10 +16,48 @@
|
||||||
#include "OctreePacketProcessor.h"
|
#include "OctreePacketProcessor.h"
|
||||||
#include "SceneScriptingInterface.h"
|
#include "SceneScriptingInterface.h"
|
||||||
|
|
||||||
|
OctreePacketProcessor::OctreePacketProcessor() {
|
||||||
|
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||||
|
packetReceiver.registerPacketListener(PacketType::OctreeStats, this, "handleEntityDataPacket");
|
||||||
|
packetReceiver.registerPacketListener(PacketType::EntityData, this, "handleEntityDataPacket");
|
||||||
|
packetReceiver.registerPacketListener(PacketType::EntityErase, this, "handleEntityErasePacket");
|
||||||
|
packetReceiver.registerPacketListener(PacketType::OctreeStats, this, "handleOctreeStatsPacket");
|
||||||
|
packetReceiver.registerPacketListener(PacketType::EnvironmentData, this, "handleEnvironmentDataPacket");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO implement packet processing in PacketType-specific methods
|
||||||
|
void OctreePacketProcessor::handleEntityDataPacket(std::unique_ptr<NLPacket> packet, HifiSockAddr senderSockAddr) {
|
||||||
|
SharedNodePointer sendingNode = DependencyManager::get<NodeList>()->nodeWithUUID(packet->getSourceID());
|
||||||
|
if (sendingNode) {
|
||||||
|
processPacket(sendingNode, QByteArray::fromRawData(packet->getData(), packet->getSizeWithHeader()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OctreePacketProcessor::handleEntityErasePacket(std::unique_ptr<NLPacket> packet, HifiSockAddr senderSockAddr) {
|
||||||
|
SharedNodePointer sendingNode = DependencyManager::get<NodeList>()->nodeWithUUID(packet->getSourceID());
|
||||||
|
if (sendingNode) {
|
||||||
|
processPacket(sendingNode, QByteArray::fromRawData(packet->getData(), packet->getSizeWithHeader()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OctreePacketProcessor::handleOctreeStatsPacket(std::unique_ptr<NLPacket> packet, HifiSockAddr senderSockAddr) {
|
||||||
|
SharedNodePointer sendingNode = DependencyManager::get<NodeList>()->nodeWithUUID(packet->getSourceID());
|
||||||
|
if (sendingNode) {
|
||||||
|
processPacket(sendingNode, QByteArray::fromRawData(packet->getData(), packet->getSizeWithHeader()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OctreePacketProcessor::handleEnvironmentDataPacket(std::unique_ptr<NLPacket> packet, HifiSockAddr senderSockAddr) {
|
||||||
|
SharedNodePointer sendingNode = DependencyManager::get<NodeList>()->nodeWithUUID(packet->getSourceID());
|
||||||
|
if (sendingNode) {
|
||||||
|
processPacket(sendingNode, QByteArray::fromRawData(packet->getData(), packet->getSizeWithHeader()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
|
void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
|
||||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||||
"OctreePacketProcessor::processPacket()");
|
"OctreePacketProcessor::processPacket()");
|
||||||
|
|
||||||
QByteArray mutablePacket = packet;
|
QByteArray mutablePacket = packet;
|
||||||
|
|
||||||
const int WAY_BEHIND = 300;
|
const int WAY_BEHIND = 300;
|
||||||
|
@ -34,7 +72,7 @@ void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode,
|
||||||
|
|
||||||
|
|
||||||
PacketType::Value voxelPacketType = packetTypeForPacket(mutablePacket);
|
PacketType::Value voxelPacketType = packetTypeForPacket(mutablePacket);
|
||||||
|
|
||||||
// note: PacketType_OCTREE_STATS can have PacketType_VOXEL_DATA
|
// note: PacketType_OCTREE_STATS can have PacketType_VOXEL_DATA
|
||||||
// immediately following them inside the same packet. So, we process the PacketType_OCTREE_STATS first
|
// immediately following them inside the same packet. So, we process the PacketType_OCTREE_STATS first
|
||||||
// then process any remaining bytes as if it was another packet
|
// then process any remaining bytes as if it was another packet
|
||||||
|
@ -43,7 +81,7 @@ void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode,
|
||||||
wasStatsPacket = true;
|
wasStatsPacket = true;
|
||||||
if (messageLength > statsMessageLength) {
|
if (messageLength > statsMessageLength) {
|
||||||
mutablePacket = mutablePacket.mid(statsMessageLength);
|
mutablePacket = mutablePacket.mid(statsMessageLength);
|
||||||
|
|
||||||
// TODO: this does not look correct, the goal is to test the packet version for the piggyback, but
|
// TODO: this does not look correct, the goal is to test the packet version for the piggyback, but
|
||||||
// this is testing the version and hash of the original packet
|
// this is testing the version and hash of the original packet
|
||||||
if (!DependencyManager::get<NodeList>()->packetVersionAndHashMatch(packet)) {
|
if (!DependencyManager::get<NodeList>()->packetVersionAndHashMatch(packet)) {
|
||||||
|
@ -54,28 +92,28 @@ void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode,
|
||||||
return; // bail since no piggyback data
|
return; // bail since no piggyback data
|
||||||
}
|
}
|
||||||
} // fall through to piggyback message
|
} // fall through to piggyback message
|
||||||
|
|
||||||
voxelPacketType = packetTypeForPacket(mutablePacket);
|
voxelPacketType = packetTypeForPacket(mutablePacket);
|
||||||
PacketVersion packetVersion = mutablePacket[1];
|
PacketVersion packetVersion = mutablePacket[1];
|
||||||
PacketVersion expectedVersion = versionForPacketType(voxelPacketType);
|
PacketVersion expectedVersion = versionForPacketType(voxelPacketType);
|
||||||
|
|
||||||
// check version of piggyback packet against expected version
|
// check version of piggyback packet against expected version
|
||||||
if (packetVersion != expectedVersion) {
|
if (packetVersion != expectedVersion) {
|
||||||
static QMultiMap<QUuid, PacketType> versionDebugSuppressMap;
|
static QMultiMap<QUuid, PacketType> versionDebugSuppressMap;
|
||||||
|
|
||||||
QUuid senderUUID = uuidFromPacketHeader(packet);
|
QUuid senderUUID = uuidFromPacketHeader(packet);
|
||||||
if (!versionDebugSuppressMap.contains(senderUUID, voxelPacketType)) {
|
if (!versionDebugSuppressMap.contains(senderUUID, voxelPacketType)) {
|
||||||
qDebug() << "Packet version mismatch on" << voxelPacketType << "- Sender"
|
qDebug() << "Packet version mismatch on" << voxelPacketType << "- Sender"
|
||||||
<< senderUUID << "sent" << (int)packetVersion << "but"
|
<< senderUUID << "sent" << (int)packetVersion << "but"
|
||||||
<< (int)expectedVersion << "expected.";
|
<< (int)expectedVersion << "expected.";
|
||||||
|
|
||||||
emit packetVersionMismatch();
|
emit packetVersionMismatch();
|
||||||
|
|
||||||
versionDebugSuppressMap.insert(senderUUID, voxelPacketType);
|
versionDebugSuppressMap.insert(senderUUID, voxelPacketType);
|
||||||
}
|
}
|
||||||
return; // bail since piggyback version doesn't match
|
return; // bail since piggyback version doesn't match
|
||||||
}
|
}
|
||||||
|
|
||||||
app->trackIncomingOctreePacket(mutablePacket, sendingNode, wasStatsPacket);
|
app->trackIncomingOctreePacket(mutablePacket, sendingNode, wasStatsPacket);
|
||||||
|
|
||||||
if (sendingNode) {
|
if (sendingNode) {
|
||||||
|
|
|
@ -16,13 +16,21 @@
|
||||||
|
|
||||||
/// Handles processing of incoming voxel packets for the interface application. As with other ReceivedPacketProcessor classes
|
/// Handles processing of incoming voxel packets for the interface application. As with other ReceivedPacketProcessor classes
|
||||||
/// the user is responsible for reading inbound packets and adding them to the processing queue by calling queueReceivedPacket()
|
/// the user is responsible for reading inbound packets and adding them to the processing queue by calling queueReceivedPacket()
|
||||||
class OctreePacketProcessor : public ReceivedPacketProcessor {
|
class OctreePacketProcessor : public GenericThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
OctreePacketProcessor();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void packetVersionMismatch();
|
void packetVersionMismatch();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet);
|
virtual void processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void handleEntityDataPacket(std::unique_ptr<NLPacket> packet, HifiSockAddr senderSockAddr);
|
||||||
|
void handleEntityErasePacket(std::unique_ptr<NLPacket> packet, HifiSockAddr senderSockAddr);
|
||||||
|
void handleOctreeStatsPacket(std::unique_ptr<NLPacket> packet, HifiSockAddr senderSockAddr);
|
||||||
|
void handleEnvironmentDataPacket(std::unique_ptr<NLPacket> packet, HifiSockAddr senderSockAddr);
|
||||||
};
|
};
|
||||||
#endif // hifi_OctreePacketProcessor_h
|
#endif // hifi_OctreePacketProcessor_h
|
||||||
|
|
Loading…
Reference in a new issue