From db729a04aa953668d993dd9e93e02402e397e760 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 13 Jun 2013 11:11:59 -0700 Subject: [PATCH 1/2] Converted double timestamps to long long (64 bit integers), fixed bug with updating agent timestamps. --- animation-server/src/main.cpp | 6 +- audio-mixer/src/main.cpp | 2 +- domain-server/src/main.cpp | 56 +++++++++--------- eve/src/main.cpp | 4 +- injector/src/main.cpp | 2 +- interface/src/Application.cpp | 5 +- interface/src/VoxelSystem.cpp | 14 ++--- libraries/audio/src/AudioInjector.cpp | 2 +- libraries/shared/src/Agent.cpp | 2 + libraries/shared/src/Agent.h | 12 ++-- libraries/shared/src/AgentList.cpp | 6 +- libraries/shared/src/PerfStat.cpp | 2 +- libraries/shared/src/PerfStat.h | 2 +- libraries/shared/src/SharedUtil.cpp | 8 +-- libraries/shared/src/SharedUtil.h | 4 +- libraries/shared/src/SimpleMovingAverage.h | 2 +- libraries/voxels/src/VoxelNode.h | 4 +- voxel-server/src/main.cpp | 66 +++++++++++----------- 18 files changed, 99 insertions(+), 100 deletions(-) diff --git a/animation-server/src/main.cpp b/animation-server/src/main.cpp index c02e8e8383..bceb276a8a 100644 --- a/animation-server/src/main.cpp +++ b/animation-server/src/main.cpp @@ -644,14 +644,14 @@ void* animateVoxels(void* args) { sendDanceFloor(); } - double end = usecTimestampNow(); - double elapsedSeconds = (end - ::start) / 1000000.0; + long long end = usecTimestampNow(); + long long elapsedSeconds = (end - ::start) / 1000000; if (::shouldShowPacketsPerSecond) { printf("packetsSent=%ld, bytesSent=%ld pps=%f bps=%f\n",packetsSent,bytesSent, (float)(packetsSent/elapsedSeconds),(float)(bytesSent/elapsedSeconds)); } // dynamically sleep until we need to fire off the next set of voxels - double usecToSleep = ANIMATE_VOXELS_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime)); + long long usecToSleep = ANIMATE_VOXELS_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime)); if (usecToSleep > 0) { usleep(usecToSleep); diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index c9ea474354..fbcba0979f 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -318,7 +318,7 @@ int main(int argc, const char* argv[]) { } } - double usecToSleep = usecTimestamp(&startTime) + (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - usecTimestampNow(); + long long usecToSleep = usecTimestamp(&startTime) + (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - usecTimestampNow(); if (usecToSleep > 0) { usleep(usecToSleep); diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index d84dd64a1b..67c1123205 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -133,37 +133,26 @@ int main(int argc, const char * argv[]) if (numInterestTypes > 0) { // if the agent has sent no types of interest, assume they want nothing but their own ID back for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - if (!agent->matches((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType)) { - if (memchr(agentTypesOfInterest, agent->getType(), numInterestTypes)) { - // this is not the agent themselves - // and this is an agent of a type in the passed agent types of interest - // or the agent did not pass us any specific types they are interested in - - if (memchr(SOLO_AGENT_TYPES, agent->getType(), sizeof(SOLO_AGENT_TYPES)) == NULL) { - // this is an agent of which there can be multiple, just add them to the packet - // don't send avatar agents to other avatars, that will come from avatar mixer - if (agentType != AGENT_TYPE_AVATAR || agent->getType() != AGENT_TYPE_AVATAR) { - currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent)); - } - - } else { - // solo agent, we need to only send newest - if (newestSoloAgents[agent->getType()] == NULL || - newestSoloAgents[agent->getType()]->getWakeMicrostamp() < agent->getWakeMicrostamp()) { - // we have to set the newer solo agent to add it to the broadcast later - newestSoloAgents[agent->getType()] = &(*agent); - } + if (!agent->matches((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType) && + memchr(agentTypesOfInterest, agent->getType(), numInterestTypes)) { + // this is not the agent themselves + // and this is an agent of a type in the passed agent types of interest + // or the agent did not pass us any specific types they are interested in + + if (memchr(SOLO_AGENT_TYPES, agent->getType(), sizeof(SOLO_AGENT_TYPES)) == NULL) { + // this is an agent of which there can be multiple, just add them to the packet + // don't send avatar agents to other avatars, that will come from avatar mixer + if (agentType != AGENT_TYPE_AVATAR || agent->getType() != AGENT_TYPE_AVATAR) { + currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent)); } - } - } else { - double timeNow = usecTimestampNow(); - // this is the agent, just update last receive to now - agent->setLastHeardMicrostamp(timeNow); - - if (packetData[0] == PACKET_HEADER_DOMAIN_REPORT_FOR_DUTY - && memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES))) { - agent->setWakeMicrostamp(timeNow); + } else { + // solo agent, we need to only send newest + if (newestSoloAgents[agent->getType()] == NULL || + newestSoloAgents[agent->getType()]->getWakeMicrostamp() < agent->getWakeMicrostamp()) { + // we have to set the newer solo agent to add it to the broadcast later + newestSoloAgents[agent->getType()] = &(*agent); + } } } } @@ -175,6 +164,15 @@ int main(int argc, const char * argv[]) currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, soloAgent->second); } } + + // update last receive to now + long long timeNow = usecTimestampNow(); + newAgent->setLastHeardMicrostamp(timeNow); + + if (packetData[0] == PACKET_HEADER_DOMAIN_REPORT_FOR_DUTY + && memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES))) { + newAgent->setWakeMicrostamp(timeNow); + } // add the agent ID to the end of the pointer currentBufferPos += packAgentId(currentBufferPos, newAgent->getAgentID()); diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 387c72633b..9310e2b316 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -128,7 +128,7 @@ int main(int argc, const char* argv[]) { broadcastPacket[0] = PACKET_HEADER_HEAD_DATA; timeval thisSend; - double numMicrosecondsSleep = 0; + long long numMicrosecondsSleep = 0; int handStateTimer = 0; @@ -212,4 +212,4 @@ int main(int argc, const char* argv[]) { // stop the agent list's threads agentList->stopPingUnknownAgentsThread(); agentList->stopSilentAgentRemovalThread(); -} \ No newline at end of file +} diff --git a/injector/src/main.cpp b/injector/src/main.cpp index f2e87990d1..a0c07179f7 100644 --- a/injector/src/main.cpp +++ b/injector/src/main.cpp @@ -187,7 +187,7 @@ int main(int argc, char* argv[]) { unsigned char broadcastPacket = PACKET_HEADER_INJECT_AUDIO; timeval thisSend; - double numMicrosecondsSleep = 0; + long long numMicrosecondsSleep = 0; timeval lastDomainServerCheckIn = {}; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d864fb86dd..e69e40f527 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2078,9 +2078,8 @@ void Application::displayOverlay() { // Show on-screen msec timer if (_renderFrameTimerOn->isChecked()) { char frameTimer[10]; - double mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5); - mSecsNow = mSecsNow - floor(mSecsNow / 1000.0) * 1000.0; - sprintf(frameTimer, "%3.0f\n", mSecsNow); + long long mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5); + sprintf(frameTimer, "%d\n", (int)(mSecsNow % 1000)); drawtext(_glWidget->width() - 100, _glWidget->height() - 20, 0.30, 0, 1.0, 0, frameTimer, 0, 0, 0); drawtext(_glWidget->width() - 102, _glWidget->height() - 22, 0.30, 0, 1.0, 0, frameTimer, 1, 1, 1); } diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 9cde8906be..716fe708a3 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -165,15 +165,15 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { void VoxelSystem::setupNewVoxelsForDrawing() { PerformanceWarning warn(_renderWarningsOn, "setupNewVoxelsForDrawing()"); // would like to include _voxelsInArrays, _voxelsUpdated - double start = usecTimestampNow(); - double sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000.0; + long long start = usecTimestampNow(); + long long sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000; bool iAmDebugging = false; // if you're debugging set this to true, so you won't get skipped for slow debugging if (!iAmDebugging && sinceLastTime <= std::max(_setupNewVoxelsForDrawingLastElapsed, SIXTY_FPS_IN_MILLISECONDS)) { return; // bail early, it hasn't been long enough since the last time we ran } - double sinceLastViewCulling = (start - _lastViewCulling) / 1000.0; + long long sinceLastViewCulling = (start - _lastViewCulling) / 1000; // If the view frustum is no longer changing, but has changed, since last time, then remove nodes that are out of view if ((sinceLastViewCulling >= std::max(_lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS)) && !isViewChanging() && hasViewChanged()) { @@ -189,8 +189,8 @@ void VoxelSystem::setupNewVoxelsForDrawing() { // VBO reubuilding. Possibly we should do this only if our actual VBO usage crosses some lower boundary. cleanupRemovedVoxels(); - double endViewCulling = usecTimestampNow(); - _lastViewCullingElapsed = (endViewCulling - start) / 1000.0; + long long endViewCulling = usecTimestampNow(); + _lastViewCullingElapsed = (endViewCulling - start) / 1000; } bool didWriteFullVBO = _writeRenderFullVBO; @@ -226,8 +226,8 @@ void VoxelSystem::setupNewVoxelsForDrawing() { pthread_mutex_unlock(&_bufferWriteLock); - double end = usecTimestampNow(); - double elapsedmsec = (end - start) / 1000.0; + long long end = usecTimestampNow(); + long long elapsedmsec = (end - start) / 1000; _setupNewVoxelsForDrawingLastFinished = end; _setupNewVoxelsForDrawingLastElapsed = elapsedmsec; } diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index f9f1bcc094..24e0a369d5 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -115,7 +115,7 @@ void AudioInjector::injectAudio(UDPSocket* injectorSocket, sockaddr* destination injectorSocket->send(destinationSocket, dataPacket, sizeof(dataPacket)); - double usecToSleep = usecTimestamp(&startTime) + (++nextFrame * INJECT_INTERVAL_USECS) - usecTimestampNow(); + long long usecToSleep = usecTimestamp(&startTime) + (++nextFrame * INJECT_INTERVAL_USECS) - usecTimestampNow(); if (usecToSleep > 0) { usleep(usecToSleep); } diff --git a/libraries/shared/src/Agent.cpp b/libraries/shared/src/Agent.cpp index 4556f670d6..88d0f901f2 100644 --- a/libraries/shared/src/Agent.cpp +++ b/libraries/shared/src/Agent.cpp @@ -6,6 +6,8 @@ // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. // +#include "stdio.h" + #include #include "Agent.h" #include "AgentTypes.h" diff --git a/libraries/shared/src/Agent.h b/libraries/shared/src/Agent.h index 5201fd9048..18d42fdf3d 100644 --- a/libraries/shared/src/Agent.h +++ b/libraries/shared/src/Agent.h @@ -37,11 +37,11 @@ public: uint16_t getAgentID() const { return _agentID; } void setAgentID(uint16_t agentID) { _agentID = agentID;} - double getWakeMicrostamp() const { return _wakeMicrostamp; } - void setWakeMicrostamp(double wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; } + long long getWakeMicrostamp() const { return _wakeMicrostamp; } + void setWakeMicrostamp(long long wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; } - double getLastHeardMicrostamp() const { return _lastHeardMicrostamp; } - void setLastHeardMicrostamp(double lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; } + long long getLastHeardMicrostamp() const { return _lastHeardMicrostamp; } + void setLastHeardMicrostamp(long long lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; } sockaddr* getPublicSocket() const { return _publicSocket; } void setPublicSocket(sockaddr* publicSocket) { _publicSocket = publicSocket; } @@ -71,8 +71,8 @@ private: char _type; uint16_t _agentID; - double _wakeMicrostamp; - double _lastHeardMicrostamp; + long long _wakeMicrostamp; + long long _lastHeardMicrostamp; sockaddr* _publicSocket; sockaddr* _localSocket; sockaddr* _activeSocket; diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 56641bd2a0..e1b4bd9d63 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -392,7 +392,7 @@ void *pingUnknownAgents(void *args) { } } - double usecToSleep = PING_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSend)); + long long usecToSleep = PING_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSend)); if (usecToSleep > 0) { usleep(usecToSleep); @@ -413,7 +413,7 @@ void AgentList::stopPingUnknownAgentsThread() { void *removeSilentAgents(void *args) { AgentList* agentList = (AgentList*) args; - double checkTimeUSecs, sleepTime; + long long checkTimeUSecs, sleepTime; while (!silentAgentThreadStopFlag) { checkTimeUSecs = usecTimestampNow(); @@ -422,7 +422,7 @@ void *removeSilentAgents(void *args) { if ((checkTimeUSecs - agent->getLastHeardMicrostamp()) > AGENT_SILENCE_THRESHOLD_USECS && agent->getType() != AGENT_TYPE_VOXEL_SERVER) { - + printLog("Killed "); Agent::printLog(*agent); diff --git a/libraries/shared/src/PerfStat.cpp b/libraries/shared/src/PerfStat.cpp index 3c30c62993..2de5aa2816 100644 --- a/libraries/shared/src/PerfStat.cpp +++ b/libraries/shared/src/PerfStat.cpp @@ -104,7 +104,7 @@ int PerfStat::DumpStats(char** array) { // Destructor handles recording all of our stats PerformanceWarning::~PerformanceWarning() { - double end = usecTimestampNow(); + long long end = usecTimestampNow(); double elapsedmsec = (end - _start) / 1000.0; if ((_alwaysDisplay || _renderWarningsOn) && elapsedmsec > 1) { if (elapsedmsec > 1000) { diff --git a/libraries/shared/src/PerfStat.h b/libraries/shared/src/PerfStat.h index 8898899960..f57d49aa46 100644 --- a/libraries/shared/src/PerfStat.h +++ b/libraries/shared/src/PerfStat.h @@ -84,7 +84,7 @@ typedef std::map >::iterator class PerformanceWarning { private: - double _start; + long long _start; const char* _message; bool _renderWarningsOn; bool _alwaysDisplay; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index 697719b36d..0ec2c6e302 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -22,14 +22,14 @@ #include #endif -double usecTimestamp(timeval *time) { - return (time->tv_sec * 1000000.0 + time->tv_usec); +long long usecTimestamp(timeval *time) { + return (time->tv_sec * 1000000 + time->tv_usec); } -double usecTimestampNow() { +long long usecTimestampNow() { timeval now; gettimeofday(&now, NULL); - return (now.tv_sec * 1000000.0 + now.tv_usec); + return (now.tv_sec * 1000000 + now.tv_usec); } float randFloat () { diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 28c4adb296..e227137470 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -36,8 +36,8 @@ static const float DECIMETER = 0.1f; static const float CENTIMETER = 0.01f; static const float MILLIIMETER = 0.001f; -double usecTimestamp(timeval *time); -double usecTimestampNow(); +long long usecTimestamp(timeval *time); +long long usecTimestampNow(); float randFloat(); int randIntInRange (int min, int max); diff --git a/libraries/shared/src/SimpleMovingAverage.h b/libraries/shared/src/SimpleMovingAverage.h index e24b639133..b1d0709342 100644 --- a/libraries/shared/src/SimpleMovingAverage.h +++ b/libraries/shared/src/SimpleMovingAverage.h @@ -25,7 +25,7 @@ public: float getAverageSampleValuePerSecond(); private: int _numSamples; - double _lastEventTimestamp; + long long _lastEventTimestamp; float _average; float _eventDeltaAverage; diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index 952ad15bb7..8f71ef64f1 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -29,7 +29,7 @@ private: #endif glBufferIndex _glBufferIndex; bool _isDirty; - double _lastChanged; + long long _lastChanged; bool _shouldRender; bool _isStagedForDeletion; AABox _box; @@ -80,7 +80,7 @@ public: void printDebugDetails(const char* label) const; bool isDirty() const { return _isDirty; }; void clearDirtyBit() { _isDirty = false; }; - bool hasChangedSince(double time) const { return (_lastChanged > time); }; + bool hasChangedSince(long long time) const { return (_lastChanged > time); }; void markWithChangedTime() { _lastChanged = usecTimestampNow(); }; void handleSubtreeChanged(VoxelTree* myTree); diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 1f6a386eda..aae631bb16 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -32,7 +32,7 @@ const char* LOCAL_VOXELS_PERSIST_FILE = "resources/voxels.svo"; const char* VOXELS_PERSIST_FILE = "/etc/highfidelity/voxel-server/resources/voxels.svo"; -const double VOXEL_PERSIST_INTERVAL = 1000.0 * 30; // every 30 seconds +const long long VOXEL_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds const int VOXEL_LISTEN_PORT = 40106; @@ -118,7 +118,7 @@ void resInVoxelDistributor(AgentList* agentList, bool searchReset = false; int searchLoops = 0; int searchLevelWas = agentData->getMaxSearchLevel(); - double start = usecTimestampNow(); + long long start = usecTimestampNow(); while (!searchReset && agentData->nodeBag.isEmpty()) { searchLoops++; @@ -137,19 +137,19 @@ void resInVoxelDistributor(AgentList* agentList, } } } - double end = usecTimestampNow(); - double elapsedmsec = (end - start)/1000.0; + long long end = usecTimestampNow(); + int elapsedmsec = (end - start)/1000; if (elapsedmsec > 100) { if (elapsedmsec > 1000) { - double elapsedsec = (end - start)/1000000.0; - printf("WARNING! searchForColoredNodes() took %lf seconds to identify %d nodes at level %d in %d loops\n", + int elapsedsec = (end - start)/1000000; + printf("WARNING! searchForColoredNodes() took %d seconds to identify %d nodes at level %d in %d loops\n", elapsedsec, agentData->nodeBag.count(), searchLevelWas, searchLoops); } else { - printf("WARNING! searchForColoredNodes() took %lf milliseconds to identify %d nodes at level %d in %d loops\n", + printf("WARNING! searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d in %d loops\n", elapsedmsec, agentData->nodeBag.count(), searchLevelWas, searchLoops); } } else if (::debugVoxelSending) { - printf("searchForColoredNodes() took %lf milliseconds to identify %d nodes at level %d in %d loops\n", + printf("searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d in %d loops\n", elapsedmsec, agentData->nodeBag.count(), searchLevelWas, searchLoops); } @@ -161,7 +161,7 @@ void resInVoxelDistributor(AgentList* agentList, int packetsSentThisInterval = 0; int truePacketsSent = 0; int trueBytesSent = 0; - double start = usecTimestampNow(); + long long start = usecTimestampNow(); bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS); while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) { @@ -206,19 +206,19 @@ void resInVoxelDistributor(AgentList* agentList, trueBytesSent += envPacketLength; truePacketsSent++; } - double end = usecTimestampNow(); - double elapsedmsec = (end - start)/1000.0; + long long end = usecTimestampNow(); + int elapsedmsec = (end - start)/1000; if (elapsedmsec > 100) { if (elapsedmsec > 1000) { - double elapsedsec = (end - start)/1000000.0; - printf("WARNING! packetLoop() took %lf seconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n", + int elapsedsec = (end - start)/1000000; + printf("WARNING! packetLoop() took %d seconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n", elapsedsec, trueBytesSent, truePacketsSent, searchLevelWas, agentData->nodeBag.count()); } else { - printf("WARNING! packetLoop() took %lf milliseconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n", + printf("WARNING! packetLoop() took %d milliseconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n", elapsedmsec, trueBytesSent, truePacketsSent, searchLevelWas, agentData->nodeBag.count()); } } else if (::debugVoxelSending) { - printf("packetLoop() took %lf milliseconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n", + printf("packetLoop() took %d milliseconds to generate %d bytes in %d packets at level %d, %d nodes still to send\n", elapsedmsec, trueBytesSent, truePacketsSent, searchLevelWas, agentData->nodeBag.count()); } @@ -245,7 +245,7 @@ void deepestLevelVoxelDistributor(AgentList* agentList, pthread_mutex_lock(&::treeLock); int maxLevelReached = 0; - double start = usecTimestampNow(); + long long start = usecTimestampNow(); // FOR NOW... agent tells us if it wants to receive only view frustum deltas bool wantDelta = agentData->getWantDelta(); @@ -281,19 +281,19 @@ void deepestLevelVoxelDistributor(AgentList* agentList, } } - double end = usecTimestampNow(); - double elapsedmsec = (end - start)/1000.0; + long long end = usecTimestampNow(); + int elapsedmsec = (end - start)/1000; if (elapsedmsec > 100) { if (elapsedmsec > 1000) { - double elapsedsec = (end - start)/1000000.0; - printf("WARNING! searchForColoredNodes() took %lf seconds to identify %d nodes at level %d\n", + int elapsedsec = (end - start)/1000000; + printf("WARNING! searchForColoredNodes() took %d seconds to identify %d nodes at level %d\n", elapsedsec, agentData->nodeBag.count(), maxLevelReached); } else { - printf("WARNING! searchForColoredNodes() took %lf milliseconds to identify %d nodes at level %d\n", + printf("WARNING! searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d\n", elapsedmsec, agentData->nodeBag.count(), maxLevelReached); } } else if (::debugVoxelSending) { - printf("searchForColoredNodes() took %lf milliseconds to identify %d nodes at level %d\n", + printf("searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d\n", elapsedmsec, agentData->nodeBag.count(), maxLevelReached); } @@ -304,7 +304,7 @@ void deepestLevelVoxelDistributor(AgentList* agentList, int packetsSentThisInterval = 0; int truePacketsSent = 0; int trueBytesSent = 0; - double start = usecTimestampNow(); + long long start = usecTimestampNow(); bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS); while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) { @@ -351,19 +351,19 @@ void deepestLevelVoxelDistributor(AgentList* agentList, truePacketsSent++; } - double end = usecTimestampNow(); - double elapsedmsec = (end - start)/1000.0; + long long end = usecTimestampNow(); + int elapsedmsec = (end - start)/1000; if (elapsedmsec > 100) { if (elapsedmsec > 1000) { - double elapsedsec = (end - start)/1000000.0; - printf("WARNING! packetLoop() took %lf seconds to generate %d bytes in %d packets %d nodes still to send\n", + int elapsedsec = (end - start)/1000000; + printf("WARNING! packetLoop() took %d seconds to generate %d bytes in %d packets %d nodes still to send\n", elapsedsec, trueBytesSent, truePacketsSent, agentData->nodeBag.count()); } else { - printf("WARNING! packetLoop() took %lf milliseconds to generate %d bytes in %d packets, %d nodes still to send\n", + printf("WARNING! packetLoop() took %d milliseconds to generate %d bytes in %d packets, %d nodes still to send\n", elapsedmsec, trueBytesSent, truePacketsSent, agentData->nodeBag.count()); } } else if (::debugVoxelSending) { - printf("packetLoop() took %lf milliseconds to generate %d bytes in %d packets, %d nodes still to send\n", + printf("packetLoop() took %d milliseconds to generate %d bytes in %d packets, %d nodes still to send\n", elapsedmsec, trueBytesSent, truePacketsSent, agentData->nodeBag.count()); } @@ -380,10 +380,10 @@ void deepestLevelVoxelDistributor(AgentList* agentList, pthread_mutex_unlock(&::treeLock); } -double lastPersistVoxels = 0; +long long lastPersistVoxels = 0; void persistVoxelsWhenDirty() { - double now = usecTimestampNow(); - double sinceLastTime = (now - ::lastPersistVoxels) / 1000.0; + long long now = usecTimestampNow(); + long long sinceLastTime = (now - ::lastPersistVoxels) / 1000; // check the dirty bit and persist here... if (::wantVoxelPersist && ::serverTree.isDirty() && sinceLastTime > VOXEL_PERSIST_INTERVAL) { @@ -428,7 +428,7 @@ void *distributeVoxelsToListeners(void *args) { } // dynamically sleep until we need to fire off the next set of voxels - double usecToSleep = VOXEL_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime)); + long long usecToSleep = VOXEL_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime)); if (usecToSleep > 0) { usleep(usecToSleep); From b57a78c414f76d6c877e362b66645a2696bedceb Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 13 Jun 2013 13:15:08 -0700 Subject: [PATCH 2/2] Another fix: using strlen to determine the length of the packet is... unwise. Remember the length when we create it. This should fix the voxel server's not appearing. --- libraries/shared/src/AgentList.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index e1b4bd9d63..7a4803586e 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -205,6 +205,7 @@ void AgentList::sendDomainServerCheckIn() { // construct the DS check in packet if we need to static unsigned char* checkInPacket = NULL; + static int checkInPacketSize; if (!checkInPacket) { int numBytesAgentsOfInterest = _agentTypesOfInterest ? strlen((char*) _agentTypesOfInterest) : 0; @@ -236,10 +237,10 @@ void AgentList::sendDomainServerCheckIn() { packetPosition += numBytesAgentsOfInterest; } - *packetPosition = '\0'; + checkInPacketSize = packetPosition - checkInPacket; } - _agentSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, checkInPacket, strlen((char*) checkInPacket)); + _agentSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, checkInPacket, checkInPacketSize); } int AgentList::processDomainServerList(unsigned char *packetData, size_t dataBytes) {