From c1080bca1aa21342f286d0b553dbe31f49280ea3 Mon Sep 17 00:00:00 2001 From: Eric Johnston Date: Wed, 10 Jul 2013 11:32:18 -0700 Subject: [PATCH 1/9] Added a read me with instructions on installing the Leap libraries. --- interface/external/Leap/readme.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 interface/external/Leap/readme.txt diff --git a/interface/external/Leap/readme.txt b/interface/external/Leap/readme.txt new file mode 100644 index 0000000000..e69de29bb2 From ca8f25955a923affe42a19bfce89015b07fd7f12 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 10 Jul 2013 11:46:48 -0700 Subject: [PATCH 2/9] switch usec timestamps to uint64_t --- animation-server/src/main.cpp | 6 ++--- audio-mixer/src/main.cpp | 4 +-- domain-server/src/main.cpp | 2 +- eve/src/main.cpp | 2 +- interface/src/Application.cpp | 4 +-- interface/src/VoxelSystem.cpp | 12 ++++----- interface/src/Webcam.cpp | 4 +-- interface/src/Webcam.h | 4 +-- libraries/audio/src/AudioInjector.cpp | 2 +- libraries/audio/src/AudioInjector.h | 2 +- libraries/shared/src/Node.h | 12 ++++----- libraries/shared/src/NodeList.cpp | 7 ++--- libraries/shared/src/PerfStat.cpp | 2 +- libraries/shared/src/PerfStat.h | 2 +- libraries/shared/src/SharedUtil.cpp | 4 +-- libraries/shared/src/SharedUtil.h | 4 +-- libraries/shared/src/SimpleMovingAverage.h | 2 +- libraries/voxels/src/VoxelNode.h | 4 +-- voxel-server/src/VoxelNodeData.h | 6 ++--- voxel-server/src/main.cpp | 30 +++++++++++----------- 20 files changed, 58 insertions(+), 57 deletions(-) diff --git a/animation-server/src/main.cpp b/animation-server/src/main.cpp index 8a3d70d83d..963d8f73b8 100644 --- a/animation-server/src/main.cpp +++ b/animation-server/src/main.cpp @@ -643,14 +643,14 @@ void* animateVoxels(void* args) { sendDanceFloor(); } - long long end = usecTimestampNow(); - long long elapsedSeconds = (end - ::start) / 1000000; + uint64_t end = usecTimestampNow(); + int 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 - long long usecToSleep = ANIMATE_VOXELS_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime)); + uint64_t 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 26f4bb23f8..68d66ac7ac 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -47,7 +47,7 @@ const unsigned short MIXER_LISTEN_PORT = 55443; const short JITTER_BUFFER_MSECS = 12; const short JITTER_BUFFER_SAMPLES = JITTER_BUFFER_MSECS * (SAMPLE_RATE / 1000.0); -const long long BUFFER_SEND_INTERVAL_USECS = floorf((BUFFER_LENGTH_SAMPLES_PER_CHANNEL / SAMPLE_RATE) * 1000000); +const unsigned int BUFFER_SEND_INTERVAL_USECS = floorf((BUFFER_LENGTH_SAMPLES_PER_CHANNEL / SAMPLE_RATE) * 1000000); const long MAX_SAMPLE_VALUE = std::numeric_limits::max(); const long MIN_SAMPLE_VALUE = std::numeric_limits::min(); @@ -412,7 +412,7 @@ int main(int argc, const char* argv[]) { numStatCollections++; } - long long usecToSleep = usecTimestamp(&startTime) + (++nextFrame * BUFFER_SEND_INTERVAL_USECS) - usecTimestampNow(); + int 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 6fd5fae887..b4174d986f 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -159,7 +159,7 @@ int main(int argc, const char * argv[]) } // update last receive to now - long long timeNow = usecTimestampNow(); + uint64_t timeNow = usecTimestampNow(); newNode->setLastHeardMicrostamp(timeNow); if (packetData[0] == PACKET_HEADER_DOMAIN_REPORT_FOR_DUTY diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 8a03dc453b..5e7eb5d541 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; - long long numMicrosecondsSleep = 0; + int numMicrosecondsSleep = 0; int handStateTimer = 0; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5a0b45960e..5368e43e6f 100755 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -903,7 +903,7 @@ void Application::wheelEvent(QWheelEvent* event) { void Application::sendPingPackets() { char nodeTypesOfInterest[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER}; - long long currentTime = usecTimestampNow(); + uint64_t currentTime = usecTimestampNow(); unsigned char pingPacket[1 + sizeof(currentTime)]; pingPacket[0] = PACKET_HEADER_PING; @@ -2429,7 +2429,7 @@ void Application::displayOverlay() { // Show on-screen msec timer if (_renderFrameTimerOn->isChecked()) { char frameTimer[10]; - long long mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5); + uint64_t 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 97c3e4bcd5..00b8e7486c 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -168,15 +168,15 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { void VoxelSystem::setupNewVoxelsForDrawing() { PerformanceWarning warn(_renderWarningsOn, "setupNewVoxelsForDrawing()"); // would like to include _voxelsInArrays, _voxelsUpdated - long long start = usecTimestampNow(); - long long sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000; + uint64_t start = usecTimestampNow(); + int 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 } - long long sinceLastViewCulling = (start - _lastViewCulling) / 1000; + int 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()) { @@ -192,7 +192,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { // VBO reubuilding. Possibly we should do this only if our actual VBO usage crosses some lower boundary. cleanupRemovedVoxels(); - long long endViewCulling = usecTimestampNow(); + uint64_t endViewCulling = usecTimestampNow(); _lastViewCullingElapsed = (endViewCulling - start) / 1000; } @@ -229,8 +229,8 @@ void VoxelSystem::setupNewVoxelsForDrawing() { pthread_mutex_unlock(&_bufferWriteLock); - long long end = usecTimestampNow(); - long long elapsedmsec = (end - start) / 1000; + uint64_t end = usecTimestampNow(); + int elapsedmsec = (end - start) / 1000; _setupNewVoxelsForDrawingLastFinished = end; _setupNewVoxelsForDrawingLastElapsed = elapsedmsec; } diff --git a/interface/src/Webcam.cpp b/interface/src/Webcam.cpp index 6c7006c5f4..1a5aa9fa7c 100644 --- a/interface/src/Webcam.cpp +++ b/interface/src/Webcam.cpp @@ -191,8 +191,8 @@ void Webcam::setFrame(const Mat& frame, int format, const Mat& depth, const Rota const int MAX_FPS = 60; const int MIN_FRAME_DELAY = 1000000 / MAX_FPS; - long long now = usecTimestampNow(); - long long remaining = MIN_FRAME_DELAY; + uint64_t now = usecTimestampNow(); + int remaining = MIN_FRAME_DELAY; if (_startTimestamp == 0) { _startTimestamp = now; } else { diff --git a/interface/src/Webcam.h b/interface/src/Webcam.h index f0910c7bce..c39f8660da 100644 --- a/interface/src/Webcam.h +++ b/interface/src/Webcam.h @@ -73,10 +73,10 @@ private: cv::RotatedRect _initialFaceRect; JointVector _joints; - long long _startTimestamp; + uint64_t _startTimestamp; int _frameCount; - long long _lastFrameTimestamp; + uint64_t _lastFrameTimestamp; glm::vec3 _estimatedPosition; glm::vec3 _estimatedRotation; diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index 16c381a036..d97ea8abdd 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)); - long long usecToSleep = usecTimestamp(&startTime) + (++nextFrame * INJECT_INTERVAL_USECS) - usecTimestampNow(); + int usecToSleep = usecTimestamp(&startTime) + (++nextFrame * INJECT_INTERVAL_USECS) - usecTimestampNow(); if (usecToSleep > 0) { usleep(usecToSleep); } diff --git a/libraries/audio/src/AudioInjector.h b/libraries/audio/src/AudioInjector.h index 29ff920317..875bc815ce 100644 --- a/libraries/audio/src/AudioInjector.h +++ b/libraries/audio/src/AudioInjector.h @@ -21,7 +21,7 @@ const int STREAM_IDENTIFIER_NUM_BYTES = 8; const int MAX_INJECTOR_VOLUME = 0xFF; -const long long INJECT_INTERVAL_USECS = floorf((BUFFER_LENGTH_SAMPLES_PER_CHANNEL / SAMPLE_RATE) * 1000000); +const int INJECT_INTERVAL_USECS = floorf((BUFFER_LENGTH_SAMPLES_PER_CHANNEL / SAMPLE_RATE) * 1000000); class AudioInjector { public: diff --git a/libraries/shared/src/Node.h b/libraries/shared/src/Node.h index 7bafbd5b58..de43558b7a 100644 --- a/libraries/shared/src/Node.h +++ b/libraries/shared/src/Node.h @@ -37,11 +37,11 @@ public: uint16_t getNodeID() const { return _nodeID; } void setNodeID(uint16_t nodeID) { _nodeID = nodeID;} - long long getWakeMicrostamp() const { return _wakeMicrostamp; } - void setWakeMicrostamp(long long wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; } + uint64_t getWakeMicrostamp() const { return _wakeMicrostamp; } + void setWakeMicrostamp(uint64_t wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; } - long long getLastHeardMicrostamp() const { return _lastHeardMicrostamp; } - void setLastHeardMicrostamp(long long lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; } + uint64_t getLastHeardMicrostamp() const { return _lastHeardMicrostamp; } + void setLastHeardMicrostamp(uint64_t lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; } sockaddr* getPublicSocket() const { return _publicSocket; } void setPublicSocket(sockaddr* publicSocket) { _publicSocket = publicSocket; } @@ -74,8 +74,8 @@ private: char _type; uint16_t _nodeID; - long long _wakeMicrostamp; - long long _lastHeardMicrostamp; + uint64_t _wakeMicrostamp; + uint64_t _lastHeardMicrostamp; sockaddr* _publicSocket; sockaddr* _localSocket; sockaddr* _activeSocket; diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 832c81cd24..75fa0ed1d9 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -81,7 +81,7 @@ void NodeList::timePingReply(sockaddr *nodeAddress, unsigned char *packetData) { for(NodeList::iterator node = begin(); node != end(); node++) { if (socketMatch(node->getPublicSocket(), nodeAddress) || socketMatch(node->getLocalSocket(), nodeAddress)) { - int pingTime = usecTimestampNow() - *(long long *)(packetData + 1); + int pingTime = usecTimestampNow() - *(uint64_t *)(packetData + 1); node->setPingMs(pingTime / 1000); break; } @@ -422,7 +422,7 @@ void *pingUnknownNodes(void *args) { } } - long long usecToSleep = PING_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSend)); + int usecToSleep = PING_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSend)); if (usecToSleep > 0) { usleep(usecToSleep); @@ -443,7 +443,8 @@ void NodeList::stopPingUnknownNodesThread() { void *removeSilentNodes(void *args) { NodeList* nodeList = (NodeList*) args; - long long checkTimeUSecs, sleepTime; + uint64_t checkTimeUSecs; + int sleepTime; while (!silentNodeThreadStopFlag) { checkTimeUSecs = usecTimestampNow(); diff --git a/libraries/shared/src/PerfStat.cpp b/libraries/shared/src/PerfStat.cpp index c376cfcb3e..3cf272ecf8 100644 --- a/libraries/shared/src/PerfStat.cpp +++ b/libraries/shared/src/PerfStat.cpp @@ -105,7 +105,7 @@ int PerfStat::DumpStats(char** array) { // Destructor handles recording all of our stats PerformanceWarning::~PerformanceWarning() { - long long end = usecTimestampNow(); + uint64_t 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 d39c1f31fb..22eb5d38b5 100644 --- a/libraries/shared/src/PerfStat.h +++ b/libraries/shared/src/PerfStat.h @@ -85,7 +85,7 @@ typedef std::map >::iterator class PerformanceWarning { private: - long long _start; + uint64_t _start; const char* _message; bool _renderWarningsOn; bool _alwaysDisplay; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index bdc35ff3f5..4aef5d8a6a 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -22,11 +22,11 @@ #include #endif -long long usecTimestamp(timeval *time) { +uint64_t usecTimestamp(timeval *time) { return (time->tv_sec * 1000000 + time->tv_usec); } -long long usecTimestampNow() { +uint64_t usecTimestampNow() { timeval now; gettimeofday(&now, NULL); return (now.tv_sec * 1000000 + now.tv_usec); diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 2c9e1e6317..dd9e0c1446 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; -long long usecTimestamp(timeval *time); -long long usecTimestampNow(); +uint64_t usecTimestamp(timeval *time); +uint64_t usecTimestampNow(); float randFloat(); int randIntInRange (int min, int max); diff --git a/libraries/shared/src/SimpleMovingAverage.h b/libraries/shared/src/SimpleMovingAverage.h index 7c8605db5d..2d23400f7b 100644 --- a/libraries/shared/src/SimpleMovingAverage.h +++ b/libraries/shared/src/SimpleMovingAverage.h @@ -26,7 +26,7 @@ public: float getAverageSampleValuePerSecond(); private: int _numSamples; - long long _lastEventTimestamp; + uint64_t _lastEventTimestamp; float _average; float _eventDeltaAverage; diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index 4aa64f019e..284821c3bd 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -29,7 +29,7 @@ private: #endif glBufferIndex _glBufferIndex; bool _isDirty; - long long _lastChanged; + uint64_t _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(long long time) const { return (_lastChanged > time); }; + bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); }; void markWithChangedTime() { _lastChanged = usecTimestampNow(); }; void handleSubtreeChanged(VoxelTree* myTree); diff --git a/voxel-server/src/VoxelNodeData.h b/voxel-server/src/VoxelNodeData.h index ded4093f41..48ddee8aa4 100644 --- a/voxel-server/src/VoxelNodeData.h +++ b/voxel-server/src/VoxelNodeData.h @@ -50,8 +50,8 @@ public: bool getViewSent() const { return _viewSent; }; void setViewSent(bool viewSent) { _viewSent = viewSent; } - long long getLastTimeBagEmpty() const { return _lastTimeBagEmpty; }; - void setLastTimeBagEmpty(long long lastTimeBagEmpty) { _lastTimeBagEmpty = lastTimeBagEmpty; }; + uint64_t getLastTimeBagEmpty() const { return _lastTimeBagEmpty; }; + void setLastTimeBagEmpty(uint64_t lastTimeBagEmpty) { _lastTimeBagEmpty = lastTimeBagEmpty; }; private: @@ -67,7 +67,7 @@ private: int _maxLevelReachedInLastSearch; ViewFrustum _currentViewFrustum; ViewFrustum _lastKnownViewFrustum; - long long _lastTimeBagEmpty; + uint64_t _lastTimeBagEmpty; }; diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 64a4565b6c..4901ea27d3 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 long long VOXEL_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds +const int VOXEL_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds const int VOXEL_LISTEN_PORT = 40106; @@ -119,7 +119,7 @@ void resInVoxelDistributor(NodeList* nodeList, bool searchReset = false; int searchLoops = 0; int searchLevelWas = nodeData->getMaxSearchLevel(); - long long start = usecTimestampNow(); + uint64_t start = usecTimestampNow(); while (!searchReset && nodeData->nodeBag.isEmpty()) { searchLoops++; @@ -138,7 +138,7 @@ void resInVoxelDistributor(NodeList* nodeList, } } } - long long end = usecTimestampNow(); + uint64_t end = usecTimestampNow(); int elapsedmsec = (end - start)/1000; if (elapsedmsec > 100) { if (elapsedmsec > 1000) { @@ -162,7 +162,7 @@ void resInVoxelDistributor(NodeList* nodeList, int packetsSentThisInterval = 0; int truePacketsSent = 0; int trueBytesSent = 0; - long long start = usecTimestampNow(); + uint64_t start = usecTimestampNow(); bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS); while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) { @@ -209,7 +209,7 @@ void resInVoxelDistributor(NodeList* nodeList, trueBytesSent += envPacketLength; truePacketsSent++; } - long long end = usecTimestampNow(); + uint64_t end = usecTimestampNow(); int elapsedmsec = (end - start)/1000; if (elapsedmsec > 100) { if (elapsedmsec > 1000) { @@ -248,7 +248,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, pthread_mutex_lock(&::treeLock); int maxLevelReached = 0; - long long start = usecTimestampNow(); + uint64_t start = usecTimestampNow(); // FOR NOW... node tells us if it wants to receive only view frustum deltas bool wantDelta = nodeData->getWantDelta(); @@ -267,7 +267,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, if (::debugVoxelSending) { printf("(viewFrustumChanged=%s || nodeData->nodeBag.isEmpty() =%s)...\n", debug::valueOf(viewFrustumChanged), debug::valueOf(nodeData->nodeBag.isEmpty())); - long long now = usecTimestampNow(); + uint64_t now = usecTimestampNow(); if (nodeData->getLastTimeBagEmpty() > 0) { float elapsedSceneSend = (now - nodeData->getLastTimeBagEmpty()) / 1000000.0f; @@ -306,7 +306,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, } } - long long end = usecTimestampNow(); + uint64_t end = usecTimestampNow(); int elapsedmsec = (end - start)/1000; if (elapsedmsec > 100) { if (elapsedmsec > 1000) { @@ -329,12 +329,12 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, int packetsSentThisInterval = 0; int truePacketsSent = 0; int trueBytesSent = 0; - long long start = usecTimestampNow(); + uint64_t start = usecTimestampNow(); bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS); while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) { // Check to see if we're taking too long, and if so bail early... - long long now = usecTimestampNow(); + uint64_t now = usecTimestampNow(); long elapsedUsec = (now - start); long elapsedUsecPerPacket = (truePacketsSent == 0) ? 0 : (elapsedUsec / truePacketsSent); long usecRemaining = (VOXEL_SEND_INTERVAL_USECS - elapsedUsec); @@ -396,7 +396,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, truePacketsSent++; } - long long end = usecTimestampNow(); + uint64_t end = usecTimestampNow(); int elapsedmsec = (end - start)/1000; if (elapsedmsec > 100) { if (elapsedmsec > 1000) { @@ -425,10 +425,10 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, pthread_mutex_unlock(&::treeLock); } -long long lastPersistVoxels = 0; +uint64_t lastPersistVoxels = 0; void persistVoxelsWhenDirty() { - long long now = usecTimestampNow(); - long long sinceLastTime = (now - ::lastPersistVoxels) / 1000; + uint64_t now = usecTimestampNow(); + int sinceLastTime = (now - ::lastPersistVoxels) / 1000; // check the dirty bit and persist here... if (::wantVoxelPersist && ::serverTree.isDirty() && sinceLastTime > VOXEL_PERSIST_INTERVAL) { @@ -473,7 +473,7 @@ void *distributeVoxelsToListeners(void *args) { } // dynamically sleep until we need to fire off the next set of voxels - long long usecToSleep = VOXEL_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime)); + int usecToSleep = VOXEL_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime)); if (usecToSleep > 0) { usleep(usecToSleep); From 38fe6201a858a7e1c6c33cc26940c2e6bc09f411 Mon Sep 17 00:00:00 2001 From: Eric Johnston Date: Wed, 10 Jul 2013 15:33:28 -0700 Subject: [PATCH 3/9] Added content to read me --- interface/external/Leap/readme.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/interface/external/Leap/readme.txt b/interface/external/Leap/readme.txt index e69de29bb2..24a79299c0 100644 --- a/interface/external/Leap/readme.txt +++ b/interface/external/Leap/readme.txt @@ -0,0 +1,11 @@ + +Instructions for adding the Leap driver to Interface +Eric Johnston, July 10, 2013 + +NOTE: Without doing step 2, you will crash at program start time. + +1. Copy the Leap sdk folders (lib, include, etc.) into the interface/external/Leap folder. There should be a folder already there called "stub", and this read me.txt should be there as well. + +2. IMPORTANT: Copy the file interface/external/Leap/lib/libc++/libLeap.dylib to /usr/lib + +3. Delete your build directory, run cmake and build, and you should be all set. From d8f368a50c1aa6a23fe71f1bc1d693e8f1b7f83a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 10 Jul 2013 16:06:23 -0700 Subject: [PATCH 4/9] lazy load stars file only if stars render enabled --- interface/src/Application.cpp | 6 +++--- interface/src/Stars.cpp | 5 +++-- interface/src/Stars.h | 3 +++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6480a39539..10fc5c4cfd 100755 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1682,8 +1682,6 @@ void Application::init() { _headMouseX = _mouseX = _glWidget->width() / 2; _headMouseY = _mouseY = _glWidget->height() / 2; - _stars.readInput(STAR_FILE, STAR_CACHE_FILE, 0); - _myAvatar.init(); _myAvatar.setPosition(START_LOCATION); _myCamera.setMode(CAMERA_MODE_FIRST_PERSON); @@ -1709,7 +1707,6 @@ void Application::init() { printLog("Loaded settings.\n"); - sendAvatarVoxelURLMessage(_myAvatar.getVoxels()->getVoxelURL()); _palette.init(_glWidget->width(), _glWidget->height()); @@ -2275,6 +2272,9 @@ void Application::displaySide(Camera& whichCamera) { glMateriali(GL_FRONT, GL_SHININESS, 96); if (_renderStarsOn->isChecked()) { + if (!_stars.getFileLoaded()) { + _stars.readInput(STAR_FILE, STAR_CACHE_FILE, 0); + } // should be the first rendering pass - w/o depth buffer / lighting // compute starfield alpha based on distance from atmosphere diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index 7934190e4c..e663ef33bd 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -14,7 +14,7 @@ #undef __interface__Starfield_impl__ Stars::Stars() : - _controller(0l) { + _controller(0l), _fileLoaded(false) { _controller = new starfield::Controller; } @@ -23,7 +23,8 @@ Stars::~Stars() { } bool Stars::readInput(const char* url, const char* cacheFile, unsigned limit) { - return _controller->readInput(url, cacheFile, limit); + _fileLoaded = _controller->readInput(url, cacheFile, limit); + return _fileLoaded; } bool Stars::setResolution(unsigned k) { diff --git a/interface/src/Stars.h b/interface/src/Stars.h index ac2abcde42..83d55d3766 100644 --- a/interface/src/Stars.h +++ b/interface/src/Stars.h @@ -65,6 +65,7 @@ class Stars { float changeLOD(float factor, float overalloc = 0.25, float realloc = 0.15); + bool getFileLoaded() const { return _fileLoaded; }; private: // don't copy/assign Stars(Stars const&); // = delete; @@ -73,6 +74,8 @@ class Stars { // variables starfield::Controller* _controller; + + bool _fileLoaded; }; From 1439b47e846052079da993d9907100e464193e1e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 10 Jul 2013 16:09:45 -0700 Subject: [PATCH 5/9] only get boundary distance once, since its the same for all grandchildren --- libraries/voxels/src/VoxelTree.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 207573b860..0df9ff0885 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -1284,6 +1284,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp if (params.viewFrustum && childNode->isColored() && !childNode->isLeaf()) { int grandChildrenInView = 0; int grandChildrenInLOD = 0; + float grandChildBoundaryDistance = boundaryDistanceForRenderLevel(childNode->getLevel() + 2); for (int grandChildIndex = 0; grandChildIndex < NUMBER_OF_CHILDREN; grandChildIndex++) { VoxelNode* grandChild = childNode->getChildAtIndex(grandChildIndex); @@ -1291,7 +1292,6 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp grandChildrenInView++; float grandChildDistance = grandChild->distanceToCamera(*params.viewFrustum); - float grandChildBoundaryDistance = boundaryDistanceForRenderLevel(grandChild->getLevel() + 1); if (grandChildDistance < grandChildBoundaryDistance) { grandChildrenInLOD++; } From d59b9ce955303b78a140c2bb38d46672adab7e42 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 10 Jul 2013 17:31:21 -0700 Subject: [PATCH 6/9] Flip x when in mirror mode, rather than special-casing all the head rotations. Also fixed sideways leaning (was correct in mirror mode, incorrect in world). --- interface/src/Application.cpp | 9 +++++++++ interface/src/Avatar.cpp | 4 ++-- interface/src/Head.cpp | 13 +++++-------- interface/src/Head.h | 3 +-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ae9466dabe..3b44799e69 100755 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2246,6 +2246,15 @@ void Application::displayOculus(Camera& whichCamera) { void Application::displaySide(Camera& whichCamera) { // transform by eye offset + // flip x if in mirror mode (also requires reversing winding order for backface culling) + if (_lookingInMirror->isChecked()) { + glScalef(-1.0f, 1.0f, 1.0f); + glFrontFace(GL_CW); + + } else { + glFrontFace(GL_CCW); + } + glm::vec3 eyeOffsetPos = whichCamera.getEyeOffsetPosition(); glm::quat eyeOffsetOrient = whichCamera.getEyeOffsetOrientation(); glm::vec3 eyeOffsetAxis = glm::axis(eyeOffsetOrient); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 00bf65fd7d..426aad57b3 100755 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -324,7 +324,7 @@ void Avatar::updateFromGyrosAndOrWebcam(bool gyroLook, const glm::vec3& amplifyA // Update torso lean distance based on accelerometer data const float TORSO_LENGTH = 0.5f; const float MAX_LEAN = 45.0f; - _head.setLeanSideways(glm::clamp(glm::degrees(atanf(-estimatedPosition.x * _leanScale / TORSO_LENGTH)), + _head.setLeanSideways(glm::clamp(glm::degrees(atanf(estimatedPosition.x * _leanScale / TORSO_LENGTH)), -MAX_LEAN, MAX_LEAN)); _head.setLeanForward(glm::clamp(glm::degrees(atanf(estimatedPosition.z * _leanScale / TORSO_LENGTH)), -MAX_LEAN, MAX_LEAN)); @@ -1222,7 +1222,7 @@ void Avatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) { // Always render other people, and render myself when beyond threshold distance if (b == BODY_BALL_HEAD_BASE) { // the head is rendered as a special if (alpha > 0.0f) { - _head.render(lookingInMirror, alpha); + _head.render(alpha); } } else if (alpha > 0.0f) { // Render the body ball sphere diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 39f0da3ca9..8b116b48ff 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -67,7 +67,6 @@ Head::Head(Avatar* owningAvatar) : _audioAttack(0.0f), _returnSpringScale(1.0f), _bodyRotation(0.0f, 0.0f, 0.0f), - _lookingInMirror(false), _renderLookatVectors(false), _mohawkTriangleFan(NULL), _mohawkColors(NULL), @@ -283,11 +282,10 @@ void Head::calculateGeometry() { } -void Head::render(bool lookingInMirror, float alpha) { +void Head::render(float alpha) { _renderAlpha = alpha; - _lookingInMirror = lookingInMirror; - + calculateGeometry(); glEnable(GL_DEPTH_TEST); @@ -375,8 +373,8 @@ void Head::renderMohawk() { } else { glPushMatrix(); glTranslatef(_position.x, _position.y, _position.z); - glRotatef((_lookingInMirror ? (_bodyRotation.y - _yaw) : (_bodyRotation.y + _yaw)), 0, 1, 0); - glRotatef(_lookingInMirror ? _roll: -_roll, 0, 0, 1); + glRotatef(_bodyRotation.y + _yaw, 0, 1, 0); + glRotatef(-_roll, 0, 0, 1); glRotatef(-_pitch - _bodyRotation.x, 1, 0, 0); glBegin(GL_TRIANGLE_FAN); @@ -391,8 +389,7 @@ void Head::renderMohawk() { } glm::quat Head::getOrientation() const { - return glm::quat(glm::radians(_bodyRotation)) * glm::quat(glm::radians(_lookingInMirror ? - glm::vec3(_pitch, -_yaw, -_roll) : glm::vec3(_pitch, _yaw, _roll))); + return glm::quat(glm::radians(_bodyRotation)) * glm::quat(glm::radians(glm::vec3(_pitch, _yaw, _roll))); } glm::quat Head::getCameraOrientation () const { diff --git a/interface/src/Head.h b/interface/src/Head.h index e8bcfb5277..2b1b7aabfb 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -35,7 +35,7 @@ public: void init(); void reset(); void simulate(float deltaTime, bool isMine); - void render(bool lookingInMirror, float alpha); + void render(float alpha); void renderMohawk(); void setScale (float scale ) { _scale = scale; } @@ -102,7 +102,6 @@ private: float _audioAttack; float _returnSpringScale; //strength of return springs glm::vec3 _bodyRotation; - bool _lookingInMirror; bool _renderLookatVectors; HairTuft _hairTuft[NUM_HAIR_TUFTS]; glm::vec3* _mohawkTriangleFan; From cbf18160cb040cab53cbaa4ad330f15d42d6ab63 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Jul 2013 09:22:08 -0700 Subject: [PATCH 7/9] include stdint for uint64_t in SimpleMovingAverage --- libraries/shared/src/SimpleMovingAverage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/SimpleMovingAverage.h b/libraries/shared/src/SimpleMovingAverage.h index 2d23400f7b..e8a6bc22d0 100644 --- a/libraries/shared/src/SimpleMovingAverage.h +++ b/libraries/shared/src/SimpleMovingAverage.h @@ -11,7 +11,7 @@ #ifndef __hifi__Stats__ #define __hifi__Stats__ -#include +#include class SimpleMovingAverage { public: From ca0f6a4d105a1b66491a3674a4a07ff2bf8e2004 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Jul 2013 09:30:45 -0700 Subject: [PATCH 8/9] header re-arranging and changing --- animation-server/src/main.cpp | 10 ++++++---- libraries/voxels/src/SceneUtils.cpp | 7 +++++-- libraries/voxels/src/SquarePixelMap.cpp | 9 ++++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/animation-server/src/main.cpp b/animation-server/src/main.cpp index 963d8f73b8..8123fa439c 100644 --- a/animation-server/src/main.cpp +++ b/animation-server/src/main.cpp @@ -10,14 +10,16 @@ #include #include #include -#include +#include + +#include #include #include -#include -#include -#include +#include #include #include +#include +#include #ifdef _WIN32 #include "Syssocket.h" diff --git a/libraries/voxels/src/SceneUtils.cpp b/libraries/voxels/src/SceneUtils.cpp index da92734350..bd126ebf31 100644 --- a/libraries/voxels/src/SceneUtils.cpp +++ b/libraries/voxels/src/SceneUtils.cpp @@ -3,12 +3,15 @@ // hifi // // Created by Brad Hefta-Gaub on 5/7/2013. -// +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. // -#include "SceneUtils.h" +#include + #include +#include "SceneUtils.h" + void addCornersAndAxisLines(VoxelTree* tree) { // We want our corner voxels to be about 1/2 meter high, and our TREE_SCALE is in meters, so... float voxelSize = 0.5f / TREE_SCALE; diff --git a/libraries/voxels/src/SquarePixelMap.cpp b/libraries/voxels/src/SquarePixelMap.cpp index bdc97624a7..f37bee4757 100644 --- a/libraries/voxels/src/SquarePixelMap.cpp +++ b/libraries/voxels/src/SquarePixelMap.cpp @@ -3,12 +3,15 @@ // hifi // // Created by Tomáš Horáček on 6/25/13. -// +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. // -#include "SquarePixelMap.h" -#include +#include +#include #include +#include + +#include "SquarePixelMap.h" #define CHILD_COORD_X_IS_1 0x1 #define CHILD_COORD_Y_IS_1 0x2 From dc264c98ec4d3cb59f829f244f9d148c499fcc8d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Jul 2013 09:38:55 -0700 Subject: [PATCH 9/9] delete a function accidentally added on merge --- voxel-server/src/main.cpp | 126 -------------------------------------- 1 file changed, 126 deletions(-) diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 4e90df2646..f38b82886d 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -110,132 +110,6 @@ void eraseVoxelTreeAndCleanupNodeVisitData() { } } - -// Version of voxel distributor that sends each LOD level at a time -void resInVoxelDistributor(NodeList* nodeList, - NodeList::iterator& node, - VoxelNodeData* nodeData) { - ViewFrustum viewFrustum = nodeData->getCurrentViewFrustum(); - bool searchReset = false; - int searchLoops = 0; - int searchLevelWas = nodeData->getMaxSearchLevel(); - uint64_t start = usecTimestampNow(); - while (!searchReset && nodeData->nodeBag.isEmpty()) { - searchLoops++; - - searchLevelWas = nodeData->getMaxSearchLevel(); - int maxLevelReached = serverTree.searchForColoredNodes(nodeData->getMaxSearchLevel(), serverTree.rootNode, - viewFrustum, nodeData->nodeBag); - nodeData->setMaxLevelReached(maxLevelReached); - - // If nothing got added, then we bump our levels. - if (nodeData->nodeBag.isEmpty()) { - if (nodeData->getMaxLevelReached() < nodeData->getMaxSearchLevel()) { - nodeData->resetMaxSearchLevel(); - searchReset = true; - } else { - nodeData->incrementMaxSearchLevel(); - } - } - } - uint64_t end = usecTimestampNow(); - int elapsedmsec = (end - start)/1000; - if (elapsedmsec > 100) { - if (elapsedmsec > 1000) { - int elapsedsec = (end - start)/1000000; - printf("WARNING! searchForColoredNodes() took %d seconds to identify %d nodes at level %d in %d loops\n", - elapsedsec, nodeData->nodeBag.count(), searchLevelWas, searchLoops); - } else { - printf("WARNING! searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d in %d loops\n", - elapsedmsec, nodeData->nodeBag.count(), searchLevelWas, searchLoops); - } - } else if (::debugVoxelSending) { - printf("searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d in %d loops\n", - elapsedmsec, nodeData->nodeBag.count(), searchLevelWas, searchLoops); - } - - - // If we have something in our nodeBag, then turn them into packets and send them out... - if (!nodeData->nodeBag.isEmpty()) { - static unsigned char tempOutputBuffer[MAX_VOXEL_PACKET_SIZE - 1]; // save on allocs by making this static - int bytesWritten = 0; - int packetsSentThisInterval = 0; - int truePacketsSent = 0; - int trueBytesSent = 0; - uint64_t start = usecTimestampNow(); - - bool shouldSendEnvironments = shouldDo(ENVIRONMENT_SEND_INTERVAL_USECS, VOXEL_SEND_INTERVAL_USECS); - while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) { - if (!nodeData->nodeBag.isEmpty()) { - VoxelNode* subTree = nodeData->nodeBag.extract(); - - EncodeBitstreamParams params(nodeData->getMaxSearchLevel(), &viewFrustum, - nodeData->getWantColor(), WANT_EXISTS_BITS); - - bytesWritten = serverTree.encodeTreeBitstream(subTree, &tempOutputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, - nodeData->nodeBag, params); - - if (nodeData->getAvailable() >= bytesWritten) { - nodeData->writeToPacket(&tempOutputBuffer[0], bytesWritten); - } else { - nodeList->getNodeSocket()->send(node->getActiveSocket(), - nodeData->getPacket(), nodeData->getPacketLength()); - trueBytesSent += nodeData->getPacketLength(); - truePacketsSent++; - packetsSentThisInterval++; - nodeData->resetVoxelPacket(); - nodeData->writeToPacket(&tempOutputBuffer[0], bytesWritten); - } - } else { - if (nodeData->isPacketWaiting()) { - nodeList->getNodeSocket()->send(node->getActiveSocket(), - nodeData->getPacket(), nodeData->getPacketLength()); - trueBytesSent += nodeData->getPacketLength(); - truePacketsSent++; - nodeData->resetVoxelPacket(); - - } - packetsSentThisInterval = PACKETS_PER_CLIENT_PER_INTERVAL; // done for now, no nodes left - } - } - // send the environment packets - if (shouldSendEnvironments) { - int envPacketLength = 1; - *tempOutputBuffer = PACKET_HEADER_ENVIRONMENT_DATA; - for (int i = 0; i < sizeof(environmentData) / sizeof(environmentData[0]); i++) { - envPacketLength += environmentData[i].getBroadcastData(tempOutputBuffer + envPacketLength); - } - nodeList->getNodeSocket()->send(node->getActiveSocket(), tempOutputBuffer, envPacketLength); - trueBytesSent += envPacketLength; - truePacketsSent++; - } - uint64_t end = usecTimestampNow(); - int elapsedmsec = (end - start)/1000; - if (elapsedmsec > 100) { - if (elapsedmsec > 1000) { - 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, nodeData->nodeBag.count()); - } else { - 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, nodeData->nodeBag.count()); - } - } else if (::debugVoxelSending) { - 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, nodeData->nodeBag.count()); - } - - // if during this last pass, we emptied our bag, then we want to move to the next level. - if (nodeData->nodeBag.isEmpty()) { - if (nodeData->getMaxLevelReached() < nodeData->getMaxSearchLevel()) { - nodeData->resetMaxSearchLevel(); - } else { - nodeData->incrementMaxSearchLevel(); - } - } - } -} - pthread_mutex_t treeLock; // Version of voxel distributor that sends the deepest LOD level at once