diff --git a/src/app/core/common.h b/src/app/core/common.h index 9621a3ff..609c7bd9 100644 --- a/src/app/core/common.h +++ b/src/app/core/common.h @@ -30,9 +30,6 @@ namespace core { class ExperimentFlags { public: struct Flags { - // Bitmap manager abstraction to manage graphics bin of Rom. - bool kUseBitmapManager = true; - // Log instructions to the GUI debugger. bool kLogInstructions = true; diff --git a/src/app/editor/dungeon/dungeon_editor.h b/src/app/editor/dungeon/dungeon_editor.h index 5b78804c..ce549607 100644 --- a/src/app/editor/dungeon/dungeon_editor.h +++ b/src/app/editor/dungeon/dungeon_editor.h @@ -124,7 +124,6 @@ class DungeonEditor : public Editor, std::vector room_gfx_sheets_; std::vector rooms_; std::vector entrances_; - std::vector room_graphics_; zelda3::dungeon::DungeonObjectRenderer object_renderer_; absl::flat_hash_map spriteset_usage_; diff --git a/src/app/editor/graphics/gfx_group_editor.cc b/src/app/editor/graphics/gfx_group_editor.cc index c5905cf2..c2f21b9c 100644 --- a/src/app/editor/graphics/gfx_group_editor.cc +++ b/src/app/editor/graphics/gfx_group_editor.cc @@ -1,7 +1,5 @@ #include "gfx_group_editor.h" -#include "imgui/imgui.h" - #include #include "absl/status/status.h" @@ -17,6 +15,7 @@ #include "app/gui/input.h" #include "app/rom.h" #include "app/zelda3/overworld/overworld.h" +#include "imgui/imgui.h" namespace yaze { namespace app { @@ -123,7 +122,7 @@ void GfxGroupEditor::DrawBlocksetViewer(bool sheet_only) { BeginGroup(); for (int i = 0; i < 8; i++) { int sheet_id = rom()->main_blockset_ids[selected_blockset_][i]; - auto sheet = rom()->bitmap_manager()[sheet_id]; + auto sheet = rom()->gfx_sheets().at(sheet_id); gui::BitmapCanvasPipeline(blockset_canvas_, sheet, 256, 0x10 * 0x04, 0x20, true, false, 22); } @@ -176,7 +175,7 @@ void GfxGroupEditor::DrawRoomsetViewer() { BeginGroup(); for (int i = 0; i < 4; i++) { int sheet_id = rom()->room_blockset_ids[selected_roomset_][i]; - auto sheet = rom()->bitmap_manager()[sheet_id]; + auto sheet = rom()->gfx_sheets().at(sheet_id); gui::BitmapCanvasPipeline(roomset_canvas_, sheet, 256, 0x10 * 0x04, 0x20, true, false, 23); } @@ -214,7 +213,7 @@ void GfxGroupEditor::DrawSpritesetViewer(bool sheet_only) { BeginGroup(); for (int i = 0; i < 4; i++) { int sheet_id = rom()->spriteset_ids[selected_spriteset_][i]; - auto sheet = rom()->bitmap_manager()[115 + sheet_id]; + auto sheet = rom()->gfx_sheets().at(115 + sheet_id); gui::BitmapCanvasPipeline(spriteset_canvas_, sheet, 256, 0x10 * 0x04, 0x20, true, false, 24); } diff --git a/src/app/editor/message/message_editor.cc b/src/app/editor/message/message_editor.cc index bd11c913..8e082475 100644 --- a/src/app/editor/message/message_editor.cc +++ b/src/app/editor/message/message_editor.cc @@ -305,9 +305,7 @@ void MessageEditor::ReadAllTextData() { current_message_parsed.clear(); continue; - } - - if (current_byte == 0xFF) { + } else if (current_byte == 0xFF) { break; } @@ -381,7 +379,7 @@ void MessageEditor::ReadAllTextData() { TextElement MessageEditor::FindMatchingCommand(uint8_t b) { TextElement empty_element; - for (const auto text_element : TextCommands) { + for (const auto& text_element : TextCommands) { if (text_element.ID == b) { return text_element; } diff --git a/src/app/editor/overworld/overworld_editor.cc b/src/app/editor/overworld/overworld_editor.cc index d4a4c688..751f14a1 100644 --- a/src/app/editor/overworld/overworld_editor.cc +++ b/src/app/editor/overworld/overworld_editor.cc @@ -695,7 +695,8 @@ void OverworldEditor::DrawTile8Selector() { graphics_bin_canvas_.DrawBackground(); graphics_bin_canvas_.DrawContextMenu(); if (all_gfx_loaded_) { - for (auto &[key, value] : rom()->bitmap_manager()) { + int key = 0; + for (auto &value : rom()->gfx_sheets()) { int offset = 0x40 * (key + 1); int top_left_y = graphics_bin_canvas_.zero_point().y + 2; if (key >= 1) { @@ -707,6 +708,7 @@ void OverworldEditor::DrawTile8Selector() { ImVec2(graphics_bin_canvas_.zero_point().x + 2, top_left_y), ImVec2(graphics_bin_canvas_.zero_point().x + 0x100, graphics_bin_canvas_.zero_point().y + offset)); + key++; } } graphics_bin_canvas_.DrawGrid(); diff --git a/src/app/editor/sprite/sprite_editor.cc b/src/app/editor/sprite/sprite_editor.cc index bd03da0f..74b0fe6d 100644 --- a/src/app/editor/sprite/sprite_editor.cc +++ b/src/app/editor/sprite/sprite_editor.cc @@ -175,7 +175,7 @@ void SpriteEditor::DrawCurrentSheets() { graphics_sheet_canvas_.DrawTileSelector(32); for (int i = 0; i < 8; i++) { graphics_sheet_canvas_.DrawBitmap( - rom()->bitmap_manager()[current_sheets_[i]], 1, (i * 0x40) + 1, 2); + rom()->gfx_sheets().at(current_sheets_[i]), 1, (i * 0x40) + 1, 2); } graphics_sheet_canvas_.DrawGrid(); graphics_sheet_canvas_.DrawOverlay(); diff --git a/src/app/editor/utils/flags.h b/src/app/editor/utils/flags.h index bde5bc19..1e04e8f3 100644 --- a/src/app/editor/utils/flags.h +++ b/src/app/editor/utils/flags.h @@ -52,7 +52,6 @@ struct FlagsMenu : public core::ExperimentFlags { Checkbox("Enable Console Logging", &mutable_flags()->kLogToConsole); Checkbox("Enable Texture Streaming", &mutable_flags()->kLoadTexturesAsStreaming); - Checkbox("Use Bitmap Manager", &mutable_flags()->kUseBitmapManager); Checkbox("Log Instructions to Debugger", &mutable_flags()->kLogInstructions); Checkbox("Save All Palettes", &mutable_flags()->kSaveAllPalettes); diff --git a/src/app/gfx/bitmap.h b/src/app/gfx/bitmap.h index fe8db58f..a2821706 100644 --- a/src/app/gfx/bitmap.h +++ b/src/app/gfx/bitmap.h @@ -219,51 +219,6 @@ class Bitmap { using BitmapTable = std::unordered_map; -/** - * @brief Hash map container of shared pointers to Bitmaps. - * \deprecated Moved to fixed array or vector for storing groups of bitmaps. - */ -class BitmapManager { - private: - std::unordered_map bitmap_cache_; - - public: - void LoadBitmap(int id, const Bytes &data, int width, int height, int depth) { - bitmap_cache_[id].Create(width, height, depth, data); - } - - gfx::Bitmap &operator[](int id) { - auto it = bitmap_cache_.find(id); - if (it != bitmap_cache_.end()) { - return it->second; - } - return bitmap_cache_.begin()->second; - } - gfx::Bitmap &shared_bitmap(int id) { - auto it = bitmap_cache_.find(id); - if (it != bitmap_cache_.end()) { - return it->second; - } - throw std::runtime_error( - absl::StrCat("Bitmap with id ", id, " not found.")); - } - auto mutable_bitmap(int id) { return &bitmap_cache_[id]; } - void clear_cache() { bitmap_cache_.clear(); } - auto size() const { return bitmap_cache_.size(); } - auto at(int id) const { return bitmap_cache_.at(id); } - - using value_type = std::pair; - using iterator = std::unordered_map::iterator; - using const_iterator = std::unordered_map::const_iterator; - - iterator begin() noexcept { return bitmap_cache_.begin(); } - iterator end() noexcept { return bitmap_cache_.end(); } - const_iterator begin() const noexcept { return bitmap_cache_.begin(); } - const_iterator end() const noexcept { return bitmap_cache_.end(); } - const_iterator cbegin() const noexcept { return bitmap_cache_.cbegin(); } - const_iterator cend() const noexcept { return bitmap_cache_.cend(); } -}; - } // namespace gfx } // namespace app } // namespace yaze diff --git a/src/app/rom.cc b/src/app/rom.cc index 690c0b0a..c426de7e 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -116,33 +116,24 @@ absl::Status Rom::LoadAllGraphicsData() { auto converted_sheet = gfx::SnesTo8bppSheet(sheet, 3); graphics_sheets_[i].Create(core::kTilesheetWidth, core::kTilesheetHeight, core::kTilesheetDepth, converted_sheet); + if (graphics_sheets_[i].is_active()) { + if (i > 115) { + // Apply sprites palette + RETURN_IF_ERROR(graphics_sheets_[i].ApplyPaletteWithTransparent( + palette_groups_.global_sprites[0], 0)); + } else { + RETURN_IF_ERROR(graphics_sheets_[i].ApplyPaletteWithTransparent( + palette_groups_.dungeon_main[0], 0)); + } + } graphics_sheets_[i].CreateTexture(Renderer::GetInstance().renderer()); - if (flags()->kUseBitmapManager) { - graphics_manager_.LoadBitmap(i, converted_sheet, core::kTilesheetWidth, - core::kTilesheetHeight, - core::kTilesheetDepth); - if (graphics_manager_[i].is_active()) { - if (i > 115) { - // Apply sprites palette - RETURN_IF_ERROR(graphics_manager_[i].ApplyPaletteWithTransparent( - palette_groups_.global_sprites[0], 0)); - } else { - RETURN_IF_ERROR(graphics_manager_[i].ApplyPaletteWithTransparent( - palette_groups_.dungeon_main[0], 0)); - } - graphics_manager_[i].CreateTexture( - Renderer::GetInstance().renderer()); - } + for (int j = 0; j < graphics_sheets_[i].size(); ++j) { + graphics_buffer_.push_back(graphics_sheets_[i].at(j)); } - if (flags()->kUseBitmapManager) { - for (int j = 0; j < graphics_manager_[i].size(); ++j) { - graphics_buffer_.push_back(graphics_manager_[i].at(j)); - } - } } else { - for (int j = 0; j < graphics_manager_[0].size(); ++j) { + for (int j = 0; j < graphics_sheets_[0].size(); ++j) { graphics_buffer_.push_back(0xFF); } } diff --git a/src/app/rom.h b/src/app/rom.h index e9063b18..7711b585 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -410,8 +410,6 @@ class Rom : public core::ExperimentFlags { // Full graphical data for the game Bytes graphics_buffer() const { return graphics_buffer_; } - [[deprecated]] auto bitmap_manager() { return graphics_manager_; } - auto link_graphics() { return link_graphics_; } auto mutable_link_graphics() { return &link_graphics_; } @@ -524,8 +522,6 @@ class Rom : public core::ExperimentFlags { Z3_Version version_ = Z3_Version::US; - [[deprecated("BitmapManager has unpredictable destructor behavior.")]] gfx:: - BitmapManager graphics_manager_; gfx::SnesPalette link_palette_; gfx::PaletteGroupMap palette_groups_; core::ResourceLabelManager resource_label_manager_;