diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 702b7b40..f9648c5b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,8 +34,8 @@ set( set( YAZE_APP_ZELDA3_SRC - app/zelda3/overworld_map.cc - app/zelda3/overworld.cc + app/zelda3/overworld/overworld_map.cc + app/zelda3/overworld/overworld.cc app/zelda3/screen/inventory.cc app/zelda3/screen/title_screen.cc app/zelda3/sprite/sprite.cc diff --git a/src/app/editor/graphics_editor.h b/src/app/editor/graphics_editor.h index 58ecb23b..6f27dd37 100644 --- a/src/app/editor/graphics_editor.h +++ b/src/app/editor/graphics_editor.h @@ -15,7 +15,7 @@ #include "app/gui/input.h" #include "app/gui/pipeline.h" #include "app/rom.h" -#include "app/zelda3/overworld.h" +#include "app/zelda3/overworld/overworld.h" namespace yaze { namespace app { @@ -167,7 +167,7 @@ class GraphicsEditor : public SharedROM { ROM temp_rom_; ROM tilemap_rom_; - zelda3::Overworld overworld_; + zelda3::overworld::Overworld overworld_; MemoryEditor cgx_memory_editor_; MemoryEditor col_memory_editor_; PaletteEditor palette_editor_; diff --git a/src/app/editor/modules/gfx_group_editor.cc b/src/app/editor/modules/gfx_group_editor.cc index cb84ccee..634a5a84 100644 --- a/src/app/editor/modules/gfx_group_editor.cc +++ b/src/app/editor/modules/gfx_group_editor.cc @@ -18,7 +18,7 @@ #include "app/gui/pipeline.h" #include "app/gui/widgets.h" #include "app/rom.h" -#include "app/zelda3/overworld.h" +#include "app/zelda3/overworld/overworld.h" namespace yaze { namespace app { diff --git a/src/app/editor/modules/gfx_group_editor.h b/src/app/editor/modules/gfx_group_editor.h index 4f45be28..7a44447c 100644 --- a/src/app/editor/modules/gfx_group_editor.h +++ b/src/app/editor/modules/gfx_group_editor.h @@ -17,7 +17,7 @@ #include "app/gui/pipeline.h" #include "app/gui/widgets.h" #include "app/rom.h" -#include "app/zelda3/overworld.h" +#include "app/zelda3/overworld/overworld.h" namespace yaze { namespace app { @@ -65,7 +65,7 @@ class GfxGroupEditor : public SharedROM { std::vector tile16_individual_; gui::BitmapViewer gfx_group_viewer_; - zelda3::Overworld overworld_; + zelda3::overworld::Overworld overworld_; }; } // namespace editor diff --git a/src/app/editor/modules/tile16_editor.cc b/src/app/editor/modules/tile16_editor.cc index 733fea5b..fd5959cd 100644 --- a/src/app/editor/modules/tile16_editor.cc +++ b/src/app/editor/modules/tile16_editor.cc @@ -19,7 +19,7 @@ #include "app/gui/style.h" #include "app/gui/widgets.h" #include "app/rom.h" -#include "app/zelda3/overworld.h" +#include "app/zelda3/overworld/overworld.h" namespace yaze { namespace app { diff --git a/src/app/editor/modules/tile16_editor.h b/src/app/editor/modules/tile16_editor.h index f3a322d2..3b450798 100644 --- a/src/app/editor/modules/tile16_editor.h +++ b/src/app/editor/modules/tile16_editor.h @@ -18,7 +18,7 @@ #include "app/gui/icons.h" #include "app/gui/pipeline.h" #include "app/rom.h" -#include "app/zelda3/overworld.h" +#include "app/zelda3/overworld/overworld.h" namespace yaze { namespace app { @@ -128,7 +128,7 @@ class Tile16Editor : public context::GfxContext, public SharedROM { PaletteEditor palette_editor_; gfx::SnesPalette palette_; - zelda3::Overworld transfer_overworld_; + zelda3::overworld::Overworld transfer_overworld_; gfx::BitmapTable graphics_bin_; diff --git a/src/app/editor/overworld_editor.cc b/src/app/editor/overworld_editor.cc index 169f03ae..6f23e858 100644 --- a/src/app/editor/overworld_editor.cc +++ b/src/app/editor/overworld_editor.cc @@ -23,7 +23,7 @@ #include "app/gui/style.h" #include "app/gui/widgets.h" #include "app/rom.h" -#include "app/zelda3/overworld.h" +#include "app/zelda3/overworld/overworld.h" namespace yaze { namespace app { @@ -863,8 +863,9 @@ bool IsMouseHoveringOverEntity(const zelda3::OverworldEntity &entity, return false; } -void MoveEntityOnGrid(zelda3::OverworldEntity *entity, ImVec2 canvas_p0, - ImVec2 scrolling, bool free_movement = false) { +void MoveEntityOnGrid(zelda3::OverworldEntity *entity, + ImVec2 canvas_p0, ImVec2 scrolling, + bool free_movement = false) { // Get the mouse position relative to the canvas const ImGuiIO &io = ImGui::GetIO(); const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y); @@ -883,8 +884,9 @@ void MoveEntityOnGrid(zelda3::OverworldEntity *entity, ImVec2 canvas_p0, entity->set_y(new_y); } -void HandleEntityDragging(zelda3::OverworldEntity *entity, ImVec2 canvas_p0, - ImVec2 scrolling, bool &is_dragging_entity, +void HandleEntityDragging(zelda3::OverworldEntity *entity, + ImVec2 canvas_p0, ImVec2 scrolling, + bool &is_dragging_entity, zelda3::OverworldEntity *&dragged_entity, zelda3::OverworldEntity *¤t_entity, bool free_movement = false) { @@ -960,7 +962,8 @@ bool DrawEntranceInserterPopup() { } // TODO: Implement deleting OverworldEntrance objects, currently only hides them -bool DrawOverworldEntrancePopup(zelda3::OverworldEntrance &entrance) { +bool DrawOverworldEntrancePopup( + zelda3::overworld::OverworldEntrance &entrance) { static bool set_done = false; if (set_done) { set_done = false; @@ -1084,7 +1087,7 @@ void DrawExitInserterPopup() { } } -bool DrawExitEditorPopup(zelda3::OverworldExit &exit) { +bool DrawExitEditorPopup(zelda3::overworld::OverworldExit &exit) { static bool set_done = false; if (set_done) { set_done = false; @@ -1280,8 +1283,8 @@ void DrawItemInsertPopup() { ImGui::Text("Add Item"); ImGui::BeginChild("ScrollRegion", ImVec2(150, 150), true, ImGuiWindowFlags_AlwaysVerticalScrollbar); - for (int i = 0; i < zelda3::kSecretItemNames.size(); i++) { - if (ImGui::Selectable(zelda3::kSecretItemNames[i].c_str(), + for (int i = 0; i < zelda3::overworld::kSecretItemNames.size(); i++) { + if (ImGui::Selectable(zelda3::overworld::kSecretItemNames[i].c_str(), i == new_item_id)) { new_item_id = i; } @@ -1304,7 +1307,7 @@ void DrawItemInsertPopup() { } // TODO: Implement deleting OverworldItem objects, currently only hides them -bool DrawItemEditorPopup(zelda3::OverworldItem &item) { +bool DrawItemEditorPopup(zelda3::overworld::OverworldItem &item) { static bool set_done = false; if (set_done) { set_done = false; @@ -1314,8 +1317,8 @@ bool DrawItemEditorPopup(zelda3::OverworldItem &item) { ImGui::BeginChild("ScrollRegion", ImVec2(150, 150), true, ImGuiWindowFlags_AlwaysVerticalScrollbar); ImGui::BeginGroup(); - for (int i = 0; i < zelda3::kSecretItemNames.size(); i++) { - if (ImGui::Selectable(zelda3::kSecretItemNames[i].c_str(), + for (int i = 0; i < zelda3::overworld::kSecretItemNames.size(); i++) { + if (ImGui::Selectable(zelda3::overworld::kSecretItemNames[i].c_str(), item.id == i)) { item.id = i; } @@ -1348,7 +1351,7 @@ void OverworldEditor::DrawOverworldItems() { // Get the item's bitmap and real X and Y positions if (item.room_map_id < 0x40 + (current_world_ * 0x40) && item.room_map_id >= (current_world_ * 0x40) && !item.deleted) { - std::string item_name = zelda3::kSecretItemNames[item.id]; + std::string item_name = zelda3::overworld::kSecretItemNames[item.id]; ow_map_canvas_.DrawRect(item.x_, item.y_, 16, 16, ImVec4(255, 0, 0, 150)); @@ -1647,7 +1650,7 @@ absl::Status OverworldEditor::LoadGraphics() { } // Render the overworld maps loaded from the ROM. - for (int i = 0; i < zelda3::kNumOverworldMaps; ++i) { + for (int i = 0; i < zelda3::overworld::kNumOverworldMaps; ++i) { overworld_.set_current_map(i); auto palette = overworld_.AreaPalette(); gui::BuildAndRenderBitmapPipeline(0x200, 0x200, 0x200, diff --git a/src/app/editor/overworld_editor.h b/src/app/editor/overworld_editor.h index a7c714ab..8b427b4e 100644 --- a/src/app/editor/overworld_editor.h +++ b/src/app/editor/overworld_editor.h @@ -25,7 +25,7 @@ #include "app/gui/icons.h" #include "app/gui/pipeline.h" #include "app/rom.h" -#include "app/zelda3/overworld.h" +#include "app/zelda3/overworld/overworld.h" namespace yaze { namespace app { @@ -235,11 +235,11 @@ class OverworldEditor : public Editor, zelda3::OverworldEntity* current_entity_; int current_entrance_id_ = 0; - zelda3::OverworldEntrance current_entrance_; + zelda3::overworld::OverworldEntrance current_entrance_; int current_exit_id_ = 0; - zelda3::OverworldExit current_exit_; + zelda3::overworld::OverworldExit current_exit_; int current_item_id_ = 0; - zelda3::OverworldItem current_item_; + zelda3::overworld::OverworldItem current_item_; int current_sprite_id_ = 0; zelda3::Sprite current_sprite_; @@ -257,7 +257,7 @@ class OverworldEditor : public Editor, Tile16Editor tile16_editor_; GfxGroupEditor gfx_group_editor_; PaletteEditor palette_editor_; - zelda3::Overworld overworld_; + zelda3::overworld::Overworld overworld_; gui::Canvas ow_map_canvas_{ImVec2(0x200 * 8, 0x200 * 8), gui::CanvasGridSize::k64x64}; diff --git a/src/app/zelda3/overworld.cc b/src/app/zelda3/overworld/overworld.cc similarity index 99% rename from src/app/zelda3/overworld.cc rename to src/app/zelda3/overworld/overworld.cc index 9b7a3a22..7a3d9c89 100644 --- a/src/app/zelda3/overworld.cc +++ b/src/app/zelda3/overworld/overworld.cc @@ -17,12 +17,13 @@ #include "app/gfx/compression.h" #include "app/gfx/snes_tile.h" #include "app/rom.h" -#include "app/zelda3/overworld_map.h" +#include "app/zelda3/overworld/overworld_map.h" #include "app/zelda3/sprite/sprite.h" namespace yaze { namespace app { namespace zelda3 { +namespace overworld { namespace { @@ -427,7 +428,7 @@ absl::Status Overworld::LoadExits() { absl::Status Overworld::LoadItems() { ASSIGN_OR_RETURN(uint32_t pointer, - rom()->ReadLong(zelda3::overworldItemsAddress)); + rom()->ReadLong(zelda3::overworld::kOverworldItemsAddress)); uint32_t pointer_pc = core::SnesToPc(pointer); // 1BC2F9 -> 0DC2F9 for (int i = 0; i < 128; i++) { ASSIGN_OR_RETURN(uint16_t word_address, @@ -1568,6 +1569,7 @@ OWBlockset &Overworld::GetMapTiles(int world_type) { } } +} // namespace overworld } // namespace zelda3 } // namespace app } // namespace yaze diff --git a/src/app/zelda3/overworld.h b/src/app/zelda3/overworld/overworld.h similarity index 98% rename from src/app/zelda3/overworld.h rename to src/app/zelda3/overworld/overworld.h index 2022f492..6937efcc 100644 --- a/src/app/zelda3/overworld.h +++ b/src/app/zelda3/overworld/overworld.h @@ -15,13 +15,19 @@ #include "app/gfx/snes_tile.h" #include "app/rom.h" #include "app/zelda3/common.h" -#include "app/zelda3/overworld_map.h" +#include "app/zelda3/overworld/overworld_map.h" #include "app/zelda3/sprite/sprite.h" namespace yaze { namespace app { namespace zelda3 { +/** + * @namespace yaze::app::zelda3::overworld + * @brief Represents the Overworld data. + */ +namespace overworld { + // List of secret item names const std::vector kSecretItemNames = { "Nothing", // 0 @@ -55,7 +61,7 @@ const std::vector kSecretItemNames = { }; constexpr int overworldItemsPointers = 0xDC2F9; -constexpr int overworldItemsAddress = 0xDC8B9; // 1BC2F9 +constexpr int kOverworldItemsAddress = 0xDC8B9; // 1BC2F9 constexpr int overworldItemsBank = 0xDC8BF; constexpr int overworldItemsEndData = 0xDC89C; // 0DC89E @@ -624,6 +630,7 @@ class Overworld : public SharedROM, public core::ExperimentFlags { absl::flat_hash_map proto_map_data_; }; +} // namespace overworld } // namespace zelda3 } // namespace app } // namespace yaze diff --git a/src/app/zelda3/overworld_map.cc b/src/app/zelda3/overworld/overworld_map.cc similarity index 96% rename from src/app/zelda3/overworld_map.cc rename to src/app/zelda3/overworld/overworld_map.cc index f2282245..199aec84 100644 --- a/src/app/zelda3/overworld_map.cc +++ b/src/app/zelda3/overworld/overworld_map.cc @@ -13,11 +13,12 @@ #include "app/gfx/bitmap.h" #include "app/gfx/snes_tile.h" #include "app/rom.h" -#include "app/zelda3/overworld.h" +#include "app/zelda3/overworld/overworld.h" namespace yaze { namespace app { namespace zelda3 { +namespace overworld { OverworldMap::OverworldMap(int index, ROM& rom, std::vector& tiles16) @@ -557,6 +558,7 @@ absl::Status OverworldMap::BuildBitmap(OWBlockset& world_blockset) { return absl::OkStatus(); } +} // namespace overworld } // namespace zelda3 } // namespace app -} // namespace yaze \ No newline at end of file +} // namespace yaze diff --git a/src/app/zelda3/overworld_map.h b/src/app/zelda3/overworld/overworld_map.h similarity index 95% rename from src/app/zelda3/overworld_map.h rename to src/app/zelda3/overworld/overworld_map.h index 087dbec2..85d3109c 100644 --- a/src/app/zelda3/overworld_map.h +++ b/src/app/zelda3/overworld/overworld_map.h @@ -20,6 +20,7 @@ namespace yaze { namespace app { namespace zelda3 { +namespace overworld { static constexpr int kTileOffsets[] = {0, 8, 4096, 4104}; @@ -144,6 +145,7 @@ class OverworldMap : public editor::context::GfxContext { std::vector tiles16_; }; +} // namespace overworld } // namespace zelda3 } // namespace app } // namespace yaze diff --git a/src/app/zelda3/sprite/sprite.cc b/src/app/zelda3/sprite/sprite.cc index 4e413318..56263256 100644 --- a/src/app/zelda3/sprite/sprite.cc +++ b/src/app/zelda3/sprite/sprite.cc @@ -1,5 +1,7 @@ #include "sprite.h" +#include "app/zelda3/overworld/overworld.h" + namespace yaze { namespace app { namespace zelda3 { diff --git a/src/cli/command_handler.h b/src/cli/command_handler.h index 7832560a..d4fcc507 100644 --- a/src/cli/command_handler.h +++ b/src/cli/command_handler.h @@ -22,7 +22,7 @@ #include "app/gui/canvas.h" #include "app/gui/pipeline.h" #include "app/rom.h" // for ROM -#include "app/zelda3/overworld.h" +#include "app/zelda3/overworld/overworld.h" #include "cli/patch.h" // for ApplyBpsPatch, CreateBpsPatch namespace yaze {