From b488f8df3accab7472a0f2aa3dd9d458eb1b516f Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Thu, 4 Aug 2022 14:53:35 -0400 Subject: [PATCH 1/5] Started documentation --- docs/changelog.md | 18 ++++++++++++++++++ docs/manual.md | 14 ++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 docs/changelog.md create mode 100644 docs/manual.md diff --git a/docs/changelog.md b/docs/changelog.md new file mode 100644 index 00000000..9ba1e665 --- /dev/null +++ b/docs/changelog.md @@ -0,0 +1,18 @@ +## August 2022 + +- Added ValidateCompressionResults to ROM::Compress + +## July 2022 + +- Display current overworld map graphics tile sheets. +- Added CreateAllGraphicsData to the ROM class +- Added Google Abseil C++ library for error handling, string manipulation +- Refactor ROM class to use smart pointers and STL containers + +## June 2022 + +- Implemented LC_LZ2 Decompression +- Created Bitmap class for displaying SNES Graphics +- Added Overworld and OverworldMap class definitions +- Built user interface using ImGui and SDL2 +- Started YAZE \ No newline at end of file diff --git a/docs/manual.md b/docs/manual.md new file mode 100644 index 00000000..9de25311 --- /dev/null +++ b/docs/manual.md @@ -0,0 +1,14 @@ +# Yet Another Zelda3 Editor Manual + +## Opening a ROM + +YAZE supports The Legend of Zelda: A Link to the Past US ROMs with the file formats sfc and smc. Prefer sfc as it is historically more accurate. + + +## Editing the Overworld + +## Editing the Dungeons + +## Editing Sprites + +## Editing Mosaic Transitions From 7903e0cdc470a67818376fd853d8e495701ee9f1 Mon Sep 17 00:00:00 2001 From: Justin Scofield Date: Thu, 4 Aug 2022 19:03:35 +0000 Subject: [PATCH 2/5] Convert to status codes for Controller init. --- src/app/core/controller.cc | 85 ++++---------------------------------- src/app/core/controller.h | 12 ++---- 2 files changed, 12 insertions(+), 85 deletions(-) diff --git a/src/app/core/controller.cc b/src/app/core/controller.cc index 5a8b7b63..4930d166 100644 --- a/src/app/core/controller.cc +++ b/src/app/core/controller.cc @@ -79,13 +79,14 @@ void HandleMouseMovement(int &wheel) { bool Controller::isActive() const { return active_; } -void Controller::onEntry() { - CreateWindow(); - CreateRenderer(); - CreateGuiContext(); +absl::Status Controller::onEntry() { + CHECK_STATUS(CreateWindow()) + CHECK_STATUS(CreateRenderer()) + CHECK_STATUS(CreateGuiContext()) InitializeKeymap(); master_editor_.SetupScreen(renderer_); active_ = true; + return absl::OkStatus(); } void Controller::onInput() { @@ -144,77 +145,7 @@ void Controller::onExit() const { SDL_Quit(); } -void Controller::CreateWindow() { - if (SDL_Init(SDL_INIT_EVERYTHING)) { - SDL_Log("SDL_Init: %s\n", SDL_GetError()); - } else { - window_ = std::unique_ptr( - SDL_CreateWindow("Yet Another Zelda3 Editor", // window title - SDL_WINDOWPOS_UNDEFINED, // initial x position - SDL_WINDOWPOS_UNDEFINED, // initial y position - 1200, // width, in pixels - 800, // height, in pixels - SDL_WINDOW_RESIZABLE), - sdl_deleter()); - } -} - -void Controller::CreateRenderer() { - if (window_ == nullptr) { - SDL_Log("SDL_CreateWindow: %s\n", SDL_GetError()); - SDL_Quit(); - } else { - renderer_ = std::unique_ptr( - SDL_CreateRenderer( - window_.get(), -1, - SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC), - sdl_deleter()); - if (renderer_ == nullptr) { - SDL_Log("SDL_CreateRenderer: %s\n", SDL_GetError()); - SDL_Quit(); - } else { - SDL_SetRenderDrawBlendMode(renderer_.get(), SDL_BLENDMODE_BLEND); - SDL_SetRenderDrawColor(renderer_.get(), 0x00, 0x00, 0x00, 0x00); - } - } -} - -void Controller::CreateGuiContext() const { - // Create the ImGui and ImPlot contexts - ImGui::CreateContext(); - - // Initialize ImGui for SDL - ImGui_ImplSDL2_InitForSDLRenderer(window_.get(), renderer_.get()); - ImGui_ImplSDLRenderer_Init(renderer_.get()); - - // Load available fonts - const ImGuiIO &io = ImGui::GetIO(); - io.Fonts->AddFontFromFileTTF("assets/font/Karla-Regular.ttf", 14.0f); - - // merge in icons from Google Material Design - static const ImWchar icons_ranges[] = {ICON_MIN_MD, 0xf900, 0}; - ImFontConfig icons_config; - icons_config.MergeMode = true; - icons_config.GlyphOffset.y = 5.0f; - icons_config.GlyphMinAdvanceX = 13.0f; - icons_config.PixelSnapH = true; - io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_MD, 18.0f, &icons_config, - icons_ranges); - io.Fonts->AddFontFromFileTTF("assets/font/Roboto-Medium.ttf", 14.0f); - io.Fonts->AddFontFromFileTTF("assets/font/Cousine-Regular.ttf", 14.0f); - io.Fonts->AddFontFromFileTTF("assets/font/DroidSans.ttf", 16.0f); - - // Set the default style - gui::ColorsYaze(); - - // Build a new ImGui frame - ImGui_ImplSDLRenderer_NewFrame(); - ImGui_ImplSDL2_NewFrame(window_.get()); -} - -// V2 functions --------------------------------------------------------------- - -absl::Status Controller::CreateWindowV2() { +absl::Status Controller::CreateWindow() { if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { return absl::InternalError( absl::StrFormat("SDL_Init: %s\n", SDL_GetError())); @@ -235,7 +166,7 @@ absl::Status Controller::CreateWindowV2() { return absl::OkStatus(); } -absl::Status Controller::CreateRendererV2() { +absl::Status Controller::CreateRenderer() { renderer_ = std::unique_ptr( SDL_CreateRenderer(window_.get(), -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC), @@ -250,7 +181,7 @@ absl::Status Controller::CreateRendererV2() { return absl::OkStatus(); } -absl::Status Controller::CreateGuiContextV2() { +absl::Status Controller::CreateGuiContext() { ImGui::CreateContext(); // Initialize ImGui for SDL diff --git a/src/app/core/controller.h b/src/app/core/controller.h index 7c66b04f..d3bb255b 100644 --- a/src/app/core/controller.h +++ b/src/app/core/controller.h @@ -23,7 +23,7 @@ namespace core { class Controller { public: bool isActive() const; - void onEntry(); + absl::Status onEntry(); void onInput(); void onLoad(); void doRender() const; @@ -36,15 +36,11 @@ class Controller { void operator()(SDL_Texture *p) const { SDL_DestroyTexture(p); } }; - void CreateWindow(); - void CreateRenderer(); - void CreateGuiContext() const; + absl::Status CreateWindow(); + absl::Status CreateRenderer(); + absl::Status CreateGuiContext(); void CloseWindow() { active_ = false; } - absl::Status CreateWindowV2(); - absl::Status CreateRendererV2(); - absl::Status CreateGuiContextV2(); - friend int ::main(int argc, char **argv); bool active_; From c1ac8cd71c514c9a6dbd6681e1ca79f81e8d95b9 Mon Sep 17 00:00:00 2001 From: Justin Scofield Date: Thu, 4 Aug 2022 19:03:46 +0000 Subject: [PATCH 3/5] Add CHECK_STATUS macro --- src/app/core/constants.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/app/core/constants.h b/src/app/core/constants.h index 4986be5a..55a0e640 100644 --- a/src/app/core/constants.h +++ b/src/app/core/constants.h @@ -25,6 +25,11 @@ #define MENU_ITEM(w) if (ImGui::MenuItem(w)) #define MENU_ITEM2(w, v) if (ImGui::MenuItem(w, v)) +#define CHECK_STATUS(w) \ + if (!w.ok()) { \ + return w; \ + } + using ushort = unsigned short; using uint = unsigned int; using uchar = unsigned char; From 3b0dc9c195f43a1d19523dc8862ce2250f8ade9e Mon Sep 17 00:00:00 2001 From: Justin Scofield Date: Thu, 4 Aug 2022 19:04:09 +0000 Subject: [PATCH 4/5] Return Controller onEntry error in main. --- src/yaze.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/yaze.cc b/src/yaze.cc index b1699c80..5c780550 100644 --- a/src/yaze.cc +++ b/src/yaze.cc @@ -11,7 +11,13 @@ int main(int argc, char** argv) { absl::InstallFailureSignalHandler(options); yaze::app::core::Controller controller; - controller.onEntry(); + + auto entry_status = controller.onEntry(); + if (!entry_status.ok()) { + // TODO(@scawful): log the specific error + return EXIT_FAILURE; + } + while (controller.isActive()) { controller.onInput(); controller.onLoad(); From 2e8f14ee6ee5e05070c7539d9c6ef43e282a96c3 Mon Sep 17 00:00:00 2001 From: Justin Scofield Date: Thu, 4 Aug 2022 23:14:45 +0000 Subject: [PATCH 5/5] Add Asar and organize CMakeLists.txt --- .gitmodules | 3 ++ CMakeLists.txt | 1 + src/CMakeLists.txt | 69 ++++++++++++++++++++++++++++++++-------------- src/lib/asar | 1 + 4 files changed, 54 insertions(+), 20 deletions(-) create mode 160000 src/lib/asar diff --git a/.gitmodules b/.gitmodules index 8910036c..956da4d1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,6 @@ [submodule "src/lib/SDL"] path = src/lib/SDL url = https://github.com/libsdl-org/SDL.git +[submodule "src/lib/asar"] + path = src/lib/asar + url = https://github.com/RPGHacker/asar.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 319d028e..36d42414 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,5 +31,6 @@ find_package(GLEW REQUIRED) # Project Files add_subdirectory(src/lib/abseil-cpp) add_subdirectory(src/lib/SDL) +add_subdirectory(src/lib/asar/src) add_subdirectory(src) add_subdirectory(test) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9946651d..8bed4879 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,44 +1,72 @@ include_directories(lib/cmake) -# gui libraries --------------------------------------------------------------------------------------------------- +# gui libraries --------------------------------------------------------------- set(IMGUI_PATH "lib/imgui") file(GLOB IMGUI_SOURCES ${IMGUI_PATH}/*.cpp) add_library("ImGui" STATIC ${IMGUI_SOURCES}) target_include_directories("ImGui" PUBLIC ${IMGUI_PATH}) target_include_directories(ImGui PUBLIC ${SDL2_INCLUDE_DIR}) -target_compile_definitions(ImGui PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM= GL_GLEXT_PROTOTYPES=1) +target_compile_definitions(ImGui PUBLIC + IMGUI_IMPL_OPENGL_LOADER_CUSTOM= GL_GLEXT_PROTOTYPES=1) set(IMGUI_FILE_DLG_PATH "lib/ImGuiFileDialog") file(GLOB IMGUI_FILE_DLG_SOURCES ${IMGUI_FILE_DLG_PATH}/*.cpp) add_library("ImGuiFileDialog" STATIC ${IMGUI_FILE_DLG_SOURCES}) target_include_directories(ImGuiFileDialog PUBLIC ${IMGUI_PATH}) -target_compile_definitions(ImGuiFileDialog PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM= GL_GLEXT_PROTOTYPES=1) +target_compile_definitions(ImGuiFileDialog PUBLIC + IMGUI_IMPL_OPENGL_LOADER_CUSTOM= GL_GLEXT_PROTOTYPES=1) set(IMGUI_COLOR_TEXT_EDIT_PATH "lib/ImGuiColorTextEdit") file(GLOB IMGUI_COLOR_TEXT_EDIT_SOURCES ${IMGUI_COLOR_TEXT_EDIT_PATH}/*.cpp) add_library("ImGuiColorTextEdit" STATIC ${IMGUI_COLOR_TEXT_EDIT_SOURCES}) target_include_directories(ImGuiColorTextEdit PUBLIC ${IMGUI_PATH}) -target_compile_definitions(ImGuiColorTextEdit PUBLIC IMGUI_IMPL_OPENGL_LOADER_CUSTOM= GL_GLEXT_PROTOTYPES=1) +target_compile_definitions(ImGuiColorTextEdit PUBLIC + IMGUI_IMPL_OPENGL_LOADER_CUSTOM= GL_GLEXT_PROTOTYPES=1) + +# asar assembly --------------------------------------------------------------- +get_target_property(ASAR_INCLUDE_DIR asar-static INCLUDE_DIRECTORIES) +include_directories(${ASAR_INCLUDE_DIR}) + +# executable linkage ---------------------------------------------------------- + +set( + YAZE_APP_CORE_SRC + app/core/common.cc + app/core/controller.cc +) + +set( + YAZE_APP_EDITOR_SRC + app/editor/assembly_editor.cc + app/editor/dungeon_editor.cc + app/editor/master_editor.cc + app/editor/overworld_editor.cc + app/editor/palette_editor.cc + app/editor/screen_editor.cc +) + +set( + YAZE_APP_GFX_SRC + app/gfx/bitmap.cc + app/gfx/pseudo_vram.cc + app/gfx/snes_palette.cc + app/gfx/snes_tile.cc +) + +set( + YAZE_APP_ZELDA3_SRC + app/zelda3/overworld_map.cc + app/zelda3/overworld.cc + app/zelda3/screen.cc +) -# Executable Linkage -------------------------------------------------------------------------------------- add_executable( yaze yaze.cc - app/core/common.cc - app/core/controller.cc - app/editor/assembly_editor.cc - app/editor/dungeon_editor.cc - app/editor/master_editor.cc - app/editor/overworld_editor.cc - app/editor/palette_editor.cc - app/editor/screen_editor.cc - app/gfx/bitmap.cc - app/gfx/pseudo_vram.cc - app/gfx/snes_palette.cc - app/gfx/snes_tile.cc - app/zelda3/overworld_map.cc - app/zelda3/overworld.cc - app/zelda3/screen.cc + ${YAZE_APP_CORE_SRC} + ${YAZE_APP_EDITOR_SRC} + ${YAZE_APP_GFX_SRC} + ${YAZE_APP_ZELDA3_SRC} app/rom.cc gui/canvas.cc gui/input.cc @@ -96,6 +124,7 @@ target_link_libraries( ${PNG_LIBRARIES} ${GLEW_LIBRARIES} ${OPENGL_LIBRARIES} + asar-static ImGui ) diff --git a/src/lib/asar b/src/lib/asar new file mode 160000 index 00000000..634d6baf --- /dev/null +++ b/src/lib/asar @@ -0,0 +1 @@ +Subproject commit 634d6baf7ad073ef01055c9f0ce923636738d2a7