diff --git a/CMakeLists.txt b/CMakeLists.txt index 734e6cb..4cc551b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,15 +115,15 @@ set(COMPILE_FLAGS -Wpedantic # -Wpadded -pedantic - -ffunction-sections - -fdata-sections +# -ffunction-sections +# -fdata-sections -fuse-ld=gold -funroll-loops -fdevirtualize-at-ltrans -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free ) set(LINKER_OPTIONS - -Wl,--sort-common,--as-needed,--gc-sections,--strip-all + -Wl,--sort-common,--as-needed#[[,--gc-sections,--strip-all]] -fuse-ld=gold -fdevirtualize-at-ltrans ) diff --git a/include/controller.hpp b/include/controller.hpp index 983082b..7df617d 100644 --- a/include/controller.hpp +++ b/include/controller.hpp @@ -21,7 +21,9 @@ public: ~Controller() noexcept = default; - void control() noexcept; + void control_menu() const noexcept; + + void control_sheet()const noexcept; }; diff --git a/include/gui/gui.hpp b/include/gui/gui.hpp index 557fef3..999fb27 100644 --- a/include/gui/gui.hpp +++ b/include/gui/gui.hpp @@ -3,6 +3,7 @@ #include #include "gui/menu/menu.hpp" +#include "controller.hpp" namespace fs = std::filesystem; @@ -28,7 +29,7 @@ namespace gui { ~Gui() noexcept; - void render_gui(); + void render_gui(const Controller &controller); void render_gpu() const; }; diff --git a/include/gui/menu/menu_data.hpp b/include/gui/menu/menu_data.hpp index 3cdce3d..e46bd7e 100644 --- a/include/gui/menu/menu_data.hpp +++ b/include/gui/menu/menu_data.hpp @@ -14,9 +14,9 @@ namespace character { namespace gui::menu { class MenuData final { public: - static constexpr const char *const open_character_key{ "CharacterSheetOpen" }; + const std::string open_character_key{ "CharacterSheetOpen" }; - static constexpr const char *const save_character_key{ "CharacterSheetSaveAs" }; + const std::string save_character_key{ "CharacterSheetSaveAs" }; private: friend class Menu; diff --git a/src/controller.cpp b/src/controller.cpp index 0251e41..fad716b 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -3,27 +3,24 @@ #include "ImFileDialog.h" #include -void Controller::control() noexcept { - SPDLOG_DEBUG("Check \"open character\" task"); - if (ifd::FileDialog::Instance().IsDone(gui::menu::MenuData::open_character_key)) { - SPDLOG_DEBUG("Task done"); +void Controller::control_menu() const noexcept { + if (ifd::FileDialog::Instance().IsDone(menu_data.open_character_key)) { if (ifd::FileDialog::Instance().HasResult()) { - SPDLOG_DEBUG("Has Result"); fs::path str = ifd::FileDialog::Instance().GetResult(); SPDLOG_DEBUG("path opening: {}", str.string()); } ifd::FileDialog::Instance().Close(); } - SPDLOG_DEBUG("Check \"saving character\" task"); - if (ifd::FileDialog::Instance().IsDone(gui::menu::MenuData::save_character_key)) { - SPDLOG_DEBUG("Task done"); + if (ifd::FileDialog::Instance().IsDone(menu_data.save_character_key)) { if (ifd::FileDialog::Instance().HasResult()) { - SPDLOG_DEBUG("Has Result"); const fs::path str = ifd::FileDialog::Instance().GetResult(); SPDLOG_DEBUG("path saving: {}", str.string()); } ifd::FileDialog::Instance().Close(); } +} + +void Controller::control_sheet() const noexcept { if (menu_data.is_edit_mode()) { // TODO } else { diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 68c998c..0938cb1 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -6,6 +6,7 @@ #include "gui/window.hpp" #include "gui/gui_data.hpp" #include "character_sheet.hpp" +#include "controller.hpp" gui::Gui::Gui(GuiData &data, menu::MenuData &menuData) : data(data), menu(menuData), font("font/DejaVuSans.ttf") { SPDLOG_DEBUG("Creating GUI"); @@ -23,7 +24,7 @@ gui::Gui::~Gui() noexcept { ImGui::DestroyContext(); } -void gui::Gui::render_gui() { +void gui::Gui::render_gui(const Controller &controller) { if (initialized) { constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoMove | @@ -88,6 +89,8 @@ void gui::Gui::render_gui() { ImGui::End(); + controller.control_menu(); + ImGui::Render(); } } diff --git a/src/gui/menu/menu.cpp b/src/gui/menu/menu.cpp index 5032d8d..5027d4e 100644 --- a/src/gui/menu/menu.cpp +++ b/src/gui/menu/menu.cpp @@ -40,7 +40,7 @@ void gui::menu::Menu::gui() const noexcept { if (ImGui::BeginMenu("File")) { if (ImGui::MenuItem("Open file")) { SPDLOG_DEBUG("Opening file"); - ifd::FileDialog::Instance().Open(MenuData::open_character_key, "Open a character sheet", "Character sheet (*.json){.json},.*"); + ifd::FileDialog::Instance().Open(data.open_character_key, "Open a character sheet", "Character sheet (*.json){.json},.*"); SPDLOG_DEBUG("File opened"); } @@ -49,12 +49,12 @@ void gui::menu::Menu::gui() const noexcept { std::ofstream file{ data.save_path / data.filename }; nlohmann::json j; j.emplace("character_sheet", data.character_sheet); - file << j; + file << j.dump(4); } if (ImGui::MenuItem("Save as...")) { SPDLOG_DEBUG("Saving with file dialog"); - ifd::FileDialog::Instance().Save(MenuData::save_character_key, "Save character sheet as...", "*.json {.json}"); + ifd::FileDialog::Instance().Save(data.save_character_key, "Save character sheet as...", "*.json {.json}"); SPDLOG_DEBUG("File saved with dialog"); } diff --git a/src/main.cpp b/src/main.cpp index ed0b1bf..7224f1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,3 @@ -#include #include #include #include "gui/window.hpp" @@ -8,15 +7,7 @@ #include "controller.hpp" #include "character_sheet.hpp" -void myTerminateHandler() { - try { - SPDLOG_CRITICAL(to_string(boost::stacktrace::stacktrace())); - } catch (...) {} - std::abort(); -} - int main() { - std::set_terminate(myTerminateHandler); std::ios::sync_with_stdio(false); spdlog::set_default_logger(spdlog::stdout_color_st("console")); @@ -30,9 +21,9 @@ int main() { while (!window.should_close()) { glfwPollEvents(); - controller.control(); +// controller.control(); - gui.render_gui(); + gui.render_gui(controller); gui.render_gpu(); window.swap_buffers();