Я хочу следить за развитием темы.Я уже реализовал индикатор выполнения графически, но мне интересно, как эффективно измерить прогресс потока в реальном времени.
Индикатор выполнения
template<typename T>
inline T Saturate(T value, T min = static_cast<T>(0.0f), T max = static_cast<T>(1.0f))
{
return value < static_cast<T>(min) ? static_cast<T>(min) : value > static_cast<T>(max) ? static_cast<T>(max) : value;
}
void ProgressBar(float progress, const Vector2& size)
{
Panel* window = getPanel();
Vector2 position = //some position
progress = Saturate(progress);
window->renderer->FillRect({ position, size }, 0xff00a5ff);
window->renderer->FillRect(Rect(position.x, position.y, Lerp(0.0f, size.w, progress), size.h), 0xff0000ff);
//progress will be shown as a %
std::string progressText;
//ToString(value, how many decimal places)
progressText = ToString(progress * 100.0f, 2) + "%";
const float textWidth = font->getWidth(progressText) * context.fontScale,
textX = Clamp(Lerp(position.x, position.x + size.w, progress), position.x, position.x + size.w - textWidth);
window->renderer->DrawString(progressText, Vector2(textX, position.y + font->getAscender(progressText) * context.fontScale * 0.5f), 0xffffffff, context.fontScale, *font.get());
}
и где-нибудь в игровом цикле, напримериспользование
static float prog = 0.0f;
float progSpeed = 0.01f;
static float progDir = 1.0f;
prog += progSpeed * (1.0f / 60.0f) * progDir;
ProgressBar(prog, { 100.0f, 30.0f });
Я знаю, как измерить время выполнения:
uint t1 = getTime();
//... do sth
uint t2 = getTime();
uint executionTime = t2 - t1;
, но, конечно, индикатор выполнения будет обновляться после выполнения, поэтому он не будет отображаться в реальном времени.
Должен ли я использовать новую тему?Есть ли другие способы сделать это?