Const is good. Use it for viewer stats.
This commit is contained in:
@@ -80,9 +80,10 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BOOL mUseFrameTimer;
|
const BOOL mUseFrameTimer;
|
||||||
|
const U32 mNumBins;
|
||||||
|
|
||||||
U32 mNumValues;
|
U32 mNumValues;
|
||||||
U32 mNumBins;
|
|
||||||
|
|
||||||
struct ValueEntry
|
struct ValueEntry
|
||||||
{
|
{
|
||||||
@@ -101,7 +102,7 @@ private:
|
|||||||
S32 mCurBin;
|
S32 mCurBin;
|
||||||
S32 mNextBin;
|
S32 mNextBin;
|
||||||
|
|
||||||
std::string mName;
|
const std::string mName;
|
||||||
|
|
||||||
static LLTimer sTimer;
|
static LLTimer sTimer;
|
||||||
static LLFrameTimer sFrameTimer;
|
static LLFrameTimer sFrameTimer;
|
||||||
|
|||||||
@@ -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)
|
BOOL default_bar, BOOL default_history)
|
||||||
: LLView(name, rect, TRUE),
|
: LLView(name, rect, TRUE),
|
||||||
mSetting(setting),
|
mSetting(setting),
|
||||||
mLabel(name),
|
mLabel(name),
|
||||||
mMinBar(0.f),
|
mParameters(parameters),
|
||||||
mMaxBar(50.f),
|
mStatp(stat),
|
||||||
mStatp(NULL),
|
mValue(0.f),
|
||||||
mTickSpacing(10.f),
|
mMinShift(0),
|
||||||
mLabelSpacing(10.f),
|
mMaxShift(0)
|
||||||
mPrecision(0),
|
|
||||||
mUpdatesPerSec(5),
|
|
||||||
mPerSec(true),
|
|
||||||
mDisplayMean(true)
|
|
||||||
{
|
{
|
||||||
mValue = 0.f;
|
|
||||||
|
|
||||||
S32 mode = -1;
|
S32 mode = -1;
|
||||||
if (mSetting.length() > 0)
|
if (mSetting.length() > 0)
|
||||||
{
|
{
|
||||||
@@ -133,7 +127,7 @@ void LLStatBar::draw()
|
|||||||
|
|
||||||
// Get the values.
|
// Get the values.
|
||||||
F32 current, min, max, mean;
|
F32 current, min, max, mean;
|
||||||
if (mPerSec)
|
if (mParameters.mPerSec)
|
||||||
{
|
{
|
||||||
current = mStatp->getCurrentPerSec();
|
current = mStatp->getCurrentPerSec();
|
||||||
min = mStatp->getMinPerSec();
|
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;
|
mValue = mean;
|
||||||
}
|
}
|
||||||
@@ -170,20 +164,20 @@ void LLStatBar::draw()
|
|||||||
S32 tick_width = 1;
|
S32 tick_width = 1;
|
||||||
S32 left, top, right, bottom;
|
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::getFontMonospace()->renderUTF8(mLabel, 0, 0, getRect().getHeight(), LLColor4(1.f, 1.f, 1.f, 1.f),
|
||||||
LLFontGL::LEFT, LLFontGL::TOP);
|
LLFontGL::LEFT, LLFontGL::TOP);
|
||||||
|
|
||||||
|
|
||||||
std::string value_str;
|
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
|
else
|
||||||
{
|
{
|
||||||
value_str = llformat("%.*f", mPrecision, mValue);
|
value_str = llformat("%.*f", mParameters.mPrecision, mValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the value.
|
// Draw the value.
|
||||||
@@ -200,23 +194,23 @@ void LLStatBar::draw()
|
|||||||
|
|
||||||
LLGLSUIDefault gls_ui;
|
LLGLSUIDefault gls_ui;
|
||||||
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
|
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;
|
right = left + tick_width;
|
||||||
gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 1.f, 1.f, 0.1f));
|
gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 1.f, 1.f, 0.1f));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the tick labels (and big ticks).
|
// Draw the tick labels (and big ticks).
|
||||||
bottom = bar_top - bar_height - tick_height;
|
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;
|
right = left + tick_width;
|
||||||
gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 1.f, 1.f, 0.25f));
|
gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 1.f, 1.f, 0.25f));
|
||||||
|
|
||||||
// draw labels for the tick marks
|
// 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),
|
LLColor4(1.f, 1.f, 1.f, 0.5f),
|
||||||
LLFontGL::LEFT, LLFontGL::TOP);
|
LLFontGL::LEFT, LLFontGL::TOP);
|
||||||
}
|
}
|
||||||
@@ -236,7 +230,7 @@ void LLStatBar::draw()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// draw min and max
|
// draw min and max
|
||||||
left = (S32) ((min - mMinBar) * value_scale);
|
left = (S32) ((min - (mParameters.mMinBar + mMinShift)) * value_scale);
|
||||||
|
|
||||||
if (left < 0)
|
if (left < 0)
|
||||||
{
|
{
|
||||||
@@ -244,7 +238,7 @@ void LLStatBar::draw()
|
|||||||
LL_WARNS() << "Min:" << min << LL_ENDL;
|
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));
|
gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 0.f, 0.f, 0.25f));
|
||||||
|
|
||||||
S32 num_values = mStatp->getNumValues() - 1;
|
S32 num_values = mStatp->getNumValues() - 1;
|
||||||
@@ -257,16 +251,16 @@ void LLStatBar::draw()
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (mPerSec)
|
if (mParameters.mPerSec)
|
||||||
{
|
{
|
||||||
left = (S32)((mStatp->getPrevPerSec(i) - mMinBar) * value_scale);
|
left = (S32)((mStatp->getPrevPerSec(i) - (mParameters.mMinBar + mMinShift)) * value_scale);
|
||||||
right = (S32)((mStatp->getPrevPerSec(i) - mMinBar) * value_scale) + 1;
|
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));
|
gl_rect_2d(left, bottom+i+1, right, bottom+i, LLColor4(1.f, 0.f, 0.f, 1.f));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
left = (S32)((mStatp->getPrev(i) - mMinBar) * value_scale);
|
left = (S32)((mStatp->getPrev(i) - (mParameters.mMinBar + mMinShift)) * value_scale);
|
||||||
right = (S32)((mStatp->getPrev(i) - mMinBar) * value_scale) + 1;
|
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));
|
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
|
else
|
||||||
{
|
{
|
||||||
// draw current
|
// draw current
|
||||||
left = (S32) ((current - mMinBar) * value_scale) - 1;
|
left = (S32) ((current - (mParameters.mMinBar + mMinShift)) * value_scale) - 1;
|
||||||
right = (S32) ((current - mMinBar) * 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));
|
gl_rect_2d(left, top, right, bottom, LLColor4(1.f, 0.f, 0.f, 1.f));
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw mean bar
|
// draw mean bar
|
||||||
top = bar_top + 2;
|
top = bar_top + 2;
|
||||||
bottom = bar_top - bar_height - 2;
|
bottom = bar_top - bar_height - 2;
|
||||||
left = (S32) ((mean - mMinBar) * value_scale) - 1;
|
left = (S32) ((mean - (mParameters.mMinBar + mMinShift)) * value_scale) - 1;
|
||||||
right = (S32) ((mean - mMinBar) * 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));
|
gl_rect_2d(left, top, right, bottom, LLColor4(0.f, 1.f, 0.f, 1.f));
|
||||||
}
|
}
|
||||||
|
|
||||||
LLView::draw();
|
LLView::draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLStatBar::setUnitLabel(const std::string& unit_label)
|
|
||||||
{
|
|
||||||
mUnitLabel = unit_label;
|
|
||||||
}
|
|
||||||
|
|
||||||
LLRect LLStatBar::getRequiredRect()
|
LLRect LLStatBar::getRequiredRect()
|
||||||
{
|
{
|
||||||
LLRect rect;
|
LLRect rect;
|
||||||
|
|||||||
@@ -47,33 +47,60 @@ class LLStatBar : public LLView
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
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);
|
BOOL default_bar = FALSE, BOOL default_history = FALSE);
|
||||||
|
|
||||||
virtual void draw();
|
virtual void draw();
|
||||||
virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
|
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.
|
/*virtual*/ LLRect getRequiredRect(); // Return the height of this object, given the set options.
|
||||||
|
|
||||||
F32 mMinBar;
|
private:
|
||||||
F32 mMaxBar;
|
const Parameters mParameters;
|
||||||
F32 mTickSpacing;
|
|
||||||
F32 mLabelSpacing;
|
|
||||||
U32 mPrecision;
|
|
||||||
F32 mUpdatesPerSec;
|
|
||||||
BOOL mPerSec; // Use the per sec stats.
|
|
||||||
BOOL mDisplayBar; // Display the bar graph.
|
BOOL mDisplayBar; // Display the bar graph.
|
||||||
BOOL mDisplayHistory;
|
BOOL mDisplayHistory;
|
||||||
BOOL mDisplayMean; // If true, display mean, if false, display current value
|
|
||||||
|
|
||||||
LLStat *mStatp;
|
const LLStat* mStatp;
|
||||||
private:
|
const LLUIString mLabel;
|
||||||
|
const std::string mSetting;
|
||||||
|
|
||||||
LLFrameTimer mUpdateTimer;
|
LLFrameTimer mUpdateTimer;
|
||||||
LLUIString mLabel;
|
|
||||||
std::string mUnitLabel;
|
|
||||||
F32 mValue;
|
F32 mValue;
|
||||||
std::string mSetting;
|
F32 mMinShift;
|
||||||
|
F32 mMaxShift;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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)
|
const std::string& setting, BOOL default_bar, BOOL default_history)
|
||||||
{
|
{
|
||||||
LLStatBar *stat_barp;
|
LLStatBar *stat_barp;
|
||||||
@@ -74,8 +74,7 @@ LLStatBar *LLStatView::addStat(const std::string& name, LLStat *statp,
|
|||||||
|
|
||||||
mNumStatBars++;
|
mNumStatBars++;
|
||||||
|
|
||||||
stat_barp = new LLStatBar(name, r, setting, default_bar, default_history);
|
stat_barp = new LLStatBar(name, r, statp, parameters, setting, default_bar, default_history);
|
||||||
stat_barp->mStatp = statp;
|
|
||||||
|
|
||||||
stat_barp->setVisible(mDisplayChildren);
|
stat_barp->setVisible(mDisplayChildren);
|
||||||
addChildInBack(stat_barp);
|
addChildInBack(stat_barp);
|
||||||
|
|||||||
@@ -58,9 +58,10 @@ protected:
|
|||||||
friend class LLUICtrlFactory;
|
friend class LLUICtrlFactory;
|
||||||
public:
|
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);
|
const std::string& setting = std::string(), BOOL default_bar = FALSE, BOOL default_history = FALSE);
|
||||||
LLStatView *addStatView(LLStatView::Params& p);
|
LLStatView *addStatView(LLStatView::Params& p);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::vector<LLStatBar *> sb_vector_t;
|
typedef std::vector<LLStatBar *> sb_vector_t;
|
||||||
sb_vector_t mStatBars;
|
sb_vector_t mStatBars;
|
||||||
|
|||||||
@@ -72,17 +72,8 @@ void LLFloaterJoystick::draw()
|
|||||||
for (U32 i = 0; i < 6; ++i)
|
for (U32 i = 0; i < 6; ++i)
|
||||||
{
|
{
|
||||||
F32 value = joystick->getJoystickAxis(i);
|
F32 value = joystick->getJoystickAxis(i);
|
||||||
|
mAxisStatsBar[i]->fit(value);
|
||||||
mAxisStats[i]->addValue(value * gFrameIntervalSeconds);
|
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();
|
LLFloater::draw();
|
||||||
@@ -118,11 +109,12 @@ BOOL LLFloaterJoystick::postBuild()
|
|||||||
axis.setArg("[NUM]", llformat("%d", i));
|
axis.setArg("[NUM]", llformat("%d", i));
|
||||||
std::string stat_name(llformat("Joystick axis %d", i));
|
std::string stat_name(llformat("Joystick axis %d", i));
|
||||||
mAxisStats[i] = new LLStat(stat_name,4);
|
mAxisStats[i] = new LLStat(stat_name,4);
|
||||||
mAxisStatsBar[i] = mAxisStatsView->addStat(axis, mAxisStats[i]);
|
LLStatBar::Parameters params;
|
||||||
mAxisStatsBar[i]->mMinBar = -range;
|
params.mMinBar = -range;
|
||||||
mAxisStatsBar[i]->mMaxBar = range;
|
params.mMaxBar = range;
|
||||||
mAxisStatsBar[i]->mLabelSpacing = range * 0.5f;
|
params.mLabelSpacing = range * 0.5f;
|
||||||
mAxisStatsBar[i]->mTickSpacing = range * 0.25f;
|
params.mTickSpacing = range * 0.25f;
|
||||||
|
mAxisStatsBar[i] = mAxisStatsView->addStat(axis, mAxisStats[i], params);
|
||||||
}
|
}
|
||||||
|
|
||||||
addChild(mAxisStatsView);
|
addChild(mAxisStatsView);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user