From 7fedea14acabc8914b868c04c36f06ad382fd3cd Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 26 Nov 2023 16:24:32 -0500 Subject: [PATCH] Add GfxContext, Load all gfx from MasterEditor --- src/CMakeLists.txt | 1 + src/app/editor/context/gfx_context.cc | 35 +++++++++++++++++ src/app/editor/context/gfx_context.h | 56 +++++++++++++++++++++++++++ src/app/editor/master_editor.cc | 17 ++++---- src/app/editor/master_editor.h | 6 ++- 5 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 src/app/editor/context/gfx_context.cc create mode 100644 src/app/editor/context/gfx_context.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 197bbe8d..43d9ad61 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,6 +18,7 @@ set( app/editor/modules/assembly_editor.cc app/editor/modules/tile16_editor.cc app/editor/modules/gfx_group_editor.cc + app/editor/context/gfx_context.cc ) set( diff --git a/src/app/editor/context/gfx_context.cc b/src/app/editor/context/gfx_context.cc new file mode 100644 index 00000000..fa5f5c5d --- /dev/null +++ b/src/app/editor/context/gfx_context.cc @@ -0,0 +1,35 @@ +#include "app/editor/context/gfx_context.h" + +#include + +#include + +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "app/core/editor.h" +#include "app/core/pipeline.h" +#include "app/editor/modules/palette_editor.h" +#include "app/gfx/bitmap.h" +#include "app/gfx/snes_palette.h" +#include "app/gfx/snes_tile.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" +#include "app/rom.h" +#include "app/zelda3/overworld.h" + +namespace yaze { +namespace app { +namespace editor { + +absl::Status GfxContext::Update() { return absl::OkStatus(); } + +gfx::Bitmap GfxContext::current_ow_gfx_bmp_; +gfx::SNESPalette GfxContext::current_ow_palette_; +gfx::Bitmap GfxContext::tile16_blockset_bmp_; +gfx::Bitmap GfxContext::tile8_blockset_bmp_; +std::vector GfxContext::tile16_individual_bmp_; +std::vector GfxContext::tile8_individual_bmp_; + +} // namespace editor +} // namespace app +} // namespace yaze \ No newline at end of file diff --git a/src/app/editor/context/gfx_context.h b/src/app/editor/context/gfx_context.h new file mode 100644 index 00000000..a15ae07d --- /dev/null +++ b/src/app/editor/context/gfx_context.h @@ -0,0 +1,56 @@ +#ifndef YAZE_APP_EDITOR_VRAM_CONTEXT_H +#define YAZE_APP_EDITOR_VRAM_CONTEXT_H + +#include + +#include +#include + +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "app/core/editor.h" +#include "app/core/pipeline.h" +#include "app/editor/modules/palette_editor.h" +#include "app/gfx/bitmap.h" +#include "app/gfx/snes_palette.h" +#include "app/gfx/snes_tile.h" +#include "app/gui/canvas.h" +#include "app/gui/icons.h" +#include "app/rom.h" +#include "app/zelda3/overworld.h" + +// Create a class which manages the current VRAM state of Link to the Past, +// including static members for the Bitmaps and Palettes as well as the current +// blockset as to update all of the overworld maps with the new blockset when it +// is changed. This class will also manage the current tile16 and tile8 +// selection, as well as the current palette selection. + +namespace yaze { +namespace app { +namespace editor { + +class GfxContext { + public: + absl::Status Update(); + + protected: + static gfx::Bitmap current_ow_gfx_bmp_; + + static gfx::SNESPalette current_ow_palette_; + + static gfx::Bitmap tile16_blockset_bmp_; + + static gfx::Bitmap tile8_blockset_bmp_; + + // Bitmaps for the tile16 individual tiles + static std::vector tile16_individual_bmp_; + + // Bitmaps for the tile8 individual tiles + static std::vector tile8_individual_bmp_; +}; + +} // namespace editor +} // namespace app +} // namespace yaze + +#endif // YAZE_APP_EDITOR_VRAM_CONTEXT_H \ No newline at end of file diff --git a/src/app/editor/master_editor.cc b/src/app/editor/master_editor.cc index ffa5963b..9bff2a0b 100644 --- a/src/app/editor/master_editor.cc +++ b/src/app/editor/master_editor.cc @@ -128,6 +128,12 @@ absl::Status MasterEditor::Update() { DrawAboutPopup(); DrawInfoPopup(); + if (rom()->isLoaded() && !rom_assets_loaded_) { + // Initialize overworld graphics, maps, and palettes + RETURN_IF_ERROR(overworld_editor_.LoadGraphics()); + rom_assets_loaded_ = true; + } + TAB_BAR("##TabBar") gui::RenderTabItem("Overworld", [&]() { @@ -249,7 +255,7 @@ void MasterEditor::DrawYazeMenu() { } ImGui::PopStyleColor(); - Text(absl::StrCat("yaze v", core::kYazeVersion).c_str()); + Text("%s", absl::StrCat("yaze v", core::kYazeVersion).c_str()); END_MENU_BAR() @@ -277,16 +283,9 @@ void MasterEditor::DrawFileMenu() { auto file_name = FileDialogWrapper::ShowOpenFileDialog(); PRINT_IF_ERROR(rom()->LoadFromFile(file_name)); static RecentFilesManager manager("recent_files.txt"); - - // Load existing recent files manager.Load(); - - // Add a new file manager.AddFile(file_name); - - // Save the updated list manager.Save(); - } else { ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Open ROM", ".sfc,.smc", "."); @@ -322,6 +321,8 @@ void MasterEditor::DrawFileMenu() { ImGui::MenuItem("Backup ROM", "", &backup_rom_); ImGui::Separator(); Text("Experiment Flags"); + ImGui::Checkbox("Enable Texture Streaming", + &mutable_flags()->kLoadTexturesAsStreaming); ImGui::Checkbox("Enable Overworld Sprites", &mutable_flags()->kDrawOverworldSprites); ImGui::Checkbox("Use Bitmap Manager", diff --git a/src/app/editor/master_editor.h b/src/app/editor/master_editor.h index 4f46101d..2feebf38 100644 --- a/src/app/editor/master_editor.h +++ b/src/app/editor/master_editor.h @@ -11,6 +11,7 @@ #include "app/core/common.h" #include "app/core/constants.h" #include "app/core/pipeline.h" +#include "app/editor/context/gfx_context.h" #include "app/editor/dungeon_editor.h" #include "app/editor/graphics_editor.h" #include "app/editor/modules/assembly_editor.h" @@ -31,7 +32,9 @@ namespace yaze { namespace app { namespace editor { -class MasterEditor : public SharedROM, public core::ExperimentFlags { +class MasterEditor : public SharedROM, + public GfxContext, + public core::ExperimentFlags { public: MasterEditor() { current_editor_ = &overworld_editor_; } @@ -56,6 +59,7 @@ class MasterEditor : public SharedROM, public core::ExperimentFlags { bool rom_info_ = false; bool backup_rom_ = true; bool show_status_ = false; + bool rom_assets_loaded_ = false; absl::Status status_; absl::Status prev_status_;