From 6e66512a277d39222be032b83c8bdd7f80767363 Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 25 Aug 2024 17:26:02 -0400 Subject: [PATCH] feat: Refactor OverworldMap to use custom_gfx_ids array for custom tileset --- src/app/zelda3/overworld/overworld.cc | 23 +++-- src/app/zelda3/overworld/overworld_map.cc | 109 +++++++--------------- src/app/zelda3/overworld/overworld_map.h | 35 +------ 3 files changed, 47 insertions(+), 120 deletions(-) diff --git a/src/app/zelda3/overworld/overworld.cc b/src/app/zelda3/overworld/overworld.cc index d2d69235..adfecc57 100644 --- a/src/app/zelda3/overworld/overworld.cc +++ b/src/app/zelda3/overworld/overworld.cc @@ -171,7 +171,7 @@ void Overworld::AssembleMap32Tiles() { 256)); }; - // Loop through each 32x32 pixel tile in the rom()-> + // Loop through each 32x32 pixel tile in the rom for (int i = 0; i < 0x33F0; i += 6) { // Loop through each quadrant of the 32x32 pixel tile. for (int k = 0; k < 4; k++) { @@ -252,8 +252,8 @@ absl::Status Overworld::DecompressAllMapTiles() { return core::SnesToPc(p); }; - int lowest = 0x0FFFFF; - int highest = 0x0F8000; + uint32_t lowest = 0x0FFFFF; + uint32_t highest = 0x0F8000; int sx = 0; int sy = 0; int c = 0; @@ -275,14 +275,14 @@ absl::Status Overworld::DecompressAllMapTiles() { int size1, size2; auto decomp = gfx::lc_lz2::Uncompress(rom()->data() + p2, &size1, 1); bytes.resize(size1); - for (int i = 0; i < size1; i++) { - bytes[i] = decomp[i]; + for (int j = 0; j < size1; j++) { + bytes[j] = decomp[j]; } free(decomp); decomp = gfx::lc_lz2::Uncompress(rom()->data() + p1, &size2, 1); bytes2.resize(size2); - for (int i = 0; i < size2; i++) { - bytes2[i] = decomp[i]; + for (int j = 0; j < size2; j++) { + bytes2[j] = decomp[j]; } free(decomp); @@ -1081,8 +1081,7 @@ absl::Status Overworld::CreateTile32Tilemap() { } // Create the unique tiles list - for (int i = 0; i < unique_tiles.size(); ++i) { - // static_cast(tile) + for (size_t i = 0; i < unique_tiles.size(); ++i) { tiles32_unique_.emplace_back(gfx::Tile32(unique_tiles[i])); } @@ -1331,9 +1330,9 @@ bool compareItemsArrays(std::vector itemArray1, } bool match; - for (int i = 0; i < itemArray1.size(); i++) { + for (size_t i = 0; i < itemArray1.size(); i++) { match = false; - for (int j = 0; j < itemArray2.size(); j++) { + for (size_t j = 0; j < itemArray2.size(); j++) { // Check all sprite in 2nd array if one match if (itemArray1[i].x_ == itemArray2[j].x_ && itemArray1[i].y_ == itemArray2[j].y_ && @@ -1482,7 +1481,7 @@ absl::Status Overworld::DecompressProtoMapTiles(const std::string &filename) { int sx = 0; int sy = 0; int c = 0; - for (int i = 0; i < proto_map_data_.size(); i++) { + for (size_t i = 0; i < proto_map_data_.size(); i++) { int ttpos = 0; ASSIGN_OR_RETURN(auto bytes, gfx::lc_lz2::DecompressOverworld( diff --git a/src/app/zelda3/overworld/overworld_map.cc b/src/app/zelda3/overworld/overworld_map.cc index 917f3951..c7e057e2 100644 --- a/src/app/zelda3/overworld/overworld_map.cc +++ b/src/app/zelda3/overworld/overworld_map.cc @@ -190,52 +190,41 @@ void OverworldMap::LoadCustomOverworldData() { rom_.version_constants().kOverworldGfxGroups2; // Main Blocksets - custom_tileset_.TileGFX0 = - (uint8_t)rom_[overworld_gfx_groups2 + (indexWorld * 8) + 0]; - custom_tileset_.TileGFX1 = - (uint8_t)rom_[overworld_gfx_groups2 + (indexWorld * 8) + 1]; - custom_tileset_.TileGFX2 = - (uint8_t)rom_[overworld_gfx_groups2 + (indexWorld * 8) + 2]; - custom_tileset_.TileGFX3 = - (uint8_t)rom_[overworld_gfx_groups2 + (indexWorld * 8) + 3]; - custom_tileset_.TileGFX4 = - (uint8_t)rom_[overworld_gfx_groups2 + (indexWorld * 8) + 4]; - custom_tileset_.TileGFX5 = - (uint8_t)rom_[overworld_gfx_groups2 + (indexWorld * 8) + 5]; - custom_tileset_.TileGFX6 = - (uint8_t)rom_[overworld_gfx_groups2 + (indexWorld * 8) + 6]; - custom_tileset_.TileGFX7 = - (uint8_t)rom_[overworld_gfx_groups2 + (indexWorld * 8) + 7]; + + for (int i = 0; i < 8; i++) { + custom_gfx_ids_[i] = + (uint8_t)rom_[overworld_gfx_groups2 + (indexWorld * 8) + i]; + } const auto overworldgfxGroups = rom_.version_constants().kOverworldGfxGroups1; // Replace the variable tiles with the variable ones. uint8_t temp = rom_[overworldgfxGroups + (area_graphics_ * 4)]; if (temp != 0) { - custom_tileset_.TileGFX3 = temp; + custom_gfx_ids_[3] = temp; } else { - custom_tileset_.TileGFX3 = 0xFF; + custom_gfx_ids_[3] = 0xFF; } temp = rom_[overworldgfxGroups + (area_graphics_ * 4) + 1]; if (temp != 0) { - custom_tileset_.TileGFX4 = temp; + custom_gfx_ids_[4] = temp; } else { - custom_tileset_.TileGFX4 = 0xFF; + custom_gfx_ids_[4] = 0xFF; } temp = rom_[overworldgfxGroups + (area_graphics_ * 4) + 2]; if (temp != 0) { - custom_tileset_.TileGFX5 = temp; + custom_gfx_ids_[5] = temp; } else { - custom_tileset_.TileGFX5 = 0xFF; + custom_gfx_ids_[5] = 0xFF; } temp = rom_[overworldgfxGroups + (area_graphics_ * 4) + 3]; if (temp != 0) { - custom_tileset_.TileGFX6 = temp; + custom_gfx_ids_[6] = temp; } else { - custom_tileset_.TileGFX6 = 0xFF; + custom_gfx_ids_[6] = 0xFF; } // Set the animated GFX values. @@ -282,22 +271,10 @@ void OverworldMap::SetupCustomTileset(uint8_t asm_version) { // This is just to load the GFX groups for ROMs that have an older version // of the Overworld ASM already applied. if (asm_version >= 0x01 && asm_version != 0xFF) { - custom_tileset_.TileGFX0 = - rom_[OverworldCustomTileGFXGroupArray + (index_ * 8) + 0]; - custom_tileset_.TileGFX1 = - rom_[OverworldCustomTileGFXGroupArray + (index_ * 8) + 1]; - custom_tileset_.TileGFX2 = - rom_[OverworldCustomTileGFXGroupArray + (index_ * 8) + 2]; - custom_tileset_.TileGFX3 = - rom_[OverworldCustomTileGFXGroupArray + (index_ * 8) + 3]; - custom_tileset_.TileGFX4 = - rom_[OverworldCustomTileGFXGroupArray + (index_ * 8) + 4]; - custom_tileset_.TileGFX5 = - rom_[OverworldCustomTileGFXGroupArray + (index_ * 8) + 5]; - custom_tileset_.TileGFX6 = - rom_[OverworldCustomTileGFXGroupArray + (index_ * 8) + 6]; - custom_tileset_.TileGFX7 = - rom_[OverworldCustomTileGFXGroupArray + (index_ * 8) + 7]; + for (int i = 0; i < 8; i++) { + custom_gfx_ids_[i] = + rom_[OverworldCustomTileGFXGroupArray + (index_ * 8) + i]; + } animated_gfx_ = rom_[OverworldCustomAnimatedGFXArray + index_]; } else { @@ -312,30 +289,12 @@ void OverworldMap::SetupCustomTileset(uint8_t asm_version) { } // Main Blocksets - custom_tileset_.TileGFX0 = - (uint8_t)rom_[rom_.version_constants().kOverworldGfxGroups2 + - (indexWorld * 8) + 0]; - custom_tileset_.TileGFX1 = - (uint8_t)rom_[rom_.version_constants().kOverworldGfxGroups2 + - (indexWorld * 8) + 1]; - custom_tileset_.TileGFX2 = - (uint8_t)rom_[rom_.version_constants().kOverworldGfxGroups2 + - (indexWorld * 8) + 2]; - custom_tileset_.TileGFX3 = - (uint8_t)rom_[rom_.version_constants().kOverworldGfxGroups2 + - (indexWorld * 8) + 3]; - custom_tileset_.TileGFX4 = - (uint8_t)rom_[rom_.version_constants().kOverworldGfxGroups2 + - (indexWorld * 8) + 4]; - custom_tileset_.TileGFX5 = - (uint8_t)rom_[rom_.version_constants().kOverworldGfxGroups2 + - (indexWorld * 8) + 5]; - custom_tileset_.TileGFX6 = - (uint8_t)rom_[rom_.version_constants().kOverworldGfxGroups2 + - (indexWorld * 8) + 6]; - custom_tileset_.TileGFX7 = - (uint8_t)rom_[rom_.version_constants().kOverworldGfxGroups2 + - (indexWorld * 8) + 7]; + + for (int i = 0; i < 8; i++) { + custom_gfx_ids_[i] = + (uint8_t)rom_[rom_.version_constants().kOverworldGfxGroups2 + + (indexWorld * 8) + i]; + } const auto overworldgfxGroups = rom_.version_constants().kOverworldGfxGroups1; @@ -345,30 +304,30 @@ void OverworldMap::SetupCustomTileset(uint8_t asm_version) { // anything" value. uint8_t temp = rom_[overworldgfxGroups + (area_graphics_ * 4)]; if (temp != 0x00) { - custom_tileset_.TileGFX3 = temp; + custom_gfx_ids_[3] = temp; } else { - custom_tileset_.TileGFX3 = 0xFF; + custom_gfx_ids_[3] = 0xFF; } temp = rom_[overworldgfxGroups + (area_graphics_ * 4) + 1]; if (temp != 0x00) { - custom_tileset_.TileGFX4 = temp; + custom_gfx_ids_[4] = temp; } else { - custom_tileset_.TileGFX4 = 0xFF; + custom_gfx_ids_[4] = 0xFF; } temp = rom_[overworldgfxGroups + (area_graphics_ * 4) + 2]; if (temp != 0x00) { - custom_tileset_.TileGFX5 = temp; + custom_gfx_ids_[5] = temp; } else { - custom_tileset_.TileGFX5 = 0xFF; + custom_gfx_ids_[5] = 0xFF; } temp = rom_[overworldgfxGroups + (area_graphics_ * 4) + 3]; if (temp != 0x00) { - custom_tileset_.TileGFX6 = temp; + custom_gfx_ids_[6] = temp; } else { - custom_tileset_.TileGFX6 = 0xFF; + custom_gfx_ids_[6] = 0xFF; } // Set the animated GFX values. @@ -453,9 +412,9 @@ void OverworldMap::LoadAreaGraphicsBlocksets() { // TODO: Change the conditions for death mountain gfx // JaredBrian: This is how ZS did it, but in 3.0.4 I changed it to just check -// for 03, 05, 07, and the DW ones as that's how it would appear in-game if you -// were to make area 03 not a large area anymore for example, so you might want -// to do the same. +// for 03, 05, 07, and the DW ones as that's how it would appear in-game if +// you were to make area 03 not a large area anymore for example, so you might +// want to do the same. void OverworldMap::LoadDeathMountainGFX() { static_graphics_[7] = (((parent_ >= 0x03 && parent_ <= 0x07) || (parent_ >= 0x0B && parent_ <= 0x0E)) || diff --git a/src/app/zelda3/overworld/overworld_map.h b/src/app/zelda3/overworld/overworld_map.h index b1c093a2..9e0dce4f 100644 --- a/src/app/zelda3/overworld/overworld_map.h +++ b/src/app/zelda3/overworld/overworld_map.h @@ -119,26 +119,7 @@ class OverworldMap : public editor::context::GfxContext { auto set_message_id(uint16_t value) { message_id_ = value; } uint8_t* mutable_custom_tileset(int index) { - switch (index) { - case 0: - return &custom_tileset_.TileGFX0; - case 1: - return &custom_tileset_.TileGFX1; - case 2: - return &custom_tileset_.TileGFX2; - case 3: - return &custom_tileset_.TileGFX3; - case 4: - return &custom_tileset_.TileGFX4; - case 5: - return &custom_tileset_.TileGFX5; - case 6: - return &custom_tileset_.TileGFX6; - case 7: - return &custom_tileset_.TileGFX7; - default: - return &custom_tileset_.TileGFX0; - } + return &custom_gfx_ids_[index]; } void SetAsLargeMap(int parent_index, int quadrant) { @@ -198,19 +179,7 @@ class OverworldMap : public editor::context::GfxContext { uint8_t animated_gfx_ = 0; // Custom Overworld Animated ID uint16_t subscreen_overlay_ = 0; // Custom Overworld Subscreen Overlay ID - struct CustomTileset { - uint8_t TileGFX0; - uint8_t TileGFX1; - uint8_t TileGFX2; - uint8_t TileGFX3; - uint8_t TileGFX4; - uint8_t TileGFX5; - uint8_t TileGFX6; - uint8_t TileGFX7; - }; - - struct CustomTileset custom_tileset_; - + uint8_t custom_gfx_ids_[8]; uchar sprite_graphics_[3]; uchar sprite_palette_[3]; uchar area_music_[4];