From 4773e70c152f9fbcabae2c9a4471d6a770bfe336 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 9 Jul 2013 17:13:21 -0700 Subject: [PATCH] rewrite Operative stubbed code to be able to be killed --- interface/src/Application.cpp | 0 libraries/shared/src/Operative.cpp | 24 +++++++++++++++++------- libraries/shared/src/Operative.h | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) mode change 100755 => 100644 interface/src/Application.cpp diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp old mode 100755 new mode 100644 diff --git a/libraries/shared/src/Operative.cpp b/libraries/shared/src/Operative.cpp index c84093f5e9..6440e0eb8e 100644 --- a/libraries/shared/src/Operative.cpp +++ b/libraries/shared/src/Operative.cpp @@ -89,7 +89,7 @@ const BugPart bugParts[VOXELS_PER_BUG] = { BugPart(glm::vec3(-2, -1, 0), 153, 200, 0) , }; -static void renderMovingBug() { +void removeOldBug() { VoxelDetail details[VOXELS_PER_BUG]; unsigned char* bufferOut; int sizeOut; @@ -118,11 +118,17 @@ static void renderMovingBug() { ::packetsSent++; ::bytesSent += sizeOut; - printf("sending packet of size=%d\n", sizeOut); - NodeList::getInstance()->broadcastToNodes(bufferOut, sizeOut, &NODE_TYPE_VOXEL_SERVER, 1); delete[] bufferOut; } +} + +static void renderMovingBug() { + VoxelDetail details[VOXELS_PER_BUG]; + unsigned char* bufferOut; + int sizeOut; + + removeOldBug(); // Move the bug... if (moveBugInLine) { @@ -181,14 +187,12 @@ static void renderMovingBug() { } // send the "create message" ... - message = PACKET_HEADER_SET_VOXEL_DESTRUCTIVE; + PACKET_HEADER message = PACKET_HEADER_SET_VOXEL_DESTRUCTIVE; if (createVoxelEditMessage(message, 0, VOXELS_PER_BUG, (VoxelDetail*)&details, bufferOut, sizeOut)){ ::packetsSent++; ::bytesSent += sizeOut; - printf("sending packet of size=%d\n", sizeOut); - NodeList::getInstance()->broadcastToNodes(bufferOut, sizeOut, &NODE_TYPE_VOXEL_SERVER, 1); delete[] bufferOut; } @@ -212,8 +216,9 @@ void Operative::run() { // change the owner type on our NodeList NodeList::getInstance()->setOwnerType(NODE_TYPE_AGENT); NodeList::getInstance()->setNodeTypesOfInterest(&NODE_TYPE_VOXEL_SERVER, 1); + NodeList::getInstance()->getNodeSocket()->setBlocking(false); - while (true) { + while (!shouldStop) { gettimeofday(&lastSendTime, NULL); renderMovingBug(); @@ -238,4 +243,9 @@ void Operative::run() { std::cout << "Last send took too much time, not sleeping!\n"; } } + + printf("Removing the old bird and dying.\n"); + + // we've been told to stop, remove the last bug + removeOldBug(); } \ No newline at end of file diff --git a/libraries/shared/src/Operative.h b/libraries/shared/src/Operative.h index a9dbf8bf94..3b0c3fd270 100644 --- a/libraries/shared/src/Operative.h +++ b/libraries/shared/src/Operative.h @@ -11,6 +11,7 @@ class Operative { public: + bool volatile shouldStop; void run(); };