diff --git a/src/Game.cpp b/src/Game.cpp index 6c7c9421c9..5697696296 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -586,3 +586,8 @@ const fs::path& Game::GetGamePath() return _gamePath; } + +void Game::SetTime(float time) +{ + GetSky().SetTime(time); +} diff --git a/src/Game.h b/src/Game.h index eaee1e19d9..447d052c84 100644 --- a/src/Game.h +++ b/src/Game.h @@ -111,7 +111,6 @@ class Game Config() {} bool wireframe {false}; - bool waterDebug {false}; bool showVillagerNames {false}; bool debugVillagerNames {false}; @@ -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; } diff --git a/src/Gui/Gui.cpp b/src/Gui/Gui.cpp index 788497287f..c55d831db7 100644 --- a/src/Gui/Gui.cpp +++ b/src/Gui/Gui.cpp @@ -22,6 +22,7 @@ #pragma GCC diagnostic pop #endif #include +#include #include #include #include @@ -31,10 +32,6 @@ #endif #include <3D/Camera.h> -#include <3D/LandIsland.h> -#include <3D/MeshPack.h> -#include <3D/Sky.h> -#include <3D/Water.h> #include #include #include @@ -73,11 +70,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::create(const GameWindow* window, graphics::RenderPass viewId, float scale) @@ -520,7 +520,6 @@ bool Gui::Loop(Game& game, const Renderer& renderer) } ShowVillagerNames(game); ShowCameraPositionOverlay(game); - ShowWaterFramebuffer(game); ImGui::Render(); @@ -537,9 +536,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)); } @@ -577,8 +576,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(drawList->VtxBuffer.size()); + auto numIndices = static_cast(drawList->IdxBuffer.size()); bgfx::update(_vertexBuffer, vertexBufferOffset, bgfx::makeRef(drawList->VtxBuffer.begin(), numVertices * sizeof(ImDrawVert))); @@ -617,8 +616,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(texture.s.mip), 1.0f, 0.0f, 0.0f}; + bgfx::setUniform(_u_imageLodEnabled, glm::value_ptr(lodEnabled)); program = _imageProgram; } } @@ -704,19 +703,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")) @@ -979,7 +982,7 @@ void Gui::ShowVillagerNames(const Game& game) glm::vec4(ImGui::GetStyle().WindowPadding.x, 0, displaySize.x - ImGui::GetStyle().WindowPadding.x, displaySize.y); std::vector coveredAreas; coveredAreas.reserve(game.GetEntityRegistry().Size()); - game.GetEntityRegistry().Each([this, &i, &coveredAreas, camera, config, + game.GetEntityRegistry().Each([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 @@ -1033,23 +1036,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 diff --git a/src/Gui/Gui.h b/src/Gui/Gui.h index 71cdd14afc..69e706f408 100644 --- a/src/Gui/Gui.h +++ b/src/Gui/Gui.h @@ -99,7 +99,6 @@ class Gui float arrowLength, std::function 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(ud)->GetClipboardText(); }