From 190917ff6f17b0850ec7faeb5e74f3f028c04954 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 27 Aug 2023 10:20:10 -0400 Subject: [PATCH] Add Changes stack to ROM for saving --- src/app/editor/master_editor.cc | 6 ++---- src/app/editor/overworld_editor.cc | 16 +++++++++------- src/app/rom.cc | 18 ++++++++++++++++-- src/app/rom.h | 6 ++++++ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/app/editor/master_editor.cc b/src/app/editor/master_editor.cc index c0d1e500..a54e6049 100644 --- a/src/app/editor/master_editor.cc +++ b/src/app/editor/master_editor.cc @@ -306,12 +306,10 @@ void MasterEditor::DrawHelpMenu() { ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::Text("File -> Open"); ImGui::Text("Select a ROM file to open"); - ImGui::Text("Supported ROMs:"); + ImGui::Text("Supported ROMs (headered or unheadered):"); ImGui::Text("The Legend of Zelda: A Link to the Past"); ImGui::Text("US Version 1.0"); - ImGui::Separator(); - ImGui::Text("Must remove header before opening"); - ImGui::Text("Header is 0x200 bytes of data at the beginning of the ROM"); + ImGui::Text("JP Version 1.0"); if (ImGui::Button("Close", gui::kDefaultModalSize)) { open_rom_help = false; diff --git a/src/app/editor/overworld_editor.cc b/src/app/editor/overworld_editor.cc index 494cb10b..3da7724f 100644 --- a/src/app/editor/overworld_editor.cc +++ b/src/app/editor/overworld_editor.cc @@ -245,13 +245,15 @@ void OverworldEditor::RenderUpdatedMapBitmap(const ImVec2 &click_position, void OverworldEditor::QueueROMChanges(int index, ushort new_tile16) { // Store the changes made by the user to the ROM (or project file) - overworld_.SaveOverworldMaps(); - if (!overworld_.CreateTile32Tilemap()) { - // overworld_.SaveMap16Tiles(); - overworld_.SaveMap32Tiles(); - } else { - std::cout << "Failed to create tile32 tilemap" << std::endl; - } + rom()->QueueChanges([&]() { + overworld_.SaveOverworldMaps(); + if (!overworld_.CreateTile32Tilemap()) { + // overworld_.SaveMap16Tiles(); + overworld_.SaveMap32Tiles(); + } else { + std::cout << "Failed to create tile32 tilemap" << std::endl; + } + }); } void OverworldEditor::DetermineActiveMap(const ImVec2 &mouse_position) { diff --git a/src/app/rom.cc b/src/app/rom.cc index 96d85fc0..605f7165 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -3,16 +3,24 @@ #include #include +#include +#include #include -#include +#include #include +#include #include #include +#include #include +#include #include +#include #include +#include #include +#include "absl/container/flat_hash_map.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" @@ -21,8 +29,9 @@ #include "app/core/common.h" #include "app/core/constants.h" #include "app/gfx/bitmap.h" -#include "app/gfx/compression.h" +#include "app/gfx/snes_palette.h" #include "app/gfx/snes_tile.h" +#include "app/gfx/compression.h" namespace yaze { namespace app { @@ -324,6 +333,11 @@ absl::Status ROM::SaveToFile(bool backup, absl::string_view filename) { // Run the other save functions // SaveAllPalettes(); + while (!changes_.empty()) { + auto change = changes_.top(); + change(); + changes_.pop(); + } // Open the file that we know exists for writing std::fstream file(filename.data(), std::ios::binary | std::ios::out); diff --git a/src/app/rom.h b/src/app/rom.h index 973c6204..131c2e91 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,9 @@ #include "app/core/common.h" #include "app/core/constants.h" #include "app/gfx/bitmap.h" +#include "app/gfx/compression.h" #include "app/gfx/snes_palette.h" +#include "app/gfx/snes_tile.h" namespace yaze { namespace app { @@ -197,6 +200,8 @@ class ROM { WriteShort(address, bgr); } + void QueueChanges(std::function function) { changes_.push(function); } + VersionConstants GetVersionConstants() const { return kVersionConstantsMap.at(version_); } @@ -286,6 +291,7 @@ class ROM { Z3_Version version_ = Z3_Version::US; gfx::BitmapTable graphics_bin_; + std::stack> changes_; std::shared_ptr renderer_; std::unordered_map palette_groups_; };