Const is good. Use it for viewer stats.

This commit is contained in:
Shyotl
2019-07-25 22:30:44 -05:00
parent ea2b1e179e
commit 6dc9210a7e
7 changed files with 764 additions and 581 deletions

View File

@@ -80,9 +80,10 @@ public:
private:
BOOL mUseFrameTimer;
const BOOL mUseFrameTimer;
const U32 mNumBins;
U32 mNumValues;
U32 mNumBins;
struct ValueEntry
{
@@ -101,7 +102,7 @@ private:
S32 mCurBin;
S32 mNextBin;
std::string mName;
const std::string mName;
static LLTimer sTimer;
static LLFrameTimer sFrameTimer;

View File

@@ -45,23 +45,17 @@
///////////////////////////////////////////////////////////////////////////////////
LLStatBar::LLStatBar(const std::string& name, const LLRect& rect, const std::string& setting,
LLStatBar::LLStatBar(const std::string& name, const LLRect& rect, LLStat* stat, const Parameters& parameters, const std::string& setting,
BOOL default_bar, BOOL default_history)
: LLView(name, rect, TRUE),
mSetting(setting),
mLabel(name),
mMinBar(0.f),
mMaxBar(50.f),
mStatp(NULL),
mTickSpacing(10.f),
mLabelSpacing(10.f),
mPrecision(0),
mUpdatesPerSec(5),
mPerSec(true),
mDisplayMean(true)
mParameters(parameters),
mStatp(stat),
mValue(0.f),
mMinShift(0),
mMaxShift(0)
{
mValue = 0.f;
S32 mode = -1;
if (mSetting.length() > 0)
{
@@ -133,7 +127,7 @@ void LLStatBar::draw()
// Get the values.
F32 current, min, max, mean;
if (mPerSec)
if (mParameters.mPerSec)
{
current = mStatp->getCurrentPerSec();
min = mStatp->getMinPerSec();
@@ -149,9 +143,9 @@ void LLStatBar::draw()
}
if ((mUpdatesPerSec == 0.f) || (mUpdateTimer.getElapsedTimeF32() > 1.f/mUpdatesPerSec) || (mValue == 0.f))
if ((mParameters.mUpdatesPerSec == 0.f) || (mUpdateTimer.getElapsedTimeF32() > 1.f/mParameters.mUpdatesPerSec) || (mValue == 0.f))
{
if (mDisplayMean)
if (mParameters.mDisplayMean)
{
mValue = mean;
}
@@ -170,20 +164,20 @@ void LLStatBar::draw()
S32 tick_width = 1;
S32 left, top, right, bottom;
F32 value_scale = max_width/(mMaxBar - mMinBar);
F32 value_scale = max_width/((mParameters.mMaxBar + mMaxShift) - (mParameters.mMinBar + mMinShift));
LLFontGL::getFontMonospace()->renderUTF8(mLabel, 0, 0, getRect().getHeight(), LLColor4(1.f, 1.f, 1.f, 1.f),
LLFontGL::LEFT, LLFontGL::TOP);
std::string value_str;
if (!mUnitLabel.empty())
if (!mParameters.mUnitLabel.empty())
{
value_str = llformat( "%.*f%s", mPrecision, mValue, mUnitLabel.c_str());
value_str = llformat( "%.*f%s", mParameters.mPrecision, mValue, mParameters.mUnitLabel.c_str());
}
else
{
value_str = llformat("%.*f", mPrecision, mValue);
value_str = llformat("%.*f", mParameters.mPrecision, mValue);
}
// Draw the value.
@@ -200,23 +194,23 @@ void LLStatBar::draw()
LLGLSUIDefault gls_ui;
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
for (tick_value = mMinBar; tick_value <= mMaxBar; tick_value += mTickSpacing)
for (tick_value = mParameters.mMinBar + mMinShift; tick_value <= (mParameters.mMaxBar + mMaxShift); tick_value += mParameters.mTickSpacing)
{
left = llfloor((tick_value - mMinBar)*value_scale);
left = llfloor((tick_value - (mParameters.mMinBar + mMinShift))*value_scale);
right = left + tick_width;
gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 1.f, 1.f, 0.1f));
}
// Draw the tick labels (and big ticks).
bottom = bar_top - bar_height - tick_height;
for (tick_value = mMinBar; tick_value <= mMaxBar; tick_value += mLabelSpacing)
for (tick_value = mParameters.mMinBar + mMinShift; tick_value <= (mParameters.mMaxBar + mMaxShift); tick_value += mParameters.mLabelSpacing)
{
left = llfloor((tick_value - mMinBar)*value_scale);
left = llfloor((tick_value - (mParameters.mMinBar + mMinShift))*value_scale);
right = left + tick_width;
gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 1.f, 1.f, 0.25f));
// draw labels for the tick marks
LLFontGL::getFontMonospace()->renderUTF8(llformat("%.*f", mPrecision, tick_value), 0, left - 1, bar_top - bar_height - tick_height,
LLFontGL::getFontMonospace()->renderUTF8(llformat("%.*f", mParameters.mPrecision, tick_value), 0, left - 1, bar_top - bar_height - tick_height,
LLColor4(1.f, 1.f, 1.f, 0.5f),
LLFontGL::LEFT, LLFontGL::TOP);
}
@@ -236,7 +230,7 @@ void LLStatBar::draw()
return;
}
// draw min and max
left = (S32) ((min - mMinBar) * value_scale);
left = (S32) ((min - (mParameters.mMinBar + mMinShift)) * value_scale);
if (left < 0)
{
@@ -244,7 +238,7 @@ void LLStatBar::draw()
LL_WARNS() << "Min:" << min << LL_ENDL;
}
right = (S32) ((max - mMinBar) * value_scale);
right = (S32) ((max - (mParameters.mMinBar + mMinShift)) * value_scale);
gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 0.f, 0.f, 0.25f));
S32 num_values = mStatp->getNumValues() - 1;
@@ -257,16 +251,16 @@ void LLStatBar::draw()
{
continue;
}
if (mPerSec)
if (mParameters.mPerSec)
{
left = (S32)((mStatp->getPrevPerSec(i) - mMinBar) * value_scale);
right = (S32)((mStatp->getPrevPerSec(i) - mMinBar) * value_scale) + 1;
left = (S32)((mStatp->getPrevPerSec(i) - (mParameters.mMinBar + mMinShift)) * value_scale);
right = (S32)((mStatp->getPrevPerSec(i) - (mParameters.mMinBar + mMinShift)) * value_scale) + 1;
gl_rect_2d(left, bottom+i+1, right, bottom+i, LLColor4(1.f, 0.f, 0.f, 1.f));
}
else
{
left = (S32)((mStatp->getPrev(i) - mMinBar) * value_scale);
right = (S32)((mStatp->getPrev(i) - mMinBar) * value_scale) + 1;
left = (S32)((mStatp->getPrev(i) - (mParameters.mMinBar + mMinShift)) * value_scale);
right = (S32)((mStatp->getPrev(i) - (mParameters.mMinBar + mMinShift)) * value_scale) + 1;
gl_rect_2d(left, bottom+i+1, right, bottom+i, LLColor4(1.f, 0.f, 0.f, 1.f));
}
}
@@ -274,27 +268,22 @@ void LLStatBar::draw()
else
{
// draw current
left = (S32) ((current - mMinBar) * value_scale) - 1;
right = (S32) ((current - mMinBar) * value_scale) + 1;
left = (S32) ((current - (mParameters.mMinBar + mMinShift)) * value_scale) - 1;
right = (S32) ((current - (mParameters.mMinBar + mMinShift)) * value_scale) + 1;
gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 0.f, 0.f, 1.f));
}
// draw mean bar
top = bar_top + 2;
bottom = bar_top - bar_height - 2;
left = (S32) ((mean - mMinBar) * value_scale) - 1;
right = (S32) ((mean - mMinBar) * value_scale) + 1;
left = (S32) ((mean - (mParameters.mMinBar + mMinShift)) * value_scale) - 1;
right = (S32) ((mean - (mParameters.mMinBar + mMinShift)) * value_scale) + 1;
gl_rect_2d(left, top, right, bottom, LLColor4(0.f, 1.f, 0.f, 1.f));
}
LLView::draw();
}
void LLStatBar::setUnitLabel(const std::string& unit_label)
{
mUnitLabel = unit_label;
}
LLRect LLStatBar::getRequiredRect()
{
LLRect rect;

View File

@@ -47,33 +47,60 @@ class LLStatBar : public LLView
};
public:
LLStatBar(const std::string& name, const LLRect& rect, const std::string& setting = std::string(),
struct Parameters {
Parameters() :
mMinBar(0.f),
mMaxBar(50.f),
mTickSpacing(10.f),
mLabelSpacing(10.f),
mPrecision(0),
mUpdatesPerSec(5),
mPerSec(true),
mDisplayMean(true),
mUnitLabel("")
{}
F32 mMinBar;
F32 mMaxBar;
F32 mTickSpacing;
F32 mLabelSpacing;
U32 mPrecision;
F32 mUpdatesPerSec;
BOOL mPerSec; // Use the per sec stats.
BOOL mDisplayMean; // If true, display mean, if false, display current value
std::string mUnitLabel;
};
LLStatBar(const std::string& name, const LLRect& rect, LLStat* stat, const LLStatBar::Parameters& parameters, const std::string& setting = std::string(),
BOOL default_bar = FALSE, BOOL default_history = FALSE);
virtual void draw();
virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
void fit(F32 value) {
if (mParameters.mMinBar + mMinShift > value)
{
mMinShift = value - mParameters.mMinBar;
}
if (mParameters.mMaxBar + mMaxShift < value)
{
mMaxShift = value - mParameters.mMaxBar;
}
}
void setUnitLabel(const std::string& unit_label);
/*virtual*/ LLRect getRequiredRect(); // Return the height of this object, given the set options.
F32 mMinBar;
F32 mMaxBar;
F32 mTickSpacing;
F32 mLabelSpacing;
U32 mPrecision;
F32 mUpdatesPerSec;
BOOL mPerSec; // Use the per sec stats.
private:
const Parameters mParameters;
BOOL mDisplayBar; // Display the bar graph.
BOOL mDisplayHistory;
BOOL mDisplayMean; // If true, display mean, if false, display current value
LLStat *mStatp;
private:
const LLStat* mStatp;
const LLUIString mLabel;
const std::string mSetting;
LLFrameTimer mUpdateTimer;
LLUIString mLabel;
std::string mUnitLabel;
F32 mValue;
std::string mSetting;
F32 mMinShift;
F32 mMaxShift;
};
#endif

View File

@@ -66,7 +66,7 @@ LLStatView::~LLStatView()
}
}
LLStatBar *LLStatView::addStat(const std::string& name, LLStat *statp,
LLStatBar *LLStatView::addStat(const std::string& name, LLStat *statp, const LLStatBar::Parameters& parameters,
const std::string& setting, BOOL default_bar, BOOL default_history)
{
LLStatBar *stat_barp;
@@ -74,8 +74,7 @@ LLStatBar *LLStatView::addStat(const std::string& name, LLStat *statp,
mNumStatBars++;
stat_barp = new LLStatBar(name, r, setting, default_bar, default_history);
stat_barp->mStatp = statp;
stat_barp = new LLStatBar(name, r, statp, parameters, setting, default_bar, default_history);
stat_barp->setVisible(mDisplayChildren);
addChildInBack(stat_barp);

View File

@@ -58,9 +58,10 @@ protected:
friend class LLUICtrlFactory;
public:
LLStatBar *addStat(const std::string& name, LLStat *statp,
LLStatBar *addStat(const std::string& name, LLStat *statp, const LLStatBar::Parameters& parameters,
const std::string& setting = std::string(), BOOL default_bar = FALSE, BOOL default_history = FALSE);
LLStatView *addStatView(LLStatView::Params& p);
protected:
typedef std::vector<LLStatBar *> sb_vector_t;
sb_vector_t mStatBars;

View File

@@ -72,17 +72,8 @@ void LLFloaterJoystick::draw()
for (U32 i = 0; i < 6; ++i)
{
F32 value = joystick->getJoystickAxis(i);
mAxisStatsBar[i]->fit(value);
mAxisStats[i]->addValue(value * gFrameIntervalSeconds);
auto& bar = mAxisStatsBar[i];
if (bar->mMinBar > value)
{
bar->mMinBar = value;
}
if (bar->mMaxBar < value)
{
bar->mMaxBar = value;
}
}
LLFloater::draw();
@@ -118,11 +109,12 @@ BOOL LLFloaterJoystick::postBuild()
axis.setArg("[NUM]", llformat("%d", i));
std::string stat_name(llformat("Joystick axis %d", i));
mAxisStats[i] = new LLStat(stat_name,4);
mAxisStatsBar[i] = mAxisStatsView->addStat(axis, mAxisStats[i]);
mAxisStatsBar[i]->mMinBar = -range;
mAxisStatsBar[i]->mMaxBar = range;
mAxisStatsBar[i]->mLabelSpacing = range * 0.5f;
mAxisStatsBar[i]->mTickSpacing = range * 0.25f;
LLStatBar::Parameters params;
params.mMinBar = -range;
params.mMaxBar = range;
params.mLabelSpacing = range * 0.5f;
params.mTickSpacing = range * 0.25f;
mAxisStatsBar[i] = mAxisStatsView->addStat(axis, mAxisStats[i], params);
}
addChild(mAxisStatsView);

File diff suppressed because it is too large Load Diff