From 7c9b0d8f58eea1ddc8ae96db5b432c69f41874a0 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 7 May 2013 15:10:02 -0700 Subject: [PATCH] Have the voxel server push out an environment packet with its regular updates. --- libraries/voxels/src/EnvironmentData.cpp | 2 ++ voxel-server/src/main.cpp | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/libraries/voxels/src/EnvironmentData.cpp b/libraries/voxels/src/EnvironmentData.cpp index a616715aa8..e951c55c06 100644 --- a/libraries/voxels/src/EnvironmentData.cpp +++ b/libraries/voxels/src/EnvironmentData.cpp @@ -26,6 +26,8 @@ EnvironmentData::EnvironmentData() : int EnvironmentData::getBroadcastData(unsigned char* destinationBuffer) const { unsigned char* bufferStart = destinationBuffer; + *destinationBuffer++ = PACKET_HEADER_ENVIRONMENT_DATA; + memcpy(destinationBuffer, &_atmosphereCenter, sizeof(_atmosphereCenter)); destinationBuffer += sizeof(_atmosphereCenter); diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 380f2cc794..dca2dc49ae 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "VoxelAgentData.h" #include @@ -48,6 +49,8 @@ bool wantVoxelPersist = true; bool wantColorRandomizer = false; bool debugVoxelSending = false; +EnvironmentData environmentData; + void addSphere(VoxelTree * tree,bool random, bool wantColorRandomizer) { float r = random ? randFloatInRange(0.05,0.1) : 0.25; float xc = random ? randFloatInRange(r,(1-r)) : 0.5; @@ -237,7 +240,7 @@ void voxelDistributor(AgentList* agentList, AgentList::iterator& agent, VoxelAge int trueBytesSent = 0; double start = usecTimestampNow(); - while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL) { + while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - 1) { if (!agentData->nodeBag.isEmpty()) { VoxelNode* subTree = agentData->nodeBag.extract(); bytesWritten = randomTree.encodeTreeBitstream(agentData->getMaxSearchLevel(), subTree, @@ -267,6 +270,12 @@ void voxelDistributor(AgentList* agentList, AgentList::iterator& agent, VoxelAge packetsSentThisInterval = PACKETS_PER_CLIENT_PER_INTERVAL; // done for now, no nodes left } } + // send the environment packet + int envPacketLength = environmentData.getBroadcastData(tempOutputBuffer); + agentList->getAgentSocket().send(agent->getActiveSocket(), tempOutputBuffer, envPacketLength); + trueBytesSent += envPacketLength; + truePacketsSent++; + double end = usecTimestampNow(); double elapsedmsec = (end - start)/1000.0; if (elapsedmsec > 100) { @@ -559,4 +568,4 @@ int main(int argc, const char * argv[]) pthread_join(sendVoxelThread, NULL); return 0; -} \ No newline at end of file +}