From 94739cf8d38fb2a62c04cfe7f0518ad411eeed05 Mon Sep 17 00:00:00 2001 From: Stephen Birarda <commit@birarda.com> Date: Fri, 1 May 2015 10:26:53 -0700 Subject: [PATCH] move number constants out of SharedUtil to NumericalConstants --- assignment-client/src/avatars/AvatarMixer.cpp | 23 +++++++--- .../src/avatars/AvatarMixerClientData.cpp | 2 + .../src/avatars/AvatarMixerClientData.h | 8 ++++ .../octree/OctreeInboundPacketProcessor.cpp | 2 + .../src/octree/OctreeSendThread.cpp | 2 +- assignment-client/src/octree/OctreeServer.cpp | 1 + interface/src/LODManager.cpp | 2 +- interface/src/LODManager.h | 6 +-- interface/src/Stars.cpp | 6 ++- interface/src/avatar/Head.h | 2 +- interface/src/devices/DdeFaceTracker.cpp | 1 + interface/src/devices/Faceshift.cpp | 2 +- interface/src/ui/overlays/Overlay.cpp | 3 +- libraries/audio/src/AudioFilter.h | 11 ++--- libraries/audio/src/AudioFilterBank.cpp | 6 --- libraries/audio/src/AudioFilterBank.h | 6 +++ libraries/audio/src/AudioFormat.h | 1 + libraries/audio/src/AudioPan.h | 4 ++ libraries/audio/src/AudioSourceTone.cpp | 8 +--- libraries/audio/src/AudioSourceTone.h | 6 ++- libraries/audio/src/InboundAudioStream.h | 8 ++-- libraries/avatars/src/HandData.h | 2 +- libraries/entities/src/EntityItemProperties.h | 1 + libraries/fbx/src/FBXReader.cpp | 1 + libraries/networking/src/LimitedNodeList.cpp | 7 ++-- libraries/octree/src/OctreePersistThread.cpp | 2 +- libraries/octree/src/OctreeSceneStats.cpp | 2 +- libraries/octree/src/OctreeSceneStats.h | 3 +- libraries/octree/src/ViewFrustum.cpp | 3 +- .../render-utils/src/DeferredLightingEffect.h | 2 +- libraries/render-utils/src/GeometryCache.cpp | 2 +- libraries/render-utils/src/JointState.h | 3 +- libraries/script-engine/src/TouchEvent.cpp | 2 +- libraries/shared/src/AABox.cpp | 4 +- libraries/shared/src/AACube.cpp | 2 +- libraries/shared/src/AACubeShape.cpp | 2 +- libraries/shared/src/AngularConstraint.cpp | 1 + libraries/shared/src/ByteCountCoding.h | 2 +- libraries/shared/src/CapsuleShape.cpp | 2 +- libraries/shared/src/CapsuleShape.h | 2 +- libraries/shared/src/CollisionInfo.cpp | 4 +- libraries/shared/src/GLMHelpers.cpp | 2 + libraries/shared/src/GeometryUtil.cpp | 2 +- libraries/shared/src/NumericalConstants.h | 42 +++++++++++++++++++ libraries/shared/src/OctalCode.cpp | 3 +- libraries/shared/src/PerfStat.cpp | 2 +- libraries/shared/src/PhysicsHelpers.cpp | 2 +- libraries/shared/src/PlaneShape.cpp | 2 +- libraries/shared/src/ShapeCollider.cpp | 1 + libraries/shared/src/ShapeInfo.cpp | 6 +-- libraries/shared/src/SharedUtil.cpp | 1 + libraries/shared/src/SharedUtil.h | 24 ----------- libraries/shared/src/SphereShape.h | 3 +- tests/jitter/src/main.cpp | 1 + tests/physics/src/BulletUtilTests.cpp | 2 +- tests/shared/src/AngularConstraintTests.cpp | 2 +- 56 files changed, 157 insertions(+), 97 deletions(-) create mode 100644 libraries/shared/src/NumericalConstants.h diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 04048672f3..0c7f9fbce1 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -173,8 +173,12 @@ void AvatarMixer::broadcastAvatarData() { // keep a counter of the number of considered avatars int numOtherAvatars = 0; - - float dataRateLastSecond = node->getOutboundBandwidth(); + + // keep track of outbound data rate specifically for avatar data + int numAvatarDataBytes = 0; + + // use the data rate specifically for avatar data for FRD adjustment checks + float avatarDataRateLastSecond = node->getOutboundBandwidth(); // Check if it is time to adjust what we send this client based on the observed // bandwidth to this node. We do this once a second, which is also the window for @@ -183,12 +187,12 @@ void AvatarMixer::broadcastAvatarData() { const float FRD_ADJUSTMENT_ACCEPTABLE_RATIO = 0.8f; - qDebug() << "current node outbound bandwidth is" << dataRateLastSecond; + qDebug() << "current node outbound bandwidth is" << avatarDataRateLastSecond; - if(dataRateLastSecond > _maxKbpsPerNode) { + if (avatarDataRateLastSecond > _maxKbpsPerNode) { qDebug() << "Adjustment down required for avatar" << node->getUUID() << "whose current send rate is" - << dataRateLastSecond; + << avatarDataRateLastSecond; // is the FRD greater than the MAX FRD? if so, before we calculate anything, set it to the MAX FRD float newFullRateDistance = nodeData->getFullRateDistance(); @@ -208,7 +212,7 @@ void AvatarMixer::broadcastAvatarData() { nodeData->resetNumFramesSinceFRDAdjustment(); } else if (nodeData->getFullRateDistance() < nodeData->getMaxFullRateDistance() - && dataRateLastSecond < _maxKbpsPerNode * FRD_ADJUSTMENT_ACCEPTABLE_RATIO) { + && avatarDataRateLastSecond < _maxKbpsPerNode * FRD_ADJUSTMENT_ACCEPTABLE_RATIO) { // we are constrained AND we've recovered to below the acceptable ratio, adjust the FRD upwards // by covering half the distance to the max FRD @@ -276,6 +280,8 @@ void AvatarMixer::broadcastAvatarData() { if (avatarByteArray.size() + mixedAvatarByteArray.size() > MAX_PACKET_SIZE) { nodeList->writeDatagram(mixedAvatarByteArray, node); + + numAvatarDataBytes += mixedAvatarByteArray.size(); // reset the packet mixedAvatarByteArray.resize(numPacketHeaderBytes); @@ -323,7 +329,12 @@ void AvatarMixer::broadcastAvatarData() { ++_sumIdentityPackets; } }); + + // send the last packet nodeList->writeDatagram(mixedAvatarByteArray, node); + + // record the bytes sent for other avatar data in the AvatarMixerClientData + nodeData->recordSentAvatarData(numAvatarDataBytes + mixedAvatarByteArray.size()); if (numOtherAvatars == 0) { // update the full rate distance to FLOAT_MAX since we didn't have any other avatars to send diff --git a/assignment-client/src/avatars/AvatarMixerClientData.cpp b/assignment-client/src/avatars/AvatarMixerClientData.cpp index 27c9b0d436..1748aeb23e 100644 --- a/assignment-client/src/avatars/AvatarMixerClientData.cpp +++ b/assignment-client/src/avatars/AvatarMixerClientData.cpp @@ -30,4 +30,6 @@ void AvatarMixerClientData::loadJSONStats(QJsonObject& jsonObject) const { jsonObject["full_rate_distance"] = _fullRateDistance; jsonObject["max_full_rate_distance"] = _maxFullRateDistance; jsonObject["num_avatars_sent_last_frame"] = _numAvatarsSentLastFrame; + + jsonObject["other_avatar_data_kbps"] = getSentAvatarDataKbps(); } diff --git a/assignment-client/src/avatars/AvatarMixerClientData.h b/assignment-client/src/avatars/AvatarMixerClientData.h index 49bc6ad05e..e3f94f83a8 100644 --- a/assignment-client/src/avatars/AvatarMixerClientData.h +++ b/assignment-client/src/avatars/AvatarMixerClientData.h @@ -20,6 +20,8 @@ #include <AvatarData.h> #include <NodeData.h> +#include <NumericalConstants.h> +#include <SimpleMovingAverage.h> class AvatarMixerClientData : public NodeData { Q_OBJECT @@ -49,6 +51,11 @@ public: void incrementNumFramesSinceFRDAdjustment() { ++_numFramesSinceAdjustment; } void resetNumFramesSinceFRDAdjustment() { _numFramesSinceAdjustment = 0; } + void recordSentAvatarData(int numBytes) { _avgOtherAvatarDataRate.updateAverage((float) numBytes); } + + float getSentAvatarDataKbps() const + { return _avgOtherAvatarDataRate.getAverageSampleValuePerSecond() / (float) BYTES_PER_KILOBIT; } + void loadJSONStats(QJsonObject& jsonObject) const; private: AvatarData _avatar; @@ -59,6 +66,7 @@ private: float _maxFullRateDistance = FLT_MAX; int _numAvatarsSentLastFrame = 0; int _numFramesSinceAdjustment = 0; + SimpleMovingAverage _avgOtherAvatarDataRate; }; #endif // hifi_AvatarMixerClientData_h diff --git a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp index 8a560984a6..f6ab12f421 100644 --- a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp +++ b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp @@ -10,6 +10,8 @@ // #include <limits> + +#include <NumericalConstants.h> #include <PacketHeaders.h> #include <PerfStat.h> diff --git a/assignment-client/src/octree/OctreeSendThread.cpp b/assignment-client/src/octree/OctreeSendThread.cpp index 277d4fac1f..4e61793910 100644 --- a/assignment-client/src/octree/OctreeSendThread.cpp +++ b/assignment-client/src/octree/OctreeSendThread.cpp @@ -10,9 +10,9 @@ // #include <NodeList.h> +#include <NumericalConstants.h> #include <PacketHeaders.h> #include <PerfStat.h> -#include <SharedUtil.h> #include "OctreeSendThread.h" #include "OctreeServer.h" diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index 266183745f..6c5eb38fad 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -21,6 +21,7 @@ #include <HTTPConnection.h> #include <LogHandler.h> #include <NetworkingConstants.h> +#include <NumericalConstants.h> #include <UUID.h> #include "../AssignmentClient.h" diff --git a/interface/src/LODManager.cpp b/interface/src/LODManager.cpp index 93ef8041ac..cfc1c94995 100644 --- a/interface/src/LODManager.cpp +++ b/interface/src/LODManager.cpp @@ -1,6 +1,6 @@ // // LODManager.cpp -// +// interface/src/LODManager.h // // Created by Clement on 1/16/15. // Copyright 2015 High Fidelity, Inc. diff --git a/interface/src/LODManager.h b/interface/src/LODManager.h index 77f156531a..615bcec24d 100644 --- a/interface/src/LODManager.h +++ b/interface/src/LODManager.h @@ -1,6 +1,6 @@ // // LODManager.h -// +// interface/src/LODManager.h // // Created by Clement on 1/16/15. // Copyright 2015 High Fidelity, Inc. @@ -13,8 +13,8 @@ #define hifi_LODManager_h #include <DependencyManager.h> +#include <NumericalConstants.h> #include <OctreeConstants.h> -#include <SharedUtil.h> #include <SimpleMovingAverage.h> const float DEFAULT_DESKTOP_LOD_DOWN_FPS = 30.0; @@ -115,4 +115,4 @@ private: QMap<float, float> _shouldRenderTable; }; -#endif // hifi_LODManager_h \ No newline at end of file +#endif // hifi_LODManager_h diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index e5662005d5..c406828d59 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -9,9 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "InterfaceConfig.h" -#include "Stars.h" +#include "Stars.h" +#include <NumericalConstants.h> + +#include "InterfaceConfig.h" #include "starfield/Controller.h" Stars::Stars() : diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index 7ae36675be..e523d958a6 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -106,7 +106,7 @@ public: void addLeanDeltas(float sideways, float forward); private: - glm::vec3 calculateAverageEyePosition() const { return _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF; } + glm::vec3 calculateAverageEyePosition() const { return _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * 0.5f; } // disallow copies of the Head, copy of owning Avatar is disallowed too Head(const Head&); diff --git a/interface/src/devices/DdeFaceTracker.cpp b/interface/src/devices/DdeFaceTracker.cpp index be25c0794d..c607d9fa0e 100644 --- a/interface/src/devices/DdeFaceTracker.cpp +++ b/interface/src/devices/DdeFaceTracker.cpp @@ -18,6 +18,7 @@ #include <QTimer> #include <GLMHelpers.h> +#include <NumericalConstants.h> #include "DdeFaceTracker.h" #include "FaceshiftConstants.h" diff --git a/interface/src/devices/Faceshift.cpp b/interface/src/devices/Faceshift.cpp index 8a0e5a324c..183c7695af 100644 --- a/interface/src/devices/Faceshift.cpp +++ b/interface/src/devices/Faceshift.cpp @@ -12,8 +12,8 @@ #include <QTimer> #include <GLMHelpers.h> +#include <NumericalConstants.h> #include <PerfStat.h> -#include <SharedUtil.h> #include "Faceshift.h" #include "Menu.h" diff --git a/interface/src/ui/overlays/Overlay.cpp b/interface/src/ui/overlays/Overlay.cpp index 2cb8b3c91d..024a94e950 100644 --- a/interface/src/ui/overlays/Overlay.cpp +++ b/interface/src/ui/overlays/Overlay.cpp @@ -11,10 +11,9 @@ // include this before QGLWidget, which includes an earlier version of OpenGL #include "InterfaceConfig.h" -#include <SharedUtil.h> - #include "Overlay.h" +#include <NumericalConstants.h> Overlay::Overlay() : _isLoaded(true), diff --git a/libraries/audio/src/AudioFilter.h b/libraries/audio/src/AudioFilter.h index ee823c00da..04db775433 100644 --- a/libraries/audio/src/AudioFilter.h +++ b/libraries/audio/src/AudioFilter.h @@ -12,7 +12,8 @@ #ifndef hifi_AudioFilter_h #define hifi_AudioFilter_h -// +#include <NumericalConstants.h> + // Implements a standard biquad filter in "Direct Form 1" // Reference http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt // @@ -183,10 +184,10 @@ public: a2 = (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha */ const float32_t b0 = +1.0f * (aAdd1 - aSub1TimesCosOmega + zeta) * a; - const float32_t b1 = +2.0f * (aSub1 - aAdd1TimesCosOmega + ZERO) * a; + const float32_t b1 = +2.0f * (aSub1 - aAdd1TimesCosOmega + 0.0f) * a; const float32_t b2 = +1.0f * (aAdd1 - aSub1TimesCosOmega - zeta) * a; const float32_t a0 = +1.0f * (aAdd1 + aSub1TimesCosOmega + zeta); - const float32_t a1 = -2.0f * (aSub1 + aAdd1TimesCosOmega + ZERO); + const float32_t a1 = -2.0f * (aSub1 + aAdd1TimesCosOmega + 0.0f); const float32_t a2 = +1.0f * (aAdd1 + aSub1TimesCosOmega - zeta); const float32_t normA0 = 1.0f / a0; @@ -224,10 +225,10 @@ public: a2 = (A+1) - (A-1)*cos(w0) - 2*sqrt(A)*alpha */ const float32_t b0 = +1.0f * (aAdd1 + aSub1TimesCosOmega + zeta) * a; - const float32_t b1 = -2.0f * (aSub1 + aAdd1TimesCosOmega + ZERO) * a; + const float32_t b1 = -2.0f * (aSub1 + aAdd1TimesCosOmega + 0.0f) * a; const float32_t b2 = +1.0f * (aAdd1 + aSub1TimesCosOmega - zeta) * a; const float32_t a0 = +1.0f * (aAdd1 - aSub1TimesCosOmega + zeta); - const float32_t a1 = +2.0f * (aSub1 - aAdd1TimesCosOmega + ZERO); + const float32_t a1 = +2.0f * (aSub1 - aAdd1TimesCosOmega + 0.0f); const float32_t a2 = +1.0f * (aAdd1 - aSub1TimesCosOmega - zeta); const float32_t normA0 = 1.0f / a0; diff --git a/libraries/audio/src/AudioFilterBank.cpp b/libraries/audio/src/AudioFilterBank.cpp index d5792ae97c..919b26b8fb 100644 --- a/libraries/audio/src/AudioFilterBank.cpp +++ b/libraries/audio/src/AudioFilterBank.cpp @@ -9,12 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include <assert.h> -#include <math.h> -#include <SharedUtil.h> -#include "AudioFormat.h" -#include "AudioBuffer.h" -#include "AudioFilter.h" #include "AudioFilterBank.h" template<> diff --git a/libraries/audio/src/AudioFilterBank.h b/libraries/audio/src/AudioFilterBank.h index 7b3b45f56b..a81c3db996 100644 --- a/libraries/audio/src/AudioFilterBank.h +++ b/libraries/audio/src/AudioFilterBank.h @@ -12,6 +12,12 @@ #ifndef hifi_AudioFilterBank_h #define hifi_AudioFilterBank_h +#include <stdint.h> + +#include "AudioBuffer.h" +#include "AudioFilter.h" +#include "AudioFormat.h" + // // Helper/convenience class that implements a bank of Filter objects // diff --git a/libraries/audio/src/AudioFormat.h b/libraries/audio/src/AudioFormat.h index 3fee254957..d50fae017d 100644 --- a/libraries/audio/src/AudioFormat.h +++ b/libraries/audio/src/AudioFormat.h @@ -22,6 +22,7 @@ typedef float float32_t; typedef double float64_t; #endif +#include <assert.h> #include <cstring> #include "AudioConstants.h" diff --git a/libraries/audio/src/AudioPan.h b/libraries/audio/src/AudioPan.h index 2fe8c5cc28..bcd3fac08e 100644 --- a/libraries/audio/src/AudioPan.h +++ b/libraries/audio/src/AudioPan.h @@ -12,6 +12,10 @@ #ifndef hifi_AudioPan_h #define hifi_AudioPan_h +#include <NumericalConstants.h> + +#include "AudioFormat.h" + class AudioPan { float32_t _pan; diff --git a/libraries/audio/src/AudioSourceTone.cpp b/libraries/audio/src/AudioSourceTone.cpp index c28e40ad1d..2e5b59521b 100644 --- a/libraries/audio/src/AudioSourceTone.cpp +++ b/libraries/audio/src/AudioSourceTone.cpp @@ -9,12 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include <assert.h> -#include <math.h> -#include <SharedUtil.h> -#include "AudioRingBuffer.h" -#include "AudioFormat.h" -#include "AudioBuffer.h" +#include <NumericalConstants.h> + #include "AudioSourceTone.h" AudioSourceTone::AudioSourceTone() { diff --git a/libraries/audio/src/AudioSourceTone.h b/libraries/audio/src/AudioSourceTone.h index f0c72ca9b3..f2e791fb77 100644 --- a/libraries/audio/src/AudioSourceTone.h +++ b/libraries/audio/src/AudioSourceTone.h @@ -12,9 +12,11 @@ #ifndef hifi_AudioSourceTone_h #define hifi_AudioSourceTone_h +#include "AudioBuffer.h" +#include "AudioFormat.h" + // Implements a two-pole Gordon-Smith oscillator -class AudioSourceTone -{ +class AudioSourceTone { float32_t _frequency; float32_t _amplitude; float32_t _sampleRate; diff --git a/libraries/audio/src/InboundAudioStream.h b/libraries/audio/src/InboundAudioStream.h index 99039b5482..f80961675d 100644 --- a/libraries/audio/src/InboundAudioStream.h +++ b/libraries/audio/src/InboundAudioStream.h @@ -12,13 +12,15 @@ #ifndef hifi_InboundAudioStream_h #define hifi_InboundAudioStream_h -#include "NodeData.h" +#include <NodeData.h> +#include <NumericalConstants.h> +#include <PacketHeaders.h> +#include <StDev.h> + #include "AudioRingBuffer.h" #include "MovingMinMaxAvg.h" #include "SequenceNumberStats.h" #include "AudioStreamStats.h" -#include "PacketHeaders.h" -#include "StDev.h" #include "TimeWeightedAvg.h" // This adds some number of frames to the desired jitter buffer frames target we use when we're dropping frames. diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h index a5e2b2907e..6388c882c7 100644 --- a/libraries/avatars/src/HandData.h +++ b/libraries/avatars/src/HandData.h @@ -18,7 +18,7 @@ #include <glm/glm.hpp> #include <glm/gtc/quaternion.hpp> -#include "SharedUtil.h" +#include <NumericalConstants.h> class AvatarData; class PalmData; diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index faec9e1206..9dfa8802ba 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -24,6 +24,7 @@ #include <AACube.h> #include <FBXReader.h> // for SittingPoint +#include <NumericalConstants.h> #include <PropertyFlags.h> #include <OctreeConstants.h> #include <ShapeInfo.h> diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index ca4ccc294f..ac7d4736bd 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -25,6 +25,7 @@ #include <FaceshiftConstants.h> #include <GeometryUtil.h> #include <GLMHelpers.h> +#include <NumericalConstants.h> #include <OctalCode.h> #include <Shape.h> diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index f476b36514..e5badc32eb 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -19,16 +19,17 @@ #include <QtCore/QUrl> #include <QtNetwork/QHostInfo> -#include <LogHandler.h> - #include <tbb/parallel_for.h> +#include <LogHandler.h> +#include <NumericalConstants.h> +#include <SharedUtil.h> + #include "AccountManager.h" #include "Assignment.h" #include "HifiSockAddr.h" #include "LimitedNodeList.h" #include "PacketHeaders.h" -#include "SharedUtil.h" #include "UUID.h" #include "NetworkLogging.h" diff --git a/libraries/octree/src/OctreePersistThread.cpp b/libraries/octree/src/OctreePersistThread.cpp index 210d074001..eafc9065a2 100644 --- a/libraries/octree/src/OctreePersistThread.cpp +++ b/libraries/octree/src/OctreePersistThread.cpp @@ -22,8 +22,8 @@ #include <QJsonObject> #include <QJsonDocument> +#include <NumericalConstants.h> #include <PerfStat.h> -#include <SharedUtil.h> #include <PathUtils.h> #include "OctreeLogging.h" diff --git a/libraries/octree/src/OctreeSceneStats.cpp b/libraries/octree/src/OctreeSceneStats.cpp index d2b1ed91d1..c5a5678503 100644 --- a/libraries/octree/src/OctreeSceneStats.cpp +++ b/libraries/octree/src/OctreeSceneStats.cpp @@ -14,8 +14,8 @@ #include <QStringList> #include <LogHandler.h> +#include <NumericalConstants.h> #include <PacketHeaders.h> -#include <SharedUtil.h> #include "OctreePacketData.h" #include "OctreeElement.h" diff --git a/libraries/octree/src/OctreeSceneStats.h b/libraries/octree/src/OctreeSceneStats.h index ccef16da64..fdb4a7d545 100644 --- a/libraries/octree/src/OctreeSceneStats.h +++ b/libraries/octree/src/OctreeSceneStats.h @@ -13,8 +13,9 @@ #define hifi_OctreeSceneStats_h #include <stdint.h> + #include <NodeList.h> -#include <SharedUtil.h> + #include "JurisdictionMap.h" #include "OctreePacketData.h" #include "SequenceNumberStats.h" diff --git a/libraries/octree/src/ViewFrustum.cpp b/libraries/octree/src/ViewFrustum.cpp index 9570bcdd03..b18b2fcb3e 100644 --- a/libraries/octree/src/ViewFrustum.cpp +++ b/libraries/octree/src/ViewFrustum.cpp @@ -17,9 +17,10 @@ #include <QtCore/QDebug> +#include <NumericalConstants.h> + #include "GeometryUtil.h" #include "GLMHelpers.h" -#include "SharedUtil.h" #include "ViewFrustum.h" #include "OctreeLogging.h" #include "OctreeConstants.h" diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 0d3d370fd4..e64163b330 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -15,7 +15,7 @@ #include <QVector> #include <DependencyManager.h> -#include <SharedUtil.h> +#include <NumericalConstants.h> #include "ProgramObject.h" diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 9d71ec5cc2..142fd2543b 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -22,7 +22,7 @@ #include <gpu/GLBackend.h> #include <FSTReader.h> -#include <SharedUtil.h> +#include <NumericalConstants.h> #include "TextureCache.h" #include "RenderUtilsLogging.h" diff --git a/libraries/render-utils/src/JointState.h b/libraries/render-utils/src/JointState.h index 363aeecd01..fbe2e9c986 100644 --- a/libraries/render-utils/src/JointState.h +++ b/libraries/render-utils/src/JointState.h @@ -16,8 +16,9 @@ #include <glm/gtx/quaternion.hpp> #include <glm/gtx/transform.hpp> -#include <GLMHelpers.h> #include <FBXReader.h> +#include <GLMHelpers.h> +#include <NumericalConstants.h> const float DEFAULT_PRIORITY = 3.0f; diff --git a/libraries/script-engine/src/TouchEvent.cpp b/libraries/script-engine/src/TouchEvent.cpp index b1cbbc2f15..49266c3fa8 100644 --- a/libraries/script-engine/src/TouchEvent.cpp +++ b/libraries/script-engine/src/TouchEvent.cpp @@ -14,7 +14,7 @@ #include <QTouchEvent> #include <RegisteredMetaTypes.h> -#include <SharedUtil.h> +#include <NumericalConstants.h> #include "TouchEvent.h" diff --git a/libraries/shared/src/AABox.cpp b/libraries/shared/src/AABox.cpp index 6cb361a4a3..3c6be43850 100644 --- a/libraries/shared/src/AABox.cpp +++ b/libraries/shared/src/AABox.cpp @@ -10,11 +10,11 @@ // #include "AABox.h" + #include "AACube.h" #include "Extents.h" #include "GeometryUtil.h" -#include "SharedUtil.h" - +#include "NumericalConstants.h" AABox::AABox(const AACube& other) : _corner(other.getCorner()), _scale(other.getScale(), other.getScale(), other.getScale()) { diff --git a/libraries/shared/src/AACube.cpp b/libraries/shared/src/AACube.cpp index 55940ba50b..0a2f4a0c41 100644 --- a/libraries/shared/src/AACube.cpp +++ b/libraries/shared/src/AACube.cpp @@ -15,7 +15,7 @@ #include "AACube.h" #include "Extents.h" #include "GeometryUtil.h" -#include "SharedUtil.h" +#include "NumericalConstants.h" AACube::AACube(const AABox& other) : _corner(other.getCorner()), _scale(other.getLargestDimension()) { diff --git a/libraries/shared/src/AACubeShape.cpp b/libraries/shared/src/AACubeShape.cpp index 30197d6bfd..5c40b3bb64 100644 --- a/libraries/shared/src/AACubeShape.cpp +++ b/libraries/shared/src/AACubeShape.cpp @@ -13,7 +13,7 @@ #include <glm/gtx/norm.hpp> #include "AACubeShape.h" -#include "SharedUtil.h" // for SQUARE_ROOT_OF_3 +#include "NumericalConstants.h" // for SQUARE_ROOT_OF_3 glm::vec3 faceNormals[3] = { glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f) }; diff --git a/libraries/shared/src/AngularConstraint.cpp b/libraries/shared/src/AngularConstraint.cpp index 369885c91d..0387dd8219 100644 --- a/libraries/shared/src/AngularConstraint.cpp +++ b/libraries/shared/src/AngularConstraint.cpp @@ -13,6 +13,7 @@ #include "AngularConstraint.h" #include "GLMHelpers.h" +#include "NumericalConstants.h" // helper function /// \param angle radian angle to be clamped within angleMin and angleMax diff --git a/libraries/shared/src/ByteCountCoding.h b/libraries/shared/src/ByteCountCoding.h index 1ca0deaa3a..2a39ee7a8c 100644 --- a/libraries/shared/src/ByteCountCoding.h +++ b/libraries/shared/src/ByteCountCoding.h @@ -24,7 +24,7 @@ #include <QBitArray> #include <QByteArray> -#include "SharedUtil.h" +#include "NumericalConstants.h" template<typename T> class ByteCountCoded { public: diff --git a/libraries/shared/src/CapsuleShape.cpp b/libraries/shared/src/CapsuleShape.cpp index 24ac6634ea..ec71ebadbb 100644 --- a/libraries/shared/src/CapsuleShape.cpp +++ b/libraries/shared/src/CapsuleShape.cpp @@ -14,7 +14,7 @@ #include "CapsuleShape.h" #include "GeometryUtil.h" -#include "SharedUtil.h" +#include "NumericalConstants.h" CapsuleShape::CapsuleShape() : Shape(CAPSULE_SHAPE), _radius(0.0f), _halfHeight(0.0f) {} diff --git a/libraries/shared/src/CapsuleShape.h b/libraries/shared/src/CapsuleShape.h index ad3066bab7..32c09696d7 100644 --- a/libraries/shared/src/CapsuleShape.h +++ b/libraries/shared/src/CapsuleShape.h @@ -12,8 +12,8 @@ #ifndef hifi_CapsuleShape_h #define hifi_CapsuleShape_h +#include "NumericalConstants.h" #include "Shape.h" -#include "SharedUtil.h" // default axis of CapsuleShape is Y-axis const glm::vec3 DEFAULT_CAPSULE_AXIS(0.0f, 1.0f, 0.0f); diff --git a/libraries/shared/src/CollisionInfo.cpp b/libraries/shared/src/CollisionInfo.cpp index 1403e444cf..7f145efb20 100644 --- a/libraries/shared/src/CollisionInfo.cpp +++ b/libraries/shared/src/CollisionInfo.cpp @@ -9,11 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // - - #include "CollisionInfo.h" +#include "NumericalConstants.h" #include "Shape.h" -#include "SharedUtil.h" CollisionInfo::CollisionInfo() : _data(NULL), diff --git a/libraries/shared/src/GLMHelpers.cpp b/libraries/shared/src/GLMHelpers.cpp index 5d1b70275c..b32219c11c 100644 --- a/libraries/shared/src/GLMHelpers.cpp +++ b/libraries/shared/src/GLMHelpers.cpp @@ -11,6 +11,8 @@ #include "GLMHelpers.h" +#include "NumericalConstants.h" + // Safe version of glm::mix; based on the code in Nick Bobick's article, // http://www.gamasutra.com/features/19980703/quaternions_01.htm (via Clyde, // https://github.com/threerings/clyde/blob/master/src/main/java/com/threerings/math/Quaternion.java) diff --git a/libraries/shared/src/GeometryUtil.cpp b/libraries/shared/src/GeometryUtil.cpp index 13d78ec8b3..afb5890d05 100644 --- a/libraries/shared/src/GeometryUtil.cpp +++ b/libraries/shared/src/GeometryUtil.cpp @@ -13,9 +13,9 @@ #include <cmath> #include "GeometryUtil.h" +#include "NumericalConstants.h" #include "PlaneShape.h" #include "RayIntersectionInfo.h" -#include "SharedUtil.h" glm::vec3 computeVectorFromPointToSegment(const glm::vec3& point, const glm::vec3& start, const glm::vec3& end) { // compute the projection of the point vector onto the segment vector diff --git a/libraries/shared/src/NumericalConstants.h b/libraries/shared/src/NumericalConstants.h new file mode 100644 index 0000000000..6d1689fe4b --- /dev/null +++ b/libraries/shared/src/NumericalConstants.h @@ -0,0 +1,42 @@ +// +// NumericalConstants.h +// libraries/shared/src +// +// Created by Stephen Birarda on 05/01/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_NumericalConstants_h +#define hifi_NumericalConstants_h + +#pragma once + +#include <cmath> + +#include <QtGlobal> + +const float PI = 3.14159265358979f; +const float TWO_PI = 2.0f * PI; +const float PI_OVER_TWO = 0.5f * PI; +const float RADIANS_PER_DEGREE = PI / 180.0f; +const float DEGREES_PER_RADIAN = 180.0f / PI; + +const float EPSILON = 0.000001f; //smallish positive number - used as margin of error for some computations +const float SQUARE_ROOT_OF_2 = (float)sqrt(2.0f); +const float SQUARE_ROOT_OF_3 = (float)sqrt(3.0f); +const float METERS_PER_DECIMETER = 0.1f; +const float METERS_PER_CENTIMETER = 0.01f; +const float METERS_PER_MILLIMETER = 0.001f; +const float MILLIMETERS_PER_METER = 1000.0f; +const quint64 USECS_PER_MSEC = 1000; +const quint64 MSECS_PER_SECOND = 1000; +const quint64 USECS_PER_SECOND = USECS_PER_MSEC * MSECS_PER_SECOND; + +const int BITS_IN_BYTE = 8; +const int BYTES_PER_KILOBYTE = 1000; +const int BYTES_PER_KILOBIT = BYTES_PER_KILOBYTE / BITS_IN_BYTE; + +#endif // hifi_NumericalConstants_h diff --git a/libraries/shared/src/OctalCode.cpp b/libraries/shared/src/OctalCode.cpp index f26f103487..f9391514ca 100644 --- a/libraries/shared/src/OctalCode.cpp +++ b/libraries/shared/src/OctalCode.cpp @@ -16,8 +16,9 @@ #include <QtCore/QDebug> -#include "SharedUtil.h" +#include "NumericalConstants.h" #include "OctalCode.h" +#include "SharedUtil.h" int numberOfThreeBitSectionsInCode(const unsigned char* octalCode, int maxBytes) { if (maxBytes == OVERFLOWED_OCTCODE_BUFFER) { diff --git a/libraries/shared/src/PerfStat.cpp b/libraries/shared/src/PerfStat.cpp index f16e6d7d9d..286d257d1f 100644 --- a/libraries/shared/src/PerfStat.cpp +++ b/libraries/shared/src/PerfStat.cpp @@ -18,8 +18,8 @@ #include "PerfStat.h" +#include "NumericalConstants.h" #include "SharedLogging.h" -#include "SharedUtil.h" // ---------------------------------------------------------------------------- // PerformanceWarning diff --git a/libraries/shared/src/PhysicsHelpers.cpp b/libraries/shared/src/PhysicsHelpers.cpp index 80b8d11f26..be06920325 100644 --- a/libraries/shared/src/PhysicsHelpers.cpp +++ b/libraries/shared/src/PhysicsHelpers.cpp @@ -10,7 +10,7 @@ // #include "PhysicsHelpers.h" -#include "SharedUtil.h" +#include "NumericalConstants.h" // This chunk of code was copied from Bullet-2.82, so we include the Bullet license here: /* diff --git a/libraries/shared/src/PlaneShape.cpp b/libraries/shared/src/PlaneShape.cpp index a247641122..cad04afa42 100644 --- a/libraries/shared/src/PlaneShape.cpp +++ b/libraries/shared/src/PlaneShape.cpp @@ -10,8 +10,8 @@ // #include "GLMHelpers.h" +#include "NumericalConstants.h" #include "PlaneShape.h" -#include "SharedUtil.h" const glm::vec3 UNROTATED_NORMAL(0.0f, 1.0f, 0.0f); diff --git a/libraries/shared/src/ShapeCollider.cpp b/libraries/shared/src/ShapeCollider.cpp index b4f9d984f7..57ac9c4471 100644 --- a/libraries/shared/src/ShapeCollider.cpp +++ b/libraries/shared/src/ShapeCollider.cpp @@ -15,6 +15,7 @@ #include "CapsuleShape.h" #include "GeometryUtil.h" #include "ListShape.h" +#include "NumericalConstants.h" #include "PlaneShape.h" #include "ShapeCollider.h" #include "SphereShape.h" diff --git a/libraries/shared/src/ShapeInfo.cpp b/libraries/shared/src/ShapeInfo.cpp index 1c86f109c5..ca812532fa 100644 --- a/libraries/shared/src/ShapeInfo.cpp +++ b/libraries/shared/src/ShapeInfo.cpp @@ -9,11 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "ShapeInfo.h" + #include <math.h> -#include "SharedUtil.h" // for MILLIMETERS_PER_METER - -#include "ShapeInfo.h" +#include "NumericalConstants.h" // for MILLIMETERS_PER_METER void ShapeInfo::clear() { _type = SHAPE_TYPE_NONE; diff --git a/libraries/shared/src/SharedUtil.cpp b/libraries/shared/src/SharedUtil.cpp index ce566df0b6..f78c8c47e0 100644 --- a/libraries/shared/src/SharedUtil.cpp +++ b/libraries/shared/src/SharedUtil.cpp @@ -29,6 +29,7 @@ #include <QElapsedTimer> #include <QThread> +#include "NumericalConstants.h" #include "OctalCode.h" #include "SharedLogging.h" #include "SharedUtil.h" diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index 9cf76dd1dc..7b18d01d80 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -43,30 +43,6 @@ inline QDebug& operator<<(QDebug& dbg, const xColor& c) { return dbg; } -static const float ZERO = 0.0f; -static const float ONE = 1.0f; -static const float ONE_HALF = 0.5f; -static const float ONE_THIRD = 0.333333f; - -static const float PI = 3.14159265358979f; -static const float TWO_PI = 2.0f * PI; -static const float PI_OVER_TWO = ONE_HALF * PI; -static const float RADIANS_PER_DEGREE = PI / 180.0f; -static const float DEGREES_PER_RADIAN = 180.0f / PI; - -static const float EPSILON = 0.000001f; //smallish positive number - used as margin of error for some computations -static const float SQUARE_ROOT_OF_2 = (float)sqrt(2.0f); -static const float SQUARE_ROOT_OF_3 = (float)sqrt(3.0f); -static const float METERS_PER_DECIMETER = 0.1f; -static const float METERS_PER_CENTIMETER = 0.01f; -static const float METERS_PER_MILLIMETER = 0.001f; -static const float MILLIMETERS_PER_METER = 1000.0f; -static const quint64 USECS_PER_MSEC = 1000; -static const quint64 MSECS_PER_SECOND = 1000; -static const quint64 USECS_PER_SECOND = USECS_PER_MSEC * MSECS_PER_SECOND; - -const int BITS_IN_BYTE = 8; - // Use a custom User-Agent to avoid ModSecurity filtering, e.g. by hosting providers. const QByteArray HIGH_FIDELITY_USER_AGENT = "Mozilla/5.0 (HighFidelityInterface)"; diff --git a/libraries/shared/src/SphereShape.h b/libraries/shared/src/SphereShape.h index 3bce2e96a1..964881a715 100644 --- a/libraries/shared/src/SphereShape.h +++ b/libraries/shared/src/SphereShape.h @@ -12,9 +12,8 @@ #ifndef hifi_SphereShape_h #define hifi_SphereShape_h +#include "NumericalConstants.h" #include "Shape.h" -#include "SharedUtil.h" - class SphereShape : public Shape { public: diff --git a/tests/jitter/src/main.cpp b/tests/jitter/src/main.cpp index 788ae89c6f..9ad08368b5 100644 --- a/tests/jitter/src/main.cpp +++ b/tests/jitter/src/main.cpp @@ -16,6 +16,7 @@ #include <cerrno> #include <stdio.h> +#include <NumericalConstants.h> #include <MovingMinMaxAvg.h> #include <SequenceNumberStats.h> #include <SharedUtil.h> // for usecTimestampNow diff --git a/tests/physics/src/BulletUtilTests.cpp b/tests/physics/src/BulletUtilTests.cpp index a094cfe94b..b7fc9a1991 100644 --- a/tests/physics/src/BulletUtilTests.cpp +++ b/tests/physics/src/BulletUtilTests.cpp @@ -12,7 +12,7 @@ #include <iostream> #include <BulletUtil.h> -#include <SharedUtil.h> +#include <NumericalConstants.h> #include "BulletUtilTests.h" diff --git a/tests/shared/src/AngularConstraintTests.cpp b/tests/shared/src/AngularConstraintTests.cpp index d7a7835655..76f33be249 100644 --- a/tests/shared/src/AngularConstraintTests.cpp +++ b/tests/shared/src/AngularConstraintTests.cpp @@ -12,7 +12,7 @@ #include <iostream> #include <AngularConstraint.h> -#include <SharedUtil.h> +#include <NumericalConstants.h> #include <StreamUtils.h> #include "AngularConstraintTests.h"