From aaccbe08afaa98d7b66f17ffdd08c2d0c6bf19d4 Mon Sep 17 00:00:00 2001 From: scawful Date: Fri, 10 Nov 2023 23:23:20 -0500 Subject: [PATCH] Cleanup `Overworld` stuff --- src/app/rom.cc | 6 +-- src/app/zelda3/overworld.cc | 76 +++++++++++++-------------------- src/app/zelda3/overworld.h | 7 +-- src/app/zelda3/overworld_map.cc | 2 +- 4 files changed, 36 insertions(+), 55 deletions(-) diff --git a/src/app/rom.cc b/src/app/rom.cc index b47a0110..f971c01b 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -426,9 +426,9 @@ void ROM::SavePalette(int index, const std::string& group_name, for (size_t j = 0; j < palette.size(); ++j) { gfx::SNESColor color = palette[j]; // If the color is modified, save the color to the ROM - if (color.isModified()) { + if (color.IsModified()) { WriteColor(gfx::GetPaletteAddress(group_name, index, j), color); - color.setModified(false); // Reset the modified flag after saving + color.SetModified(false); // Reset the modified flag after saving } } } @@ -457,7 +457,7 @@ absl::Status ROM::UpdatePaletteColor(const std::string& groupName, if (colorIndex < palette_groups_[groupName][paletteIndex].size()) { // Update the color value in the palette palette_groups_[groupName][paletteIndex][colorIndex] = newColor; - palette_groups_[groupName][paletteIndex][colorIndex].setModified(true); + palette_groups_[groupName][paletteIndex][colorIndex].SetModified(true); } else { return absl::AbortedError( "Error: Invalid color index in UpdatePaletteColor."); diff --git a/src/app/zelda3/overworld.cc b/src/app/zelda3/overworld.cc index 2e477678..e2206f76 100644 --- a/src/app/zelda3/overworld.cc +++ b/src/app/zelda3/overworld.cc @@ -139,21 +139,40 @@ absl::Status Overworld::Load(ROM &rom) { FetchLargeMaps(); LoadEntrances(); + // Load Sprites will go here. + RETURN_IF_ERROR(LoadOverworldMaps()) + is_loaded_ = true; + return absl::OkStatus(); +} + +OWBlockset &Overworld::GetMapTiles(int world_type) { + switch (world_type) { + case 0: + return map_tiles_.light_world; + case 1: + return map_tiles_.dark_world; + case 2: + return map_tiles_.special_world; + default: + return map_tiles_.light_world; + } +} + +absl::Status Overworld::LoadOverworldMaps() { auto size = tiles16.size(); std::vector> futures; for (int i = 0; i < kNumOverworldMaps; ++i) { - futures.push_back(std::async(std::launch::async, [this, i, size]() { - if (i < 64) { - return overworld_maps_[i].BuildMap(size, game_state_, 0, map_parent_, - map_tiles_.light_world); - } else if (i < 0x80 && i >= 0x40) { - return overworld_maps_[i].BuildMap(size, game_state_, 1, map_parent_, - map_tiles_.dark_world); - } else { - return overworld_maps_[i].BuildMap(size, game_state_, 2, map_parent_, - map_tiles_.special_world); - } + int world_type = 0; + if (i >= 64 && i < 0x80) { + world_type = 1; + } else if (i >= 0x80) { + world_type = 2; + } + futures.push_back(std::async(std::launch::async, [this, i, size, + world_type]() { + return overworld_maps_[i].BuildMap(size, game_state_, world_type, + map_parent_, GetMapTiles(world_type)); })); } @@ -164,10 +183,6 @@ absl::Status Overworld::Load(ROM &rom) { return status; } } - - // LoadSprites(); - - is_loaded_ = true; return absl::OkStatus(); } @@ -274,8 +289,6 @@ absl::Status Overworld::SaveOverworldMaps() { return absl::OkStatus(); } -// ---------------------------------------------------------------------------- - absl::Status Overworld::SaveLargeMaps() { for (int i = 0; i < 0x40; i++) { int yPos = i / 8; @@ -469,8 +482,6 @@ absl::Status Overworld::SaveLargeMaps() { return absl::OkStatus(); } -// ---------------------------------------------------------------------------- - bool Overworld::CreateTile32Tilemap(bool only_show) { tiles32_unique_.clear(); tiles32.clear(); @@ -539,8 +550,6 @@ bool Overworld::CreateTile32Tilemap(bool only_show) { return false; } -// ---------------------------------------------------------------------------- - absl::Status Overworld::SaveMap16Tiles() { int tpos = kMap16Tiles; // 3760 @@ -557,8 +566,6 @@ absl::Status Overworld::SaveMap16Tiles() { return absl::OkStatus(); } -// ---------------------------------------------------------------------------- - absl::Status Overworld::SaveMap32Tiles() { constexpr int kMaxUniqueTiles = 0x4540; constexpr int kTilesPer32x32Tile = 6; @@ -618,8 +625,6 @@ absl::Status Overworld::SaveMap32Tiles() { return absl::OkStatus(); } -// ---------------------------------------------------------------------------- - uint16_t Overworld::GenerateTile32(int index, int quadrant, int dimension) { // The addresses of the four 32x32 pixel tiles in the ROM. const uint32_t map32address[4] = {rom()->GetVersionConstants().kMap32TileTL, @@ -635,8 +640,6 @@ uint16_t Overworld::GenerateTile32(int index, int quadrant, int dimension) { 256)); } -// ---------------------------------------------------------------------------- - void Overworld::AssembleMap32Tiles() { // Loop through each 32x32 pixel tile in the ROM. for (int i = 0; i < 0x33F0; i += 6) { @@ -666,8 +669,6 @@ void Overworld::AssembleMap32Tiles() { } } -// ---------------------------------------------------------------------------- - void Overworld::AssembleMap16Tiles() { int tpos = kMap16Tiles; for (int i = 0; i < 4096; i += 1) { @@ -683,8 +684,6 @@ void Overworld::AssembleMap16Tiles() { } } -// ---------------------------------------------------------------------------- - void Overworld::AssignWorldTiles(int x, int y, int sx, int sy, int tpos, OWBlockset &world) { int position_x1 = (x * 2) + (sx * 32); @@ -697,8 +696,6 @@ void Overworld::AssignWorldTiles(int x, int y, int sx, int sy, int tpos, world[position_x2][position_y2] = tiles32[tpos].tile3_; } -// ---------------------------------------------------------------------------- - void Overworld::OrganizeMapTiles(Bytes &bytes, Bytes &bytes2, int i, int sx, int sy, int &ttpos) { for (int y = 0; y < 16; y++) { @@ -718,8 +715,6 @@ void Overworld::OrganizeMapTiles(Bytes &bytes, Bytes &bytes2, int i, int sx, } } -// ---------------------------------------------------------------------------- - absl::Status Overworld::DecompressAllMapTiles() { int lowest = 0x0FFFFF; int highest = 0x0F8000; @@ -768,9 +763,6 @@ absl::Status Overworld::DecompressAllMapTiles() { c = 0; } } - - std::cout << "MapPointers(lowest) : " << lowest << std::endl; - std::cout << "MapPointers(highest) : " << highest << std::endl; return absl::OkStatus(); } @@ -807,8 +799,6 @@ absl::Status Overworld::DecompressProtoMapTiles(const std::string &filename) { return absl::OkStatus(); } -// ---------------------------------------------------------------------------- - void Overworld::FetchLargeMaps() { for (int i = 128; i < 145; i++) { map_parent_[i] = 0; @@ -866,8 +856,6 @@ void Overworld::FetchLargeMaps() { } } -// ---------------------------------------------------------------------------- - void Overworld::LoadEntrances() { for (int i = 0; i < 129; i++) { short mapId = rom()->toint16(OWEntranceMap + (i * 2)); @@ -902,8 +890,6 @@ void Overworld::LoadEntrances() { } } -// ---------------------------------------------------------------------------- - void Overworld::LoadSprites() { for (int i = 0; i < 3; i++) { all_sprites_.emplace_back(); @@ -926,8 +912,6 @@ void Overworld::LoadSprites() { LoadSpritesFromMap(overworldSpritesAgahnim, 144, 2); } -// ---------------------------------------------------------------------------- - void Overworld::LoadSpritesFromMap(int spriteStart, int spriteCount, int spriteIndex) { for (int i = 0; i < spriteCount; i++) { diff --git a/src/app/zelda3/overworld.h b/src/app/zelda3/overworld.h index 1cf70eac..ca2c543f 100644 --- a/src/app/zelda3/overworld.h +++ b/src/app/zelda3/overworld.h @@ -181,7 +181,8 @@ struct MapData { class Overworld : public SharedROM { public: absl::Status Load(ROM &rom); - + OWBlockset& GetMapTiles(int world_type); + absl::Status LoadOverworldMaps(); absl::Status SaveOverworldMaps(); absl::Status SaveLargeMaps(); @@ -189,9 +190,6 @@ class Overworld : public SharedROM { absl::Status SaveMap16Tiles(); absl::Status SaveMap32Tiles(); - auto GetTiles16() const { return tiles16; } - auto GetOverworldMap(uint index) { return overworld_maps_[index]; } - auto GetOverworldMaps() const { return overworld_maps_; } auto Sprites(int state) const { return all_sprites_[state]; } auto AreaGraphics() const { return overworld_maps_[current_map_].AreaGraphics(); @@ -207,7 +205,6 @@ class Overworld : public SharedROM { auto Tile16Blockset() const { return overworld_maps_[current_map_].Tile16Blockset(); } - auto GameState() const { return game_state_; } auto isLoaded() const { return is_loaded_; } void SetCurrentMap(int i) { current_map_ = i; } diff --git a/src/app/zelda3/overworld_map.cc b/src/app/zelda3/overworld_map.cc index f8e927a6..07c20946 100644 --- a/src/app/zelda3/overworld_map.cc +++ b/src/app/zelda3/overworld_map.cc @@ -144,7 +144,7 @@ void SetColorsPalette(ROM& rom, int index, gfx::SNESPalette& current, current.Create(new_palette); for (int i = 0; i < 256; i++) { - current[(i / 16) * 16].setTransparent(true); + current[(i / 16) * 16].SetTransparent(true); } }