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

master
mitchellhansen 7 years ago
parent 29612edd61
commit 5a47d3bad4

@ -42,6 +42,9 @@ endif()
# beignet only supports EGL and not GLX for the cl_khr_gl_sharing extension
if (UNIX)
# Find X11
find_package(X11 REQUIRED)
message(STATUS "XSS found: ${X11_FOUND}")
# find_package(EGL REQUIRED)
#message(STATUS "EGL found: ${EGL_FOUND}")
endif (UNIX)
@ -51,6 +54,7 @@ include_directories(${SFML_INCLUDE_DIR})
include_directories(${OpenCL_INCLUDE_DIRS})
include_directories(${OpenGL_INCLUDE_DIRS})
if (UNIX)
include_directories(${X11_INCLUDE_DIR})
# include_directories(${EGL_INCLUDE_DIRS})
endif()
include_directories(include)
@ -62,7 +66,7 @@ file(GLOB_RECURSE KERNELS "kernels/*.cl")
file(GLOB_RECURSE SHADERS "shaders/*.vert" "shaders/*.tesc" "shaders/*.tese" "shaders/*.geom" "shaders/*.frag" "shaders/*.comp")
add_executable(${PNAME} ${SOURCES} ${HEADERS} ${KERNELS} ${SHADERS} include/imgui/imgui-multilines.hpp)
add_executable(${PNAME} ${SOURCES} ${HEADERS} ${KERNELS} ${SHADERS})
# Follow the sub directory structure to add sub-filters in VS
# Gotta do it one by one unfortunately
@ -133,6 +137,7 @@ target_link_libraries (${PNAME} ${OpenCL_LIBRARY})
target_link_libraries (${PNAME} ${OPENGL_LIBRARIES})
if (UNIX)
target_link_libraries (${PNAME} ${X11_LIBRARIES})
# target_link_libraries (${PNAME} ${EGL_LIBRARIES})
endif()

@ -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 };

@ -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>
/**

@ -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;
};

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

@ -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,

@ -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(

@ -14,6 +14,8 @@ Application::Application() {
ImGui::SFML::Init(*window);
window->resetGLStates();
}
Application::~Application() {
@ -108,12 +110,18 @@ bool Application::init_events() {
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");
while (true) {
// Have the input handler empty the event stack, generate events for held keys, and then dispatch the events to listeners
input_handler.consume_sf_events(window.get());
input_handler.handle_held_keys();
fps.start(event_fps_idx);
input_handler.consume_sf_events(window.get());
input_handler.handle_held_keys();
input_handler.dispatch_events();
fps.stop(event_fps_idx);
if (!window->isOpen())
break;
@ -142,16 +150,18 @@ bool Application::game_loop() {
light_handle->update(delta_time);
// Run the raycast
fps.start(compute_fps_idx);
if (!raycaster->compute()) {
abort();
};
fps.stop(compute_fps_idx);
}
// Let the raycaster draw it screen buffer
raycaster->draw(window.get());
// Give the frame counter the frame time and draw the average frame time
fps.frame(delta_time);
fps.frame(fps_idx, delta_time);
fps.draw();
Gui::do_render();

@ -1,7 +1,9 @@
#include "Camera.h"
Camera::Camera() {}
Camera::Camera() {
}
Camera::Camera(sf::Vector3f position, sf::Vector2f direction, sf::RenderWindow* window) :
@ -194,11 +196,13 @@ void Camera::event_handler(VrEventPublisher *publisher, std::unique_ptr<vr::Even
deltas = fixed - sf::Vector2i(mouse_event->x, mouse_event->y);
if (deltas != sf::Vector2i(0, 0) && mouse_enabled == true) {
sf::Mouse::setPosition(fixed, *window);
slew_camera(sf::Vector2f(
deltas.y / 1200.0f,
deltas.x / 1200.0f
));
// TODO: Set Position causes some weird frame-limiting behaviour
// TODO: consider using some other mouse interaction
sf::Mouse::setPosition(fixed, *window);
slew_camera(sf::Vector2f(
deltas.y / 1200.0f,
deltas.x / 1200.0f
));
}
}
}
@ -207,10 +211,10 @@ void Camera::event_handler(VrEventPublisher *publisher, std::unique_ptr<vr::Even
vr::MouseButtonPressed *mouse_event = static_cast<vr::MouseButtonPressed*>(event.get());
if (mouse_event->button == sf::Mouse::Middle) {
mouse_enabled = !mouse_enabled;
sf::Mouse::setPosition(fixed, *window);
}
mouse_enabled = !mouse_enabled;
sf::Mouse::setPosition(fixed, *window);
}
}
else if (event->type == vr::Event::JoystickMoved) {

@ -0,0 +1,88 @@
#include "GraphTimer.h"
GraphTimer::GraphTimer() {
if (!started) {
start_time = std::chrono::system_clock::now();
started = true;
}
}
GraphTimer::~GraphTimer() {
}
unsigned int GraphTimer::create_line(std::string label) {
fps_vectors.push_back(std::vector<float>(FPS_ARRAY_LENGTH, 0));
counters.push_back(0);
checkpoints.push_back(0);
labels.push_back(label);
return fps_vectors.size()-1;
}
unsigned int GraphTimer::delete_line(unsigned int idx){
fps_vectors.erase(fps_vectors.begin() + idx);
}
void GraphTimer::start(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;
checkpoints.at(idx) = elapsed_time.count();
}
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;
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)
counters.at(idx) = 0;
}
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),
};
ImVec2 wh = ImGui::GetContentRegionAvail();
wh.x -= wh.x * 0.15;
sf::Vector2f graph_size(wh.x, wh.y);
ImGui::PlotMultiLines(fps_vectors, title, labels, colors, 200, 0,
graph_size);
//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();
}
std::chrono::time_point<std::chrono::system_clock> GraphTimer::start_time;
bool GraphTimer::started;

@ -22,7 +22,7 @@
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "imgui.h"
#include "imgui/imgui.h"
#include <ctype.h> // toupper, isprint
#include <math.h> // sqrtf, powf, cosf, sinf, floorf, ceilf
#include <stdio.h> // vsnprintf, sscanf, printf

@ -1,3 +1,4 @@
#include <cstring>
#include "map/Octree.h"
Octree::Octree() {

Loading…
Cancel
Save