Add Debugger interface, RoomObject class

- Log instructions to debugger using experiment flag
- Use BitmapManager for more functionality
- Draw framebuffer and integrated debugger
This commit is contained in:
scawful
2023-11-13 14:51:01 -05:00
parent 75ef4fd9b0
commit 299770922c
27 changed files with 740 additions and 234 deletions

View File

@@ -19,7 +19,7 @@ void DungeonEditor::Update() {
for (int i = 0; i < 0x100; i++) {
rooms_.emplace_back(zelda3::dungeon::Room(i));
rooms_[i].LoadHeader();
rooms_[i].LoadRoomGraphics(rooms_[i].blockset);
// rooms_[i].LoadRoomGraphics(rooms_[i].blockset);
}
is_loaded_ = true;
}
@@ -38,7 +38,7 @@ void DungeonEditor::Update() {
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (rom()->isLoaded()) {
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)9);
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)9);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
int i = 0;
@@ -56,6 +56,9 @@ void DungeonEditor::Update() {
ImGui::TableNextColumn();
DrawDungeonTabView();
ImGui::TableNextColumn();
if (ImGui::Button("dungeon object renderer")) {
object_renderer_.RenderObjectsAsBitmaps();
}
DrawTileSelector();
ImGui::EndTable();
}
@@ -150,13 +153,13 @@ void DungeonEditor::DrawDungeonCanvas(int room_id) {
canvas_.DrawBackground();
canvas_.DrawContextMenu();
canvas_.DrawBitmap(rooms_[room_id].current_graphics_, 2, is_loaded_);
canvas_.DrawGrid();
canvas_.DrawOverlay();
}
void DungeonEditor::DrawToolset() {
if (ImGui::BeginTable("DWToolset", 9, toolset_table_flags_, ImVec2(0, 0))) {
if (ImGui::BeginTable("DWToolset", 9, ImGuiTableFlags_SizingFixedFit,
ImVec2(0, 0))) {
ImGui::TableSetupColumn("#undoTool");
ImGui::TableSetupColumn("#redoTool");
ImGui::TableSetupColumn("#history");
@@ -209,7 +212,7 @@ void DungeonEditor::DrawRoomGraphics() {
void DungeonEditor::DrawTileSelector() {
if (ImGui::BeginTabBar("##TabBar", ImGuiTabBarFlags_FittingPolicyScroll)) {
if (ImGui::BeginTabItem("Room Graphics")) {
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)3);
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)3);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
DrawRoomGraphics();

View File

@@ -8,6 +8,7 @@
#include "app/gui/icons.h"
#include "app/rom.h"
#include "zelda3/dungeon/room.h"
#include "zelda3/dungeon/room_object.h"
namespace yaze {
namespace app {
@@ -32,6 +33,7 @@ class DungeonEditor : public SharedROM {
ImVector<int> active_rooms_;
std::vector<zelda3::dungeon::Room> rooms_;
zelda3::dungeon::DungeonObjectRenderer object_renderer_;
gui::Canvas canvas_;
gui::Canvas room_gfx_canvas_;

View File

@@ -187,10 +187,6 @@ void MasterEditor::DrawFileMenu() {
static bool save_as_menu = false;
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("New", "Ctrl+N")) {
// TODO: Implement new ROM creation.
}
if (ImGui::MenuItem("Open", "Ctrl+O")) {
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Open ROM",
".sfc,.smc", ".");
@@ -209,10 +205,13 @@ void MasterEditor::DrawFileMenu() {
if (ImGui::BeginMenu("Options")) {
ImGui::MenuItem("Backup ROM", "", &backup_rom_);
ImGui::Separator();
ImGui::Text("Experiment Flags");
ImGui::Checkbox("Enable Overworld Sprites",
&mutable_flags()->kDrawOverworldSprites);
ImGui::Checkbox("Use Bitmap Manager",
&mutable_flags()->kUseBitmapManager);
ImGui::Checkbox("Log Instructions to Debugger",
&mutable_flags()->kLogInstructions);
ImGui::EndMenu();
}

View File

@@ -32,7 +32,8 @@ absl::Status OverworldEditor::Update() {
// Initialize overworld graphics, maps, and palettes
if (rom()->isLoaded() && !all_gfx_loaded_) {
RETURN_IF_ERROR(LoadGraphics())
tile16_editor_.InitBlockset(tile16_blockset_bmp_);
tile16_editor_.InitBlockset(tile16_blockset_bmp_, tile16_individual_,
tile8_individual_);
gfx_group_editor_.InitBlockset(tile16_blockset_bmp_);
all_gfx_loaded_ = true;
}
@@ -349,10 +350,10 @@ 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)
rom()->QueueChanges([&]() {
overworld_.SaveOverworldMaps();
PRINT_IF_ERROR(overworld_.SaveOverworldMaps());
if (!overworld_.CreateTile32Tilemap()) {
// overworld_.SaveMap16Tiles();
overworld_.SaveMap32Tiles();
PRINT_IF_ERROR(overworld_.SaveMap32Tiles());
} else {
std::cout << "Failed to create tile32 tilemap" << std::endl;
}
@@ -410,14 +411,16 @@ void OverworldEditor::DrawTile8Selector() {
ImVec2(0x100 + 1, kNumSheetsToLoad * 0x40 + 1));
graphics_bin_canvas_.DrawContextMenu();
if (all_gfx_loaded_) {
for (const auto &[key, value] : graphics_bin_) {
// for (const auto &[key, value] : graphics_bin_) {
for (auto &[key, value] : rom()->BitmapManager()) {
int offset = 0x40 * (key + 1);
int top_left_y = graphics_bin_canvas_.GetZeroPoint().y + 2;
if (key >= 1) {
top_left_y = graphics_bin_canvas_.GetZeroPoint().y + 0x40 * key;
}
auto texture = value.get()->texture();
graphics_bin_canvas_.GetDrawList()->AddImage(
(void *)value.texture(),
(void *)texture,
ImVec2(graphics_bin_canvas_.GetZeroPoint().x + 2, top_left_y),
ImVec2(graphics_bin_canvas_.GetZeroPoint().x + 0x100,
graphics_bin_canvas_.GetZeroPoint().y + offset));
@@ -521,7 +524,7 @@ absl::Status OverworldEditor::LoadGraphics() {
}
if (flags()->kDrawOverworldSprites) {
LoadSpriteGraphics();
RETURN_IF_ERROR(LoadSpriteGraphics());
}
return absl::OkStatus();

View File

@@ -158,6 +158,9 @@ class OverworldEditor : public Editor,
std::vector<Bytes> tile16_individual_data_;
std::vector<gfx::Bitmap> tile16_individual_;
std::vector<Bytes> tile8_individual_data_;
std::vector<gfx::Bitmap> tile8_individual_;
Tile16Editor tile16_editor_;
GfxGroupEditor gfx_group_editor_;
PaletteEditor palette_editor_;