coding standard

This commit is contained in:
Seth Alves 2015-02-02 15:34:08 -08:00
parent e779a55e22
commit 82b8595af8
4 changed files with 83 additions and 67 deletions

View file

@ -25,22 +25,22 @@ BandwidthChannelDisplay::BandwidthChannelDisplay(QVector<NodeType_t> nodeTypesTo
QFormLayout* form, QFormLayout* form,
char const* const caption, char const* unitCaption, char const* const caption, char const* unitCaption,
const float unitScale, unsigned colorRGBA) : const float unitScale, unsigned colorRGBA) :
nodeTypesToFollow(nodeTypesToFollow), _nodeTypesToFollow(nodeTypesToFollow),
caption(caption), _caption(caption),
unitCaption(unitCaption), _unitCaption(unitCaption),
unitScale(unitScale), _unitScale(unitScale),
colorRGBA(colorRGBA) _colorRGBA(colorRGBA)
{ {
label = new QLabel(); _label = new QLabel();
label->setAlignment(Qt::AlignRight); _label->setAlignment(Qt::AlignRight);
QPalette palette = label->palette(); QPalette palette = _label->palette();
unsigned rgb = colorRGBA >> 8; unsigned rgb = colorRGBA >> 8;
rgb = ((rgb & 0xfefefeu) >> 1) + ((rgb & 0xf8f8f8) >> 3); rgb = ((rgb & 0xfefefeu) >> 1) + ((rgb & 0xf8f8f8) >> 3);
palette.setColor(QPalette::WindowText, QColor::fromRgb(rgb)); 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> bandwidthRecorder = DependencyManager::get<BandwidthRecorder>(); QSharedPointer<BandwidthRecorder> bandwidthRecorder = DependencyManager::get<BandwidthRecorder>();
for (int i = 0; i < nodeTypesToFollow.size(); ++i) { for (int i = 0; i < _nodeTypesToFollow.size(); ++i) {
inTotal += bandwidthRecorder->getAverageInputKilobitsPerSecond(nodeTypesToFollow.at(i)); inTotal += bandwidthRecorder->getAverageInputKilobitsPerSecond(_nodeTypesToFollow.at(i));
outTotal += bandwidthRecorder->getAverageOutputKilobitsPerSecond(nodeTypesToFollow.at(i)); outTotal += bandwidthRecorder->getAverageOutputKilobitsPerSecond(_nodeTypesToFollow.at(i));
} }
strBuf = _strBuf =
QString("").setNum((int) (inTotal * unitScale)) + "/" + QString("").setNum((int) (inTotal * _unitScale)) + "/" +
QString("").setNum((int) (outTotal * unitScale)) + " " + unitCaption; QString("").setNum((int) (outTotal * _unitScale)) + " " + _unitCaption;
} }
void BandwidthChannelDisplay::Paint() { void BandwidthChannelDisplay::paint() {
label->setText(strBuf); _label->setText(_strBuf);
} }
@ -83,12 +83,14 @@ BandwidthDialog::BandwidthDialog(QWidget* parent) :
_allChannelDisplays[1] = _avatarsChannelDisplay = _allChannelDisplays[1] = _avatarsChannelDisplay =
new BandwidthChannelDisplay({NodeType::Agent, NodeType::AvatarMixer}, form, "Avatars", "Kbps", 1.0, COLOR1); new BandwidthChannelDisplay({NodeType::Agent, NodeType::AvatarMixer}, form, "Avatars", "Kbps", 1.0, COLOR1);
_allChannelDisplays[2] = _octreeChannelDisplay = _allChannelDisplays[2] = _octreeChannelDisplay =
new BandwidthChannelDisplay({NodeType::DomainServer, NodeType::EntityServer}, form, "Octree", "Kbps", 1.0, COLOR2); new BandwidthChannelDisplay({NodeType::EntityServer}, form, "Octree", "Kbps", 1.0, COLOR2);
_allChannelDisplays[3] = _metavoxelsChannelDisplay = _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); 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); new BandwidthChannelDisplay({NodeType::Unassigned}, form, "Other", "Kbps", 1.0, COLOR2);
_allChannelDisplays[5] = _totalChannelDisplay = _allChannelDisplays[6] = _totalChannelDisplay =
new BandwidthChannelDisplay({NodeType::DomainServer, NodeType::EntityServer, NodeType::MetavoxelServer, new BandwidthChannelDisplay({NodeType::DomainServer, NodeType::EntityServer, NodeType::MetavoxelServer,
NodeType::EnvironmentServer, NodeType::AudioMixer, NodeType::Agent, NodeType::EnvironmentServer, NodeType::AudioMixer, NodeType::Agent,
NodeType::AvatarMixer, NodeType::Unassigned}, NodeType::AvatarMixer, NodeType::Unassigned},
@ -100,20 +102,22 @@ BandwidthDialog::BandwidthDialog(QWidget* parent) :
BandwidthDialog::~BandwidthDialog() { BandwidthDialog::~BandwidthDialog() {
for (unsigned int i=0; i<_CHANNELCOUNT; i++) for (unsigned int i = 0; i < _CHANNELCOUNT; i++) {
delete _allChannelDisplays[i]; delete _allChannelDisplays[i];
}
} }
void BandwidthDialog::updateTimerTimeout() { void BandwidthDialog::updateTimerTimeout() {
for (unsigned int i=0; i<_CHANNELCOUNT; i++) for (unsigned int i = 0; i < _CHANNELCOUNT; i++) {
_allChannelDisplays[i]->bandwidthAverageUpdated(); _allChannelDisplays[i]->bandwidthAverageUpdated();
}
} }
void BandwidthDialog::paintEvent(QPaintEvent* event) { void BandwidthDialog::paintEvent(QPaintEvent* event) {
for (unsigned int i=0; i<_CHANNELCOUNT; i++) for (unsigned int i=0; i<_CHANNELCOUNT; i++)
_allChannelDisplays[i]->Paint(); _allChannelDisplays[i]->paint();
this->QDialog::paintEvent(event); this->QDialog::paintEvent(event);
this->setFixedSize(this->width(), this->height()); this->setFixedSize(this->width(), this->height());
} }

View file

@ -33,16 +33,16 @@ class BandwidthChannelDisplay : public QObject {
BandwidthChannelDisplay(QVector<NodeType_t> nodeTypesToFollow, BandwidthChannelDisplay(QVector<NodeType_t> nodeTypesToFollow,
QFormLayout* form, QFormLayout* form,
char const* const caption, char const* unitCaption, float unitScale, unsigned colorRGBA); char const* const caption, char const* unitCaption, float unitScale, unsigned colorRGBA);
void Paint(); void paint();
private: private:
QVector<NodeType_t> nodeTypesToFollow; QVector<NodeType_t> _nodeTypesToFollow;
QLabel* label; QLabel* _label;
QString strBuf; QString _strBuf;
char const* const caption; char const* const _caption;
char const* unitCaption; char const* _unitCaption;
float const unitScale; float const _unitScale;
unsigned colorRGBA; unsigned _colorRGBA;
public slots: public slots:
@ -62,12 +62,13 @@ private:
BandwidthChannelDisplay* _audioChannelDisplay; BandwidthChannelDisplay* _audioChannelDisplay;
BandwidthChannelDisplay* _avatarsChannelDisplay; BandwidthChannelDisplay* _avatarsChannelDisplay;
BandwidthChannelDisplay* _octreeChannelDisplay; BandwidthChannelDisplay* _octreeChannelDisplay;
BandwidthChannelDisplay* _domainChannelDisplay;
BandwidthChannelDisplay* _metavoxelsChannelDisplay; BandwidthChannelDisplay* _metavoxelsChannelDisplay;
BandwidthChannelDisplay* _otherChannelDisplay; BandwidthChannelDisplay* _otherChannelDisplay;
BandwidthChannelDisplay* _totalChannelDisplay; // sums of all the other channels BandwidthChannelDisplay* _totalChannelDisplay; // sums of all the other channels
static const unsigned int _CHANNELCOUNT = 6; static const unsigned int _CHANNELCOUNT = 7;
BandwidthChannelDisplay *_allChannelDisplays[_CHANNELCOUNT]; BandwidthChannelDisplay* _allChannelDisplays[_CHANNELCOUNT];
signals: signals:

View file

@ -21,16 +21,18 @@ BandwidthRecorder::Channel::Channel() {
float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() { float BandwidthRecorder::Channel::getAverageInputPacketsPerSecond() {
float delt = _input.getEventDeltaAverage(); float delt = _input.getEventDeltaAverage();
if (delt > 0.) if (delt > 0.) {
return (1.0 / delt); return (1.0 / delt);
return 0.; }
return 0.0f;
} }
float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() { float BandwidthRecorder::Channel::getAverageOutputPacketsPerSecond() {
float delt = _input.getEventDeltaAverage(); float delt = _input.getEventDeltaAverage();
if (delt > 0.) if (delt > 0.) {
return (1.0 / _output.getEventDeltaAverage()); return (1.0 / _output.getEventDeltaAverage());
return 0.; }
return 0.0f;
} }
float BandwidthRecorder::Channel::getAverageInputKilobitsPerSecond() { float BandwidthRecorder::Channel::getAverageInputKilobitsPerSecond() {
@ -62,87 +64,97 @@ BandwidthRecorder::~BandwidthRecorder() {
void BandwidthRecorder::updateInboundData(const quint8 channelType, const int sample) { void BandwidthRecorder::updateInboundData(const quint8 channelType, const int sample) {
Q_ASSERT(channelType < CHANNEL_COUNT); Q_ASSERT(channelType < CHANNEL_COUNT);
if (! _channels[channelType]) if (! _channels[channelType]) {
_channels[channelType] = new Channel(); _channels[channelType] = new Channel();
}
_channels[channelType]->updateInputAverage(sample); _channels[channelType]->updateInputAverage(sample);
} }
void BandwidthRecorder::updateOutboundData(const quint8 channelType, const int sample) { void BandwidthRecorder::updateOutboundData(const quint8 channelType, const int sample) {
Q_ASSERT(channelType < CHANNEL_COUNT); Q_ASSERT(channelType < CHANNEL_COUNT);
if (! _channels[channelType]) if (! _channels[channelType]) {
_channels[channelType] = new Channel(); _channels[channelType] = new Channel();
}
_channels[channelType]->updateOutputAverage(sample); _channels[channelType]->updateOutputAverage(sample);
} }
float BandwidthRecorder::getAverageInputPacketsPerSecond(const quint8 channelType) { float BandwidthRecorder::getAverageInputPacketsPerSecond(const quint8 channelType) {
Q_ASSERT(channelType < CHANNEL_COUNT); Q_ASSERT(channelType < CHANNEL_COUNT);
if (! _channels[channelType]) if (! _channels[channelType]) {
return 0.; return 0.0f;
}
return _channels[channelType]->getAverageInputPacketsPerSecond(); return _channels[channelType]->getAverageInputPacketsPerSecond();
} }
float BandwidthRecorder::getAverageOutputPacketsPerSecond(const quint8 channelType) { float BandwidthRecorder::getAverageOutputPacketsPerSecond(const quint8 channelType) {
Q_ASSERT(channelType < CHANNEL_COUNT); Q_ASSERT(channelType < CHANNEL_COUNT);
if (! _channels[channelType]) if (! _channels[channelType]) {
return 0.; return 0.0f;
}
return _channels[channelType]->getAverageOutputPacketsPerSecond(); return _channels[channelType]->getAverageOutputPacketsPerSecond();
} }
float BandwidthRecorder::getAverageInputKilobitsPerSecond(const quint8 channelType) { float BandwidthRecorder::getAverageInputKilobitsPerSecond(const quint8 channelType) {
Q_ASSERT(channelType < CHANNEL_COUNT); Q_ASSERT(channelType < CHANNEL_COUNT);
if (! _channels[channelType]) if (! _channels[channelType]) {
return 0.; return 0.0f;
}
return _channels[channelType]->getAverageInputKilobitsPerSecond(); return _channels[channelType]->getAverageInputKilobitsPerSecond();
} }
float BandwidthRecorder::getAverageOutputKilobitsPerSecond(const quint8 channelType) { float BandwidthRecorder::getAverageOutputKilobitsPerSecond(const quint8 channelType) {
Q_ASSERT(channelType < CHANNEL_COUNT); Q_ASSERT(channelType < CHANNEL_COUNT);
if (! _channels[channelType]) if (! _channels[channelType]) {
return 0.; return 0.0f;
}
return _channels[channelType]->getAverageOutputKilobitsPerSecond(); return _channels[channelType]->getAverageOutputKilobitsPerSecond();
} }
float BandwidthRecorder::getTotalAverageInputPacketsPerSecond() { float BandwidthRecorder::getTotalAverageInputPacketsPerSecond() {
float result = 0.; float result = 0.0f;
for (uint i=0; i<CHANNEL_COUNT; i++) { for (uint i=0; i<CHANNEL_COUNT; i++) {
if (_channels[i]) if (_channels[i]) {
result += _channels[i]->getAverageInputPacketsPerSecond(); result += _channels[i]->getAverageInputPacketsPerSecond();
} }
}
return result; return result;
} }
float BandwidthRecorder::getTotalAverageOutputPacketsPerSecond() { float BandwidthRecorder::getTotalAverageOutputPacketsPerSecond() {
float result = 0.; float result = 0.0f;
for (uint i=0; i<CHANNEL_COUNT; i++) { for (uint i=0; i<CHANNEL_COUNT; i++) {
if (_channels[i]) if (_channels[i]) {
result += _channels[i]->getAverageOutputPacketsPerSecond(); result += _channels[i]->getAverageOutputPacketsPerSecond();
} }
}
return result; return result;
} }
float BandwidthRecorder::getTotalAverageInputKilobitsPerSecond(){ float BandwidthRecorder::getTotalAverageInputKilobitsPerSecond(){
float result = 0.; float result = 0.0f;
for (uint i=0; i<CHANNEL_COUNT; i++) { for (uint i=0; i<CHANNEL_COUNT; i++) {
if (_channels[i]) if (_channels[i]) {
result += _channels[i]->getAverageInputKilobitsPerSecond(); result += _channels[i]->getAverageInputKilobitsPerSecond();
} }
}
return result; return result;
} }
float BandwidthRecorder::getTotalAverageOutputKilobitsPerSecond(){ float BandwidthRecorder::getTotalAverageOutputKilobitsPerSecond(){
float result = 0.; float result = 0.0f;
for (uint i=0; i<CHANNEL_COUNT; i++) { for (uint i=0; i<CHANNEL_COUNT; i++) {
if (_channels[i]) if (_channels[i]) {
result += _channels[i]->getAverageOutputKilobitsPerSecond(); result += _channels[i]->getAverageOutputKilobitsPerSecond();
} }
}
return result; return result;
} }
float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() { float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() {
static qint64 lastCalculated = 0; static qint64 lastCalculated = 0;
static float cachedValue = 0.; static float cachedValue = 0.0f;
qint64 now = QDateTime::currentMSecsSinceEpoch(); qint64 now = QDateTime::currentMSecsSinceEpoch();
if (now - lastCalculated > 1000.) { if (now - lastCalculated > 1000.0f) {
lastCalculated = now; lastCalculated = now;
cachedValue = getTotalAverageInputPacketsPerSecond(); cachedValue = getTotalAverageInputPacketsPerSecond();
} }
@ -151,9 +163,9 @@ float BandwidthRecorder::getCachedTotalAverageInputPacketsPerSecond() {
float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() { float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() {
static qint64 lastCalculated = 0; static qint64 lastCalculated = 0;
static float cachedValue = 0.; static float cachedValue = 0.0f;
qint64 now = QDateTime::currentMSecsSinceEpoch(); qint64 now = QDateTime::currentMSecsSinceEpoch();
if (now - lastCalculated > 1000.) { if (now - lastCalculated > 1000.0f) {
lastCalculated = now; lastCalculated = now;
cachedValue = getTotalAverageOutputPacketsPerSecond(); cachedValue = getTotalAverageOutputPacketsPerSecond();
} }
@ -162,9 +174,9 @@ float BandwidthRecorder::getCachedTotalAverageOutputPacketsPerSecond() {
float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() { float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() {
static qint64 lastCalculated = 0; static qint64 lastCalculated = 0;
static float cachedValue = 0.; static float cachedValue = 0.0f;
qint64 now = QDateTime::currentMSecsSinceEpoch(); qint64 now = QDateTime::currentMSecsSinceEpoch();
if (now - lastCalculated > 1000.) { if (now - lastCalculated > 1000.0f) {
lastCalculated = now; lastCalculated = now;
cachedValue = getTotalAverageInputKilobitsPerSecond(); cachedValue = getTotalAverageInputKilobitsPerSecond();
} }
@ -173,9 +185,9 @@ float BandwidthRecorder::getCachedTotalAverageInputKilobitsPerSecond() {
float BandwidthRecorder::getCachedTotalAverageOutputKilobitsPerSecond() { float BandwidthRecorder::getCachedTotalAverageOutputKilobitsPerSecond() {
static qint64 lastCalculated = 0; static qint64 lastCalculated = 0;
static float cachedValue = 0.; static float cachedValue = 0.0f;
qint64 now = QDateTime::currentMSecsSinceEpoch(); qint64 now = QDateTime::currentMSecsSinceEpoch();
if (now - lastCalculated > 1000.) { if (now - lastCalculated > 1000.0f) {
lastCalculated = now; lastCalculated = now;
cachedValue = getTotalAverageOutputKilobitsPerSecond(); cachedValue = getTotalAverageOutputKilobitsPerSecond();
} }

View file

@ -214,8 +214,7 @@ qint64 LimitedNodeList::readDatagram(QByteArray& incomingPacket, QHostAddress* a
SharedNodePointer sendingNode = sendingNodeForPacket(incomingPacket); SharedNodePointer sendingNode = sendingNodeForPacket(incomingPacket);
if (sendingNode) { if (sendingNode) {
emit dataReceived(sendingNode->getType(), incomingPacket.size()); emit dataReceived(sendingNode->getType(), incomingPacket.size());
} } else {
else {
emit dataReceived(NodeType::Unassigned, incomingPacket.size()); emit dataReceived(NodeType::Unassigned, incomingPacket.size());
} }