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:
@@ -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) {
|
||||
|
||||
|
||||
88
src/GraphTimer.cpp
Normal file
88
src/GraphTimer.cpp
Normal file
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user