diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index baf04372d2..ef6a2caa35 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -201,7 +201,13 @@ void Agent::run() { while (NodeList::getInstance()->getNodeSocket()->receive((sockaddr*) &senderAddress, receivedData, &receivedBytes) && packetVersionMatch(receivedData)) { - NodeList::getInstance()->processNodeData((sockaddr*) &senderAddress, receivedData, receivedBytes); + if (receivedData[0] == PACKET_TYPE_VOXEL_JURISDICTION) { + voxelScripter.getJurisdictionListener()->queueReceivedPacket((sockaddr&) senderAddress, + receivedData, + receivedBytes); + } else { + NodeList::getInstance()->processNodeData((sockaddr*) &senderAddress, receivedData, receivedBytes); + } } } diff --git a/assignment-client/src/voxels/VoxelScriptingInterface.cpp b/assignment-client/src/voxels/VoxelScriptingInterface.cpp index e94f87264a..5b1a296aa7 100644 --- a/assignment-client/src/voxels/VoxelScriptingInterface.cpp +++ b/assignment-client/src/voxels/VoxelScriptingInterface.cpp @@ -8,6 +8,11 @@ #include "VoxelScriptingInterface.h" +VoxelScriptingInterface::VoxelScriptingInterface() { + _jurisdictionListener.initialize(true); + _voxelPacketSender.setVoxelServerJurisdictions(_jurisdictionListener.getJurisdictions()); +} + void VoxelScriptingInterface::queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDetail& addVoxelDetails) { _voxelPacketSender.queueVoxelEditMessages(addPacketType, 1, &addVoxelDetails); } @@ -35,4 +40,4 @@ void VoxelScriptingInterface::queueVoxelDelete(float x, float y, float z, float VoxelDetail deleteVoxelDetail = {x, y, z, scale, 0, 0, 0}; _voxelPacketSender.queueVoxelEditMessages(PACKET_TYPE_ERASE_VOXEL, 1, &deleteVoxelDetail); -} +} \ No newline at end of file diff --git a/assignment-client/src/voxels/VoxelScriptingInterface.h b/assignment-client/src/voxels/VoxelScriptingInterface.h index ac1de6928d..a2c18b8018 100644 --- a/assignment-client/src/voxels/VoxelScriptingInterface.h +++ b/assignment-client/src/voxels/VoxelScriptingInterface.h @@ -11,13 +11,17 @@ #include +#include #include /// handles scripting of voxel commands from JS passed to assigned clients class VoxelScriptingInterface : public QObject { Q_OBJECT public: + VoxelScriptingInterface(); + VoxelEditPacketSender* getVoxelPacketSender() { return &_voxelPacketSender; } + JurisdictionListener* getJurisdictionListener() { return &_jurisdictionListener; } public slots: /// queues the creation of a voxel which will be sent by calling process on the PacketSender /// \param x the x-coordinate of the voxel (in VS space) @@ -48,6 +52,7 @@ public slots: private: /// attached VoxelEditPacketSender that handles queuing and sending of packets to VS VoxelEditPacketSender _voxelPacketSender; + JurisdictionListener _jurisdictionListener; void queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDetail& addVoxelDetails); }; diff --git a/libraries/shared/src/PacketSender.cpp b/libraries/shared/src/PacketSender.cpp index ecd92a1f05..0b41a34caf 100644 --- a/libraries/shared/src/PacketSender.cpp +++ b/libraries/shared/src/PacketSender.cpp @@ -74,8 +74,10 @@ bool PacketSender::process() { // we can determine how many packets we need to send per call to achieve our desired // packets per second send rate. int callsPerSecond = USECS_PER_SECOND / averageCallTime; + // make sure our number of calls per second doesn't cause a divide by zero - glm::clamp(callsPerSecond, 1, _packetsPerSecond); + callsPerSecond = glm::clamp(callsPerSecond, 1, _packetsPerSecond); + packetsPerCall = ceil(_packetsPerSecond / callsPerSecond); // send at least one packet per call, if we have it