mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
introduces named constants for bandwidth meter channel indices / max. drag length
This commit is contained in:
parent
f49e63f842
commit
f062319c2b
6 changed files with 42 additions and 30 deletions
|
@ -70,6 +70,8 @@ using namespace std;
|
|||
static char STAR_FILE[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt";
|
||||
static char STAR_CACHE_FILE[] = "cachedStars.txt";
|
||||
|
||||
static const int BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH = 6; // farther dragged clicks are ignored
|
||||
|
||||
const glm::vec3 START_LOCATION(4.f, 0.f, 5.f); // Where one's own agent begins in the world
|
||||
// (will be overwritten if avatar data file is found)
|
||||
|
||||
|
@ -483,14 +485,14 @@ void Application::broadcastToAgents(unsigned char* data, size_t bytes, const cha
|
|||
|
||||
int n = AgentList::getInstance()->broadcastToAgents(data, bytes, &type, 1);
|
||||
|
||||
unsigned channel;
|
||||
BandwidthMeter::ChannelIndex channel;
|
||||
switch (type) {
|
||||
case AGENT_TYPE_AVATAR:
|
||||
case AGENT_TYPE_AVATAR_MIXER:
|
||||
channel = 1;
|
||||
channel = BandwidthMeter::AVATARS;
|
||||
break;
|
||||
case AGENT_TYPE_VOXEL_SERVER:
|
||||
channel = 2;
|
||||
channel = BandwidthMeter::VOXELS;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
|
@ -1004,7 +1006,7 @@ void Application::checkBandwidthMeterClick() {
|
|||
// ... to be called upon button release
|
||||
|
||||
if (_bandwidthDisplayOn->isChecked() &&
|
||||
glm::compMax(glm::abs(glm::ivec2(_mouseX - _mouseDragStartedX, _mouseY - _mouseDragStartedY))) <= 6 &&
|
||||
glm::compMax(glm::abs(glm::ivec2(_mouseX - _mouseDragStartedX, _mouseY - _mouseDragStartedY))) <= BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH &&
|
||||
_bandwidthMeter.isWithinArea(_mouseX, _mouseY, _glWidget->width(), _glWidget->height())) {
|
||||
|
||||
// The bandwidth meter is visible, the click didn't get dragged too far and
|
||||
|
@ -2843,7 +2845,7 @@ void* Application::networkReceive(void* args) {
|
|||
AgentList::getInstance()->processBulkAgentData(&senderAddress,
|
||||
app->_incomingPacket,
|
||||
bytesReceived);
|
||||
getInstance()->_bandwidthMeter.inputStream(1).updateValue(bytesReceived);
|
||||
getInstance()->_bandwidthMeter.inputStream(BandwidthMeter::AVATARS).updateValue(bytesReceived);
|
||||
break;
|
||||
case PACKET_HEADER_AVATAR_VOXEL_URL:
|
||||
processAvatarVoxelURLMessage(app->_incomingPacket, bytesReceived);
|
||||
|
|
|
@ -124,7 +124,7 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
|||
dataPacket,
|
||||
BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes);
|
||||
|
||||
interface->getBandwidthMeter()->outputStream(0)
|
||||
interface->getBandwidthMeter()->outputStream(BandwidthMeter::AUDIO)
|
||||
.updateValue(BUFFER_LENGTH_BYTES_PER_CHANNEL + leadingBytes);
|
||||
}
|
||||
|
||||
|
@ -448,7 +448,7 @@ void Audio::addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBy
|
|||
|
||||
_ringBuffer.parseData((unsigned char*) receivedData, PACKET_LENGTH_BYTES + sizeof(PACKET_HEADER));
|
||||
|
||||
Application::getInstance()->getBandwidthMeter()->inputStream(0)
|
||||
Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::AUDIO)
|
||||
.updateValue(PACKET_LENGTH_BYTES + sizeof(PACKET_HEADER));
|
||||
|
||||
_lastReceiveTime = currentReceiveTime;
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace { // .cpp-local
|
|||
int const INITIAL_SCALE_MAXIMUM_INDEX = 250; // / 9: exponent, % 9: mantissa - 2, 0 o--o 2 * 10^-10
|
||||
}
|
||||
|
||||
BandwidthMeter::ChannelInfo BandwidthMeter::_DEFAULT_CHANNELS[] = {
|
||||
BandwidthMeter::ChannelInfo BandwidthMeter::_CHANNELS[] = {
|
||||
{ "Audio" , "Kbps", 8000.0 / 1024.0, 0x40ff40d0 },
|
||||
{ "Avatars" , "Kbps", 8000.0 / 1024.0, 0xffef40c0 },
|
||||
{ "Voxels" , "Kbps", 8000.0 / 1024.0, 0xd0d0d0a0 }
|
||||
|
@ -46,7 +46,13 @@ BandwidthMeter::BandwidthMeter() :
|
|||
_textRenderer(SANS_FONT_FAMILY, -1, -1, false, TextRenderer::SHADOW_EFFECT),
|
||||
_scaleMaxIndex(INITIAL_SCALE_MAXIMUM_INDEX) {
|
||||
|
||||
memcpy(_channels, _DEFAULT_CHANNELS, sizeof(_DEFAULT_CHANNELS));
|
||||
_channels = static_cast<ChannelInfo*>( malloc(sizeof(_CHANNELS)) );
|
||||
memcpy(_channels, _CHANNELS, sizeof(_CHANNELS));
|
||||
}
|
||||
|
||||
BandwidthMeter::~BandwidthMeter() {
|
||||
|
||||
free(_channels);
|
||||
}
|
||||
|
||||
BandwidthMeter::Stream::Stream(float msToAverage) :
|
||||
|
@ -118,8 +124,8 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) {
|
|||
float totalIn = 0.0f, totalOut = 0.0f;
|
||||
for (int i = 0; i < N_CHANNELS; ++i) {
|
||||
|
||||
totalIn += inputStream(i).getValue();
|
||||
totalOut += outputStream(i).getValue();
|
||||
totalIn += inputStream(ChannelIndex(i)).getValue();
|
||||
totalOut += outputStream(ChannelIndex(i)).getValue();
|
||||
}
|
||||
totalIn *= UNIT_SCALE;
|
||||
totalOut *= UNIT_SCALE;
|
||||
|
@ -189,10 +195,11 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) {
|
|||
int xIn = 0, xOut = 0;
|
||||
for (int i = 0; i < N_CHANNELS; ++i) {
|
||||
|
||||
int wIn = int(barWidth * inputStream(i).getValue() * UNIT_SCALE / scaleMax);
|
||||
int wOut = int(barWidth * outputStream(i).getValue() * UNIT_SCALE / scaleMax);
|
||||
ChannelIndex chIdx = ChannelIndex(i);
|
||||
int wIn = int(barWidth * inputStream(chIdx).getValue() * UNIT_SCALE / scaleMax);
|
||||
int wOut = int(barWidth * outputStream(chIdx).getValue() * UNIT_SCALE / scaleMax);
|
||||
|
||||
setColorRGBA(channelInfo(i).colorRGBA);
|
||||
setColorRGBA(channelInfo(chIdx).colorRGBA);
|
||||
|
||||
if (wIn > 0) {
|
||||
renderBox(xIn, 0, wIn, barHeight);
|
||||
|
|
|
@ -19,6 +19,7 @@ class BandwidthMeter {
|
|||
public:
|
||||
|
||||
BandwidthMeter();
|
||||
~BandwidthMeter();
|
||||
|
||||
void render(int screenWidth, int screenHeight);
|
||||
bool isWithinArea(int x, int y, int screenWidth, int screenHeight);
|
||||
|
@ -27,13 +28,16 @@ public:
|
|||
static size_t const N_CHANNELS = 3;
|
||||
static size_t const N_STREAMS = N_CHANNELS * 2;
|
||||
|
||||
// Channel usage.
|
||||
enum ChannelIndex { AUDIO, AVATARS, VOXELS };
|
||||
|
||||
// Meta information held for a communication channel (bidirectional).
|
||||
struct ChannelInfo {
|
||||
|
||||
char const* caption;
|
||||
char const* unitCaption;
|
||||
double unitScale;
|
||||
unsigned colorRGBA;
|
||||
char const* const caption;
|
||||
char const* unitCaption;
|
||||
double unitScale;
|
||||
unsigned colorRGBA;
|
||||
};
|
||||
|
||||
// Representation of a data stream (unidirectional; input or output).
|
||||
|
@ -52,12 +56,12 @@ public:
|
|||
};
|
||||
|
||||
// Data model accessors
|
||||
Stream& inputStream(unsigned channelIndex) { return _streams[channelIndex * 2]; }
|
||||
Stream const& inputStream(unsigned channelIndex) const { return _streams[channelIndex * 2]; }
|
||||
Stream& outputStream(unsigned channelIndex) { return _streams[channelIndex * 2 + 1]; }
|
||||
Stream const& outputStream(unsigned channelIndex) const { return _streams[channelIndex * 2 + 1]; }
|
||||
ChannelInfo& channelInfo(unsigned index) { return _channels[index]; }
|
||||
ChannelInfo const& channelInfo(unsigned index) const { return _channels[index]; }
|
||||
Stream& inputStream(ChannelIndex i) { return _streams[i * 2]; }
|
||||
Stream const& inputStream(ChannelIndex i) const { return _streams[i * 2]; }
|
||||
Stream& outputStream(ChannelIndex i) { return _streams[i * 2 + 1]; }
|
||||
Stream const& outputStream(ChannelIndex i) const { return _streams[i * 2 + 1]; }
|
||||
ChannelInfo& channelInfo(ChannelIndex i) { return _channels[i]; }
|
||||
ChannelInfo const& channelInfo(ChannelIndex i) const { return _channels[i]; }
|
||||
|
||||
private:
|
||||
static void setColorRGBA(unsigned c);
|
||||
|
@ -67,10 +71,10 @@ private:
|
|||
static inline int centered(int subject, int object);
|
||||
|
||||
|
||||
static ChannelInfo _DEFAULT_CHANNELS[];
|
||||
static ChannelInfo _CHANNELS[];
|
||||
|
||||
TextRenderer _textRenderer;
|
||||
ChannelInfo _channels[N_CHANNELS];
|
||||
ChannelInfo* _channels;
|
||||
Stream _streams[N_STREAMS];
|
||||
int _scaleMaxIndex;
|
||||
};
|
||||
|
|
|
@ -161,7 +161,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
|
|||
|
||||
pthread_mutex_unlock(&_treeLock);
|
||||
|
||||
Application::getInstance()->getBandwidthMeter()->inputStream(2).updateValue(numBytes);
|
||||
Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::VOXELS).updateValue(numBytes);
|
||||
|
||||
return numBytes;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,8 @@ BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthMeter* model) :
|
|||
|
||||
// Setup labels
|
||||
for (int i = 0; i < BandwidthMeter::N_STREAMS; ++i) {
|
||||
int chIdx = i / 2;
|
||||
bool input = i % 2 == 0;
|
||||
BandwidthMeter::ChannelInfo& ch = _model->channelInfo(chIdx);
|
||||
BandwidthMeter::ChannelInfo& ch = _model->channelInfo(BandwidthMeter::ChannelIndex(i / 2));
|
||||
QLabel* label = _labels[i] = new QLabel();
|
||||
label->setAlignment(Qt::AlignRight);
|
||||
|
||||
|
@ -46,7 +45,7 @@ void BandwidthDialog::paintEvent(QPaintEvent* event) {
|
|||
// Update labels
|
||||
char strBuf[64];
|
||||
for (int i = 0; i < BandwidthMeter::N_STREAMS; ++i) {
|
||||
int chIdx = i / 2;
|
||||
BandwidthMeter::ChannelIndex chIdx = BandwidthMeter::ChannelIndex(i / 2);
|
||||
bool input = i % 2 == 0;
|
||||
BandwidthMeter::ChannelInfo& ch = _model->channelInfo(chIdx);
|
||||
BandwidthMeter::Stream& s = input ? _model->inputStream(chIdx) : _model->outputStream(chIdx);
|
||||
|
|
Loading…
Reference in a new issue