Debugging of a mouse polling issue, refactored the graph thing and finished tweaking it, added a few profiles to the graph, so pretty

This commit is contained in:
2018-02-27 22:13:59 -08:00
parent 29612edd61
commit 5a47d3bad4
12 changed files with 169 additions and 119 deletions

View File

@@ -30,6 +30,7 @@
#include "LightHandle.h"
#include "map/Map.h"
#include "util.hpp"
#include "GraphTimer.h"
// Srsly people who macro error codes are the devil
#undef ERROR
@@ -77,7 +78,7 @@ private:
// 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;
fps_counter fps;
GraphTimer fps;
// vars for us to use with ImGUI
float light_color[4] = { 0, 0, 0, 0 };

View File

@@ -2,10 +2,13 @@
#include <cmath>
#include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp>
#include "Gui.h"
#include "Pub_Sub.h"
#include "imgui/imgui.h"
#include "imgui/imgui-SFML.h"
#include "util.hpp"
#include <X11/Xlib.h>
/**

34
include/GraphTimer.h Normal file
View File

@@ -0,0 +1,34 @@
#pragma once
#include <chrono>
#include <imgui/imgui.h>
#include <imgui/imgui-multilines.hpp>
#include <vector>
#include <string>
struct GraphTimer {
public:
GraphTimer();
~GraphTimer();
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 draw();
private:
static std::chrono::time_point<std::chrono::system_clock> start_time;
static bool started;
const unsigned int FPS_ARRAY_LENGTH = 1000;
std::vector<std::vector<float>> fps_vectors;
std::vector<double> checkpoints;
std::vector<int> counters;
std::vector<std::string> labels;
};

View File

@@ -9,6 +9,7 @@
#include "LightHandle.h"
#include "Logger.h"
#include "Pub_Sub.h"
#include <imgui/imgui.h>
#include <imgui/imgui-SFML.h>
/**
*

View File

@@ -1,10 +1,9 @@
#pragma once
#include <string>
#include <vector>
#include "imgui.h"
#include "imgui_internal.h"
namespace ImGui {
static ImU32 InvertColorU32(ImU32 in)
@@ -24,7 +23,7 @@ namespace ImGui {
}
static void PlotMultiLines(
const std::vector<std::vector<int>> &data,
const std::vector<std::vector<float>> &data,
std::string title,
const std::vector<std::string> &labels,
const std::vector<ImColor> &colors,

View File

@@ -1,6 +1,7 @@
#pragma once
#include <algorithm>
#include <bitset>
#include <cmath>
#include <fstream>
#include <iostream>
@@ -10,109 +11,12 @@
#include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <imgui/imgui.h>
#include <imgui/imgui-multilines.hpp>
#include "Vector4.hpp"
const double PI = 3.141592653589793238463;
const float PI_F = 3.14159265358979f;
struct fps_counter {
public:
fps_counter() {
};
~fps_counter() {
for (auto i: fps_vectors){
delete[] i;
}
};
void frame(double delta_time) {
// Apply 100 units of smoothing
if (frame_count == 100) {
frame_count = 0;
fps_average = 0;
}
frame_count++;
fps_average += (delta_time - fps_average) / frame_count;
instant_fps = delta_time;
}
static float edit(const void* data, int idx){
*(int*)data = idx;
//return *(int*)(data+sizeof(int)*idx);
};
void draw() {
if (arr_pos == 1000)
arr_pos = 0;
fps_array[arr_pos] = static_cast<float>(1.0 / instant_fps);
arr_pos++;
ImGui::Begin("Performance");
//ImVec2 wh = ImGui::GetContentRegionAvail();
ImVec2 wh(100, 200);
int a[3] = {1, 2, 7};
int b[3] = {5, 3, 1};
int c[3] = {8, 1, 4};
const void* to_data[3] = {&a, &b, &c};
const char* to_names[3] = {"a", "b", "z"};
ImGuiPlotType plottype = ImGuiPlotType_Lines;
ImColor color = ImColor(255, 255, 255);
//ImGui::PlotMultiLines(
// "label", 3, to_names, &color, &edit,
// to_data, 3, 0.0f, 10.0f, ImVec2(300, 300));
std::vector<std::vector<int>> data = {
{1, 2, 3, 4},
{9, 3, 7, 1},
{8, 3, 6, 2}
};
std::string title = "HELLO";
std::vector<std::string> labels = {
"ONE",
"TWO",
"THREE"
};
std::vector<ImColor> colors = {
ImColor(255, 255, 255),
ImColor( 0, 255, 0),
ImColor(255, 0, 0),
};
sf::Vector2f graph_size(300, 300);
ImGui::PlotMultiLines(data, title, labels, colors, 10, 0, graph_size);
ImGui::PlotLines("FPS", fps_array, 1000, 0,
std::to_string(1.0 / fps_average).c_str(),
0.0f, 150.0f, wh);
ImGui::End();
}
private:
const unsigned int FPS_ARRAY_LENGTH = 1000;
std::vector<float*> fps_vectors;
float fps_array[1000]{60};
int arr_pos = 0;
double instant_fps = 0;
double frame_count = 0;
double fps_average = 0;
};
inline sf::Vector3f SphereToCart(sf::Vector2f i) {
auto r = sf::Vector3f(