mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-10 08:38:20 +00:00
[client] imgui: use struct for graph metrics instead of array
This allows the members to be named, making the code much easier to read.
This commit is contained in:
parent
15bc6a1509
commit
6da9428d85
@ -642,26 +642,35 @@ void app_unregisterGraph(GraphHandle handle)
|
|||||||
handle->enabled = false;
|
handle->enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct BufferMetrics
|
||||||
|
{
|
||||||
|
float min;
|
||||||
|
float max;
|
||||||
|
float sum;
|
||||||
|
float avg;
|
||||||
|
float freq;
|
||||||
|
};
|
||||||
|
|
||||||
static bool rbCalcMetrics(int index, void * value_, void * udata_)
|
static bool rbCalcMetrics(int index, void * value_, void * udata_)
|
||||||
{
|
{
|
||||||
float * value = value_;
|
float * value = value_;
|
||||||
float * udata = udata_;
|
struct BufferMetrics * udata = udata_;
|
||||||
|
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
{
|
{
|
||||||
udata[0] = *value;
|
udata->min = *value;
|
||||||
udata[1] = *value;
|
udata->max = *value;
|
||||||
udata[2] = *value;
|
udata->sum = *value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (udata[0] > *value)
|
if (udata->min > *value)
|
||||||
udata[0] = *value;
|
udata->min = *value;
|
||||||
|
|
||||||
if (udata[1] < *value)
|
if (udata->max < *value)
|
||||||
udata[1] = *value;
|
udata->max = *value;
|
||||||
|
|
||||||
udata[2] += *value;
|
udata->sum += *value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,13 +702,13 @@ bool app_renderImGui(void)
|
|||||||
if (!graph->enabled)
|
if (!graph->enabled)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float metrics[4] = {};
|
struct BufferMetrics metrics = {};
|
||||||
ringbuffer_forEach(graph->buffer, rbCalcMetrics, metrics);
|
ringbuffer_forEach(graph->buffer, rbCalcMetrics, &metrics);
|
||||||
|
|
||||||
if (metrics[2] > 0.0f)
|
if (metrics.sum > 0.0f)
|
||||||
{
|
{
|
||||||
metrics[2] /= ringbuffer_getCount(graph->buffer);
|
metrics.avg = metrics.sum / ringbuffer_getCount(graph->buffer);
|
||||||
metrics[3] = 1000.0f / metrics[2];
|
metrics.freq = 1000.0f / metrics.avg;
|
||||||
}
|
}
|
||||||
|
|
||||||
char title[64];
|
char title[64];
|
||||||
@ -707,7 +716,7 @@ bool app_renderImGui(void)
|
|||||||
|
|
||||||
snprintf(title, sizeof(title),
|
snprintf(title, sizeof(title),
|
||||||
"%s: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz",
|
"%s: min:%4.2f max:%4.2f avg:%4.2f/%4.2fHz",
|
||||||
graph->name, metrics[0], metrics[1], metrics[2], metrics[3]);
|
graph->name, metrics.min, metrics.max, metrics.avg, metrics.freq);
|
||||||
|
|
||||||
igPlotLinesFloatPtr(
|
igPlotLinesFloatPtr(
|
||||||
"",
|
"",
|
||||||
|
Loading…
Reference in New Issue
Block a user