From dfb1cffbd702c45468392ee7c9f7d48d760d424f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 30 Jan 2015 10:24:26 -0800 Subject: [PATCH 01/18] Add planet simulation --- examples/planets.js | 121 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 examples/planets.js diff --git a/examples/planets.js b/examples/planets.js new file mode 100644 index 0000000000..87ed774c93 --- /dev/null +++ b/examples/planets.js @@ -0,0 +1,121 @@ +// +// planets.js +// +// Created by Philip Rosedale on January 26, 2015 +// Copyright 2015 High Fidelity, Inc. +// +// Some planets are created in front of you. A physical object shot or thrown between them will move +// correctly. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var MAX_RANGE = 75.0; +var MAX_TRANSLATION = MAX_RANGE / 20.0; + +var LIFETIME = 600; +var DAMPING = 0.0; +var G = 3.0; + +// In this section, setup where you want your 'Planets' that will exert gravity on the +// smaller test particles. Use the first one for the simplest 'planets around sun' simulation. +// Add additional planets to make things a lot more complicated! + +var planetTypes = []; +planetTypes.push({ radius: 15, red: 0, green: 0, blue: 255, x: 0.0, y:0, z: 0.0 }); +//planetTypes.push({ radius: 10, red: 0, green: 255, blue: 0, x: 0.60, y:0, z: 0.60 }); +//planetTypes.push({ radius: 10, red: 0, green: 0, blue: 255, x: 0.75, y:0, z: 0.75 }); +//planetTypes.push({ radius: 5, red: 255, green: 0, blue: 0, x: 0.25, y:0, z: 0.25 }); +//planetTypes.push({ radius: 5, red: 0, green: 255, blue: 255, x: 0, y:0, z: 0 }); + +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(MAX_RANGE, Quat.getFront(Camera.getOrientation()))); + +var NUM_INITIAL_PARTICLES = 200; +var PARTICLE_MIN_SIZE = 0.50; +var PARTICLE_MAX_SIZE = 1.50; +var INITIAL_VELOCITY = 5.0; + +var planets = []; +var particles = []; + +// Create planets that will extert gravity on test particles +for (var i = 0; i < planetTypes.length; i++) { + var rotationalVelocity = 10 + Math.random() * 60; + var position = { x: planetTypes[i].x, y: planetTypes[i].y, z: planetTypes[i].z }; + position = Vec3.multiply(MAX_RANGE / 2, position); + position = Vec3.sum(center, position); + + planets.push(Entities.addEntity( + { type: "Sphere", + position: position, + dimensions: { x: planetTypes[i].radius, y: planetTypes[i].radius, z: planetTypes[i].radius }, + color: { red: planetTypes[i].red, green: planetTypes[i].green, blue: planetTypes[i].blue }, + gravity: { x: 0, y: 0, z: 0 }, + angularVelocity: { x: 0, y: rotationalVelocity, z: 0 }, + angularDamping: 0.0, + ignoreCollisions: false, + lifetime: LIFETIME, + collisionsWillMove: false })); +} + +Script.setTimeout(createParticles, 1000); + +function createParticles() { + // Create initial test particles that will move according to gravity from the planets + for (var i = 0; i < NUM_INITIAL_PARTICLES; i++) { + var radius = PARTICLE_MIN_SIZE + Math.random() * PARTICLE_MAX_SIZE; + var gray = Math.random() * 155; + var whichPlanet = Math.floor(Math.random() * planets.length); + var position = { x: (Math.random() - 0.5) * MAX_RANGE, y: (Math.random() - 0.5) * MAX_TRANSLATION, z: (Math.random() - 0.5) * MAX_RANGE }; + var separation = Vec3.length(position); + particles.push(Entities.addEntity( + { type: "Sphere", + position: Vec3.sum(center, position), + dimensions: { x: radius, y: radius, z: radius }, + color: { red: 100 + gray, green: 100 + gray, blue: 100 + gray }, + gravity: { x: 0, y: 0, z: 0 }, + angularVelocity: { x: 0, y: 0, z: 0 }, + velocity: Vec3.multiply(INITIAL_VELOCITY * Math.sqrt(separation), Vec3.normalize(Vec3.cross(position, { x: 0, y: 1, z: 0 }))), + ignoreCollisions: false, + damping: DAMPING, + lifetime: LIFETIME, + collisionsWillMove: true })); + } + Script.update.connect(update); +} + +function scriptEnding() { + for (var i = 0; i < planetTypes.length; i++) { + Entities.deleteEntity(planets[i]); + } + for (var i = 0; i < particles.length; i++) { + Entities.deleteEntity(particles[i]); + } +} + +function update(deltaTime) { + // Apply gravitational force from planets + for (var t = 0; t < particles.length; t++) { + var properties1 = Entities.getEntityProperties(particles[t]); + var velocity = properties1.velocity; + var vColor = Vec3.length(velocity) / 50 * 255; + var dV = { x:0, y:0, z:0 }; + var mass1 = Math.pow(properties1.dimensions.x / 2.0, 3.0); + for (var p = 0; p < planets.length; p++) { + var properties2 = Entities.getEntityProperties(planets[p]); + var mass2 = Math.pow(properties2.dimensions.x / 2.0, 3.0); + var between = Vec3.subtract(properties1.position, properties2.position); + var separation = Vec3.length(between); + dV = Vec3.sum(dV, Vec3.multiply(-G * mass1 * mass2 / separation, Vec3.normalize(between))); + } + if (Math.random() < 0.1) { + Entities.editEntity(particles[t], { color: { red: vColor, green: 100, blue: (255 - vColor) }, velocity: Vec3.sum(velocity, Vec3.multiply(deltaTime, dV))}); + } else { + Entities.editEntity(particles[t], { velocity: Vec3.sum(velocity, Vec3.multiply(deltaTime, dV))}); + } + + } +} + +Script.scriptEnding.connect(scriptEnding); \ No newline at end of file From efd383d269879b823d0c43b641cb08ac603ee053 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 30 Jan 2015 14:42:41 -0800 Subject: [PATCH 02/18] Update BillboardOverlay to use NetworkTexture --- .../src/ui/overlays/BillboardOverlay.cpp | 187 ++++++++---------- interface/src/ui/overlays/BillboardOverlay.h | 7 +- 2 files changed, 88 insertions(+), 106 deletions(-) diff --git a/interface/src/ui/overlays/BillboardOverlay.cpp b/interface/src/ui/overlays/BillboardOverlay.cpp index 03decf046c..0b067927ec 100644 --- a/interface/src/ui/overlays/BillboardOverlay.cpp +++ b/interface/src/ui/overlays/BillboardOverlay.cpp @@ -9,15 +9,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include "Application.h" #include "BillboardOverlay.h" BillboardOverlay::BillboardOverlay() : - _newTextureNeeded(true), - _fromImage(-1,-1,-1,-1), + _fromImage(), _scale(1.0f), _isFacingAvatar(true) { @@ -27,10 +24,6 @@ BillboardOverlay::BillboardOverlay() : BillboardOverlay::BillboardOverlay(const BillboardOverlay* billboardOverlay) : Base3DOverlay(billboardOverlay), _url(billboardOverlay->_url), - _billboard(billboardOverlay->_billboard), - _size(), - _billboardTexture(), - _newTextureNeeded(true), _fromImage(billboardOverlay->_fromImage), _scale(billboardOverlay->_scale), _isFacingAvatar(billboardOverlay->_isFacingAvatar) @@ -38,41 +31,23 @@ BillboardOverlay::BillboardOverlay(const BillboardOverlay* billboardOverlay) : } void BillboardOverlay::render(RenderArgs* args) { - if (!_visible || !_isLoaded) { + if (!_isLoaded) { + _isLoaded = true; + _texture = DependencyManager::get()->getTexture(_url); + } + + if (!_visible || !_texture->isLoaded()) { return; } - - if (!_billboard.isEmpty()) { - if (_newTextureNeeded && _billboardTexture) { - _billboardTexture.reset(); - } - if (!_billboardTexture) { - QImage image = QImage::fromData(_billboard); - if (image.format() != QImage::Format_ARGB32) { - image = image.convertToFormat(QImage::Format_ARGB32); - } - _size = image.size(); - if (_fromImage.x() == -1) { - _fromImage.setRect(0, 0, _size.width(), _size.height()); - } - _billboardTexture.reset(new Texture()); - _newTextureNeeded = false; - glBindTexture(GL_TEXTURE_2D, _billboardTexture->getID()); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _size.width(), _size.height(), 0, - GL_BGRA, GL_UNSIGNED_BYTE, image.constBits()); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - - } else { - glBindTexture(GL_TEXTURE_2D, _billboardTexture->getID()); - } - } - + glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5f); - + glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); - + + glBindTexture(GL_TEXTURE_2D, _texture->getID()); + glPushMatrix(); { glTranslatef(_position.x, _position.y, _position.z); glm::quat rotation; @@ -86,39 +61,55 @@ void BillboardOverlay::render(RenderArgs* args) { glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glScalef(_scale, _scale, _scale); - - if (_billboardTexture) { - float maxSize = glm::max(_fromImage.width(), _fromImage.height()); - float x = _fromImage.width() / (2.0f * maxSize); - float y = -_fromImage.height() / (2.0f * maxSize); - - const float MAX_COLOR = 255.0f; - xColor color = getColor(); - float alpha = getAlpha(); - - glm::vec2 topLeft(-x, -y); - glm::vec2 bottomRight(x, y); - glm::vec2 texCoordTopLeft((float)_fromImage.x() / (float)_size.width(), - (float)_fromImage.y() / (float)_size.height()); - glm::vec2 texCoordBottomRight(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(), - ((float)_fromImage.y() + (float)_fromImage.height()) / _size.height()); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, - glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha)); - + const float MAX_COLOR = 255.0f; + xColor color = getColor(); + float alpha = getAlpha(); + + float imageWidth = _texture->getWidth(); + float imageHeight = _texture->getHeight(); + + QRect fromImage; + if (_fromImage.isNull()) { + fromImage.setX(0); + fromImage.setY(0); + fromImage.setWidth(imageWidth); + fromImage.setHeight(imageHeight); + } else { + float scaleX = imageWidth / _texture->getOriginalWidth(); + float scaleY = imageHeight / _texture->getOriginalHeight(); + + fromImage.setX(scaleX * _fromImage.x()); + fromImage.setY(scaleY * _fromImage.y()); + fromImage.setWidth(scaleX * _fromImage.width()); + fromImage.setHeight(scaleY * _fromImage.height()); } + + float maxSize = glm::max(fromImage.width(), fromImage.height()); + float x = fromImage.width() / (2.0f * maxSize); + float y = -fromImage.height() / (2.0f * maxSize); + + glm::vec2 topLeft(-x, -y); + glm::vec2 bottomRight(x, y); + glm::vec2 texCoordTopLeft(fromImage.x() / imageWidth, fromImage.y() / imageHeight); + glm::vec2 texCoordBottomRight((fromImage.x() + fromImage.width()) / imageWidth, + (fromImage.y() + fromImage.height()) / imageHeight); + + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, + glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha)); + } glPopMatrix(); - + glDisable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glDisable(GL_ALPHA_TEST); - + glBindTexture(GL_TEXTURE_2D, 0); } void BillboardOverlay::setProperties(const QScriptValue &properties) { Base3DOverlay::setProperties(properties); - + QScriptValue urlValue = properties.property("url"); if (urlValue.isValid()) { QString newURL = urlValue.toVariant().toString(); @@ -126,39 +117,43 @@ void BillboardOverlay::setProperties(const QScriptValue &properties) { setBillboardURL(newURL); } } - + QScriptValue subImageBounds = properties.property("subImage"); if (subImageBounds.isValid()) { - QRect oldSubImageRect = _fromImage; - QRect subImageRect = _fromImage; - if (subImageBounds.property("x").isValid()) { - subImageRect.setX(subImageBounds.property("x").toVariant().toInt()); + if (subImageBounds.isNull()) { + _fromImage = QRect(); } else { - subImageRect.setX(oldSubImageRect.x()); + QRect oldSubImageRect = _fromImage; + QRect subImageRect = _fromImage; + if (subImageBounds.property("x").isValid()) { + subImageRect.setX(subImageBounds.property("x").toVariant().toInt()); + } else { + subImageRect.setX(oldSubImageRect.x()); + } + if (subImageBounds.property("y").isValid()) { + subImageRect.setY(subImageBounds.property("y").toVariant().toInt()); + } else { + subImageRect.setY(oldSubImageRect.y()); + } + if (subImageBounds.property("width").isValid()) { + subImageRect.setWidth(subImageBounds.property("width").toVariant().toInt()); + } else { + subImageRect.setWidth(oldSubImageRect.width()); + } + if (subImageBounds.property("height").isValid()) { + subImageRect.setHeight(subImageBounds.property("height").toVariant().toInt()); + } else { + subImageRect.setHeight(oldSubImageRect.height()); + } + setClipFromSource(subImageRect); } - if (subImageBounds.property("y").isValid()) { - subImageRect.setY(subImageBounds.property("y").toVariant().toInt()); - } else { - subImageRect.setY(oldSubImageRect.y()); - } - if (subImageBounds.property("width").isValid()) { - subImageRect.setWidth(subImageBounds.property("width").toVariant().toInt()); - } else { - subImageRect.setWidth(oldSubImageRect.width()); - } - if (subImageBounds.property("height").isValid()) { - subImageRect.setHeight(subImageBounds.property("height").toVariant().toInt()); - } else { - subImageRect.setHeight(oldSubImageRect.height()); - } - setClipFromSource(subImageRect); } - + QScriptValue scaleValue = properties.property("scale"); if (scaleValue.isValid()) { _scale = scaleValue.toVariant().toFloat(); } - + QScriptValue isFacingAvatarValue = properties.property("isFacingAvatar"); if (isFacingAvatarValue.isValid()) { _isFacingAvatar = isFacingAvatarValue.toVariant().toBool(); @@ -188,33 +183,23 @@ void BillboardOverlay::setURL(const QString& url) { void BillboardOverlay::setBillboardURL(const QString& url) { _url = url; - QUrl actualURL = url; - _isLoaded = false; - - // clear the billboard if previously set - _billboard.clear(); - _newTextureNeeded = true; - - QNetworkReply* reply = NetworkAccessManager::getInstance().get(QNetworkRequest(actualURL)); - connect(reply, &QNetworkReply::finished, this, &BillboardOverlay::replyFinished); } void BillboardOverlay::replyFinished() { - // replace our byte array with the downloaded data - QNetworkReply* reply = static_cast(sender()); - _billboard = reply->readAll(); - _isLoaded = true; - reply->deleteLater(); } bool BillboardOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) { - if (_billboardTexture) { - float maxSize = glm::max(_fromImage.width(), _fromImage.height()); - float x = _fromImage.width() / (2.0f * maxSize); - float y = -_fromImage.height() / (2.0f * maxSize); + if (_texture) { + bool isNull = _fromImage.isNull(); + float width = isNull ? _texture->getWidth() : _fromImage.width(); + float height = isNull ? _texture->getHeight() : _fromImage.height(); + + float maxSize = glm::max(width, height); + float x = width / (2.0f * maxSize); + float y = -height / (2.0f * maxSize); float maxDimension = glm::max(x,y); float scaledDimension = maxDimension * _scale; glm::vec3 corner = getCenter() - glm::vec3(scaledDimension, scaledDimension, scaledDimension) ; diff --git a/interface/src/ui/overlays/BillboardOverlay.h b/interface/src/ui/overlays/BillboardOverlay.h index dcb8ab8b0c..85f02364d3 100644 --- a/interface/src/ui/overlays/BillboardOverlay.h +++ b/interface/src/ui/overlays/BillboardOverlay.h @@ -47,10 +47,7 @@ private: void setBillboardURL(const QString& url); QString _url; - QByteArray _billboard; - QSize _size; - QScopedPointer _billboardTexture; - bool _newTextureNeeded; + NetworkTexturePointer _texture; QRect _fromImage; // where from in the image to sample @@ -58,4 +55,4 @@ private: bool _isFacingAvatar; }; -#endif // hifi_BillboardOverlay_h \ No newline at end of file +#endif // hifi_BillboardOverlay_h From 1f24658f673495800eb8e3c62872fa4991bed8d7 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 30 Jan 2015 14:45:45 -0800 Subject: [PATCH 03/18] Remove BillboardOverlay::replyFinished() --- interface/src/ui/overlays/BillboardOverlay.cpp | 3 --- interface/src/ui/overlays/BillboardOverlay.h | 3 --- 2 files changed, 6 deletions(-) diff --git a/interface/src/ui/overlays/BillboardOverlay.cpp b/interface/src/ui/overlays/BillboardOverlay.cpp index 0b067927ec..b1c412bf56 100644 --- a/interface/src/ui/overlays/BillboardOverlay.cpp +++ b/interface/src/ui/overlays/BillboardOverlay.cpp @@ -186,9 +186,6 @@ void BillboardOverlay::setBillboardURL(const QString& url) { _isLoaded = false; } -void BillboardOverlay::replyFinished() { -} - bool BillboardOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) { diff --git a/interface/src/ui/overlays/BillboardOverlay.h b/interface/src/ui/overlays/BillboardOverlay.h index 85f02364d3..a09c0c7528 100644 --- a/interface/src/ui/overlays/BillboardOverlay.h +++ b/interface/src/ui/overlays/BillboardOverlay.h @@ -40,9 +40,6 @@ public: virtual BillboardOverlay* createClone() const; -private slots: - void replyFinished(); - private: void setBillboardURL(const QString& url); From 97035b6cd9ceb36fb785f83f3ac363604b7724f9 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 31 Jan 2015 07:42:01 -0800 Subject: [PATCH 04/18] move some magic numbers to constants --- interface/src/BandwidthRecorder.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/interface/src/BandwidthRecorder.h b/interface/src/BandwidthRecorder.h index a64a07fd84..8613c5fdcd 100644 --- a/interface/src/BandwidthRecorder.h +++ b/interface/src/BandwidthRecorder.h @@ -16,6 +16,13 @@ #include +const double DEFAULT_UNIT_SCALE = 8000.0 / 1024.0; + +const unsigned int COLOR0 = 0x33cc99ff; +const unsigned int COLOR1 = 0xffef40c0; +const unsigned int COLOR2 = 0xd0d0d0a0; + + class BandwidthRecorder { public: BandwidthRecorder(); @@ -46,11 +53,11 @@ class BandwidthRecorder { }; // create the channels we keep track of - Channel* audioChannel = new Channel("Audio", "Kbps", 8000.0 / 1024.0, 0x33cc99ff); - Channel* avatarsChannel = new Channel("Avatars", "Kbps", 8000.0 / 1024.0, 0xffef40c0); - Channel* octreeChannel = new Channel("Octree", "Kbps", 8000.0 / 1024.0, 0xd0d0d0a0); - Channel* metavoxelsChannel = new Channel("Metavoxels", "Kbps", 8000.0 / 1024.0, 0xd0d0d0a0); - Channel* totalChannel = new Channel("Total", "Kbps", 8000.0 / 1024.0, 0xd0d0d0a0); + Channel* audioChannel = new Channel("Audio", "Kbps", DEFAULT_UNIT_SCALE, COLOR0); + Channel* avatarsChannel = new Channel("Avatars", "Kbps", DEFAULT_UNIT_SCALE, COLOR1); + Channel* octreeChannel = new Channel("Octree", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); + Channel* metavoxelsChannel = new Channel("Metavoxels", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); + Channel* totalChannel = new Channel("Total", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); }; #endif From 105b2c5fd71061d42c522ba8b0e031ecd4bef7e7 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 31 Jan 2015 10:54:01 -0800 Subject: [PATCH 05/18] shell script to regenerate emacs TAGS file for project --- tools/refresh-tags.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 tools/refresh-tags.sh diff --git a/tools/refresh-tags.sh b/tools/refresh-tags.sh new file mode 100755 index 0000000000..86749bf20c --- /dev/null +++ b/tools/refresh-tags.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +rm -f TAGS + +find . -name *.h -print | while read I +do + etags --append "$I" +done + + +find . -name *.cpp -print | while read I +do + etags --append "$I" +done From bee895ba0a3a37a9703bd979771bb9bac03107d1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 31 Jan 2015 20:02:04 -0800 Subject: [PATCH 06/18] capture network bandwidth stats from NodeList rather than various places --- .gitignore | 2 + interface/src/Application.cpp | 31 +---- interface/src/Audio.cpp | 6 - interface/src/BandwidthRecorder.cpp | 64 --------- interface/src/DatagramProcessor.cpp | 19 ++- interface/src/MetavoxelSystem.cpp | 4 - interface/src/ui/BandwidthDialog.cpp | 7 +- interface/src/ui/BandwidthDialog.h | 1 + interface/src/ui/Stats.cpp | 10 +- .../networking/src/BandwidthRecorder.cpp | 123 ++++++++++++++++++ .../networking}/src/BandwidthRecorder.h | 41 +++--- libraries/networking/src/LimitedNodeList.cpp | 27 +++- libraries/networking/src/LimitedNodeList.h | 5 + libraries/networking/src/Node.cpp | 44 +++---- libraries/networking/src/Node.h | 8 +- libraries/networking/src/NodeList.cpp | 4 + tools/refresh-tags.sh | 2 +- 17 files changed, 239 insertions(+), 159 deletions(-) delete mode 100644 interface/src/BandwidthRecorder.cpp create mode 100644 libraries/networking/src/BandwidthRecorder.cpp rename {interface => libraries/networking}/src/BandwidthRecorder.h (63%) diff --git a/.gitignore b/.gitignore index 34f11c273a..16b588bcd2 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ interface/resources/visage/* # Ignore interfaceCache for Linux users interface/interfaceCache/ + +TAGS diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8f31872437..c984df5707 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -433,6 +433,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(this, SIGNAL(aboutToQuit()), this, SLOT(saveScripts())); connect(this, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit())); + // hook up bandwidth estimator + connect(nodeList.data(), SIGNAL(dataSent(const quint8, const int)), + &_bandwidthRecorder, SLOT(updateOutboundData(const quint8, const int))); + connect(nodeList.data(), SIGNAL(dataReceived(const quint8, const int)), + &_bandwidthRecorder, SLOT(updateInboundData(const quint8, const int))); + // check first run... bool firstRun = SettingHandles::firstRun.get(); if (firstRun) { @@ -771,25 +777,8 @@ void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) void Application::controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes) { foreach(NodeType_t type, destinationNodeTypes) { - // Perform the broadcast for one type - int nReceivingNodes = DependencyManager::get()->broadcastToNodes(packet, NodeSet() << type); - - // Feed number of bytes to corresponding channel of the bandwidth meter, if any (done otherwise) - double bandwidth_amount = nReceivingNodes * packet.size(); - switch (type) { - case NodeType::Agent: - case NodeType::AvatarMixer: - _bandwidthRecorder.avatarsChannel->output.updateValue(bandwidth_amount); - _bandwidthRecorder.totalChannel->input.updateValue(bandwidth_amount); - break; - case NodeType::EntityServer: - _bandwidthRecorder.octreeChannel->output.updateValue(bandwidth_amount); - _bandwidthRecorder.totalChannel->output.updateValue(bandwidth_amount); - break; - default: - continue; - } + DependencyManager::get()->broadcastToNodes(packet, NodeSet() << type); } } @@ -2383,10 +2372,6 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node // make sure we still have an active socket nodeList->writeUnverifiedDatagram(reinterpret_cast(queryPacket), packetLength, node); - - // Feed number of bytes to corresponding channel of the bandwidth meter - _bandwidthRecorder.octreeChannel->output.updateValue(packetLength); - _bandwidthRecorder.totalChannel->output.updateValue(packetLength); } }); } @@ -3374,8 +3359,6 @@ int Application::parseOctreeStats(const QByteArray& packet, const SharedNodePoin } void Application::packetSent(quint64 length) { - _bandwidthRecorder.octreeChannel->output.updateValue(length); - _bandwidthRecorder.totalChannel->output.updateValue(length); } const QString SETTINGS_KEY = "Settings"; diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 2bc5aa5023..2c34518ba5 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -768,9 +768,6 @@ void Audio::handleAudioInput() { int packetBytes = currentPacketPtr - audioDataPacket; nodeList->writeDatagram(audioDataPacket, packetBytes, audioMixer); _outgoingAvatarAudioSequenceNumber++; - - Application::getInstance()->getBandwidthRecorder()->audioChannel->output.updateValue(packetBytes); - Application::getInstance()->getBandwidthRecorder()->totalChannel->output.updateValue(packetBytes); } delete[] inputAudioSamples; } @@ -828,9 +825,6 @@ void Audio::addReceivedAudioToStream(const QByteArray& audioByteArray) { // Audio output must exist and be correctly set up if we're going to process received audio _receivedAudioStream.parseData(audioByteArray); } - - Application::getInstance()->getBandwidthRecorder()->audioChannel->input.updateValue(audioByteArray.size()); - Application::getInstance()->getBandwidthRecorder()->totalChannel->input.updateValue(audioByteArray.size()); } void Audio::parseAudioEnvironmentData(const QByteArray &packet) { diff --git a/interface/src/BandwidthRecorder.cpp b/interface/src/BandwidthRecorder.cpp deleted file mode 100644 index db59c680f5..0000000000 --- a/interface/src/BandwidthRecorder.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// -// BandwidthMeter.cpp -// interface/src/ui -// -// Created by Seth Alves on 2015-1-30 -// Copyright 2015 High Fidelity, Inc. -// -// Based on code by Tobias Schwinger -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include -#include "BandwidthRecorder.h" - - -BandwidthRecorder::Channel::Channel(char const* const caption, - char const* unitCaption, - double unitScale, - unsigned colorRGBA) : - caption(caption), - unitCaption(unitCaption), - unitScale(unitScale), - colorRGBA(colorRGBA) -{ -} - - - -BandwidthRecorder::BandwidthRecorder() { -} - - -BandwidthRecorder::~BandwidthRecorder() { - delete audioChannel; - delete avatarsChannel; - delete octreeChannel; - delete metavoxelsChannel; - delete totalChannel; -} - - -BandwidthRecorder::Stream::Stream(float msToAverage) : _value(0.0f), _msToAverage(msToAverage) { - _prevTime.start(); -} - - -void BandwidthRecorder::Stream::updateValue(double amount) { - - // Determine elapsed time - double dt = (double)_prevTime.nsecsElapsed() / 1000000.0; // ns to ms - - // Ignore this value when timer imprecision yields dt = 0 - if (dt == 0.0) { - return; - } - - _prevTime.start(); - - // Compute approximate average - _value = glm::mix(_value, amount / dt, - glm::clamp(dt / _msToAverage, 0.0, 1.0)); -} diff --git a/interface/src/DatagramProcessor.cpp b/interface/src/DatagramProcessor.cpp index 01c1c0d0c2..eb589140d0 100644 --- a/interface/src/DatagramProcessor.cpp +++ b/interface/src/DatagramProcessor.cpp @@ -39,8 +39,7 @@ void DatagramProcessor::processDatagrams() { while (DependencyManager::get()->getNodeSocket().hasPendingDatagrams()) { incomingPacket.resize(nodeList->getNodeSocket().pendingDatagramSize()); - nodeList->getNodeSocket().readDatagram(incomingPacket.data(), incomingPacket.size(), - senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); + nodeList->readDatagram(incomingPacket, senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); _inPacketCount++; _inByteCount += incomingPacket.size(); @@ -73,7 +72,7 @@ void DatagramProcessor::processDatagrams() { if (audioMixer) { audioMixer->setLastHeardMicrostamp(usecTimestampNow()); - audioMixer->recordBytesReceived(incomingPacket.size()); + // audioMixer->recordBytesReceived(incomingPacket.size()); } break; @@ -82,8 +81,8 @@ void DatagramProcessor::processDatagrams() { // this will keep creatorTokenIDs to IDs mapped correctly EntityItemID::handleAddEntityResponse(incomingPacket); application->getEntities()->getTree()->handleAddEntityResponse(incomingPacket); - application->_bandwidthRecorder.octreeChannel->input.updateValue(incomingPacket.size()); - application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.octreeChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); break; case PacketTypeEntityData: case PacketTypeEntityErase: @@ -97,8 +96,8 @@ void DatagramProcessor::processDatagrams() { // add this packet to our list of octree packets and process them on the octree data processing application->_octreeProcessor.queueReceivedPacket(matchedNode, incomingPacket); } - application->_bandwidthRecorder.octreeChannel->input.updateValue(incomingPacket.size()); - application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.octreeChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); break; } case PacketTypeMetavoxelData: @@ -113,15 +112,15 @@ void DatagramProcessor::processDatagrams() { if (avatarMixer) { avatarMixer->setLastHeardMicrostamp(usecTimestampNow()); - avatarMixer->recordBytesReceived(incomingPacket.size()); + // avatarMixer->recordBytesReceived(incomingPacket.size()); QMetaObject::invokeMethod(&application->getAvatarManager(), "processAvatarMixerDatagram", Q_ARG(const QByteArray&, incomingPacket), Q_ARG(const QWeakPointer&, avatarMixer)); } - application->_bandwidthRecorder.avatarsChannel->input.updateValue(incomingPacket.size()); - application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.avatarsChannel->input.updateValue(incomingPacket.size()); + // application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); break; } case PacketTypeDomainConnectionDenied: { diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index c81286b579..df8632d875 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -899,8 +899,6 @@ int MetavoxelSystemClient::parseData(const QByteArray& packet) { } else { QMetaObject::invokeMethod(&_sequencer, "receivedDatagram", Q_ARG(const QByteArray&, packet)); } - Application::getInstance()->getBandwidthRecorder()->metavoxelsChannel->input.updateValue(packet.size()); - Application::getInstance()->getBandwidthRecorder()->totalChannel->input.updateValue(packet.size()); } return packet.size(); } @@ -1016,8 +1014,6 @@ void MetavoxelSystemClient::sendDatagram(const QByteArray& data) { } else { DependencyManager::get()->writeDatagram(data, _node); } - Application::getInstance()->getBandwidthRecorder()->metavoxelsChannel->output.updateValue(data.size()); - Application::getInstance()->getBandwidthRecorder()->totalChannel->output.updateValue(data.size()); } } diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index 8b1afc9abf..88d30ae5a6 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -47,8 +47,8 @@ QLabel* BandwidthDialog::ChannelDisplay::setupLabel(QFormLayout* form) { void BandwidthDialog::ChannelDisplay::setLabelText() { std::string strBuf = - std::to_string ((int) (ch->input.getValue() * ch->unitScale)) + "/" + - std::to_string ((int) (ch->output.getValue() * ch->unitScale)) + " " + ch->unitCaption; + std::to_string ((int) (ch->getAverageInputKilobitsPerSecond() * ch->unitScale)) + "/" + + std::to_string ((int) (ch->getAverageOutputKilobitsPerSecond() * ch->unitScale)) + " " + ch->unitCaption; label->setText(strBuf.c_str()); } @@ -68,6 +68,7 @@ BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthRecorder* model) : avatarsChannelDisplay = new ChannelDisplay(_model->avatarsChannel, form); octreeChannelDisplay = new ChannelDisplay(_model->octreeChannel, form); metavoxelsChannelDisplay = new ChannelDisplay(_model->metavoxelsChannel, form); + otherChannelDisplay = new ChannelDisplay(_model->otherChannel, form); totalChannelDisplay = new ChannelDisplay(_model->totalChannel, form); } @@ -77,6 +78,7 @@ BandwidthDialog::~BandwidthDialog() { delete avatarsChannelDisplay; delete octreeChannelDisplay; delete metavoxelsChannelDisplay; + delete otherChannelDisplay; delete totalChannelDisplay; } @@ -86,6 +88,7 @@ void BandwidthDialog::paintEvent(QPaintEvent* event) { avatarsChannelDisplay->setLabelText(); octreeChannelDisplay->setLabelText(); metavoxelsChannelDisplay->setLabelText(); + otherChannelDisplay->setLabelText(); totalChannelDisplay->setLabelText(); this->QDialog::paintEvent(event); diff --git a/interface/src/ui/BandwidthDialog.h b/interface/src/ui/BandwidthDialog.h index a171c98e12..7f5a9068b4 100644 --- a/interface/src/ui/BandwidthDialog.h +++ b/interface/src/ui/BandwidthDialog.h @@ -42,6 +42,7 @@ public: ChannelDisplay* avatarsChannelDisplay; ChannelDisplay* octreeChannelDisplay; ChannelDisplay* metavoxelsChannelDisplay; + ChannelDisplay* otherChannelDisplay; // sums of all the other channels ChannelDisplay* totalChannelDisplay; diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index a913aff332..0416bf31ed 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -216,6 +216,8 @@ void Stats::display( QLocale locale(QLocale::English); std::stringstream octreeStats; + BandwidthRecorder* bandwidthRecorder = Application::getInstance()->getBandwidthRecorder(); + if (_lastHorizontalOffset != horizontalOffset) { resetWidth(glCanvas->width(), horizontalOffset); _lastHorizontalOffset = horizontalOffset; @@ -440,8 +442,12 @@ void Stats::display( SharedNodePointer avatarMixer = DependencyManager::get()->soloNodeOfType(NodeType::AvatarMixer); if (avatarMixer) { sprintf(avatarMixerStats, "Avatar Mixer: %.f kbps, %.f pps", - roundf(avatarMixer->getAverageKilobitsPerSecond()), - roundf(avatarMixer->getAveragePacketsPerSecond())); + // roundf(avatarMixer->getAverageKilobitsPerSecond()), + // roundf(avatarMixer->getAveragePacketsPerSecond()) + roundf(bandwidthRecorder->audioChannel->getAverageInputKilobitsPerSecond() + + bandwidthRecorder->audioChannel->getAverageOutputKilobitsPerSecond()), + roundf(bandwidthRecorder->audioChannel->getAverageInputPacketsPerSecond() + + bandwidthRecorder->audioChannel->getAverageOutputPacketsPerSecond())); } else { sprintf(avatarMixerStats, "No Avatar Mixer"); } diff --git a/libraries/networking/src/BandwidthRecorder.cpp b/libraries/networking/src/BandwidthRecorder.cpp new file mode 100644 index 0000000000..e56bae16dd --- /dev/null +++ b/libraries/networking/src/BandwidthRecorder.cpp @@ -0,0 +1,123 @@ +// +// BandwidthMeter.cpp +// interface/src/ui +// +// Created by Seth Alves on 2015-1-30 +// Copyright 2015 High Fidelity, Inc. +// +// Based on code by Tobias Schwinger +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// #include +#include "BandwidthRecorder.h" + + +BandwidthRecorder::Channel::Channel(char const* const caption, + char const* unitCaption, + double unitScale, + unsigned colorRGBA) : + caption(caption), + unitCaption(unitCaption), + unitScale(unitScale), + colorRGBA(colorRGBA) +{ +} + +float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() { + return (1 / _input.getEventDeltaAverage()); +} + +float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() { + return (1 / _output.getEventDeltaAverage()); +} + +float BandwidthRecorder::Channel::getAverageInputKilobitsPerSecond() { + return (_input.getAverageSampleValuePerSecond() * (8.0f / 1000)); +} + +float BandwidthRecorder::Channel::getAverageOutputKilobitsPerSecond() { + return (_output.getAverageSampleValuePerSecond() * (8.0f / 1000)); +} + + +void BandwidthRecorder::Channel::updateInputAverage(const float sample) { + _input.updateAverage(sample); +} + +void BandwidthRecorder::Channel::updateOutputAverage(const float sample) { + _output.updateAverage(sample); +} + + + +BandwidthRecorder::BandwidthRecorder() { +} + + +BandwidthRecorder::~BandwidthRecorder() { + delete audioChannel; + delete avatarsChannel; + delete octreeChannel; + delete metavoxelsChannel; + delete totalChannel; +} + + +void BandwidthRecorder::updateInboundData(const quint8 channelType, const int sample) { + + totalChannel->updateInputAverage(sample); + + // see Node.h NodeType + switch (channelType) { + case NodeType::DomainServer: + case NodeType::EntityServer: + octreeChannel->updateInputAverage(sample); + break; + case NodeType::MetavoxelServer: + case NodeType::EnvironmentServer: + metavoxelsChannel->updateInputAverage(sample); + break; + case NodeType::AudioMixer: + audioChannel->updateInputAverage(sample); + break; + case NodeType::Agent: + case NodeType::AvatarMixer: + avatarsChannel->updateInputAverage(sample); + break; + case NodeType::Unassigned: + default: + otherChannel->updateInputAverage(sample); + break; + } +} + +void BandwidthRecorder::updateOutboundData(const quint8 channelType, const int sample) { + + totalChannel->updateOutputAverage(sample); + + // see Node.h NodeType + switch (channelType) { + case NodeType::DomainServer: + case NodeType::EntityServer: + octreeChannel->updateOutputAverage(sample); + break; + case NodeType::MetavoxelServer: + case NodeType::EnvironmentServer: + metavoxelsChannel->updateOutputAverage(sample); + break; + case NodeType::AudioMixer: + audioChannel->updateOutputAverage(sample); + break; + case NodeType::Agent: + case NodeType::AvatarMixer: + avatarsChannel->updateOutputAverage(sample); + break; + case NodeType::Unassigned: + default: + otherChannel->updateOutputAverage(sample); + break; + } +} diff --git a/interface/src/BandwidthRecorder.h b/libraries/networking/src/BandwidthRecorder.h similarity index 63% rename from interface/src/BandwidthRecorder.h rename to libraries/networking/src/BandwidthRecorder.h index 8613c5fdcd..6f0ccf2c04 100644 --- a/interface/src/BandwidthRecorder.h +++ b/libraries/networking/src/BandwidthRecorder.h @@ -14,42 +14,46 @@ #ifndef hifi_BandwidthRecorder_h #define hifi_BandwidthRecorder_h +#include #include +#include "Node.h" +#include "SimpleMovingAverage.h" -const double DEFAULT_UNIT_SCALE = 8000.0 / 1024.0; +const double DEFAULT_UNIT_SCALE = 1.0; const unsigned int COLOR0 = 0x33cc99ff; const unsigned int COLOR1 = 0xffef40c0; const unsigned int COLOR2 = 0xd0d0d0a0; -class BandwidthRecorder { +class BandwidthRecorder : public QObject { + Q_OBJECT + public: BandwidthRecorder(); ~BandwidthRecorder(); - // keep track of data rate in one direction - class Stream { - public: - Stream(float msToAverage = 3000.0f); - void updateValue(double amount); - double getValue() const { return _value; } - private: - double _value; // Current value. - double _msToAverage; // Milliseconds to average. - QElapsedTimer _prevTime; // Time of last feed. - }; - // keep track of data rate in two directions as well as units and style to use during display class Channel { public: Channel(char const* const caption, char const* unitCaption, double unitScale, unsigned colorRGBA); - Stream input; - Stream output; + float getAverageInputPacketsPerSecond(); + float getAverageOutputPacketsPerSecond(); + float getAverageInputKilobitsPerSecond(); + float getAverageOutputKilobitsPerSecond(); + + void updateInputAverage(const float sample); + void updateOutputAverage(const float sample); + + // XXX make these private char const* const caption; char const* unitCaption; double unitScale; unsigned colorRGBA; + + private: + SimpleMovingAverage _input; + SimpleMovingAverage _output; }; // create the channels we keep track of @@ -57,7 +61,12 @@ class BandwidthRecorder { Channel* avatarsChannel = new Channel("Avatars", "Kbps", DEFAULT_UNIT_SCALE, COLOR1); Channel* octreeChannel = new Channel("Octree", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); Channel* metavoxelsChannel = new Channel("Metavoxels", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); + Channel* otherChannel = new Channel("Other", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); Channel* totalChannel = new Channel("Total", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); + + public slots: + void updateInboundData(const quint8 channelType, const int bytes); + void updateOutboundData(const quint8 channelType, const int bytes); }; #endif diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 5bf416af7f..666424151c 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -208,6 +208,22 @@ bool LimitedNodeList::packetVersionAndHashMatch(const QByteArray& packet) { return false; } +// qint64 LimitedNodeList::readDatagram(char* data, qint64 maxSize, QHostAddress* address = 0, quint16 * port = 0) { + +qint64 LimitedNodeList::readDatagram(QByteArray& incomingPacket, QHostAddress* address = 0, quint16 * port = 0) { + qint64 result = getNodeSocket().readDatagram(incomingPacket.data(), incomingPacket.size(), address, port); + + SharedNodePointer sendingNode = sendingNodeForPacket(incomingPacket); + if (sendingNode) { + emit dataReceived(sendingNode->getType(), incomingPacket.size()); + } + else { + emit dataReceived(NodeType::Unassigned, incomingPacket.size()); + } + + return result; +} + qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr, const QUuid& connectionSecret) { QByteArray datagramCopy = datagram; @@ -231,10 +247,11 @@ qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSock return bytesWritten; } -qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode, - const HifiSockAddr& overridenSockAddr) { +qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, + const SharedNodePointer& destinationNode, + const HifiSockAddr& overridenSockAddr) { if (destinationNode) { - // if we don't have an ovveriden address, assume they want to send to the node's active socket + // if we don't have an overridden address, assume they want to send to the node's active socket const HifiSockAddr* destinationSockAddr = &overridenSockAddr; if (overridenSockAddr.isNull()) { if (destinationNode->getActiveSocket()) { @@ -245,6 +262,8 @@ qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const SharedNo return 0; } } + + emit dataSent(destinationNode->getType(), datagram.size()); return writeDatagram(datagram, *destinationSockAddr, destinationNode->getConnectionSecret()); } @@ -303,7 +322,7 @@ int LimitedNodeList::updateNodeWithDataFromPacket(const SharedNodePointer& match QMutexLocker locker(&matchingNode->getMutex()); matchingNode->setLastHeardMicrostamp(usecTimestampNow()); - matchingNode->recordBytesReceived(packet.size()); + // matchingNode->recordBytesReceived(packet.size()); if (!matchingNode->getLinkedData() && linkedDataCreateCallback) { linkedDataCreateCallback(matchingNode.data()); diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 1c841637df..233d3c9f0c 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -82,6 +82,8 @@ public: QUdpSocket& getDTLSSocket(); bool packetVersionAndHashMatch(const QByteArray& packet); + + qint64 readDatagram(QByteArray& incomingPacket, QHostAddress* address, quint16 * port); qint64 writeDatagram(const QByteArray& datagram, const SharedNodePointer& destinationNode, const HifiSockAddr& overridenSockAddr = HifiSockAddr()); @@ -180,6 +182,9 @@ signals: void localSockAddrChanged(const HifiSockAddr& localSockAddr); void publicSockAddrChanged(const HifiSockAddr& publicSockAddr); + + void dataSent(const quint8 channel_type, const int bytes); + void dataReceived(const quint8 channel_type, const int bytes); protected: LimitedNodeList(unsigned short socketListenPort = 0, unsigned short dtlsListenPort = 0); diff --git a/libraries/networking/src/Node.cpp b/libraries/networking/src/Node.cpp index 2095acdf66..e8c73896f1 100644 --- a/libraries/networking/src/Node.cpp +++ b/libraries/networking/src/Node.cpp @@ -47,7 +47,7 @@ Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket, _activeSocket(NULL), _symmetricSocket(), _connectionSecret(), - _bytesReceivedMovingAverage(NULL), + // _bytesReceivedMovingAverage(NULL), _linkedData(NULL), _isAlive(true), _pingMs(-1), // "Uninitialized" @@ -60,32 +60,32 @@ Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket, Node::~Node() { delete _linkedData; - delete _bytesReceivedMovingAverage; + // delete _bytesReceivedMovingAverage; } -void Node::recordBytesReceived(int bytesReceived) { - if (!_bytesReceivedMovingAverage) { - _bytesReceivedMovingAverage = new SimpleMovingAverage(100); - } +// void Node::recordBytesReceived(int bytesReceived) { +// if (!_bytesReceivedMovingAverage) { +// _bytesReceivedMovingAverage = new SimpleMovingAverage(100); +// } - _bytesReceivedMovingAverage->updateAverage((float) bytesReceived); -} +// _bytesReceivedMovingAverage->updateAverage((float) bytesReceived); +// } -float Node::getAveragePacketsPerSecond() { - if (_bytesReceivedMovingAverage) { - return (1 / _bytesReceivedMovingAverage->getEventDeltaAverage()); - } else { - return 0; - } -} +// float Node::getAveragePacketsPerSecond() { +// if (_bytesReceivedMovingAverage) { +// return (1 / _bytesReceivedMovingAverage->getEventDeltaAverage()); +// } else { +// return 0; +// } +// } -float Node::getAverageKilobitsPerSecond() { - if (_bytesReceivedMovingAverage) { - return (_bytesReceivedMovingAverage->getAverageSampleValuePerSecond() * (8.0f / 1000)); - } else { - return 0; - } -} +// float Node::getAverageKilobitsPerSecond() { +// if (_bytesReceivedMovingAverage) { +// return (_bytesReceivedMovingAverage->getAverageSampleValuePerSecond() * (8.0f / 1000)); +// } else { +// return 0; +// } +// } void Node::updateClockSkewUsec(int clockSkewSample) { _clockSkewMovingPercentile.updatePercentile((float)clockSkewSample); diff --git a/libraries/networking/src/Node.h b/libraries/networking/src/Node.h index 6399c80edc..7d5e088038 100644 --- a/libraries/networking/src/Node.h +++ b/libraries/networking/src/Node.h @@ -63,9 +63,9 @@ public: bool isAlive() const { return _isAlive; } void setAlive(bool isAlive) { _isAlive = isAlive; } - void recordBytesReceived(int bytesReceived); - float getAverageKilobitsPerSecond(); - float getAveragePacketsPerSecond(); + // void recordBytesReceived(int bytesReceived); + // float getAverageKilobitsPerSecond(); + // float getAveragePacketsPerSecond(); int getPingMs() const { return _pingMs; } void setPingMs(int pingMs) { _pingMs = pingMs; } @@ -99,7 +99,7 @@ private: HifiSockAddr _symmetricSocket; QUuid _connectionSecret; - SimpleMovingAverage* _bytesReceivedMovingAverage; + // SimpleMovingAverage* _bytesReceivedMovingAverage; NodeData* _linkedData; bool _isAlive; int _pingMs; diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index bb095b2a3d..f86e0b85e4 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -108,6 +108,9 @@ void NodeList::timePingReply(const QByteArray& packet, const SharedNodePointer& } void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet) { + + emit dataReceived(NodeType::AudioMixer, packet.size()); // XXX + switch (packetTypeForPacket(packet)) { case PacketTypeDomainList: { processDomainServerList(packet); @@ -157,6 +160,7 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr break; } case PacketTypeUnverifiedPing: { + // send back a reply QByteArray replyPacket = constructPingReplyPacket(packet, _domainHandler.getICEClientID()); writeUnverifiedDatagram(replyPacket, senderSockAddr); diff --git a/tools/refresh-tags.sh b/tools/refresh-tags.sh index 86749bf20c..d3157fa179 100755 --- a/tools/refresh-tags.sh +++ b/tools/refresh-tags.sh @@ -8,7 +8,7 @@ do done -find . -name *.cpp -print | while read I +find . -name *.cpp -print | grep -v 'moc_' | while read I do etags --append "$I" done From fc07ecf83dfa8bb835195a725ce4718b01c2bbc1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 31 Jan 2015 20:40:18 -0800 Subject: [PATCH 07/18] use BandwidthRecorder rather than recompute Mbps and pps in Application --- interface/src/Application.cpp | 16 ++++++++-------- interface/src/Application.h | 16 ++++++++-------- interface/src/ui/ApplicationOverlay.cpp | 9 +++++---- interface/src/ui/Stats.cpp | 8 ++++---- interface/src/ui/Stats.h | 2 +- libraries/networking/src/BandwidthRecorder.h | 4 ++-- libraries/networking/src/LimitedNodeList.cpp | 8 ++++---- 7 files changed, 32 insertions(+), 31 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c984df5707..f1aa0ee873 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -241,10 +241,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _mousePressed(false), _enableProcessOctreeThread(true), _octreeProcessor(), - _inPacketsPerSecond(0), - _outPacketsPerSecond(0), - _inBytesPerSecond(0), - _outBytesPerSecond(0), +// _inPacketsPerSecond(0), +// _outPacketsPerSecond(0), +// _inBytesPerSecond(0), +// _outBytesPerSecond(0), _nodeBoundsDisplay(this), _previousScriptLocation(), _applicationOverlay(), @@ -1380,10 +1380,10 @@ void Application::timer() { _fps = (float)_frameCount / diffTime; - _inPacketsPerSecond = (float) _datagramProcessor.getInPacketCount() / diffTime; - _outPacketsPerSecond = (float) _datagramProcessor.getOutPacketCount() / diffTime; - _inBytesPerSecond = (float) _datagramProcessor.getInByteCount() / diffTime; - _outBytesPerSecond = (float) _datagramProcessor.getOutByteCount() / diffTime; + // _inPacketsPerSecond = (float) _datagramProcessor.getInPacketCount() / diffTime; + // _outPacketsPerSecond = (float) _datagramProcessor.getOutPacketCount() / diffTime; + // _inBytesPerSecond = (float) _datagramProcessor.getInByteCount() / diffTime; + // _outBytesPerSecond = (float) _datagramProcessor.getOutByteCount() / diffTime; _frameCount = 0; _datagramProcessor.resetCounters(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 7ac05d668b..510843758b 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -208,10 +208,10 @@ public: Overlays& getOverlays() { return _overlays; } float getFps() const { return _fps; } - float getInPacketsPerSecond() const { return _inPacketsPerSecond; } - float getOutPacketsPerSecond() const { return _outPacketsPerSecond; } - float getInBytesPerSecond() const { return _inBytesPerSecond; } - float getOutBytesPerSecond() const { return _outBytesPerSecond; } + // float getInPacketsPerSecond() const { return _inPacketsPerSecond; } + // float getOutPacketsPerSecond() const { return _outPacketsPerSecond; } + // float getInBytesPerSecond() const { return _inBytesPerSecond; } + // float getOutBytesPerSecond() const { return _outBytesPerSecond; } const glm::vec3& getViewMatrixTranslation() const { return _viewMatrixTranslation; } void setViewMatrixTranslation(const glm::vec3& translation) { _viewMatrixTranslation = translation; } @@ -535,10 +535,10 @@ private: OctreePacketProcessor _octreeProcessor; EntityEditPacketSender _entityEditSender; - int _inPacketsPerSecond; - int _outPacketsPerSecond; - int _inBytesPerSecond; - int _outBytesPerSecond; + // int _inPacketsPerSecond; + // int _outPacketsPerSecond; + // int _inBytesPerSecond; + // int _outBytesPerSecond; StDev _idleLoopStdev; float _idleLoopMeasuredJitter; diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 2daa22ebdd..93dd64879b 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -904,6 +904,7 @@ void ApplicationOverlay::renderAudioMeter() { void ApplicationOverlay::renderStatsAndLogs() { Application* application = Application::getInstance(); + BandwidthRecorder* bandwidthRecorder = Application::getInstance()->getBandwidthRecorder(); auto glCanvas = DependencyManager::get(); const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor(); @@ -919,10 +920,10 @@ void ApplicationOverlay::renderStatsAndLogs() { int voxelPacketsToProcess = octreePacketProcessor.packetsToProcessCount(); // Onscreen text about position, servers, etc Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, application->getFps(), - application->getInPacketsPerSecond(), - application->getOutPacketsPerSecond(), - application->getInBytesPerSecond(), - application->getOutBytesPerSecond(), + bandwidthRecorder->totalChannel->getAverageInputPacketsPerSecond(), + bandwidthRecorder->totalChannel->getAverageOutputPacketsPerSecond(), + bandwidthRecorder->totalChannel->getAverageInputKilobitsPerSecond(), + bandwidthRecorder->totalChannel->getAverageOutputKilobitsPerSecond(), voxelPacketsToProcess); } diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 0416bf31ed..c248140ae3 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -201,8 +201,8 @@ void Stats::display( float fps, int inPacketsPerSecond, int outPacketsPerSecond, - int inBytesPerSecond, - int outBytesPerSecond, + int inKbitsPerSecond, + int outKbitsPerSecond, int voxelPacketsToProcess) { auto glCanvas = DependencyManager::get(); @@ -318,8 +318,8 @@ void Stats::display( sprintf(packetsPerSecondString, "Packets In/Out: %d/%d", inPacketsPerSecond, outPacketsPerSecond); char averageMegabitsPerSecond[30]; sprintf(averageMegabitsPerSecond, "Mbps In/Out: %3.2f/%3.2f", - (float)inBytesPerSecond * 8.0f / 1000000.0f, - (float)outBytesPerSecond * 8.0f / 1000000.0f); + (float)inKbitsPerSecond * 1.0f / 1000.0f, + (float)outKbitsPerSecond * 1.0f / 1000.0f); verticalOffset += STATS_PELS_PER_LINE; drawText(horizontalOffset, verticalOffset, scale, rotation, font, packetsPerSecondString, color); diff --git a/interface/src/ui/Stats.h b/interface/src/ui/Stats.h index 136baf448b..d6da8d8cc6 100644 --- a/interface/src/ui/Stats.h +++ b/interface/src/ui/Stats.h @@ -30,7 +30,7 @@ public: void checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseDragStartedY, int horizontalOffset); void resetWidth(int width, int horizontalOffset); void display(const float* color, int horizontalOffset, float fps, int inPacketsPerSecond, int outPacketsPerSecond, - int inBytesPerSecond, int outBytesPerSecond, int voxelPacketsToProcess); + int inKbitsPerSecond, int outKbitsPerSecond, int voxelPacketsToProcess); bool includeTimingRecord(const QString& name); Q_INVOKABLE void setMetavoxelStats(int internal, int leaves, int sendProgress, diff --git a/libraries/networking/src/BandwidthRecorder.h b/libraries/networking/src/BandwidthRecorder.h index 6f0ccf2c04..5ae5de813f 100644 --- a/libraries/networking/src/BandwidthRecorder.h +++ b/libraries/networking/src/BandwidthRecorder.h @@ -52,8 +52,8 @@ class BandwidthRecorder : public QObject { unsigned colorRGBA; private: - SimpleMovingAverage _input; - SimpleMovingAverage _output; + SimpleMovingAverage _input = SimpleMovingAverage(1000); + SimpleMovingAverage _output = SimpleMovingAverage(1000); }; // create the channels we keep track of diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 666424151c..7d188af6aa 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -47,8 +47,8 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short _localSockAddr(), _publicSockAddr(), _stunSockAddr(STUN_SERVER_HOSTNAME, STUN_SERVER_PORT), - _numCollectedPackets(0), - _numCollectedBytes(0), + // _numCollectedPackets(0), + // _numCollectedBytes(0), _packetStatTimer() { static bool firstCall = true; @@ -234,8 +234,8 @@ qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSock } // stat collection for packets - ++_numCollectedPackets; - _numCollectedBytes += datagram.size(); + // ++_numCollectedPackets; + // _numCollectedBytes += datagram.size(); qint64 bytesWritten = _nodeSocket.writeDatagram(datagramCopy, destinationSockAddr.getAddress(), destinationSockAddr.getPort()); From b85456b1e902fd92acf4ddc65e0d50a73a3ddc71 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 2 Feb 2015 05:28:28 -0800 Subject: [PATCH 08/18] refactoring, cause BandwidthDialog to only update numbers once per second --- interface/src/ui/ApplicationOverlay.cpp | 8 +-- interface/src/ui/BandwidthDialog.cpp | 68 +++++++++---------- interface/src/ui/BandwidthDialog.h | 51 +++++++++----- interface/src/ui/Stats.cpp | 8 +-- .../networking/src/BandwidthRecorder.cpp | 41 +++++------ libraries/networking/src/BandwidthRecorder.h | 25 +++---- 6 files changed, 109 insertions(+), 92 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 93dd64879b..818aab4a92 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -920,10 +920,10 @@ void ApplicationOverlay::renderStatsAndLogs() { int voxelPacketsToProcess = octreePacketProcessor.packetsToProcessCount(); // Onscreen text about position, servers, etc Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, application->getFps(), - bandwidthRecorder->totalChannel->getAverageInputPacketsPerSecond(), - bandwidthRecorder->totalChannel->getAverageOutputPacketsPerSecond(), - bandwidthRecorder->totalChannel->getAverageInputKilobitsPerSecond(), - bandwidthRecorder->totalChannel->getAverageOutputKilobitsPerSecond(), + bandwidthRecorder->totalChannel.getAverageInputPacketsPerSecond(), + bandwidthRecorder->totalChannel.getAverageOutputPacketsPerSecond(), + bandwidthRecorder->totalChannel.getAverageInputKilobitsPerSecond(), + bandwidthRecorder->totalChannel.getAverageOutputKilobitsPerSecond(), voxelPacketsToProcess); } diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index 88d30ae5a6..0a1bf78871 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -9,6 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include "BandwidthRecorder.h" @@ -21,15 +22,10 @@ #include -BandwidthDialog::ChannelDisplay::ChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form) { +BandwidthChannelDisplay::BandwidthChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form) { this->ch = ch; - this->label = setupLabel(form); -} - - -QLabel* BandwidthDialog::ChannelDisplay::setupLabel(QFormLayout* form) { - QLabel* label = new QLabel(); + label = new QLabel(); label->setAlignment(Qt::AlignRight); QPalette palette = label->palette(); @@ -38,18 +34,20 @@ QLabel* BandwidthDialog::ChannelDisplay::setupLabel(QFormLayout* form) { palette.setColor(QPalette::WindowText, QColor::fromRgb(rgb)); label->setPalette(palette); - form->addRow((std::string(" ") + ch->caption + " Bandwidth In/Out:").c_str(), label); - - return label; + form->addRow(QString(" ") + ch->caption + " Bandwidth In/Out:", label); } -void BandwidthDialog::ChannelDisplay::setLabelText() { - std::string strBuf = - std::to_string ((int) (ch->getAverageInputKilobitsPerSecond() * ch->unitScale)) + "/" + - std::to_string ((int) (ch->getAverageOutputKilobitsPerSecond() * ch->unitScale)) + " " + ch->unitCaption; - label->setText(strBuf.c_str()); +void BandwidthChannelDisplay::bandwidthAverageUpdated() { + strBuf = + QString("").setNum((int) (ch->getAverageInputKilobitsPerSecond() * ch->unitScale)) + "/" + + QString("").setNum((int) (ch->getAverageOutputKilobitsPerSecond() * ch->unitScale)) + " " + ch->unitCaption; +} + + +void BandwidthChannelDisplay::Paint() { + label->setText(strBuf); } @@ -64,43 +62,45 @@ BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthRecorder* model) : QFormLayout* form = new QFormLayout(); this->QDialog::setLayout(form); - audioChannelDisplay = new ChannelDisplay(_model->audioChannel, form); - avatarsChannelDisplay = new ChannelDisplay(_model->avatarsChannel, form); - octreeChannelDisplay = new ChannelDisplay(_model->octreeChannel, form); - metavoxelsChannelDisplay = new ChannelDisplay(_model->metavoxelsChannel, form); - otherChannelDisplay = new ChannelDisplay(_model->otherChannel, form); - totalChannelDisplay = new ChannelDisplay(_model->totalChannel, form); + _allChannelDisplays[0] = _audioChannelDisplay = new BandwidthChannelDisplay(&_model->audioChannel, form); + _allChannelDisplays[1] = _avatarsChannelDisplay = new BandwidthChannelDisplay(&_model->avatarsChannel, form); + _allChannelDisplays[2] = _octreeChannelDisplay = new BandwidthChannelDisplay(&_model->octreeChannel, form); + _allChannelDisplays[3] = _metavoxelsChannelDisplay = new BandwidthChannelDisplay(&_model->metavoxelsChannel, form); + _allChannelDisplays[4] = _otherChannelDisplay = new BandwidthChannelDisplay(&_model->otherChannel, form); + _allChannelDisplays[5] = _totalChannelDisplay = new BandwidthChannelDisplay(&_model->totalChannel, form); + + connect(averageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateTimerTimeout())); + averageUpdateTimer->start(1000); } BandwidthDialog::~BandwidthDialog() { - delete audioChannelDisplay; - delete avatarsChannelDisplay; - delete octreeChannelDisplay; - delete metavoxelsChannelDisplay; - delete otherChannelDisplay; - delete totalChannelDisplay; + for (unsigned int i=0; i<_CHANNELCOUNT; i++) + delete _allChannelDisplays[i]; +} + + +void BandwidthDialog::updateTimerTimeout() { + for (unsigned int i=0; i<_CHANNELCOUNT; i++) + _allChannelDisplays[i]->bandwidthAverageUpdated(); } void BandwidthDialog::paintEvent(QPaintEvent* event) { - audioChannelDisplay->setLabelText(); - avatarsChannelDisplay->setLabelText(); - octreeChannelDisplay->setLabelText(); - metavoxelsChannelDisplay->setLabelText(); - otherChannelDisplay->setLabelText(); - totalChannelDisplay->setLabelText(); - + for (unsigned int i=0; i<_CHANNELCOUNT; i++) + _allChannelDisplays[i]->Paint(); this->QDialog::paintEvent(event); this->setFixedSize(this->width(), this->height()); } + void BandwidthDialog::reject() { // Just regularly close upon ESC this->QDialog::close(); } + void BandwidthDialog::closeEvent(QCloseEvent* event) { this->QDialog::closeEvent(event); diff --git a/interface/src/ui/BandwidthDialog.h b/interface/src/ui/BandwidthDialog.h index 7f5a9068b4..ecf087cf63 100644 --- a/interface/src/ui/BandwidthDialog.h +++ b/interface/src/ui/BandwidthDialog.h @@ -19,6 +19,25 @@ #include "BandwidthRecorder.h" +class BandwidthChannelDisplay : public QObject { + Q_OBJECT + + public: + BandwidthChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form); + void Paint(); + + private: + + BandwidthRecorder::Channel *ch; + QLabel* label; + // std::string strBuf; + QString strBuf; + + public slots: + void bandwidthAverageUpdated(); +}; + + class BandwidthDialog : public QDialog { Q_OBJECT public: @@ -26,26 +45,19 @@ public: BandwidthDialog(QWidget* parent, BandwidthRecorder* model); ~BandwidthDialog(); - class ChannelDisplay { - public: - ChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form); - QLabel* setupLabel(QFormLayout* form); - void setLabelText(); + void paintEvent(QPaintEvent*); - private: - BandwidthRecorder::Channel *ch; +private: + BandwidthChannelDisplay* _audioChannelDisplay; + BandwidthChannelDisplay* _avatarsChannelDisplay; + BandwidthChannelDisplay* _octreeChannelDisplay; + BandwidthChannelDisplay* _metavoxelsChannelDisplay; + BandwidthChannelDisplay* _otherChannelDisplay; + BandwidthChannelDisplay* _totalChannelDisplay; // sums of all the other channels - QLabel* label; - }; + static const unsigned int _CHANNELCOUNT = 6; + BandwidthChannelDisplay *_allChannelDisplays[_CHANNELCOUNT]; - ChannelDisplay* audioChannelDisplay; - ChannelDisplay* avatarsChannelDisplay; - ChannelDisplay* octreeChannelDisplay; - ChannelDisplay* metavoxelsChannelDisplay; - ChannelDisplay* otherChannelDisplay; - - // sums of all the other channels - ChannelDisplay* totalChannelDisplay; signals: @@ -54,15 +66,18 @@ signals: public slots: void reject(); + void updateTimerTimeout(); + protected: - void paintEvent(QPaintEvent*); // Emits a 'closed' signal when this dialog is closed. void closeEvent(QCloseEvent*); private: BandwidthRecorder* _model; + QTimer *averageUpdateTimer = new QTimer(this); + }; #endif // hifi_BandwidthDialog_h diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index c248140ae3..746c2fafbe 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -444,10 +444,10 @@ void Stats::display( sprintf(avatarMixerStats, "Avatar Mixer: %.f kbps, %.f pps", // roundf(avatarMixer->getAverageKilobitsPerSecond()), // roundf(avatarMixer->getAveragePacketsPerSecond()) - roundf(bandwidthRecorder->audioChannel->getAverageInputKilobitsPerSecond() + - bandwidthRecorder->audioChannel->getAverageOutputKilobitsPerSecond()), - roundf(bandwidthRecorder->audioChannel->getAverageInputPacketsPerSecond() + - bandwidthRecorder->audioChannel->getAverageOutputPacketsPerSecond())); + roundf(bandwidthRecorder->audioChannel.getAverageInputKilobitsPerSecond() + + bandwidthRecorder->audioChannel.getAverageOutputKilobitsPerSecond()), + roundf(bandwidthRecorder->audioChannel.getAverageInputPacketsPerSecond() + + bandwidthRecorder->audioChannel.getAverageOutputPacketsPerSecond())); } else { sprintf(avatarMixerStats, "No Avatar Mixer"); } diff --git a/libraries/networking/src/BandwidthRecorder.cpp b/libraries/networking/src/BandwidthRecorder.cpp index e56bae16dd..4d595d0fa8 100644 --- a/libraries/networking/src/BandwidthRecorder.cpp +++ b/libraries/networking/src/BandwidthRecorder.cpp @@ -11,7 +11,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// #include #include "BandwidthRecorder.h" @@ -27,11 +26,17 @@ BandwidthRecorder::Channel::Channel(char const* const caption, } float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() { - return (1 / _input.getEventDeltaAverage()); + float delt = _input.getEventDeltaAverage(); + if (delt > 0.) + return (1.0 / delt); + return 0.; } float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() { - return (1 / _output.getEventDeltaAverage()); + float delt = _input.getEventDeltaAverage(); + if (delt > 0.) + return (1.0 / _output.getEventDeltaAverage()); + return 0.; } float BandwidthRecorder::Channel::getAverageInputKilobitsPerSecond() { @@ -58,66 +63,62 @@ BandwidthRecorder::BandwidthRecorder() { BandwidthRecorder::~BandwidthRecorder() { - delete audioChannel; - delete avatarsChannel; - delete octreeChannel; - delete metavoxelsChannel; - delete totalChannel; } + void BandwidthRecorder::updateInboundData(const quint8 channelType, const int sample) { - totalChannel->updateInputAverage(sample); + totalChannel.updateInputAverage(sample); // see Node.h NodeType switch (channelType) { case NodeType::DomainServer: case NodeType::EntityServer: - octreeChannel->updateInputAverage(sample); + octreeChannel.updateInputAverage(sample); break; case NodeType::MetavoxelServer: case NodeType::EnvironmentServer: - metavoxelsChannel->updateInputAverage(sample); + metavoxelsChannel.updateInputAverage(sample); break; case NodeType::AudioMixer: - audioChannel->updateInputAverage(sample); + audioChannel.updateInputAverage(sample); break; case NodeType::Agent: case NodeType::AvatarMixer: - avatarsChannel->updateInputAverage(sample); + avatarsChannel.updateInputAverage(sample); break; case NodeType::Unassigned: default: - otherChannel->updateInputAverage(sample); + otherChannel.updateInputAverage(sample); break; } } void BandwidthRecorder::updateOutboundData(const quint8 channelType, const int sample) { - totalChannel->updateOutputAverage(sample); + totalChannel.updateOutputAverage(sample); // see Node.h NodeType switch (channelType) { case NodeType::DomainServer: case NodeType::EntityServer: - octreeChannel->updateOutputAverage(sample); + octreeChannel.updateOutputAverage(sample); break; case NodeType::MetavoxelServer: case NodeType::EnvironmentServer: - metavoxelsChannel->updateOutputAverage(sample); + metavoxelsChannel.updateOutputAverage(sample); break; case NodeType::AudioMixer: - audioChannel->updateOutputAverage(sample); + audioChannel.updateOutputAverage(sample); break; case NodeType::Agent: case NodeType::AvatarMixer: - avatarsChannel->updateOutputAverage(sample); + avatarsChannel.updateOutputAverage(sample); break; case NodeType::Unassigned: default: - otherChannel->updateOutputAverage(sample); + otherChannel.updateOutputAverage(sample); break; } } diff --git a/libraries/networking/src/BandwidthRecorder.h b/libraries/networking/src/BandwidthRecorder.h index 5ae5de813f..63b8f7e163 100644 --- a/libraries/networking/src/BandwidthRecorder.h +++ b/libraries/networking/src/BandwidthRecorder.h @@ -16,6 +16,7 @@ #include #include +#include #include "Node.h" #include "SimpleMovingAverage.h" @@ -29,7 +30,7 @@ const unsigned int COLOR2 = 0xd0d0d0a0; class BandwidthRecorder : public QObject { Q_OBJECT - public: +public: BandwidthRecorder(); ~BandwidthRecorder(); @@ -52,21 +53,21 @@ class BandwidthRecorder : public QObject { unsigned colorRGBA; private: - SimpleMovingAverage _input = SimpleMovingAverage(1000); - SimpleMovingAverage _output = SimpleMovingAverage(1000); + SimpleMovingAverage _input = SimpleMovingAverage(); + SimpleMovingAverage _output = SimpleMovingAverage(); }; // create the channels we keep track of - Channel* audioChannel = new Channel("Audio", "Kbps", DEFAULT_UNIT_SCALE, COLOR0); - Channel* avatarsChannel = new Channel("Avatars", "Kbps", DEFAULT_UNIT_SCALE, COLOR1); - Channel* octreeChannel = new Channel("Octree", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); - Channel* metavoxelsChannel = new Channel("Metavoxels", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); - Channel* otherChannel = new Channel("Other", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); - Channel* totalChannel = new Channel("Total", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); + Channel audioChannel = Channel("Audio", "Kbps", DEFAULT_UNIT_SCALE, COLOR0); + Channel avatarsChannel = Channel("Avatars", "Kbps", DEFAULT_UNIT_SCALE, COLOR1); + Channel octreeChannel = Channel("Octree", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); + Channel metavoxelsChannel = Channel("Metavoxels", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); + Channel otherChannel = Channel("Other", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); + Channel totalChannel = Channel("Total", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); - public slots: - void updateInboundData(const quint8 channelType, const int bytes); - void updateOutboundData(const quint8 channelType, const int bytes); +public slots: + void updateInboundData(const quint8 channelType, const int bytes); + void updateOutboundData(const quint8 channelType, const int bytes); }; #endif From c0a219678cc17d12ad0c8b1cd516b18d1cb148f6 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 2 Feb 2015 08:55:55 -0800 Subject: [PATCH 09/18] use DependencyManager to keep track of BandwidthRecorder --- interface/src/Application.cpp | 6 ++++-- interface/src/Application.h | 4 ---- interface/src/ui/ApplicationOverlay.cpp | 2 +- interface/src/ui/BandwidthDialog.cpp | 19 ++++++++++--------- interface/src/ui/BandwidthDialog.h | 6 +----- interface/src/ui/DialogsManager.cpp | 2 +- interface/src/ui/Stats.cpp | 3 ++- libraries/networking/src/BandwidthRecorder.h | 4 +++- 8 files changed, 22 insertions(+), 24 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f1aa0ee873..517c229185 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -201,6 +201,7 @@ bool setupEssentials(int& argc, char** argv) { auto lodManager = DependencyManager::set(); auto jsConsole = DependencyManager::set(); auto dialogsManager = DependencyManager::set(); + auto bandwidthRecorder = DependencyManager::set(); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) auto speechRecognizer = DependencyManager::set(); #endif @@ -434,10 +435,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(this, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit())); // hook up bandwidth estimator + QSharedPointer bandwidthRecorder = DependencyManager::get(); connect(nodeList.data(), SIGNAL(dataSent(const quint8, const int)), - &_bandwidthRecorder, SLOT(updateOutboundData(const quint8, const int))); + &*bandwidthRecorder, SLOT(updateOutboundData(const quint8, const int))); connect(nodeList.data(), SIGNAL(dataReceived(const quint8, const int)), - &_bandwidthRecorder, SLOT(updateInboundData(const quint8, const int))); + &*bandwidthRecorder, SLOT(updateInboundData(const quint8, const int))); // check first run... bool firstRun = SettingHandles::firstRun.get(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 510843758b..dee323aa52 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -202,7 +202,6 @@ public: bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated; } FaceTracker* getActiveFaceTracker(); - BandwidthRecorder* getBandwidthRecorder() { return &_bandwidthRecorder; } QSystemTrayIcon* getTrayIcon() { return _trayIcon; } ApplicationOverlay& getApplicationOverlay() { return _applicationOverlay; } Overlays& getOverlays() { return _overlays; } @@ -484,9 +483,6 @@ private: OctreeQuery _octreeQuery; // NodeData derived class for querying octee cells from octree servers - BandwidthRecorder _bandwidthRecorder; - - AvatarManager _avatarManager; MyAvatar* _myAvatar; // TODO: move this and relevant code to AvatarManager (or MyAvatar as the case may be) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 818aab4a92..f63afb5aee 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -904,7 +904,7 @@ void ApplicationOverlay::renderAudioMeter() { void ApplicationOverlay::renderStatsAndLogs() { Application* application = Application::getInstance(); - BandwidthRecorder* bandwidthRecorder = Application::getInstance()->getBandwidthRecorder(); + QSharedPointer bandwidthRecorder = DependencyManager::get(); auto glCanvas = DependencyManager::get(); const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor(); diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index 0a1bf78871..c22bd5dec7 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -52,9 +52,8 @@ void BandwidthChannelDisplay::Paint() { -BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthRecorder* model) : - QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint), - _model(model) { +BandwidthDialog::BandwidthDialog(QWidget* parent) : + QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) { this->setWindowTitle("Bandwidth Details"); @@ -62,12 +61,14 @@ BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthRecorder* model) : QFormLayout* form = new QFormLayout(); this->QDialog::setLayout(form); - _allChannelDisplays[0] = _audioChannelDisplay = new BandwidthChannelDisplay(&_model->audioChannel, form); - _allChannelDisplays[1] = _avatarsChannelDisplay = new BandwidthChannelDisplay(&_model->avatarsChannel, form); - _allChannelDisplays[2] = _octreeChannelDisplay = new BandwidthChannelDisplay(&_model->octreeChannel, form); - _allChannelDisplays[3] = _metavoxelsChannelDisplay = new BandwidthChannelDisplay(&_model->metavoxelsChannel, form); - _allChannelDisplays[4] = _otherChannelDisplay = new BandwidthChannelDisplay(&_model->otherChannel, form); - _allChannelDisplays[5] = _totalChannelDisplay = new BandwidthChannelDisplay(&_model->totalChannel, form); + QSharedPointer bandwidthRecorder = DependencyManager::get(); + + _allChannelDisplays[0] = _audioChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->audioChannel, form); + _allChannelDisplays[1] = _avatarsChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->avatarsChannel, form); + _allChannelDisplays[2] = _octreeChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->octreeChannel, form); + _allChannelDisplays[3] = _metavoxelsChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->metavoxelsChannel,form); + _allChannelDisplays[4] = _otherChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->otherChannel, form); + _allChannelDisplays[5] = _totalChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->totalChannel, form); connect(averageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateTimerTimeout())); averageUpdateTimer->start(1000); diff --git a/interface/src/ui/BandwidthDialog.h b/interface/src/ui/BandwidthDialog.h index ecf087cf63..27d58dc1a3 100644 --- a/interface/src/ui/BandwidthDialog.h +++ b/interface/src/ui/BandwidthDialog.h @@ -27,10 +27,8 @@ class BandwidthChannelDisplay : public QObject { void Paint(); private: - BandwidthRecorder::Channel *ch; QLabel* label; - // std::string strBuf; QString strBuf; public slots: @@ -41,8 +39,7 @@ class BandwidthChannelDisplay : public QObject { class BandwidthDialog : public QDialog { Q_OBJECT public: - // Sets up the UI based on the configuration of the BandwidthRecorder - BandwidthDialog(QWidget* parent, BandwidthRecorder* model); + BandwidthDialog(QWidget* parent); ~BandwidthDialog(); void paintEvent(QPaintEvent*); @@ -75,7 +72,6 @@ protected: void closeEvent(QCloseEvent*); private: - BandwidthRecorder* _model; QTimer *averageUpdateTimer = new QTimer(this); }; diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index fa04429bf2..752e205a6a 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -102,7 +102,7 @@ void DialogsManager::editAnimations() { void DialogsManager::bandwidthDetails() { if (! _bandwidthDialog) { - _bandwidthDialog = new BandwidthDialog(qApp->getWindow(), qApp->getBandwidthRecorder()); + _bandwidthDialog = new BandwidthDialog(qApp->getWindow()); connect(_bandwidthDialog, SIGNAL(closed()), _bandwidthDialog, SLOT(deleteLater())); if (_hmdToolsDialog) { diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 746c2fafbe..a29722825f 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -25,6 +25,7 @@ #include #include "Stats.h" +#include "BandwidthRecorder.h" #include "InterfaceConfig.h" #include "Menu.h" #include "Util.h" @@ -216,7 +217,7 @@ void Stats::display( QLocale locale(QLocale::English); std::stringstream octreeStats; - BandwidthRecorder* bandwidthRecorder = Application::getInstance()->getBandwidthRecorder(); + QSharedPointer bandwidthRecorder = DependencyManager::get(); if (_lastHorizontalOffset != horizontalOffset) { resetWidth(glCanvas->width(), horizontalOffset); diff --git a/libraries/networking/src/BandwidthRecorder.h b/libraries/networking/src/BandwidthRecorder.h index 63b8f7e163..5837702783 100644 --- a/libraries/networking/src/BandwidthRecorder.h +++ b/libraries/networking/src/BandwidthRecorder.h @@ -17,6 +17,7 @@ #include #include #include +#include "DependencyManager.h" #include "Node.h" #include "SimpleMovingAverage.h" @@ -27,8 +28,9 @@ const unsigned int COLOR1 = 0xffef40c0; const unsigned int COLOR2 = 0xd0d0d0a0; -class BandwidthRecorder : public QObject { +class BandwidthRecorder : public QObject, public Dependency { Q_OBJECT + SINGLETON_DEPENDENCY public: BandwidthRecorder(); From f1cca2ac92adb1993ab953e7d1fd240b261c6611 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 2 Feb 2015 09:26:09 -0800 Subject: [PATCH 10/18] move bandwidth stats display details out of recorder class into dialog class --- interface/src/ui/BandwidthDialog.cpp | 35 +++++++++++++------ interface/src/ui/BandwidthDialog.h | 13 ++++++- .../networking/src/BandwidthRecorder.cpp | 10 +----- libraries/networking/src/BandwidthRecorder.h | 28 +++++---------- 4 files changed, 46 insertions(+), 40 deletions(-) diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index c22bd5dec7..f9ea02d662 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -22,27 +22,34 @@ #include -BandwidthChannelDisplay::BandwidthChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form) { +BandwidthChannelDisplay::BandwidthChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form, + char const* const caption, char const* unitCaption, + const float unitScale, unsigned colorRGBA) : + caption(caption), + unitCaption(unitCaption), + unitScale(unitScale), + colorRGBA(colorRGBA) +{ this->ch = ch; label = new QLabel(); label->setAlignment(Qt::AlignRight); QPalette palette = label->palette(); - unsigned rgb = ch->colorRGBA >> 8; + unsigned rgb = colorRGBA >> 8; rgb = ((rgb & 0xfefefeu) >> 1) + ((rgb & 0xf8f8f8) >> 3); palette.setColor(QPalette::WindowText, QColor::fromRgb(rgb)); label->setPalette(palette); - form->addRow(QString(" ") + ch->caption + " Bandwidth In/Out:", label); + form->addRow(QString(" ") + caption + " Bandwidth In/Out:", label); } void BandwidthChannelDisplay::bandwidthAverageUpdated() { strBuf = - QString("").setNum((int) (ch->getAverageInputKilobitsPerSecond() * ch->unitScale)) + "/" + - QString("").setNum((int) (ch->getAverageOutputKilobitsPerSecond() * ch->unitScale)) + " " + ch->unitCaption; + QString("").setNum((int) (ch->getAverageInputKilobitsPerSecond() * unitScale)) + "/" + + QString("").setNum((int) (ch->getAverageOutputKilobitsPerSecond() * unitScale)) + " " + unitCaption; } @@ -63,12 +70,18 @@ BandwidthDialog::BandwidthDialog(QWidget* parent) : QSharedPointer bandwidthRecorder = DependencyManager::get(); - _allChannelDisplays[0] = _audioChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->audioChannel, form); - _allChannelDisplays[1] = _avatarsChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->avatarsChannel, form); - _allChannelDisplays[2] = _octreeChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->octreeChannel, form); - _allChannelDisplays[3] = _metavoxelsChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->metavoxelsChannel,form); - _allChannelDisplays[4] = _otherChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->otherChannel, form); - _allChannelDisplays[5] = _totalChannelDisplay = new BandwidthChannelDisplay(&bandwidthRecorder->totalChannel, form); + _allChannelDisplays[0] = _audioChannelDisplay = + new BandwidthChannelDisplay(&bandwidthRecorder->audioChannel, form, "Audio", "Kbps", 1.0, COLOR0); + _allChannelDisplays[1] = _avatarsChannelDisplay = + new BandwidthChannelDisplay(&bandwidthRecorder->avatarsChannel, form, "Avatars", "Kbps", 1.0, COLOR1); + _allChannelDisplays[2] = _octreeChannelDisplay = + new BandwidthChannelDisplay(&bandwidthRecorder->octreeChannel, form, "Octree", "Kbps", 1.0, COLOR2); + _allChannelDisplays[3] = _metavoxelsChannelDisplay = + new BandwidthChannelDisplay(&bandwidthRecorder->metavoxelsChannel, form, "Metavoxels", "Kbps", 1.0, COLOR2); + _allChannelDisplays[4] = _otherChannelDisplay = + new BandwidthChannelDisplay(&bandwidthRecorder->otherChannel, form, "Other", "Kbps", 1.0, COLOR2); + _allChannelDisplays[5] = _totalChannelDisplay = + new BandwidthChannelDisplay(&bandwidthRecorder->totalChannel, form, "Total", "Kbps", 1.0, COLOR2); connect(averageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateTimerTimeout())); averageUpdateTimer->start(1000); diff --git a/interface/src/ui/BandwidthDialog.h b/interface/src/ui/BandwidthDialog.h index 27d58dc1a3..7209235e18 100644 --- a/interface/src/ui/BandwidthDialog.h +++ b/interface/src/ui/BandwidthDialog.h @@ -19,17 +19,28 @@ #include "BandwidthRecorder.h" +const unsigned int COLOR0 = 0x33cc99ff; +const unsigned int COLOR1 = 0xffef40c0; +const unsigned int COLOR2 = 0xd0d0d0a0; + + class BandwidthChannelDisplay : public QObject { Q_OBJECT public: - BandwidthChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form); + BandwidthChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form, + char const* const caption, char const* unitCaption, float unitScale, unsigned colorRGBA); void Paint(); private: BandwidthRecorder::Channel *ch; QLabel* label; QString strBuf; + char const* const caption; + char const* unitCaption; + float const unitScale; + unsigned colorRGBA; + public slots: void bandwidthAverageUpdated(); diff --git a/libraries/networking/src/BandwidthRecorder.cpp b/libraries/networking/src/BandwidthRecorder.cpp index 4d595d0fa8..36256755bd 100644 --- a/libraries/networking/src/BandwidthRecorder.cpp +++ b/libraries/networking/src/BandwidthRecorder.cpp @@ -14,15 +14,7 @@ #include "BandwidthRecorder.h" -BandwidthRecorder::Channel::Channel(char const* const caption, - char const* unitCaption, - double unitScale, - unsigned colorRGBA) : - caption(caption), - unitCaption(unitCaption), - unitScale(unitScale), - colorRGBA(colorRGBA) -{ +BandwidthRecorder::Channel::Channel() { } float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() { diff --git a/libraries/networking/src/BandwidthRecorder.h b/libraries/networking/src/BandwidthRecorder.h index 5837702783..24e254552d 100644 --- a/libraries/networking/src/BandwidthRecorder.h +++ b/libraries/networking/src/BandwidthRecorder.h @@ -21,12 +21,6 @@ #include "Node.h" #include "SimpleMovingAverage.h" -const double DEFAULT_UNIT_SCALE = 1.0; - -const unsigned int COLOR0 = 0x33cc99ff; -const unsigned int COLOR1 = 0xffef40c0; -const unsigned int COLOR2 = 0xd0d0d0a0; - class BandwidthRecorder : public QObject, public Dependency { Q_OBJECT @@ -39,7 +33,7 @@ public: // keep track of data rate in two directions as well as units and style to use during display class Channel { public: - Channel(char const* const caption, char const* unitCaption, double unitScale, unsigned colorRGBA); + Channel(); float getAverageInputPacketsPerSecond(); float getAverageOutputPacketsPerSecond(); float getAverageInputKilobitsPerSecond(); @@ -48,24 +42,20 @@ public: void updateInputAverage(const float sample); void updateOutputAverage(const float sample); - // XXX make these private - char const* const caption; - char const* unitCaption; - double unitScale; - unsigned colorRGBA; - private: SimpleMovingAverage _input = SimpleMovingAverage(); SimpleMovingAverage _output = SimpleMovingAverage(); }; + + // create the channels we keep track of - Channel audioChannel = Channel("Audio", "Kbps", DEFAULT_UNIT_SCALE, COLOR0); - Channel avatarsChannel = Channel("Avatars", "Kbps", DEFAULT_UNIT_SCALE, COLOR1); - Channel octreeChannel = Channel("Octree", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); - Channel metavoxelsChannel = Channel("Metavoxels", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); - Channel otherChannel = Channel("Other", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); - Channel totalChannel = Channel("Total", "Kbps", DEFAULT_UNIT_SCALE, COLOR2); + Channel audioChannel = Channel(); + Channel avatarsChannel = Channel(); + Channel octreeChannel = Channel(); + Channel metavoxelsChannel = Channel(); + Channel otherChannel = Channel(); + Channel totalChannel = Channel(); public slots: void updateInboundData(const quint8 channelType, const int bytes); From 779a0086c4862c46775c26e5d09da376df2e6595 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 2 Feb 2015 11:56:50 -0800 Subject: [PATCH 11/18] BandwidthRecorder no longer knows about channel displays. cause overlay pps and Mbps to only update once per second --- interface/src/Application.cpp | 4 +- interface/src/ui/ApplicationOverlay.cpp | 8 +- interface/src/ui/BandwidthDialog.cpp | 38 ++-- interface/src/ui/BandwidthDialog.h | 7 +- interface/src/ui/Stats.cpp | 10 +- .../networking/src/BandwidthRecorder.cpp | 177 ++++++++++++------ libraries/networking/src/BandwidthRecorder.h | 26 ++- libraries/networking/src/LimitedNodeList.cpp | 5 +- libraries/networking/src/LimitedNodeList.h | 3 + .../networking/src/ThreadedAssignment.cpp | 1 + 10 files changed, 188 insertions(+), 91 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 517c229185..acbf3492ea 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -437,9 +437,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : // hook up bandwidth estimator QSharedPointer bandwidthRecorder = DependencyManager::get(); connect(nodeList.data(), SIGNAL(dataSent(const quint8, const int)), - &*bandwidthRecorder, SLOT(updateOutboundData(const quint8, const int))); + bandwidthRecorder.data(), SLOT(updateOutboundData(const quint8, const int))); connect(nodeList.data(), SIGNAL(dataReceived(const quint8, const int)), - &*bandwidthRecorder, SLOT(updateInboundData(const quint8, const int))); + bandwidthRecorder.data(), SLOT(updateInboundData(const quint8, const int))); // check first run... bool firstRun = SettingHandles::firstRun.get(); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index f63afb5aee..0eeac9a90e 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -920,10 +920,10 @@ void ApplicationOverlay::renderStatsAndLogs() { int voxelPacketsToProcess = octreePacketProcessor.packetsToProcessCount(); // Onscreen text about position, servers, etc Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, application->getFps(), - bandwidthRecorder->totalChannel.getAverageInputPacketsPerSecond(), - bandwidthRecorder->totalChannel.getAverageOutputPacketsPerSecond(), - bandwidthRecorder->totalChannel.getAverageInputKilobitsPerSecond(), - bandwidthRecorder->totalChannel.getAverageOutputKilobitsPerSecond(), + bandwidthRecorder->getCachedTotalAverageInputPacketsPerSecond(), + bandwidthRecorder->getCachedTotalAverageOutputPacketsPerSecond(), + bandwidthRecorder->getCachedTotalAverageInputKilobitsPerSecond(), + bandwidthRecorder->getCachedTotalAverageOutputKilobitsPerSecond(), voxelPacketsToProcess); } diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index f9ea02d662..8b9fbc2da9 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -22,16 +22,16 @@ #include -BandwidthChannelDisplay::BandwidthChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form, +BandwidthChannelDisplay::BandwidthChannelDisplay(QVector nodeTypesToFollow, + QFormLayout* form, char const* const caption, char const* unitCaption, const float unitScale, unsigned colorRGBA) : + nodeTypesToFollow(nodeTypesToFollow), caption(caption), unitCaption(unitCaption), unitScale(unitScale), colorRGBA(colorRGBA) { - this->ch = ch; - label = new QLabel(); label->setAlignment(Qt::AlignRight); @@ -47,9 +47,19 @@ BandwidthChannelDisplay::BandwidthChannelDisplay(BandwidthRecorder::Channel *ch, void BandwidthChannelDisplay::bandwidthAverageUpdated() { + float inTotal = 0.; + float outTotal = 0.; + + QSharedPointer bandwidthRecorder = DependencyManager::get(); + + for (int i = 0; i < nodeTypesToFollow.size(); ++i) { + inTotal += bandwidthRecorder->getAverageInputKilobitsPerSecond(nodeTypesToFollow.at(i)); + outTotal += bandwidthRecorder->getAverageOutputKilobitsPerSecond(nodeTypesToFollow.at(i)); + } + strBuf = - QString("").setNum((int) (ch->getAverageInputKilobitsPerSecond() * unitScale)) + "/" + - QString("").setNum((int) (ch->getAverageOutputKilobitsPerSecond() * unitScale)) + " " + unitCaption; + QString("").setNum((int) (inTotal * unitScale)) + "/" + + QString("").setNum((int) (outTotal * unitScale)) + " " + unitCaption; } @@ -58,7 +68,6 @@ void BandwidthChannelDisplay::Paint() { } - BandwidthDialog::BandwidthDialog(QWidget* parent) : QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) { @@ -71,18 +80,21 @@ BandwidthDialog::BandwidthDialog(QWidget* parent) : QSharedPointer bandwidthRecorder = DependencyManager::get(); _allChannelDisplays[0] = _audioChannelDisplay = - new BandwidthChannelDisplay(&bandwidthRecorder->audioChannel, form, "Audio", "Kbps", 1.0, COLOR0); + new BandwidthChannelDisplay({NodeType::AudioMixer}, form, "Audio", "Kbps", 1.0, COLOR0); _allChannelDisplays[1] = _avatarsChannelDisplay = - new BandwidthChannelDisplay(&bandwidthRecorder->avatarsChannel, form, "Avatars", "Kbps", 1.0, COLOR1); + new BandwidthChannelDisplay({NodeType::Agent, NodeType::AvatarMixer}, form, "Avatars", "Kbps", 1.0, COLOR1); _allChannelDisplays[2] = _octreeChannelDisplay = - new BandwidthChannelDisplay(&bandwidthRecorder->octreeChannel, form, "Octree", "Kbps", 1.0, COLOR2); + new BandwidthChannelDisplay({NodeType::DomainServer, NodeType::EntityServer}, form, "Octree", "Kbps", 1.0, COLOR2); _allChannelDisplays[3] = _metavoxelsChannelDisplay = - new BandwidthChannelDisplay(&bandwidthRecorder->metavoxelsChannel, form, "Metavoxels", "Kbps", 1.0, COLOR2); + new BandwidthChannelDisplay({NodeType::MetavoxelServer, NodeType::EnvironmentServer}, form, "Metavoxels", "Kbps", 1.0, COLOR2); _allChannelDisplays[4] = _otherChannelDisplay = - new BandwidthChannelDisplay(&bandwidthRecorder->otherChannel, form, "Other", "Kbps", 1.0, COLOR2); + new BandwidthChannelDisplay({NodeType::Unassigned}, form, "Other", "Kbps", 1.0, COLOR2); _allChannelDisplays[5] = _totalChannelDisplay = - new BandwidthChannelDisplay(&bandwidthRecorder->totalChannel, form, "Total", "Kbps", 1.0, COLOR2); - + new BandwidthChannelDisplay({NodeType::DomainServer, NodeType::EntityServer, NodeType::MetavoxelServer, + NodeType::EnvironmentServer, NodeType::AudioMixer, NodeType::Agent, + NodeType::AvatarMixer, NodeType::Unassigned}, + form, "Total", "Kbps", 1.0, COLOR2); + connect(averageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateTimerTimeout())); averageUpdateTimer->start(1000); } diff --git a/interface/src/ui/BandwidthDialog.h b/interface/src/ui/BandwidthDialog.h index 7209235e18..0ca38b5e4c 100644 --- a/interface/src/ui/BandwidthDialog.h +++ b/interface/src/ui/BandwidthDialog.h @@ -15,7 +15,9 @@ #include #include #include +#include +#include "Node.h" #include "BandwidthRecorder.h" @@ -28,12 +30,13 @@ class BandwidthChannelDisplay : public QObject { Q_OBJECT public: - BandwidthChannelDisplay(BandwidthRecorder::Channel *ch, QFormLayout* form, + BandwidthChannelDisplay(QVector nodeTypesToFollow, + QFormLayout* form, char const* const caption, char const* unitCaption, float unitScale, unsigned colorRGBA); void Paint(); private: - BandwidthRecorder::Channel *ch; + QVector nodeTypesToFollow; QLabel* label; QString strBuf; char const* const caption; diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index a29722825f..b271891ed9 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -443,12 +443,10 @@ void Stats::display( SharedNodePointer avatarMixer = DependencyManager::get()->soloNodeOfType(NodeType::AvatarMixer); if (avatarMixer) { sprintf(avatarMixerStats, "Avatar Mixer: %.f kbps, %.f pps", - // roundf(avatarMixer->getAverageKilobitsPerSecond()), - // roundf(avatarMixer->getAveragePacketsPerSecond()) - roundf(bandwidthRecorder->audioChannel.getAverageInputKilobitsPerSecond() + - bandwidthRecorder->audioChannel.getAverageOutputKilobitsPerSecond()), - roundf(bandwidthRecorder->audioChannel.getAverageInputPacketsPerSecond() + - bandwidthRecorder->audioChannel.getAverageOutputPacketsPerSecond())); + roundf(bandwidthRecorder->getAverageInputKilobitsPerSecond(NodeType::AudioMixer) + + bandwidthRecorder->getAverageOutputKilobitsPerSecond(NodeType::AudioMixer)), + roundf(bandwidthRecorder->getAverageInputPacketsPerSecond(NodeType::AudioMixer) + + bandwidthRecorder->getAverageOutputPacketsPerSecond(NodeType::AudioMixer))); } else { sprintf(avatarMixerStats, "No Avatar Mixer"); } diff --git a/libraries/networking/src/BandwidthRecorder.cpp b/libraries/networking/src/BandwidthRecorder.cpp index 36256755bd..097697a685 100644 --- a/libraries/networking/src/BandwidthRecorder.cpp +++ b/libraries/networking/src/BandwidthRecorder.cpp @@ -11,6 +11,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include +#include #include "BandwidthRecorder.h" @@ -48,69 +50,134 @@ void BandwidthRecorder::Channel::updateOutputAverage(const float sample) { _output.updateAverage(sample); } - - BandwidthRecorder::BandwidthRecorder() { + for (uint i=0; iupdateInputAverage(sample); } void BandwidthRecorder::updateOutboundData(const quint8 channelType, const int sample) { - - totalChannel.updateOutputAverage(sample); - - // see Node.h NodeType - switch (channelType) { - case NodeType::DomainServer: - case NodeType::EntityServer: - octreeChannel.updateOutputAverage(sample); - break; - case NodeType::MetavoxelServer: - case NodeType::EnvironmentServer: - metavoxelsChannel.updateOutputAverage(sample); - break; - case NodeType::AudioMixer: - audioChannel.updateOutputAverage(sample); - break; - case NodeType::Agent: - case NodeType::AvatarMixer: - avatarsChannel.updateOutputAverage(sample); - break; - case NodeType::Unassigned: - default: - otherChannel.updateOutputAverage(sample); - break; - } + Q_ASSERT(channelType < CHANNEL_COUNT); + if (! _channels[channelType]) + _channels[channelType] = new Channel(); + _channels[channelType]->updateOutputAverage(sample); +} + +float BandwidthRecorder::getAverageInputPacketsPerSecond(const quint8 channelType) { + Q_ASSERT(channelType < CHANNEL_COUNT); + if (! _channels[channelType]) + return 0.; + return _channels[channelType]->getAverageInputPacketsPerSecond(); +} + +float BandwidthRecorder::getAverageOutputPacketsPerSecond(const quint8 channelType) { + Q_ASSERT(channelType < CHANNEL_COUNT); + if (! _channels[channelType]) + return 0.; + return _channels[channelType]->getAverageOutputPacketsPerSecond(); +} + +float BandwidthRecorder::getAverageInputKilobitsPerSecond(const quint8 channelType) { + Q_ASSERT(channelType < CHANNEL_COUNT); + if (! _channels[channelType]) + return 0.; + return _channels[channelType]->getAverageInputKilobitsPerSecond(); +} + +float BandwidthRecorder::getAverageOutputKilobitsPerSecond(const quint8 channelType) { + Q_ASSERT(channelType < CHANNEL_COUNT); + if (! _channels[channelType]) + return 0.; + return _channels[channelType]->getAverageOutputKilobitsPerSecond(); +} + +float BandwidthRecorder::getTotalAverageInputPacketsPerSecond() { + float result = 0.; + for (uint i=0; igetAverageInputPacketsPerSecond(); + } + return result; +} + +float BandwidthRecorder::getTotalAverageOutputPacketsPerSecond() { + float result = 0.; + for (uint i=0; igetAverageOutputPacketsPerSecond(); + } + return result; +} + +float BandwidthRecorder::getTotalAverageInputKilobitsPerSecond(){ + float result = 0.; + for (uint i=0; igetAverageInputKilobitsPerSecond(); + } + return result; +} + +float BandwidthRecorder::getTotalAverageOutputKilobitsPerSecond(){ + float result = 0.; + for (uint i=0; igetAverageOutputKilobitsPerSecond(); + } + return result; +} + +float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() { + static qint64 lastCalculated = 0; + static float cachedValue = 0.; + qint64 now = QDateTime::currentMSecsSinceEpoch(); + if (now - lastCalculated > 1000.) { + lastCalculated = now; + cachedValue = getTotalAverageInputPacketsPerSecond(); + } + return cachedValue; +} + +float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() { + static qint64 lastCalculated = 0; + static float cachedValue = 0.; + qint64 now = QDateTime::currentMSecsSinceEpoch(); + if (now - lastCalculated > 1000.) { + lastCalculated = now; + cachedValue = getTotalAverageOutputPacketsPerSecond(); + } + return cachedValue; +} + +float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() { + static qint64 lastCalculated = 0; + static float cachedValue = 0.; + qint64 now = QDateTime::currentMSecsSinceEpoch(); + if (now - lastCalculated > 1000.) { + lastCalculated = now; + cachedValue = getTotalAverageInputKilobitsPerSecond(); + } + return cachedValue; +} + +float BandwidthRecorder::getCachedTotalAverageOutputKilobitsPerSecond() { + static qint64 lastCalculated = 0; + static float cachedValue = 0.; + qint64 now = QDateTime::currentMSecsSinceEpoch(); + if (now - lastCalculated > 1000.) { + lastCalculated = now; + cachedValue = getTotalAverageOutputKilobitsPerSecond(); + } + return cachedValue; } diff --git a/libraries/networking/src/BandwidthRecorder.h b/libraries/networking/src/BandwidthRecorder.h index 24e254552d..a7f51fbb45 100644 --- a/libraries/networking/src/BandwidthRecorder.h +++ b/libraries/networking/src/BandwidthRecorder.h @@ -47,15 +47,27 @@ public: SimpleMovingAverage _output = SimpleMovingAverage(); }; + float getAverageInputPacketsPerSecond(const quint8 channelType); + float getAverageOutputPacketsPerSecond(const quint8 channelType); + float getAverageInputKilobitsPerSecond(const quint8 channelType); + float getAverageOutputKilobitsPerSecond(const quint8 channelType); + + float getTotalAverageInputPacketsPerSecond(); + float getTotalAverageOutputPacketsPerSecond(); + float getTotalAverageInputKilobitsPerSecond(); + float getTotalAverageOutputKilobitsPerSecond(); + + float getCachedTotalAverageInputPacketsPerSecond(); + float getCachedTotalAverageOutputPacketsPerSecond(); + float getCachedTotalAverageInputKilobitsPerSecond(); + float getCachedTotalAverageOutputKilobitsPerSecond(); - // create the channels we keep track of - Channel audioChannel = Channel(); - Channel avatarsChannel = Channel(); - Channel octreeChannel = Channel(); - Channel metavoxelsChannel = Channel(); - Channel otherChannel = Channel(); - Channel totalChannel = Channel(); +private: + // one for each possible Node type + static const unsigned int CHANNEL_COUNT = 256; + Channel* _channels[CHANNEL_COUNT]; + public slots: void updateInboundData(const quint8 channelType, const int bytes); diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 7d188af6aa..c7948e37aa 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -233,9 +233,10 @@ qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSock replaceHashInPacketGivenConnectionUUID(datagramCopy, connectionSecret); } + // XXX can BandwidthRecorder be used for this? // stat collection for packets - // ++_numCollectedPackets; - // _numCollectedBytes += datagram.size(); + ++_numCollectedPackets; + _numCollectedBytes += datagram.size(); qint64 bytesWritten = _nodeSocket.writeDatagram(datagramCopy, destinationSockAddr.getAddress(), destinationSockAddr.getPort()); diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 233d3c9f0c..f80f0367c7 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -206,8 +206,11 @@ protected: HifiSockAddr _localSockAddr; HifiSockAddr _publicSockAddr; HifiSockAddr _stunSockAddr; + + // XXX can BandwidthRecorder be used for this? int _numCollectedPackets; int _numCollectedBytes; + QElapsedTimer _packetStatTimer; template diff --git a/libraries/networking/src/ThreadedAssignment.cpp b/libraries/networking/src/ThreadedAssignment.cpp index 21f520babb..ea94a8e22c 100644 --- a/libraries/networking/src/ThreadedAssignment.cpp +++ b/libraries/networking/src/ThreadedAssignment.cpp @@ -83,6 +83,7 @@ void ThreadedAssignment::addPacketStatsAndSendStatsPacket(QJsonObject &statsObje auto nodeList = DependencyManager::get(); float packetsPerSecond, bytesPerSecond; + // XXX can BandwidthRecorder be used for this? nodeList->getPacketStats(packetsPerSecond, bytesPerSecond); nodeList->resetPacketStats(); From 4377105410cfa10adb54a8c969c04ec5cac17f85 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 2 Feb 2015 12:13:54 -0800 Subject: [PATCH 12/18] formatting and cleanups --- interface/src/Application.cpp | 11 --------- interface/src/Application.h | 9 ------- interface/src/DatagramProcessor.cpp | 8 ------ interface/src/ui/BandwidthDialog.cpp | 1 - libraries/networking/src/LimitedNodeList.cpp | 3 --- libraries/networking/src/Node.cpp | 26 -------------------- libraries/networking/src/Node.h | 5 ---- libraries/networking/src/NodeList.cpp | 1 - 8 files changed, 64 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index acbf3492ea..90f0c65f60 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -242,10 +242,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _mousePressed(false), _enableProcessOctreeThread(true), _octreeProcessor(), -// _inPacketsPerSecond(0), -// _outPacketsPerSecond(0), -// _inBytesPerSecond(0), -// _outBytesPerSecond(0), _nodeBoundsDisplay(this), _previousScriptLocation(), _applicationOverlay(), @@ -1381,15 +1377,8 @@ void Application::timer() { float diffTime = (float)_timerStart.nsecsElapsed() / 1000000000.0f; _fps = (float)_frameCount / diffTime; - - // _inPacketsPerSecond = (float) _datagramProcessor.getInPacketCount() / diffTime; - // _outPacketsPerSecond = (float) _datagramProcessor.getOutPacketCount() / diffTime; - // _inBytesPerSecond = (float) _datagramProcessor.getInByteCount() / diffTime; - // _outBytesPerSecond = (float) _datagramProcessor.getOutByteCount() / diffTime; _frameCount = 0; - _datagramProcessor.resetCounters(); - _timerStart.start(); // ask the node list to check in with the domain server diff --git a/interface/src/Application.h b/interface/src/Application.h index dee323aa52..c6db04813b 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -207,10 +207,6 @@ public: Overlays& getOverlays() { return _overlays; } float getFps() const { return _fps; } - // float getInPacketsPerSecond() const { return _inPacketsPerSecond; } - // float getOutPacketsPerSecond() const { return _outPacketsPerSecond; } - // float getInBytesPerSecond() const { return _inBytesPerSecond; } - // float getOutBytesPerSecond() const { return _outBytesPerSecond; } const glm::vec3& getViewMatrixTranslation() const { return _viewMatrixTranslation; } void setViewMatrixTranslation(const glm::vec3& translation) { _viewMatrixTranslation = translation; } @@ -531,11 +527,6 @@ private: OctreePacketProcessor _octreeProcessor; EntityEditPacketSender _entityEditSender; - // int _inPacketsPerSecond; - // int _outPacketsPerSecond; - // int _inBytesPerSecond; - // int _outBytesPerSecond; - StDev _idleLoopStdev; float _idleLoopMeasuredJitter; diff --git a/interface/src/DatagramProcessor.cpp b/interface/src/DatagramProcessor.cpp index eb589140d0..632c4a2ae8 100644 --- a/interface/src/DatagramProcessor.cpp +++ b/interface/src/DatagramProcessor.cpp @@ -72,7 +72,6 @@ void DatagramProcessor::processDatagrams() { if (audioMixer) { audioMixer->setLastHeardMicrostamp(usecTimestampNow()); - // audioMixer->recordBytesReceived(incomingPacket.size()); } break; @@ -81,8 +80,6 @@ void DatagramProcessor::processDatagrams() { // this will keep creatorTokenIDs to IDs mapped correctly EntityItemID::handleAddEntityResponse(incomingPacket); application->getEntities()->getTree()->handleAddEntityResponse(incomingPacket); - // application->_bandwidthRecorder.octreeChannel->input.updateValue(incomingPacket.size()); - // application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); break; case PacketTypeEntityData: case PacketTypeEntityErase: @@ -96,8 +93,6 @@ void DatagramProcessor::processDatagrams() { // add this packet to our list of octree packets and process them on the octree data processing application->_octreeProcessor.queueReceivedPacket(matchedNode, incomingPacket); } - // application->_bandwidthRecorder.octreeChannel->input.updateValue(incomingPacket.size()); - // application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); break; } case PacketTypeMetavoxelData: @@ -118,9 +113,6 @@ void DatagramProcessor::processDatagrams() { Q_ARG(const QByteArray&, incomingPacket), Q_ARG(const QWeakPointer&, avatarMixer)); } - - // application->_bandwidthRecorder.avatarsChannel->input.updateValue(incomingPacket.size()); - // application->_bandwidthRecorder.totalChannel->input.updateValue(incomingPacket.size()); break; } case PacketTypeDomainConnectionDenied: { diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index 8b9fbc2da9..45c86a7344 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -9,7 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include #include #include "BandwidthRecorder.h" diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index c7948e37aa..f9664d3bb0 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -47,8 +47,6 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short _localSockAddr(), _publicSockAddr(), _stunSockAddr(STUN_SERVER_HOSTNAME, STUN_SERVER_PORT), - // _numCollectedPackets(0), - // _numCollectedBytes(0), _packetStatTimer() { static bool firstCall = true; @@ -323,7 +321,6 @@ int LimitedNodeList::updateNodeWithDataFromPacket(const SharedNodePointer& match QMutexLocker locker(&matchingNode->getMutex()); matchingNode->setLastHeardMicrostamp(usecTimestampNow()); - // matchingNode->recordBytesReceived(packet.size()); if (!matchingNode->getLinkedData() && linkedDataCreateCallback) { linkedDataCreateCallback(matchingNode.data()); diff --git a/libraries/networking/src/Node.cpp b/libraries/networking/src/Node.cpp index e8c73896f1..697ef99b6d 100644 --- a/libraries/networking/src/Node.cpp +++ b/libraries/networking/src/Node.cpp @@ -47,7 +47,6 @@ Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket, _activeSocket(NULL), _symmetricSocket(), _connectionSecret(), - // _bytesReceivedMovingAverage(NULL), _linkedData(NULL), _isAlive(true), _pingMs(-1), // "Uninitialized" @@ -60,33 +59,8 @@ Node::Node(const QUuid& uuid, NodeType_t type, const HifiSockAddr& publicSocket, Node::~Node() { delete _linkedData; - // delete _bytesReceivedMovingAverage; } -// void Node::recordBytesReceived(int bytesReceived) { -// if (!_bytesReceivedMovingAverage) { -// _bytesReceivedMovingAverage = new SimpleMovingAverage(100); -// } - -// _bytesReceivedMovingAverage->updateAverage((float) bytesReceived); -// } - -// float Node::getAveragePacketsPerSecond() { -// if (_bytesReceivedMovingAverage) { -// return (1 / _bytesReceivedMovingAverage->getEventDeltaAverage()); -// } else { -// return 0; -// } -// } - -// float Node::getAverageKilobitsPerSecond() { -// if (_bytesReceivedMovingAverage) { -// return (_bytesReceivedMovingAverage->getAverageSampleValuePerSecond() * (8.0f / 1000)); -// } else { -// return 0; -// } -// } - void Node::updateClockSkewUsec(int clockSkewSample) { _clockSkewMovingPercentile.updatePercentile((float)clockSkewSample); _clockSkewUsec = (int)_clockSkewMovingPercentile.getValueAtPercentile(); diff --git a/libraries/networking/src/Node.h b/libraries/networking/src/Node.h index 7d5e088038..3ff8d771e0 100644 --- a/libraries/networking/src/Node.h +++ b/libraries/networking/src/Node.h @@ -63,10 +63,6 @@ public: bool isAlive() const { return _isAlive; } void setAlive(bool isAlive) { _isAlive = isAlive; } - // void recordBytesReceived(int bytesReceived); - // float getAverageKilobitsPerSecond(); - // float getAveragePacketsPerSecond(); - int getPingMs() const { return _pingMs; } void setPingMs(int pingMs) { _pingMs = pingMs; } @@ -99,7 +95,6 @@ private: HifiSockAddr _symmetricSocket; QUuid _connectionSecret; - // SimpleMovingAverage* _bytesReceivedMovingAverage; NodeData* _linkedData; bool _isAlive; int _pingMs; diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index f86e0b85e4..b3e1375058 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -160,7 +160,6 @@ void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteAr break; } case PacketTypeUnverifiedPing: { - // send back a reply QByteArray replyPacket = constructPingReplyPacket(packet, _domainHandler.getICEClientID()); writeUnverifiedDatagram(replyPacket, senderSockAddr); From 8e64417607e82db9e04c12488104fc32ef15bc7b Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 2 Feb 2015 12:21:46 -0800 Subject: [PATCH 13/18] formatting and cleanups --- interface/src/DatagramProcessor.cpp | 2 -- interface/src/ui/BandwidthDialog.cpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/interface/src/DatagramProcessor.cpp b/interface/src/DatagramProcessor.cpp index 632c4a2ae8..bb4300a584 100644 --- a/interface/src/DatagramProcessor.cpp +++ b/interface/src/DatagramProcessor.cpp @@ -107,8 +107,6 @@ void DatagramProcessor::processDatagrams() { if (avatarMixer) { avatarMixer->setLastHeardMicrostamp(usecTimestampNow()); - // avatarMixer->recordBytesReceived(incomingPacket.size()); - QMetaObject::invokeMethod(&application->getAvatarManager(), "processAvatarMixerDatagram", Q_ARG(const QByteArray&, incomingPacket), Q_ARG(const QWeakPointer&, avatarMixer)); diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index 45c86a7344..3343d99da0 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -118,14 +118,12 @@ void BandwidthDialog::paintEvent(QPaintEvent* event) { this->setFixedSize(this->width(), this->height()); } - void BandwidthDialog::reject() { // Just regularly close upon ESC this->QDialog::close(); } - void BandwidthDialog::closeEvent(QCloseEvent* event) { this->QDialog::closeEvent(event); From e779a55e2201d210c36a2175fd362a3656abeddf Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 2 Feb 2015 12:30:11 -0800 Subject: [PATCH 14/18] remove stray debugging line --- libraries/networking/src/NodeList.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index b3e1375058..bb095b2a3d 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -108,9 +108,6 @@ void NodeList::timePingReply(const QByteArray& packet, const SharedNodePointer& } void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet) { - - emit dataReceived(NodeType::AudioMixer, packet.size()); // XXX - switch (packetTypeForPacket(packet)) { case PacketTypeDomainList: { processDomainServerList(packet); From 82b8595af84d19deb41160c36512e43ef2707424 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 2 Feb 2015 15:34:08 -0800 Subject: [PATCH 15/18] coding standard --- interface/src/ui/BandwidthDialog.cpp | 54 +++++++------- interface/src/ui/BandwidthDialog.h | 21 +++--- .../networking/src/BandwidthRecorder.cpp | 72 +++++++++++-------- libraries/networking/src/LimitedNodeList.cpp | 3 +- 4 files changed, 83 insertions(+), 67 deletions(-) diff --git a/interface/src/ui/BandwidthDialog.cpp b/interface/src/ui/BandwidthDialog.cpp index 3343d99da0..044774fad6 100644 --- a/interface/src/ui/BandwidthDialog.cpp +++ b/interface/src/ui/BandwidthDialog.cpp @@ -25,22 +25,22 @@ BandwidthChannelDisplay::BandwidthChannelDisplay(QVector nodeTypesTo QFormLayout* form, char const* const caption, char const* unitCaption, const float unitScale, unsigned colorRGBA) : - nodeTypesToFollow(nodeTypesToFollow), - caption(caption), - unitCaption(unitCaption), - unitScale(unitScale), - colorRGBA(colorRGBA) + _nodeTypesToFollow(nodeTypesToFollow), + _caption(caption), + _unitCaption(unitCaption), + _unitScale(unitScale), + _colorRGBA(colorRGBA) { - label = new QLabel(); - label->setAlignment(Qt::AlignRight); + _label = new QLabel(); + _label->setAlignment(Qt::AlignRight); - QPalette palette = label->palette(); + QPalette palette = _label->palette(); unsigned rgb = colorRGBA >> 8; rgb = ((rgb & 0xfefefeu) >> 1) + ((rgb & 0xf8f8f8) >> 3); palette.setColor(QPalette::WindowText, QColor::fromRgb(rgb)); - label->setPalette(palette); + _label->setPalette(palette); - form->addRow(QString(" ") + caption + " Bandwidth In/Out:", label); + form->addRow(QString(" ") + _caption + " Bandwidth In/Out:", _label); } @@ -51,19 +51,19 @@ void BandwidthChannelDisplay::bandwidthAverageUpdated() { QSharedPointer bandwidthRecorder = DependencyManager::get(); - for (int i = 0; i < nodeTypesToFollow.size(); ++i) { - inTotal += bandwidthRecorder->getAverageInputKilobitsPerSecond(nodeTypesToFollow.at(i)); - outTotal += bandwidthRecorder->getAverageOutputKilobitsPerSecond(nodeTypesToFollow.at(i)); + for (int i = 0; i < _nodeTypesToFollow.size(); ++i) { + inTotal += bandwidthRecorder->getAverageInputKilobitsPerSecond(_nodeTypesToFollow.at(i)); + outTotal += bandwidthRecorder->getAverageOutputKilobitsPerSecond(_nodeTypesToFollow.at(i)); } - strBuf = - QString("").setNum((int) (inTotal * unitScale)) + "/" + - QString("").setNum((int) (outTotal * unitScale)) + " " + unitCaption; + _strBuf = + QString("").setNum((int) (inTotal * _unitScale)) + "/" + + QString("").setNum((int) (outTotal * _unitScale)) + " " + _unitCaption; } -void BandwidthChannelDisplay::Paint() { - label->setText(strBuf); +void BandwidthChannelDisplay::paint() { + _label->setText(_strBuf); } @@ -83,12 +83,14 @@ BandwidthDialog::BandwidthDialog(QWidget* parent) : _allChannelDisplays[1] = _avatarsChannelDisplay = new BandwidthChannelDisplay({NodeType::Agent, NodeType::AvatarMixer}, form, "Avatars", "Kbps", 1.0, COLOR1); _allChannelDisplays[2] = _octreeChannelDisplay = - new BandwidthChannelDisplay({NodeType::DomainServer, NodeType::EntityServer}, form, "Octree", "Kbps", 1.0, COLOR2); - _allChannelDisplays[3] = _metavoxelsChannelDisplay = + new BandwidthChannelDisplay({NodeType::EntityServer}, form, "Octree", "Kbps", 1.0, COLOR2); + _allChannelDisplays[3] = _octreeChannelDisplay = + new BandwidthChannelDisplay({NodeType::DomainServer}, form, "Domain", "Kbps", 1.0, COLOR2); + _allChannelDisplays[4] = _metavoxelsChannelDisplay = new BandwidthChannelDisplay({NodeType::MetavoxelServer, NodeType::EnvironmentServer}, form, "Metavoxels", "Kbps", 1.0, COLOR2); - _allChannelDisplays[4] = _otherChannelDisplay = + _allChannelDisplays[5] = _otherChannelDisplay = new BandwidthChannelDisplay({NodeType::Unassigned}, form, "Other", "Kbps", 1.0, COLOR2); - _allChannelDisplays[5] = _totalChannelDisplay = + _allChannelDisplays[6] = _totalChannelDisplay = new BandwidthChannelDisplay({NodeType::DomainServer, NodeType::EntityServer, NodeType::MetavoxelServer, NodeType::EnvironmentServer, NodeType::AudioMixer, NodeType::Agent, NodeType::AvatarMixer, NodeType::Unassigned}, @@ -100,20 +102,22 @@ BandwidthDialog::BandwidthDialog(QWidget* parent) : BandwidthDialog::~BandwidthDialog() { - for (unsigned int i=0; i<_CHANNELCOUNT; i++) + for (unsigned int i = 0; i < _CHANNELCOUNT; i++) { delete _allChannelDisplays[i]; + } } void BandwidthDialog::updateTimerTimeout() { - for (unsigned int i=0; i<_CHANNELCOUNT; i++) + for (unsigned int i = 0; i < _CHANNELCOUNT; i++) { _allChannelDisplays[i]->bandwidthAverageUpdated(); + } } void BandwidthDialog::paintEvent(QPaintEvent* event) { for (unsigned int i=0; i<_CHANNELCOUNT; i++) - _allChannelDisplays[i]->Paint(); + _allChannelDisplays[i]->paint(); this->QDialog::paintEvent(event); this->setFixedSize(this->width(), this->height()); } diff --git a/interface/src/ui/BandwidthDialog.h b/interface/src/ui/BandwidthDialog.h index 0ca38b5e4c..a73380bb8c 100644 --- a/interface/src/ui/BandwidthDialog.h +++ b/interface/src/ui/BandwidthDialog.h @@ -33,16 +33,16 @@ class BandwidthChannelDisplay : public QObject { BandwidthChannelDisplay(QVector nodeTypesToFollow, QFormLayout* form, char const* const caption, char const* unitCaption, float unitScale, unsigned colorRGBA); - void Paint(); + void paint(); private: - QVector nodeTypesToFollow; - QLabel* label; - QString strBuf; - char const* const caption; - char const* unitCaption; - float const unitScale; - unsigned colorRGBA; + QVector _nodeTypesToFollow; + QLabel* _label; + QString _strBuf; + char const* const _caption; + char const* _unitCaption; + float const _unitScale; + unsigned _colorRGBA; public slots: @@ -62,12 +62,13 @@ private: BandwidthChannelDisplay* _audioChannelDisplay; BandwidthChannelDisplay* _avatarsChannelDisplay; BandwidthChannelDisplay* _octreeChannelDisplay; + BandwidthChannelDisplay* _domainChannelDisplay; BandwidthChannelDisplay* _metavoxelsChannelDisplay; BandwidthChannelDisplay* _otherChannelDisplay; BandwidthChannelDisplay* _totalChannelDisplay; // sums of all the other channels - static const unsigned int _CHANNELCOUNT = 6; - BandwidthChannelDisplay *_allChannelDisplays[_CHANNELCOUNT]; + static const unsigned int _CHANNELCOUNT = 7; + BandwidthChannelDisplay* _allChannelDisplays[_CHANNELCOUNT]; signals: diff --git a/libraries/networking/src/BandwidthRecorder.cpp b/libraries/networking/src/BandwidthRecorder.cpp index 097697a685..d74236a521 100644 --- a/libraries/networking/src/BandwidthRecorder.cpp +++ b/libraries/networking/src/BandwidthRecorder.cpp @@ -21,16 +21,18 @@ BandwidthRecorder::Channel::Channel() { float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() { float delt = _input.getEventDeltaAverage(); - if (delt > 0.) + if (delt > 0.) { return (1.0 / delt); - return 0.; + } + return 0.0f; } float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() { float delt = _input.getEventDeltaAverage(); - if (delt > 0.) + if (delt > 0.) { return (1.0 / _output.getEventDeltaAverage()); - return 0.; + } + return 0.0f; } float BandwidthRecorder::Channel::getAverageInputKilobitsPerSecond() { @@ -62,87 +64,97 @@ BandwidthRecorder::~BandwidthRecorder() { void BandwidthRecorder::updateInboundData(const quint8 channelType, const int sample) { Q_ASSERT(channelType < CHANNEL_COUNT); - if (! _channels[channelType]) + if (! _channels[channelType]) { _channels[channelType] = new Channel(); + } _channels[channelType]->updateInputAverage(sample); } void BandwidthRecorder::updateOutboundData(const quint8 channelType, const int sample) { Q_ASSERT(channelType < CHANNEL_COUNT); - if (! _channels[channelType]) + if (! _channels[channelType]) { _channels[channelType] = new Channel(); + } _channels[channelType]->updateOutputAverage(sample); } float BandwidthRecorder::getAverageInputPacketsPerSecond(const quint8 channelType) { Q_ASSERT(channelType < CHANNEL_COUNT); - if (! _channels[channelType]) - return 0.; + if (! _channels[channelType]) { + return 0.0f; + } return _channels[channelType]->getAverageInputPacketsPerSecond(); } float BandwidthRecorder::getAverageOutputPacketsPerSecond(const quint8 channelType) { Q_ASSERT(channelType < CHANNEL_COUNT); - if (! _channels[channelType]) - return 0.; + if (! _channels[channelType]) { + return 0.0f; + } return _channels[channelType]->getAverageOutputPacketsPerSecond(); } float BandwidthRecorder::getAverageInputKilobitsPerSecond(const quint8 channelType) { Q_ASSERT(channelType < CHANNEL_COUNT); - if (! _channels[channelType]) - return 0.; + if (! _channels[channelType]) { + return 0.0f; + } return _channels[channelType]->getAverageInputKilobitsPerSecond(); } float BandwidthRecorder::getAverageOutputKilobitsPerSecond(const quint8 channelType) { Q_ASSERT(channelType < CHANNEL_COUNT); - if (! _channels[channelType]) - return 0.; + if (! _channels[channelType]) { + return 0.0f; + } return _channels[channelType]->getAverageOutputKilobitsPerSecond(); } float BandwidthRecorder::getTotalAverageInputPacketsPerSecond() { - float result = 0.; + float result = 0.0f; for (uint i=0; igetAverageInputPacketsPerSecond(); + } } return result; } float BandwidthRecorder::getTotalAverageOutputPacketsPerSecond() { - float result = 0.; + float result = 0.0f; for (uint i=0; igetAverageOutputPacketsPerSecond(); + } } return result; } float BandwidthRecorder::getTotalAverageInputKilobitsPerSecond(){ - float result = 0.; + float result = 0.0f; for (uint i=0; igetAverageInputKilobitsPerSecond(); + } } return result; } float BandwidthRecorder::getTotalAverageOutputKilobitsPerSecond(){ - float result = 0.; + float result = 0.0f; for (uint i=0; igetAverageOutputKilobitsPerSecond(); + } } return result; } float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() { static qint64 lastCalculated = 0; - static float cachedValue = 0.; + static float cachedValue = 0.0f; qint64 now = QDateTime::currentMSecsSinceEpoch(); - if (now - lastCalculated > 1000.) { + if (now - lastCalculated > 1000.0f) { lastCalculated = now; cachedValue = getTotalAverageInputPacketsPerSecond(); } @@ -151,9 +163,9 @@ float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() { float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() { static qint64 lastCalculated = 0; - static float cachedValue = 0.; + static float cachedValue = 0.0f; qint64 now = QDateTime::currentMSecsSinceEpoch(); - if (now - lastCalculated > 1000.) { + if (now - lastCalculated > 1000.0f) { lastCalculated = now; cachedValue = getTotalAverageOutputPacketsPerSecond(); } @@ -162,9 +174,9 @@ float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() { float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() { static qint64 lastCalculated = 0; - static float cachedValue = 0.; + static float cachedValue = 0.0f; qint64 now = QDateTime::currentMSecsSinceEpoch(); - if (now - lastCalculated > 1000.) { + if (now - lastCalculated > 1000.0f) { lastCalculated = now; cachedValue = getTotalAverageInputKilobitsPerSecond(); } @@ -173,9 +185,9 @@ float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() { float BandwidthRecorder::getCachedTotalAverageOutputKilobitsPerSecond() { static qint64 lastCalculated = 0; - static float cachedValue = 0.; + static float cachedValue = 0.0f; qint64 now = QDateTime::currentMSecsSinceEpoch(); - if (now - lastCalculated > 1000.) { + if (now - lastCalculated > 1000.0f) { lastCalculated = now; cachedValue = getTotalAverageOutputKilobitsPerSecond(); } diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index f9664d3bb0..bdbd5476ff 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -214,8 +214,7 @@ qint64 LimitedNodeList::readDatagram(QByteArray& incomingPacket, QHostAddress* a SharedNodePointer sendingNode = sendingNodeForPacket(incomingPacket); if (sendingNode) { emit dataReceived(sendingNode->getType(), incomingPacket.size()); - } - else { + } else { emit dataReceived(NodeType::Unassigned, incomingPacket.size()); } From 3fdf05ff7745cdbd6a44073076e895eb89075a3a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 2 Feb 2015 15:36:18 -0800 Subject: [PATCH 16/18] coding standard --- interface/src/ui/BandwidthDialog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/BandwidthDialog.h b/interface/src/ui/BandwidthDialog.h index a73380bb8c..cf4c34b0a9 100644 --- a/interface/src/ui/BandwidthDialog.h +++ b/interface/src/ui/BandwidthDialog.h @@ -87,7 +87,7 @@ protected: void closeEvent(QCloseEvent*); private: - QTimer *averageUpdateTimer = new QTimer(this); + QTimer* averageUpdateTimer = new QTimer(this); }; From 38162380ade132b9bf1a382dcbae6db1f48e4b1f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 2 Feb 2015 15:37:28 -0800 Subject: [PATCH 17/18] coding standard --- libraries/networking/src/BandwidthRecorder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/BandwidthRecorder.cpp b/libraries/networking/src/BandwidthRecorder.cpp index d74236a521..f03aaa4150 100644 --- a/libraries/networking/src/BandwidthRecorder.cpp +++ b/libraries/networking/src/BandwidthRecorder.cpp @@ -21,7 +21,7 @@ BandwidthRecorder::Channel::Channel() { float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() { float delt = _input.getEventDeltaAverage(); - if (delt > 0.) { + if (delt > 0.0f) { return (1.0 / delt); } return 0.0f; @@ -29,7 +29,7 @@ float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() { float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() { float delt = _input.getEventDeltaAverage(); - if (delt > 0.) { + if (delt > 0.0f) { return (1.0 / _output.getEventDeltaAverage()); } return 0.0f; From 13ea8ddb9e7589d8dc6e3a92d0688156187a10f1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 3 Feb 2015 08:52:58 -0800 Subject: [PATCH 18/18] Add missing _texture to BillboardOverlay copy ctor --- interface/src/ui/overlays/BillboardOverlay.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/ui/overlays/BillboardOverlay.cpp b/interface/src/ui/overlays/BillboardOverlay.cpp index b1c412bf56..27bd0c9102 100644 --- a/interface/src/ui/overlays/BillboardOverlay.cpp +++ b/interface/src/ui/overlays/BillboardOverlay.cpp @@ -24,6 +24,7 @@ BillboardOverlay::BillboardOverlay() : BillboardOverlay::BillboardOverlay(const BillboardOverlay* billboardOverlay) : Base3DOverlay(billboardOverlay), _url(billboardOverlay->_url), + _texture(billboardOverlay->_texture), _fromImage(billboardOverlay->_fromImage), _scale(billboardOverlay->_scale), _isFacingAvatar(billboardOverlay->_isFacingAvatar)