hackily adding the event count to the graph

master
mitchellhansen 7 years ago
parent 5a47d3bad4
commit 24a97e47e1

@ -72,13 +72,14 @@ private:
std::shared_ptr<CLCaster> raycaster;
std::shared_ptr<LightHandle> light_handle;
std::shared_ptr<LightController> light_controller;
GraphTimer fps;
Input input_handler;
std::shared_ptr<WindowHandler> window_handler;
// The sfml imgui wrapper I'm using requires Update be called with sf::Time
// Might modify it to also accept seconds
sf::Clock sf_delta_clock;
GraphTimer fps;
// vars for us to use with ImGUI
float light_color[4] = { 0, 0, 0, 0 };

@ -11,12 +11,15 @@ public:
~GraphTimer();
static GraphTimer* get_instance();
unsigned int create_line(std::string label);
unsigned int delete_line(unsigned int idx);
void start(unsigned int idx);
void stop(unsigned int idx);
void frame(unsigned int idx, double delta_time);
void count(unsigned int idx, int counter);
void draw();
@ -31,4 +34,7 @@ private:
std::vector<int> counters;
std::vector<std::string> labels;
// I actually think I might make this a singleton, along
static GraphTimer* instance;
};

@ -52,6 +52,9 @@ private:
std::vector<sf::Mouse::Button> held_mouse_buttons;
// TODO: Debug, remove this when finished
int graph_index = 0;
private:
static const std::vector<std::string> key_strings;

@ -13,9 +13,6 @@ Application::Application() {
ImGui::SFML::Init(*window);
window->resetGLStates();
}
Application::~Application() {
@ -112,7 +109,7 @@ bool Application::game_loop() {
int fps_idx = fps.create_line("FPS");
int compute_fps_idx = fps.create_line("Compute");
int event_fps_idx = fps.create_line("Event");
int event_fps_idx = fps.create_line("Event Time");
while (true) {

@ -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, 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;
GraphTimer* GraphTimer::instance = nullptr;

@ -1,8 +1,10 @@
#include "Input.h"
#include <GraphTimer.h>
#include "Input.h"
Input::Input() {
GraphTimer *t = GraphTimer::get_instance();
graph_index = t->create_line("Event Counter");
}
Input::~Input() {
@ -21,6 +23,9 @@ void Input::consume_sf_events(sf::RenderWindow *window) {
transpose_sf_events(sf_event_queue);
GraphTimer *t = GraphTimer::get_instance();
t->count(graph_index, sf_event_queue.size());
sf_event_queue.clear();
}

Loading…
Cancel
Save