|
|
|
@ -5,6 +5,11 @@ GraphTimer::GraphTimer() {
|
|
|
|
|
start_time = std::chrono::system_clock::now();
|
|
|
|
|
started = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: This is a cardinal sin
|
|
|
|
|
if (instance == nullptr){
|
|
|
|
|
instance = this;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GraphTimer::~GraphTimer() {
|
|
|
|
@ -36,35 +41,37 @@ void GraphTimer::stop(unsigned int idx){
|
|
|
|
|
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
|
|
|
|
|
std::chrono::duration<double> elapsed_time = now - start_time;
|
|
|
|
|
|
|
|
|
|
if (++counters.at(idx) >= FPS_ARRAY_LENGTH)
|
|
|
|
|
counters.at(idx) = 0;
|
|
|
|
|
|
|
|
|
|
fps_vectors.at(idx).at(counters.at(idx)) = elapsed_time.count() - checkpoints.at(idx);
|
|
|
|
|
fps_vectors.at(idx).at(counters.at(idx)) = 1.0f / fps_vectors.at(idx).at(counters.at(idx));
|
|
|
|
|
if (++counters.at(idx) >= FPS_ARRAY_LENGTH - 1)
|
|
|
|
|
counters.at(idx) = 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GraphTimer::frame(unsigned int idx, double delta_time) {
|
|
|
|
|
fps_vectors.at(idx).at(counters.at(idx)) = 1.0 / delta_time;
|
|
|
|
|
if (++counters.at(idx) >= FPS_ARRAY_LENGTH - 1)
|
|
|
|
|
|
|
|
|
|
// Do this before we access to make the title generation in draw a bit easier
|
|
|
|
|
if (++counters.at(idx) >= FPS_ARRAY_LENGTH)
|
|
|
|
|
counters.at(idx) = 0;
|
|
|
|
|
|
|
|
|
|
fps_vectors.at(idx).at(counters.at(idx)) = 1.0 / delta_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GraphTimer::draw() {
|
|
|
|
|
|
|
|
|
|
ImGui::Begin("Performance");
|
|
|
|
|
|
|
|
|
|
std::vector<std::vector<int>> data = {
|
|
|
|
|
{1, 2, 3, 4},
|
|
|
|
|
{9, 3, 7, 1},
|
|
|
|
|
{8, 3, 6, 2}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::string title = std::to_string(fps_vectors.at(0).at(counters.at(0)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<ImColor> colors = {
|
|
|
|
|
ImColor(255, 255, 255),
|
|
|
|
|
ImColor(0, 255, 0),
|
|
|
|
|
ImColor(255, 0, 0),
|
|
|
|
|
ImColor(255, 255, 0),
|
|
|
|
|
ImColor( 0, 255, 255),
|
|
|
|
|
ImColor(255, 0, 255),
|
|
|
|
|
ImColor(255, 0, 0),
|
|
|
|
|
ImColor( 0, 255, 0),
|
|
|
|
|
ImColor( 0, 0, 255),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ImVec2 wh = ImGui::GetContentRegionAvail();
|
|
|
|
@ -74,15 +81,21 @@ void GraphTimer::draw() {
|
|
|
|
|
ImGui::PlotMultiLines(fps_vectors, title, labels, colors, 200, 0,
|
|
|
|
|
graph_size);
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
|
|
//ImVec2 wh(100, 200);
|
|
|
|
|
// ImGui::PlotLines("FPS", fps_array, 1000, 0,
|
|
|
|
|
// std::to_string(1.0 / fps_average).c_str(),
|
|
|
|
|
// 0.0f, 150.0f, wh);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
void GraphTimer::count(unsigned int idx, int counter) {
|
|
|
|
|
if (++counters.at(idx) >= FPS_ARRAY_LENGTH)
|
|
|
|
|
counters.at(idx) = 0;
|
|
|
|
|
fps_vectors.at(idx).at(counters.at(idx)) = counter;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GraphTimer *GraphTimer::get_instance() {
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::chrono::time_point<std::chrono::system_clock> GraphTimer::start_time;
|
|
|
|
|
bool GraphTimer::started;
|
|
|
|
|
bool GraphTimer::started;
|
|
|
|
|
GraphTimer* GraphTimer::instance = nullptr;
|