Update OctreePacketProcessor to use packet callbacks

This commit is contained in:
Ryan Huffman 2015-07-09 09:23:50 -07:00
parent 1b5d526444
commit 3b7ad982a4
2 changed files with 55 additions and 9 deletions

View file

@ -16,6 +16,44 @@
#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()");

View file

@ -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