add OverworldDebug menu

This commit is contained in:
scawful
2022-09-02 17:41:58 -05:00
parent 2b345f8796
commit 2a10637e15
6 changed files with 80 additions and 41 deletions

View File

@@ -44,7 +44,7 @@ void NewMasterFrame() {
} }
bool BeginCentered(const char *name) { 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); ImVec2 pos(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f);
ImGui::SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGuiWindowFlags flags = ImGuiWindowFlags flags =
@@ -236,6 +236,9 @@ void MasterEditor::DrawViewMenu() {
ImGui::MenuItem("HEX Editor", nullptr, &show_memory_editor); ImGui::MenuItem("HEX Editor", nullptr, &show_memory_editor);
ImGui::MenuItem("ASM Editor", nullptr, &show_asm_editor); ImGui::MenuItem("ASM Editor", nullptr, &show_asm_editor);
ImGui::MenuItem("ImGui Demo", nullptr, &show_imgui_demo); ImGui::MenuItem("ImGui Demo", nullptr, &show_imgui_demo);
if (ImGui::MenuItem("Overworld Debug")) {
overworld_editor_.OverworldDebugMenu();
}
ImGui::Separator(); ImGui::Separator();
if (ImGui::BeginMenu("GUI Tools")) { if (ImGui::BeginMenu("GUI Tools")) {
ImGui::MenuItem("Metrics (ImGui)", nullptr, &show_imgui_metrics); ImGui::MenuItem("Metrics (ImGui)", nullptr, &show_imgui_metrics);

View File

@@ -43,8 +43,12 @@ absl::Status OverworldEditor::Update() {
all_gfx_loaded_ = true; all_gfx_loaded_ = true;
} }
if (overworld_debug_menu_) {
DrawOverworldDebugMenu();
}
auto toolset_status = DrawToolset(); auto toolset_status = DrawToolset();
RETURN_IF_ERROR(toolset_status); RETURN_IF_ERROR(toolset_status)
ImGui::Separator(); ImGui::Separator();
if (ImGui::BeginTable("#owEditTable", 2, ow_edit_flags, ImVec2(0, 0))) { if (ImGui::BeginTable("#owEditTable", 2, ow_edit_flags, ImVec2(0, 0))) {
@@ -102,21 +106,6 @@ absl::Status OverworldEditor::DrawToolset() {
// Music // Music
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Button(ICON_MD_MUSIC_NOTE); 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::TableNextColumn();
ImGui::Text(ICON_MD_MORE_VERT); 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_.DrawBackground(ImVec2(256 + 1, 16 * 64 + 1));
current_gfx_canvas_.DrawContextMenu(); current_gfx_canvas_.DrawContextMenu();
for (const auto &[key, value] : current_graphics_set_) { current_gfx_canvas_.DrawBitmap(current_gfx_bmp_);
int offset = 64 * (key + 1); // for (const auto &[key, value] : current_graphics_set_) {
int top_left_y = current_gfx_canvas_.GetZeroPoint().y + 2; // int offset = 64 * (key + 1);
if (key >= 1) { // int top_left_y = current_gfx_canvas_.GetZeroPoint().y + 2;
top_left_y = current_gfx_canvas_.GetZeroPoint().y + 64 * key; // if (key >= 1) {
} // top_left_y = current_gfx_canvas_.GetZeroPoint().y + 64 * key;
current_gfx_canvas_.GetDrawList()->AddImage( // }
(void *)value.GetTexture(), // current_gfx_canvas_.GetDrawList()->AddImage(
ImVec2(current_gfx_canvas_.GetZeroPoint().x + 2, top_left_y), // (void *)value.GetTexture(),
ImVec2(current_gfx_canvas_.GetZeroPoint().x + 256, // ImVec2(current_gfx_canvas_.GetZeroPoint().x + 2, top_left_y),
current_gfx_canvas_.GetZeroPoint().y + offset)); // ImVec2(current_gfx_canvas_.GetZeroPoint().x + 256,
} // current_gfx_canvas_.GetZeroPoint().y + offset));
// }
current_gfx_canvas_.DrawGrid(32.0f); current_gfx_canvas_.DrawGrid(32.0f);
current_gfx_canvas_.DrawOverlay(); 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(&current_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() { void OverworldEditor::LoadGraphics() {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
current_palette_[i].x = (i * 0.21f); current_palette_[i].x = (i * 0.21f);

View File

@@ -48,6 +48,8 @@ class OverworldEditor {
absl::Status Copy() { return absl::UnimplementedError("Copy"); } absl::Status Copy() { return absl::UnimplementedError("Copy"); }
absl::Status Paste() { return absl::UnimplementedError("Paste"); } absl::Status Paste() { return absl::UnimplementedError("Paste"); }
void OverworldDebugMenu() { overworld_debug_menu_ = true; }
private: private:
absl::Status DrawToolset(); absl::Status DrawToolset();
void DrawOverworldMapSettings(); void DrawOverworldMapSettings();
@@ -57,6 +59,8 @@ class OverworldEditor {
void DrawTile8Selector(); void DrawTile8Selector();
void DrawAreaGraphics(); void DrawAreaGraphics();
absl::Status DrawOverworldDebugMenu();
void LoadGraphics(); void LoadGraphics();
int current_world_ = 0; int current_world_ = 0;
@@ -70,6 +74,7 @@ class OverworldEditor {
bool opt_enable_grid = true; bool opt_enable_grid = true;
bool all_gfx_loaded_ = false; bool all_gfx_loaded_ = false;
bool map_blockset_loaded_ = false; bool map_blockset_loaded_ = false;
bool overworld_debug_menu_ = false;
ImVec4 current_palette_[8]; ImVec4 current_palette_[8];
@@ -89,6 +94,7 @@ class OverworldEditor {
gfx::Bitmap tile16_blockset_bmp_; // pointer size 1048576 gfx::Bitmap tile16_blockset_bmp_; // pointer size 1048576
gfx::Bitmap current_gfx_bmp_; // pointer size 32768 gfx::Bitmap current_gfx_bmp_; // pointer size 32768
gfx::Bitmap all_gfx_bmp; // pointer size 456704 gfx::Bitmap all_gfx_bmp; // pointer size 456704
gfx::Bitmap overworld_map_bmp_;
gui::Canvas overworld_map_canvas_; gui::Canvas overworld_map_canvas_;
gui::Canvas current_gfx_canvas_; gui::Canvas current_gfx_canvas_;

View File

@@ -30,6 +30,9 @@ class Overworld {
auto GetCurrentGraphics() const { auto GetCurrentGraphics() const {
return overworld_maps_[current_map_].GetCurrentGraphics(); return overworld_maps_[current_map_].GetCurrentGraphics();
} }
auto GetCurrentBitmapData() const {
return overworld_maps_[current_map_].GetBitmapData();
}
auto isLoaded() const { return is_loaded_; } auto isLoaded() const { return is_loaded_; }
private: private:

View File

@@ -20,7 +20,7 @@ namespace zelda3 {
namespace { namespace {
void CopyTile(int x, int y, int xx, int yy, int offset, gfx::TileInfo tile, 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 mx = x;
int my = y; int my = y;
uchar r = 0; 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); 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 src_pos = ((tile - ((tile / 8) * 8)) * 16) + ((tile / 8) * 2048);
int dest_pos = (x + (y * 512)); int dest_pos = (x + (y * 512));
for (int yy = 0; yy < 16; yy++) { for (int yy = 0; yy < 16; yy++) {
@@ -233,11 +233,15 @@ absl::Status OverworldMap::BuildTileset() {
current_graphics_sheet_set[i] = sheet; current_graphics_sheet_set[i] = sheet;
} }
auto allgfxData = rom_.GetGraphicsBuffer().data(); all_gfx_ = rom_.GetGraphicsBuffer();
current_gfx_.reserve(32768); 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 i = 0; i < 16; i++) {
for (int j = 0; j < 2048; j++) { 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) { switch (i) {
case 0: case 0:
case 3: case 3:
@@ -256,6 +260,9 @@ absl::Status OverworldMap::BuildTileset() {
absl::Status OverworldMap::BuildTiles16Gfx(int count) { absl::Status OverworldMap::BuildTiles16Gfx(int count) {
current_blockset_.reserve(1048576); current_blockset_.reserve(1048576);
for (int i = 0; i < 1048576; i++) {
current_blockset_.push_back(0x00);
}
int offsets[] = {0, 8, 1024, 1032}; int offsets[] = {0, 8, 1024, 1032};
auto yy = 0; auto yy = 0;
auto xx = 0; auto xx = 0;
@@ -278,13 +285,14 @@ absl::Status OverworldMap::BuildTiles16Gfx(int count) {
case 3: case 3:
info = tiles16_[i].tile3_; info = tiles16_[i].tile3_;
break; break;
default:
return absl::InternalError("Invalid Tile");
} }
int offset = offsets[tile]; int offset = offsets[tile];
for (auto y = 0; y < 8; y++) { for (auto y = 0; y < 8; y++) {
for (auto x = 0; x < 4; x++) { for (auto x = 0; x < 4; x++) {
CopyTile(x, y, xx, yy, offset, info, current_blockset_.data(), CopyTile(x, y, xx, yy, offset, info, current_blockset_, current_gfx_);
current_gfx_.data());
} }
} }
} }
@@ -300,8 +308,11 @@ absl::Status OverworldMap::BuildTiles16Gfx(int count) {
} }
absl::Status OverworldMap::BuildBitmap(OWBlockset& world_blockset) { absl::Status OverworldMap::BuildBitmap(OWBlockset& world_blockset) {
bitmap_.Create(512, 512, 8, 1048576); bitmap_data_.reserve(262144);
auto bitmap_ptr_ = bitmap_.GetData(); for (int i = 0; i < 262144; i++) {
bitmap_data_.push_back(0x00);
}
int superY = ((index_ - (world_ * 64)) / 8); int superY = ((index_ - (world_ * 64)) / 8);
int superX = index_ - (world_ * 64) - (superY * 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++) { for (int x = 0; x < 32; x++) {
auto xt = x + (superX * 32); auto xt = x + (superX * 32);
auto yt = y + (superY * 32); auto yt = y + (superY * 32);
CopyTile8bpp16((x * 16), (y * 16), world_blockset[xt][yt], bitmap_ptr_, CopyTile8bpp16((x * 16), (y * 16), world_blockset[xt][yt], bitmap_data_,
current_blockset_.data()); current_blockset_);
} }
} }
rom_.RenderBitmap(bitmap_);
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@@ -28,10 +28,11 @@ class OverworldMap {
absl::Status BuildMap(int count, int game_state, int world, uchar* map_parent, absl::Status BuildMap(int count, int game_state, int world, uchar* map_parent,
OWBlockset& world_blockset); OWBlockset& world_blockset);
auto GetBitmap() const { return bitmap_; } gfx::Bitmap& GetBitmap() { return bitmap_; }
auto GetCurrentGraphicsSet() const { return current_graphics_sheet_set; } auto GetCurrentGraphicsSet() const { return current_graphics_sheet_set; }
auto GetCurrentBlockset() const { return current_blockset_; } auto GetCurrentBlockset() const { return current_blockset_; }
auto GetCurrentGraphics() const { return current_gfx_; } auto GetCurrentGraphics() const { return current_gfx_; }
auto GetBitmapData() const { return bitmap_data_; }
auto SetLargeMap(bool is_set) { large_map_ = is_set; } auto SetLargeMap(bool is_set) { large_map_ = is_set; }
auto IsLargeMap() const { return large_map_; } auto IsLargeMap() const { return large_map_; }
auto IsInitialized() const { return initialized_; } auto IsInitialized() const { return initialized_; }
@@ -62,8 +63,10 @@ class OverworldMap {
bool large_map_ = false; bool large_map_ = false;
ROM rom_; ROM rom_;
Bytes all_gfx_;
Bytes current_blockset_; Bytes current_blockset_;
Bytes current_gfx_; Bytes current_gfx_;
Bytes bitmap_data_;
gfx::Bitmap bitmap_; gfx::Bitmap bitmap_;
OWMapTiles map_tiles_; OWMapTiles map_tiles_;