From 04c4dabd3d14010b03727aa95edea946f621f076 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 20 Sep 2013 14:35:25 -0700 Subject: [PATCH] unblock socket receive in Agent, add destructive voxel add to VS scripting --- assignment-client/src/Agent.cpp | 4 +++- assignment-client/src/main.cpp | 3 +++ .../src/voxels/VoxelScriptingInterface.cpp | 17 ++++++++++++++++- .../src/voxels/VoxelScriptingInterface.h | 12 ++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 5ba022d3a6..aa9bfae31f 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -23,6 +23,8 @@ void Agent::run() { NodeList::getInstance()->setOwnerType(NODE_TYPE_AGENT); NodeList::getInstance()->setNodeTypesOfInterest(&NODE_TYPE_VOXEL_SERVER, 1); + NodeList::getInstance()->getNodeSocket()->setBlocking(false); + QNetworkAccessManager manager; // figure out the URL for the script for this agent assignment @@ -83,7 +85,7 @@ void Agent::run() { // flush the voxel packet queue voxelScripter.getVoxelPacketSender()->process(); - if (NodeList::getInstance()->getNodeSocket()->receive((sockaddr*) &senderAddress, receivedData, &receivedBytes)) { + while (NodeList::getInstance()->getNodeSocket()->receive((sockaddr*) &senderAddress, receivedData, &receivedBytes)) { NodeList::getInstance()->processNodeData((sockaddr*) &senderAddress, receivedData, receivedBytes); } diff --git a/assignment-client/src/main.cpp b/assignment-client/src/main.cpp index 9c106ab79a..1777599c3b 100644 --- a/assignment-client/src/main.cpp +++ b/assignment-client/src/main.cpp @@ -103,6 +103,9 @@ void childClient() { nodeList->setOwnerType(NODE_TYPE_UNASSIGNED); nodeList->reset(); + // set the NodeList socket back to blocking + nodeList->getNodeSocket()->setBlocking(true); + // reset the logging target to the the CHILD_TARGET_NAME Logging::setTargetName(CHILD_TARGET_NAME); } diff --git a/assignment-client/src/voxels/VoxelScriptingInterface.cpp b/assignment-client/src/voxels/VoxelScriptingInterface.cpp index 343cb01a44..0335dde221 100644 --- a/assignment-client/src/voxels/VoxelScriptingInterface.cpp +++ b/assignment-client/src/voxels/VoxelScriptingInterface.cpp @@ -8,8 +8,23 @@ #include "VoxelScriptingInterface.h" +void VoxelScriptingInterface::queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDetail& addVoxelDetails) { + _voxelPacketSender.sendVoxelEditMessage(addPacketType, addVoxelDetails); +} + void VoxelScriptingInterface::queueVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue) { // setup a VoxelDetail struct with the data VoxelDetail addVoxelDetail = {x, y, z, scale, red, green, blue}; - _voxelPacketSender.sendVoxelEditMessage(PACKET_TYPE_SET_VOXEL, addVoxelDetail); + + // queue the packet + queueVoxelAdd(PACKET_TYPE_SET_VOXEL, addVoxelDetail); +} + +void VoxelScriptingInterface::queueDesctructiveVoxelAdd(float x, float y, float z, float scale, + uchar red, uchar green, uchar blue) { + // setup a VoxelDetail struct with the data + VoxelDetail addVoxelDetail = {x, y, z, scale, red, green, blue}; + + // queue the destructive add + queueVoxelAdd(PACKET_TYPE_SET_VOXEL_DESTRUCTIVE, addVoxelDetail); } diff --git a/assignment-client/src/voxels/VoxelScriptingInterface.h b/assignment-client/src/voxels/VoxelScriptingInterface.h index 00be3d536f..00d1b065f0 100644 --- a/assignment-client/src/voxels/VoxelScriptingInterface.h +++ b/assignment-client/src/voxels/VoxelScriptingInterface.h @@ -28,9 +28,21 @@ public slots: /// \param green the G value for RGB color of voxel /// \param blue the B value for RGB color of voxel void queueVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); + + /// queues the destructive 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) + /// \param y the y-coordinate of the voxel (in VS space) + /// \param z the z-coordinate of the voxel (in VS space) + /// \param scale the scale of the voxel (in VS space) + /// \param red the R value for RGB color of voxel + /// \param green the G value for RGB color of voxel + /// \param blue the B value for RGB color of voxel + void queueDesctructiveVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); private: /// attached VoxelEditPacketSender that handles queuing and sending of packets to VS VoxelEditPacketSender _voxelPacketSender; + + void queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDetail& addVoxelDetails); }; #endif /* defined(__hifi__VoxelScriptingInterface__) */