|
|
@ -5,6 +5,11 @@ GraphTimer::GraphTimer() {
|
|
|
|
start_time = std::chrono::system_clock::now();
|
|
|
|
start_time = std::chrono::system_clock::now();
|
|
|
|
started = true;
|
|
|
|
started = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: This is a cardinal sin
|
|
|
|
|
|
|
|
if (instance == nullptr){
|
|
|
|
|
|
|
|
instance = this;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GraphTimer::~GraphTimer() {
|
|
|
|
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::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
|
|
|
|
std::chrono::duration<double> elapsed_time = now - start_time;
|
|
|
|
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)) = elapsed_time.count() - checkpoints.at(idx);
|
|
|
|
fps_vectors.at(idx).at(counters.at(idx)) = 1.0f / fps_vectors.at(idx).at(counters.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) {
|
|
|
|
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;
|
|
|
|
counters.at(idx) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fps_vectors.at(idx).at(counters.at(idx)) = 1.0 / delta_time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GraphTimer::draw() {
|
|
|
|
void GraphTimer::draw() {
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::Begin("Performance");
|
|
|
|
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::string title = std::to_string(fps_vectors.at(0).at(counters.at(0)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<ImColor> colors = {
|
|
|
|
std::vector<ImColor> colors = {
|
|
|
|
ImColor(255, 255, 255),
|
|
|
|
ImColor(255, 255, 255),
|
|
|
|
ImColor(0, 255, 0),
|
|
|
|
ImColor(255, 255, 0),
|
|
|
|
|
|
|
|
ImColor( 0, 255, 255),
|
|
|
|
|
|
|
|
ImColor(255, 0, 255),
|
|
|
|
ImColor(255, 0, 0),
|
|
|
|
ImColor(255, 0, 0),
|
|
|
|
|
|
|
|
ImColor( 0, 255, 0),
|
|
|
|
|
|
|
|
ImColor( 0, 0, 255),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ImVec2 wh = ImGui::GetContentRegionAvail();
|
|
|
|
ImVec2 wh = ImGui::GetContentRegionAvail();
|
|
|
@ -74,15 +81,21 @@ void GraphTimer::draw() {
|
|
|
|
ImGui::PlotMultiLines(fps_vectors, title, labels, colors, 200, 0,
|
|
|
|
ImGui::PlotMultiLines(fps_vectors, title, labels, colors, 200, 0,
|
|
|
|
graph_size);
|
|
|
|
graph_size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//ImVec2 wh(100, 200);
|
|
|
|
void GraphTimer::count(unsigned int idx, int counter) {
|
|
|
|
// ImGui::PlotLines("FPS", fps_array, 1000, 0,
|
|
|
|
if (++counters.at(idx) >= FPS_ARRAY_LENGTH)
|
|
|
|
// std::to_string(1.0 / fps_average).c_str(),
|
|
|
|
counters.at(idx) = 0;
|
|
|
|
// 0.0f, 150.0f, wh);
|
|
|
|
fps_vectors.at(idx).at(counters.at(idx)) = counter;
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GraphTimer *GraphTimer::get_instance() {
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::chrono::time_point<std::chrono::system_clock> GraphTimer::start_time;
|
|
|
|
std::chrono::time_point<std::chrono::system_clock> GraphTimer::start_time;
|
|
|
|
bool GraphTimer::started;
|
|
|
|
bool GraphTimer::started;
|
|
|
|
|
|
|
|
GraphTimer* GraphTimer::instance = nullptr;
|