diff --git a/src/app/editor/master_editor.cc b/src/app/editor/master_editor.cc index 7c608e0a..6fcb7b6a 100644 --- a/src/app/editor/master_editor.cc +++ b/src/app/editor/master_editor.cc @@ -44,7 +44,7 @@ void NewMasterFrame() { } bool BeginCentered(const char *name) { - ImGuiIO &io = ImGui::GetIO(); + ImGuiIO const &io = ImGui::GetIO(); ImVec2 pos(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f); ImGui::SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGuiWindowFlags flags = @@ -236,6 +236,9 @@ void MasterEditor::DrawViewMenu() { ImGui::MenuItem("HEX Editor", nullptr, &show_memory_editor); ImGui::MenuItem("ASM Editor", nullptr, &show_asm_editor); ImGui::MenuItem("ImGui Demo", nullptr, &show_imgui_demo); + if (ImGui::MenuItem("Overworld Debug")) { + overworld_editor_.OverworldDebugMenu(); + } ImGui::Separator(); if (ImGui::BeginMenu("GUI Tools")) { ImGui::MenuItem("Metrics (ImGui)", nullptr, &show_imgui_metrics); diff --git a/src/app/editor/overworld_editor.cc b/src/app/editor/overworld_editor.cc index b90f7f81..d0140172 100644 --- a/src/app/editor/overworld_editor.cc +++ b/src/app/editor/overworld_editor.cc @@ -43,8 +43,12 @@ absl::Status OverworldEditor::Update() { all_gfx_loaded_ = true; } + if (overworld_debug_menu_) { + DrawOverworldDebugMenu(); + } + auto toolset_status = DrawToolset(); - RETURN_IF_ERROR(toolset_status); + RETURN_IF_ERROR(toolset_status) ImGui::Separator(); if (ImGui::BeginTable("#owEditTable", 2, ow_edit_flags, ImVec2(0, 0))) { @@ -102,21 +106,6 @@ absl::Status OverworldEditor::DrawToolset() { // Music ImGui::TableNextColumn(); ImGui::Button(ICON_MD_MUSIC_NOTE); - ImGui::TableNextColumn(); - ImGui::Text(ICON_MD_MORE_VERT); - // Load Overworld - ImGui::TableNextColumn(); - if (ImGui::Button(ICON_MD_UPDATE)) { - RETURN_IF_ERROR(overworld_.Load(rom_)) - current_gfx_bmp_.Create(128, 512, 8, - overworld_.GetCurrentGraphics().data(), 32768); - tile16_blockset_bmp_.Create( - 512, 8192 * 2, 8, (uchar *)overworld_.GetCurrentBlockset().data(), - 1048576); - rom_.RenderBitmap(current_gfx_bmp_); - rom_.RenderBitmap(tile16_blockset_bmp_); - } - ImGui::TableNextColumn(); ImGui::Text(ICON_MD_MORE_VERT); @@ -270,23 +259,48 @@ void OverworldEditor::DrawAreaGraphics() { } current_gfx_canvas_.DrawBackground(ImVec2(256 + 1, 16 * 64 + 1)); current_gfx_canvas_.DrawContextMenu(); - for (const auto &[key, value] : current_graphics_set_) { - int offset = 64 * (key + 1); - int top_left_y = current_gfx_canvas_.GetZeroPoint().y + 2; - if (key >= 1) { - top_left_y = current_gfx_canvas_.GetZeroPoint().y + 64 * key; - } - current_gfx_canvas_.GetDrawList()->AddImage( - (void *)value.GetTexture(), - ImVec2(current_gfx_canvas_.GetZeroPoint().x + 2, top_left_y), - ImVec2(current_gfx_canvas_.GetZeroPoint().x + 256, - current_gfx_canvas_.GetZeroPoint().y + offset)); - } + current_gfx_canvas_.DrawBitmap(current_gfx_bmp_); + // for (const auto &[key, value] : current_graphics_set_) { + // int offset = 64 * (key + 1); + // int top_left_y = current_gfx_canvas_.GetZeroPoint().y + 2; + // if (key >= 1) { + // top_left_y = current_gfx_canvas_.GetZeroPoint().y + 64 * key; + // } + // current_gfx_canvas_.GetDrawList()->AddImage( + // (void *)value.GetTexture(), + // ImVec2(current_gfx_canvas_.GetZeroPoint().x + 2, top_left_y), + // ImVec2(current_gfx_canvas_.GetZeroPoint().x + 256, + // current_gfx_canvas_.GetZeroPoint().y + offset)); + // } current_gfx_canvas_.DrawGrid(32.0f); current_gfx_canvas_.DrawOverlay(); } } +absl::Status OverworldEditor::DrawOverworldDebugMenu() { + ImGui::Begin("Overworld Debug Menu"); + if (ImGui::Button("Load Overworld")) { + RETURN_IF_ERROR(overworld_.Load(rom_)) + } + if (ImGui::Button("Current Graphics Bitmap")) { + current_gfx_bmp_.Create(128, 512, 8, overworld_.GetCurrentGraphics().data(), + 32768); + rom_.RenderBitmap(¤t_gfx_bmp_); + } + if (ImGui::Button("Tile16 Blockset Bitmap")) { + tile16_blockset_bmp_.Create( + 512, 16384, 8, overworld_.GetCurrentBlockset().data(), 1048576); + rom_.RenderBitmap(&tile16_blockset_bmp_); + } + if (ImGui::Button("Overworld Map Bitmap")) { + overworld_map_bmp_.Create(1024, 1024, 8, overworld_.GetCurrentBitmapData().data()); + rom_.RenderBitmap(&overworld_map_bmp_); + } + + ImGui::End(); + return absl::OkStatus(); +} + void OverworldEditor::LoadGraphics() { for (int i = 0; i < 8; i++) { current_palette_[i].x = (i * 0.21f); diff --git a/src/app/editor/overworld_editor.h b/src/app/editor/overworld_editor.h index c7204e39..f68348a4 100644 --- a/src/app/editor/overworld_editor.h +++ b/src/app/editor/overworld_editor.h @@ -48,6 +48,8 @@ class OverworldEditor { absl::Status Copy() { return absl::UnimplementedError("Copy"); } absl::Status Paste() { return absl::UnimplementedError("Paste"); } + void OverworldDebugMenu() { overworld_debug_menu_ = true; } + private: absl::Status DrawToolset(); void DrawOverworldMapSettings(); @@ -57,6 +59,8 @@ class OverworldEditor { void DrawTile8Selector(); void DrawAreaGraphics(); + absl::Status DrawOverworldDebugMenu(); + void LoadGraphics(); int current_world_ = 0; @@ -70,6 +74,7 @@ class OverworldEditor { bool opt_enable_grid = true; bool all_gfx_loaded_ = false; bool map_blockset_loaded_ = false; + bool overworld_debug_menu_ = false; ImVec4 current_palette_[8]; @@ -89,6 +94,7 @@ class OverworldEditor { gfx::Bitmap tile16_blockset_bmp_; // pointer size 1048576 gfx::Bitmap current_gfx_bmp_; // pointer size 32768 gfx::Bitmap all_gfx_bmp; // pointer size 456704 + gfx::Bitmap overworld_map_bmp_; gui::Canvas overworld_map_canvas_; gui::Canvas current_gfx_canvas_; diff --git a/src/app/zelda3/overworld.h b/src/app/zelda3/overworld.h index 6f59a88b..5b44d25e 100644 --- a/src/app/zelda3/overworld.h +++ b/src/app/zelda3/overworld.h @@ -30,6 +30,9 @@ class Overworld { auto GetCurrentGraphics() const { return overworld_maps_[current_map_].GetCurrentGraphics(); } + auto GetCurrentBitmapData() const { + return overworld_maps_[current_map_].GetBitmapData(); + } auto isLoaded() const { return is_loaded_; } private: diff --git a/src/app/zelda3/overworld_map.cc b/src/app/zelda3/overworld_map.cc index 020d3a87..f4c51413 100644 --- a/src/app/zelda3/overworld_map.cc +++ b/src/app/zelda3/overworld_map.cc @@ -20,7 +20,7 @@ namespace zelda3 { namespace { void CopyTile(int x, int y, int xx, int yy, int offset, gfx::TileInfo tile, - uchar* ow_blockset, uchar* current_gfx) { + Bytes& ow_blockset, Bytes& current_gfx) { int mx = x; int my = y; uchar r = 0; @@ -44,7 +44,7 @@ void CopyTile(int x, int y, int xx, int yy, int offset, gfx::TileInfo tile, ow_blockset[p2] = (uchar)(((pixel >> 4) & 0x0F) + tile.palette_ * 16); } -void CopyTile8bpp16(int x, int y, int tile, uchar* dest, uchar* src) { +void CopyTile8bpp16(int x, int y, int tile, Bytes& dest, Bytes& src) { int src_pos = ((tile - ((tile / 8) * 8)) * 16) + ((tile / 8) * 2048); int dest_pos = (x + (y * 512)); for (int yy = 0; yy < 16; yy++) { @@ -233,11 +233,15 @@ absl::Status OverworldMap::BuildTileset() { current_graphics_sheet_set[i] = sheet; } - auto allgfxData = rom_.GetGraphicsBuffer().data(); + all_gfx_ = rom_.GetGraphicsBuffer(); current_gfx_.reserve(32768); + for (int i = 0; i < 32768; i++) { + current_gfx_.push_back(0x00); + } + for (int i = 0; i < 16; i++) { for (int j = 0; j < 2048; j++) { - auto mapByte = allgfxData[j + (static_graphics_[i] * 2048)]; + auto mapByte = all_gfx_[j + (static_graphics_[i] * 2048)]; switch (i) { case 0: case 3: @@ -256,6 +260,9 @@ absl::Status OverworldMap::BuildTileset() { absl::Status OverworldMap::BuildTiles16Gfx(int count) { current_blockset_.reserve(1048576); + for (int i = 0; i < 1048576; i++) { + current_blockset_.push_back(0x00); + } int offsets[] = {0, 8, 1024, 1032}; auto yy = 0; auto xx = 0; @@ -278,13 +285,14 @@ absl::Status OverworldMap::BuildTiles16Gfx(int count) { case 3: info = tiles16_[i].tile3_; break; + default: + return absl::InternalError("Invalid Tile"); } int offset = offsets[tile]; for (auto y = 0; y < 8; y++) { for (auto x = 0; x < 4; x++) { - CopyTile(x, y, xx, yy, offset, info, current_blockset_.data(), - current_gfx_.data()); + CopyTile(x, y, xx, yy, offset, info, current_blockset_, current_gfx_); } } } @@ -300,8 +308,11 @@ absl::Status OverworldMap::BuildTiles16Gfx(int count) { } absl::Status OverworldMap::BuildBitmap(OWBlockset& world_blockset) { - bitmap_.Create(512, 512, 8, 1048576); - auto bitmap_ptr_ = bitmap_.GetData(); + bitmap_data_.reserve(262144); + for (int i = 0; i < 262144; i++) { + bitmap_data_.push_back(0x00); + } + int superY = ((index_ - (world_ * 64)) / 8); int superX = index_ - (world_ * 64) - (superY * 8); @@ -309,11 +320,10 @@ absl::Status OverworldMap::BuildBitmap(OWBlockset& world_blockset) { for (int x = 0; x < 32; x++) { auto xt = x + (superX * 32); auto yt = y + (superY * 32); - CopyTile8bpp16((x * 16), (y * 16), world_blockset[xt][yt], bitmap_ptr_, - current_blockset_.data()); + CopyTile8bpp16((x * 16), (y * 16), world_blockset[xt][yt], bitmap_data_, + current_blockset_); } } - rom_.RenderBitmap(bitmap_); return absl::OkStatus(); } diff --git a/src/app/zelda3/overworld_map.h b/src/app/zelda3/overworld_map.h index ad36fa6a..50875933 100644 --- a/src/app/zelda3/overworld_map.h +++ b/src/app/zelda3/overworld_map.h @@ -28,10 +28,11 @@ class OverworldMap { absl::Status BuildMap(int count, int game_state, int world, uchar* map_parent, OWBlockset& world_blockset); - auto GetBitmap() const { return bitmap_; } + gfx::Bitmap& GetBitmap() { return bitmap_; } auto GetCurrentGraphicsSet() const { return current_graphics_sheet_set; } auto GetCurrentBlockset() const { return current_blockset_; } auto GetCurrentGraphics() const { return current_gfx_; } + auto GetBitmapData() const { return bitmap_data_; } auto SetLargeMap(bool is_set) { large_map_ = is_set; } auto IsLargeMap() const { return large_map_; } auto IsInitialized() const { return initialized_; } @@ -62,8 +63,10 @@ class OverworldMap { bool large_map_ = false; ROM rom_; + Bytes all_gfx_; Bytes current_blockset_; Bytes current_gfx_; + Bytes bitmap_data_; gfx::Bitmap bitmap_; OWMapTiles map_tiles_;