Debug: Introduce Dear ImGui interfaces
Introduce Dear ImGui to the CMakeBuild, allow building without it. Add two debug interfaces : one FPS counter and frame time graph, one map visualizer and editor.
This commit is contained in:
parent
52fdd8328f
commit
f25a649144
3 changed files with 160 additions and 8 deletions
63
main.cpp
63
main.cpp
|
@ -1,20 +1,35 @@
|
|||
#include <iostream>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
#ifdef IMGUI
|
||||
#include <imgui.h>
|
||||
#include <imgui-SFML.h>
|
||||
#endif
|
||||
|
||||
#include "World.h"
|
||||
|
||||
// TODO: Find a way to go to edges instead of just equally split (?)
|
||||
|
||||
int main()
|
||||
{
|
||||
World world(10,10);
|
||||
world.setBlock(BlockType::AIR,1,1,8,8);
|
||||
World world(32,32);
|
||||
world.setBlock(BlockType::AIR,1,1,30,30);
|
||||
world.setBlock(BlockType::WALL,4,4,2,2);
|
||||
world.player.move(2,2);
|
||||
std::cout << world << std::endl;
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode(800,600),"Da raycasting");
|
||||
sf::RenderWindow window(sf::VideoMode(1000,1000),"Da raycasting");
|
||||
#ifdef IMGUI
|
||||
if (!ImGui::SFML::Init(window)) {
|
||||
std::cout << "Failed to init Dear ImGui SFML" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
sf::Clock fpsDataClock;
|
||||
float frameTimings[100];
|
||||
unsigned int frameCount = 0;
|
||||
#endif
|
||||
|
||||
// window.setFramerateLimit(60);
|
||||
|
||||
sf::Event event{};
|
||||
sf::Clock frameTime;
|
||||
|
@ -34,6 +49,13 @@ int main()
|
|||
window.setView(sf::View(newView));
|
||||
continue;
|
||||
}
|
||||
#ifdef IMGUI
|
||||
ImGui::SFML::ProcessEvent(window, event);
|
||||
// Check if Dear ImGui should process the key events.
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (io.WantCaptureMouse || io.WantCaptureKeyboard)
|
||||
continue;
|
||||
#endif
|
||||
if (event.type == sf::Event::KeyPressed) {
|
||||
switch (event.key.code) {
|
||||
case sf::Keyboard::Key::Escape:
|
||||
|
@ -71,11 +93,44 @@ int main()
|
|||
}
|
||||
}
|
||||
window.clear();
|
||||
const sf::Time& deltaT = frameTime.restart();
|
||||
|
||||
world.step(frameTime.restart().asSeconds());
|
||||
#ifdef IMGUI
|
||||
ImGui::SFML::Update(window, deltaT);
|
||||
#endif
|
||||
|
||||
world.step(deltaT.asSeconds());
|
||||
world.render(window);
|
||||
|
||||
#ifdef IMGUI
|
||||
// ImGui::ShowDemoWindow();
|
||||
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration
|
||||
| ImGuiWindowFlags_AlwaysAutoResize
|
||||
| ImGuiWindowFlags_NoSavedSettings
|
||||
| ImGuiWindowFlags_NoFocusOnAppearing
|
||||
| ImGuiWindowFlags_NoNav;
|
||||
ImVec2 window_area = ImGui::GetMainViewport()->WorkSize;
|
||||
ImGui::SetNextWindowPos({window_area.x - 20, 20}, ImGuiCond_Always, {1,0});
|
||||
ImGui::SetNextWindowBgAlpha(0.2f);
|
||||
ImGui::Begin("FPS", nullptr ,window_flags);
|
||||
if (fpsDataClock.getElapsedTime().asMilliseconds() > 20) {
|
||||
frameTimings[frameCount%100] = static_cast<float>(deltaT.asMicroseconds());
|
||||
frameCount++;
|
||||
fpsDataClock.restart();
|
||||
}
|
||||
ImGui::Text("FPS : %d", (int)(1.0/deltaT.asSeconds()));
|
||||
ImGui::PlotLines("µs", frameTimings, frameCount >= 100 ? 100 : frameCount);
|
||||
ImGui::End();
|
||||
|
||||
ImGui::SFML::Render(window);
|
||||
#endif
|
||||
|
||||
window.display();
|
||||
}
|
||||
|
||||
#ifdef IMGUI
|
||||
ImGui::SFML::Shutdown();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue