From 82b8595af84d19deb41160c36512e43ef2707424 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 2 Feb 2015 15:34:08 -0800 Subject: [PATCH] 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()); }