diff --git a/src/app/editor/dungeon_editor.cc b/src/app/editor/dungeon_editor.cc index 6adc85a2..9151f6ca 100644 --- a/src/app/editor/dungeon_editor.cc +++ b/src/app/editor/dungeon_editor.cc @@ -92,7 +92,7 @@ absl::Status DungeonEditor::Initialize() { graphics_bin_ = *rom()->mutable_bitmap_manager(); // Create a vector of pointers to the current block bitmaps for (int block : rooms_[current_room_id_].blocks()) { - room_gfx_sheets_.emplace_back(graphics_bin_[block].get()); + room_gfx_sheets_.emplace_back(&graphics_bin_[block]); } return absl::OkStatus(); } @@ -100,16 +100,16 @@ absl::Status DungeonEditor::Initialize() { absl::Status DungeonEditor::RefreshGraphics() { for (int i = 0; i < 8; i++) { int block = rooms_[current_room_id_].blocks()[i]; - RETURN_IF_ERROR(graphics_bin_[block].get()->ApplyPaletteWithTransparent( + RETURN_IF_ERROR(graphics_bin_[block].ApplyPaletteWithTransparent( current_palette_group_[current_palette_id_], 0)); - rom()->UpdateBitmap(graphics_bin_[block].get(), true); + rom()->UpdateBitmap(&graphics_bin_[block], true); } auto sprites_aux1_pal_group = rom()->palette_group().sprites_aux1; for (int i = 9; i < 16; i++) { int block = rooms_[current_room_id_].blocks()[i]; - RETURN_IF_ERROR(graphics_bin_[block].get()->ApplyPaletteWithTransparent( + RETURN_IF_ERROR(graphics_bin_[block].ApplyPaletteWithTransparent( sprites_aux1_pal_group[current_palette_id_], 0)); - rom()->UpdateBitmap(graphics_bin_[block].get(), true); + rom()->UpdateBitmap(&graphics_bin_[block], true); } return absl::OkStatus(); } @@ -505,7 +505,7 @@ void DungeonEditor::DrawRoomGraphics() { top_left_y = room_gfx_canvas_.zero_point().y + height * current_block; } room_gfx_canvas_.draw_list()->AddImage( - (void*)graphics_bin_[block].get()->texture(), + (void*)graphics_bin_[block].texture(), ImVec2(room_gfx_canvas_.zero_point().x + 2, top_left_y), ImVec2(room_gfx_canvas_.zero_point().x + 0x100, room_gfx_canvas_.zero_point().y + offset)); diff --git a/src/app/editor/graphics_editor.cc b/src/app/editor/graphics_editor.cc index 974b4831..a7f5af0d 100644 --- a/src/app/editor/graphics_editor.cc +++ b/src/app/editor/graphics_editor.cc @@ -109,7 +109,7 @@ void GraphicsEditor::DrawGfxEditToolset() { TableNextColumn(); if (Button(ICON_MD_CONTENT_COPY)) { std::vector png_data = - rom()->bitmap_manager().shared_bitmap(current_sheet_)->GetPngData(); + rom()->bitmap_manager().shared_bitmap(current_sheet_).GetPngData(); CopyImageToClipboard(png_data); } HOVER_HINT("Copy to Clipboard"); @@ -124,10 +124,8 @@ void GraphicsEditor::DrawGfxEditToolset() { ->mutable_bitmap_manager() ->mutable_bitmap(current_sheet_) ->Create(width, height, 8, png_data); - rom()->UpdateBitmap(rom() - ->mutable_bitmap_manager() - ->mutable_bitmap(current_sheet_) - .get()); + rom()->UpdateBitmap( + rom()->mutable_bitmap_manager()->mutable_bitmap(current_sheet_)); } } HOVER_HINT("Paste from Clipboard"); @@ -148,7 +146,7 @@ void GraphicsEditor::DrawGfxEditToolset() { TableNextColumn(); auto bitmap = rom()->bitmap_manager()[current_sheet_]; - auto palette = bitmap->palette(); + auto palette = bitmap.palette(); for (int i = 0; i < 8; i++) { ImGui::SameLine(); auto color = @@ -186,16 +184,16 @@ absl::Status GraphicsEditor::UpdateGfxSheetList() { graphics_bin_canvas_.DrawBackground(ImVec2(0x100 + 1, 0x40 + 1)); graphics_bin_canvas_.DrawContextMenu(); - if (value.get()->is_active()) { - auto texture = value.get()->texture(); + if (value.is_active()) { + auto texture = value.texture(); graphics_bin_canvas_.draw_list()->AddImage( (void*)texture, ImVec2(graphics_bin_canvas_.zero_point().x + 2, graphics_bin_canvas_.zero_point().y + 2), ImVec2(graphics_bin_canvas_.zero_point().x + - value.get()->width() * sheet_scale_, + value.width() * sheet_scale_, graphics_bin_canvas_.zero_point().y + - value.get()->height() * sheet_scale_)); + value.height() * sheet_scale_)); if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) { current_sheet_ = key; @@ -269,7 +267,7 @@ absl::Status GraphicsEditor::UpdateGfxTabView() { }; current_sheet_canvas_.UpdateColorPainter( - *rom()->bitmap_manager()[sheet_id], current_color_, draw_tile_event, + rom()->bitmap_manager()[sheet_id], current_color_, draw_tile_event, tile_size_, current_scale_); ImGui::EndChild(); @@ -302,7 +300,7 @@ absl::Status GraphicsEditor::UpdateGfxTabView() { current_sheet_ = id; // ImVec2(0x100, 0x40), current_sheet_canvas_.UpdateColorPainter( - *rom()->bitmap_manager()[id], current_color_, + rom()->bitmap_manager()[id], current_color_, [&]() { }, @@ -342,11 +340,10 @@ absl::Status GraphicsEditor::UpdatePaletteColumn() { if (refresh_graphics_ && !open_sheets_.empty()) { RETURN_IF_ERROR( - rom()->bitmap_manager()[current_sheet_]->ApplyPaletteWithTransparent( + rom()->bitmap_manager()[current_sheet_].ApplyPaletteWithTransparent( palette, edit_palette_sub_index_)); rom()->UpdateBitmap( - rom()->mutable_bitmap_manager()->mutable_bitmap(current_sheet_).get(), - true); + rom()->mutable_bitmap_manager()->mutable_bitmap(current_sheet_), true); refresh_graphics_ = false; } diff --git a/src/app/editor/modules/gfx_group_editor.cc b/src/app/editor/modules/gfx_group_editor.cc index 920a064e..a034282b 100644 --- a/src/app/editor/modules/gfx_group_editor.cc +++ b/src/app/editor/modules/gfx_group_editor.cc @@ -113,7 +113,7 @@ void GfxGroupEditor::DrawBlocksetViewer(bool sheet_only) { ImGui::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()->bitmap_manager()[sheet_id]; gui::BitmapCanvasPipeline(blockset_canvas_, sheet, 256, 0x10 * 0x04, 0x20, true, false, 22); } @@ -166,7 +166,7 @@ void GfxGroupEditor::DrawRoomsetViewer() { ImGui::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()->bitmap_manager()[sheet_id]; gui::BitmapCanvasPipeline(roomset_canvas_, sheet, 256, 0x10 * 0x04, 0x20, true, false, 23); } @@ -204,7 +204,7 @@ void GfxGroupEditor::DrawSpritesetViewer(bool sheet_only) { ImGui::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()->bitmap_manager()[115 + sheet_id]; gui::BitmapCanvasPipeline(spriteset_canvas_, sheet, 256, 0x10 * 0x04, 0x20, true, false, 24); } diff --git a/src/app/editor/overworld_editor.cc b/src/app/editor/overworld_editor.cc index 30953098..d60acaae 100644 --- a/src/app/editor/overworld_editor.cc +++ b/src/app/editor/overworld_editor.cc @@ -769,7 +769,7 @@ void OverworldEditor::DrawTile8Selector() { if (key >= 1) { top_left_y = graphics_bin_canvas_.zero_point().y + 0x40 * key; } - auto texture = value.get()->texture(); + auto texture = value.texture(); graphics_bin_canvas_.draw_list()->AddImage( (void *)texture, ImVec2(graphics_bin_canvas_.zero_point().x + 2, top_left_y), diff --git a/src/app/editor/sprite_editor.cc b/src/app/editor/sprite_editor.cc index 0bbad94b..08be2806 100644 --- a/src/app/editor/sprite_editor.cc +++ b/src/app/editor/sprite_editor.cc @@ -156,7 +156,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()->bitmap_manager()[current_sheets_[i]], 1, (i * 0x40) + 1, 2); } graphics_sheet_canvas_.DrawGrid(); graphics_sheet_canvas_.DrawOverlay(); diff --git a/src/app/gfx/bitmap.h b/src/app/gfx/bitmap.h index 94c19927..e771fcbe 100644 --- a/src/app/gfx/bitmap.h +++ b/src/app/gfx/bitmap.h @@ -268,22 +268,21 @@ using BitmapTable = std::unordered_map; */ class BitmapManager { private: - std::unordered_map> bitmap_cache_; + std::unordered_map bitmap_cache_; public: void LoadBitmap(int id, const Bytes &data, int width, int height, int depth) { - bitmap_cache_[id] = - std::make_shared(width, height, depth, data); + bitmap_cache_[id].Create(width, height, depth, data); } - std::shared_ptr const &operator[](int id) { + gfx::Bitmap &operator[](int id) { auto it = bitmap_cache_.find(id); if (it != bitmap_cache_.end()) { return it->second; } return bitmap_cache_.begin()->second; } - std::shared_ptr const &shared_bitmap(int id) { + gfx::Bitmap &shared_bitmap(int id) { auto it = bitmap_cache_.find(id); if (it != bitmap_cache_.end()) { return it->second; @@ -291,14 +290,12 @@ class BitmapManager { throw std::runtime_error( absl::StrCat("Bitmap with id ", id, " not found.")); } - auto mutable_bitmap(int id) { return bitmap_cache_[id]; } + auto mutable_bitmap(int id) { return &bitmap_cache_[id]; } void clear_cache() { bitmap_cache_.clear(); } - using value_type = std::pair>; - using iterator = - std::unordered_map>::iterator; - using const_iterator = - std::unordered_map>::const_iterator; + 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(); } diff --git a/src/app/gui/pipeline.cc b/src/app/gui/pipeline.cc index 8df6536d..c4dab89c 100644 --- a/src/app/gui/pipeline.cc +++ b/src/app/gui/pipeline.cc @@ -113,7 +113,7 @@ void GraphicsManagerCanvasPipeline(int width, int height, int tile_size, top_left_y = canvas.zero_point().y + height * key; } canvas.draw_list()->AddImage( - (void*)value->texture(), + (void*)value.texture(), ImVec2(canvas.zero_point().x + 2, top_left_y), ImVec2(canvas.zero_point().x + 0x100, canvas.zero_point().y + offset)); diff --git a/src/app/rom.cc b/src/app/rom.cc index c3a75cf3..b0007665 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -99,13 +99,13 @@ absl::Status Rom::LoadAllGraphicsData() { core::kTilesheetDepth); if (i > 115) { // Apply sprites palette - RETURN_IF_ERROR(graphics_manager_[i]->ApplyPaletteWithTransparent( + RETURN_IF_ERROR(graphics_manager_[i].ApplyPaletteWithTransparent( palette_groups_.global_sprites[0], 0)); } else { - RETURN_IF_ERROR(graphics_manager_[i]->ApplyPaletteWithTransparent( + RETURN_IF_ERROR(graphics_manager_[i].ApplyPaletteWithTransparent( palette_groups_.dungeon_main[0], 0)); } - graphics_manager_[i]->CreateTexture(renderer_); + graphics_manager_[i].CreateTexture(renderer_); } graphics_bin_[i] = gfx::Bitmap(core::kTilesheetWidth, core::kTilesheetHeight, @@ -113,8 +113,8 @@ absl::Status Rom::LoadAllGraphicsData() { graphics_bin_.at(i).CreateTexture(renderer_); if (flags()->kUseBitmapManager) { - for (int j = 0; j < graphics_manager_[i].get()->size(); ++j) { - graphics_buffer_.push_back(graphics_manager_[i]->at(j)); + for (int j = 0; j < graphics_manager_[i].size(); ++j) { + graphics_buffer_.push_back(graphics_manager_[i].at(j)); } } } else {