1
0
Fork 0

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:
trotFunky 2024-01-26 23:05:11 +00:00
parent 52fdd8328f
commit f25a649144
3 changed files with 160 additions and 8 deletions

View file

@ -5,6 +5,10 @@
#include "World.h"
#include <cmath>
#ifdef IMGUI
#include <imgui.h>
#include <imgui-SFML.h>
#endif
World::World(int w, int h, sf::Color groundColor, sf::Color ceilingColor, std::vector<BlockType> worldMap) :
player(0,0,0), w(w), h(h), map(std::move(worldMap)),
@ -263,4 +267,77 @@ void World::step(const float& stepTime) {
-player.currentMoveSpeedY*stepTime);
}
player.rotate(player.currentRotationSpeed*stepTime);
#ifdef IMGUI
ImGui::Begin("MapEdit");
static int blockToPlace = 1;
/*
* Group all the select boxes together : makes it a big block in the
* Dear ImGui layout an allows adding things on the side.
*/
ImGui::BeginGroup();
for (int y = 0 ; y < h ; y++) {
for (int x = 0 ; x < w ; x++) {
ImGui::PushID(x + y*w);
if (x > 0)
ImGui::SameLine();
BlockType currentBlock = map[x + w*y];
ImVec4 hoverColor;
switch ((BlockType)blockToPlace) {
case BlockType::WALL:
hoverColor = (ImVec4)ImColor(84, 56, 34);
break;
case BlockType::DOOR:
hoverColor = (ImVec4)ImColor(186, 152, 107);
break;
case BlockType::WINDOW:
hoverColor = (ImVec4)ImColor(104, 123, 165);
break;
default:
/* Default header color, it seems ? */
hoverColor = (ImVec4)ImColor(188, 120, 32);
break;
}
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, hoverColor);
ImVec4 blockColor;
switch (currentBlock) {
case BlockType::WALL:
blockColor = (ImVec4)ImColor(84, 56, 34);
break;
case BlockType::DOOR:
blockColor = (ImVec4)ImColor(186, 152, 107);
break;
case BlockType::WINDOW:
blockColor = (ImVec4)ImColor(104, 123, 165);
break;
default:
blockColor = (ImVec4)ImColor(188, 120, 32);
break;
}
ImGui::PushStyleColor(ImGuiCol_Header, blockColor);
if(ImGui::Selectable("", currentBlock != BlockType::AIR, 0, ImVec2(10, 10))) {
map[x + w*y] = currentBlock == (BlockType)blockToPlace ? BlockType::AIR : (BlockType)blockToPlace;
}
ImGui::PopStyleColor(2);
ImGui::PopID();
}
}
ImGui::EndGroup();
ImGui::SameLine();
ImGui::BeginGroup();
ImGui::Indent();
ImGui::Text("Place :");
ImGui::RadioButton("Wall", &blockToPlace, (int)BlockType::WALL);
ImGui::RadioButton("Door", &blockToPlace, (int)BlockType::DOOR);
ImGui::RadioButton("Window", &blockToPlace, (int)BlockType::WINDOW);
ImGui::Unindent();
ImGui::EndGroup();
ImGui::End();
#endif
}