Skip to content

Commit

Permalink
Gui: Clean-up
Browse files Browse the repository at this point in the history
Move All windows into Debug/Windows menu
Remove code to show Water Debug. It was dead code and it can be seen in
renderdoc.
  • Loading branch information
bwrsandman committed Nov 15, 2021
1 parent 61ece37 commit fd9ff5b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 41 deletions.
5 changes: 5 additions & 0 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,8 @@ const fs::path& Game::GetGamePath()

return _gamePath;
}

void Game::SetTime(float time)
{
GetSky().SetTime(time);
}
2 changes: 1 addition & 1 deletion src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class Game
Config() {}

bool wireframe {false};
bool waterDebug {false};
bool showVillagerNames {false};
bool debugVillagerNames {false};

Expand Down Expand Up @@ -151,6 +150,7 @@ class Game

void SetGamePath(const fs::path& path);
const fs::path& GetGamePath();
void SetTime(float time);
void SetGameSpeed(float multiplier) { _gameSpeedMultiplier = multiplier; }
float GetGameSpeed() const { return _gameSpeedMultiplier; }

Expand Down
65 changes: 26 additions & 39 deletions src/Gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#pragma GCC diagnostic ignored "-Wpedantic"
#include <bx/math.h>
#pragma GCC diagnostic pop
#include <SDL2/SDL.h>
#include <bx/timer.h>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/compatibility.hpp>
#include <imgui.h>
#include <imgui_internal.h>
Expand All @@ -25,10 +27,6 @@
#endif

#include <3D/Camera.h>
#include <3D/LandIsland.h>
#include <3D/MeshPack.h>
#include <3D/Sky.h>
#include <3D/Water.h>
#include <Common/FileSystem.h>
#include <Entities/Components/Transform.h>
#include <Entities/Registry.h>
Expand Down Expand Up @@ -67,11 +65,14 @@ using namespace openblack::gui;

namespace
{
const bgfx::EmbeddedShader s_embeddedShaders[] = {BGFX_EMBEDDED_SHADER(vs_ocornut_imgui),
BGFX_EMBEDDED_SHADER(fs_ocornut_imgui), BGFX_EMBEDDED_SHADER(vs_imgui_image),
BGFX_EMBEDDED_SHADER(fs_imgui_image),

BGFX_EMBEDDED_SHADER_END()};
const bgfx::EmbeddedShader s_embeddedShaders[] = {
BGFX_EMBEDDED_SHADER(vs_ocornut_imgui),
BGFX_EMBEDDED_SHADER(fs_ocornut_imgui),
BGFX_EMBEDDED_SHADER(vs_imgui_image),
BGFX_EMBEDDED_SHADER(fs_imgui_image),

BGFX_EMBEDDED_SHADER_END(),
};
} // namespace

std::unique_ptr<Gui> Gui::create(const GameWindow* window, graphics::RenderPass viewId, float scale)
Expand Down Expand Up @@ -514,7 +515,6 @@ bool Gui::Loop(Game& game, const Renderer& renderer)
}
ShowVillagerNames(game);
ShowCameraPositionOverlay(game);
ShowWaterFramebuffer(game);

ImGui::Render();

Expand All @@ -531,9 +531,9 @@ void Gui::RenderDrawDataBgfx(ImDrawData* drawData)

const bgfx::Caps* caps = bgfx::getCaps();
{
float ortho[16];
bx::mtxOrtho(ortho, 0.0f, width, height, 0.0f, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth);
bgfx::setViewTransform(_viewId, NULL, ortho);
glm::mat4 ortho;
bx::mtxOrtho(glm::value_ptr(ortho), 0.0f, width, height, 0.0f, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth);
bgfx::setViewTransform(_viewId, nullptr, glm::value_ptr(ortho));
bgfx::setViewRect(_viewId, 0, 0, uint16_t(width), uint16_t(height));
}

Expand Down Expand Up @@ -571,8 +571,8 @@ void Gui::RenderDrawDataBgfx(ImDrawData* drawData)
for (int32_t ii = 0, num = drawData->CmdListsCount; ii < num; ++ii)
{
const ImDrawList* drawList = drawData->CmdLists[ii];
uint32_t numVertices = (uint32_t)drawList->VtxBuffer.size();
uint32_t numIndices = (uint32_t)drawList->IdxBuffer.size();
auto numVertices = static_cast<uint32_t>(drawList->VtxBuffer.size());
auto numIndices = static_cast<uint32_t>(drawList->IdxBuffer.size());

bgfx::update(_vertexBuffer, vertexBufferOffset,
bgfx::makeRef(drawList->VtxBuffer.begin(), numVertices * sizeof(ImDrawVert)));
Expand Down Expand Up @@ -611,8 +611,8 @@ void Gui::RenderDrawDataBgfx(ImDrawData* drawData)
th = texture.s.handle;
if (0 != texture.s.mip)
{
const float lodEnabled[4] = {float(texture.s.mip), 1.0f, 0.0f, 0.0f};
bgfx::setUniform(_u_imageLodEnabled, lodEnabled);
const glm::vec4 lodEnabled = {static_cast<float>(texture.s.mip), 1.0f, 0.0f, 0.0f};
bgfx::setUniform(_u_imageLodEnabled, glm::value_ptr(lodEnabled));
program = _imageProgram;
}
}
Expand Down Expand Up @@ -698,19 +698,23 @@ bool Gui::ShowMenu(Game& game)
if (ImGui::BeginMenu("World"))
{
if (ImGui::SliderFloat("Time of Day", &config.timeOfDay, 0.0f, 1.0f, "%.3f"))
Game::instance()->GetSky().SetTime(config.timeOfDay);
Game::instance()->SetTime(config.timeOfDay);

ImGui::EndMenu();
}

if (ImGui::BeginMenu("Debug"))
{
for (auto& window : _debugWindows)
if (ImGui::BeginMenu("Windows"))
{
if (ImGui::MenuItem(("Open " + window->GetName()).c_str()))
for (auto& window : _debugWindows)
{
window->Open();
if (ImGui::MenuItem(window->GetName().c_str()))
{
window->Open();
}
}
ImGui::EndMenu();
}

if (ImGui::BeginMenu("Villager Names"))
Expand Down Expand Up @@ -973,7 +977,7 @@ void Gui::ShowVillagerNames(const Game& game)
glm::vec4(ImGui::GetStyle().WindowPadding.x, 0, displaySize.x - ImGui::GetStyle().WindowPadding.x, displaySize.y);
std::vector<glm::vec4> coveredAreas;
coveredAreas.reserve(game.GetEntityRegistry().Size<Villager>());
game.GetEntityRegistry().Each<Villager, const Transform>([this, &i, &coveredAreas, camera, config,
game.GetEntityRegistry().Each<Villager, const Transform>([this, &i, &coveredAreas, &camera, config,
viewport](Villager& entity, const Transform& transform) {
++i;
const float height = 2.0f * transform.scale.y; // TODO(bwrsandman): get from bounding box max y
Expand Down Expand Up @@ -1027,23 +1031,6 @@ void Gui::ShowVillagerNames(const Game& game)
});
}

void Gui::ShowWaterFramebuffer(const Game& game)
{
auto& config = game.GetConfig();

if (!config.waterDebug)
{
return;
}

const auto& water = game.GetWater();

ImGui::Begin("Water Debug");
ImGui::Image(water.GetFrameBuffer().GetColorAttachment().GetNativeHandle(), ImGui::GetContentRegionAvail(), ImVec2(0, 1),
ImVec2(1, 0));
ImGui::End();
}

void Gui::ShowCameraPositionOverlay(const Game& game)
{
// clang-format off
Expand Down
1 change: 0 additions & 1 deletion src/Gui/Gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class Gui
float arrowLength, std::function<void(void)> debugCallback) const;
bool ShowMenu(Game& game);
void ShowVillagerNames(const Game& game);
void ShowWaterFramebuffer(const Game& game);
void ShowCameraPositionOverlay(const Game& game);

static const char* StaticGetClipboardText(void* ud) { return reinterpret_cast<Gui*>(ud)->GetClipboardText(); }
Expand Down

0 comments on commit fd9ff5b

Please sign in to comment.