Refactor AssembleMap32Tiles to report errors
This commit is contained in:
@@ -80,7 +80,7 @@ absl::flat_hash_map<int, MapData> parseFile(const std::string &filename) {
|
||||
absl::Status Overworld::Load(Rom &rom) {
|
||||
rom_ = rom;
|
||||
|
||||
AssembleMap32Tiles();
|
||||
RETURN_IF_ERROR(AssembleMap32Tiles());
|
||||
AssembleMap16Tiles();
|
||||
RETURN_IF_ERROR(DecompressAllMapTiles())
|
||||
|
||||
@@ -154,30 +154,37 @@ void Overworld::FetchLargeMaps() {
|
||||
}
|
||||
}
|
||||
|
||||
void Overworld::AssembleMap32Tiles() {
|
||||
auto get_tile16_for_tile32 = [this](int index, int quadrant, int dimension) {
|
||||
const uint32_t map32address[4] = {rom()->version_constants().kMap32TileTL,
|
||||
rom()->version_constants().kMap32TileTR,
|
||||
rom()->version_constants().kMap32TileBL,
|
||||
rom()->version_constants().kMap32TileBR};
|
||||
return (uint16_t)(rom_[map32address[dimension] + quadrant + (index)] +
|
||||
(((rom_[map32address[dimension] + (index) +
|
||||
(quadrant <= 1 ? 4 : 5)] >>
|
||||
(quadrant % 2 == 0 ? 4 : 0)) &
|
||||
0x0F) *
|
||||
256));
|
||||
};
|
||||
absl::StatusOr<uint16_t> Overworld::GetTile16ForTile32(int index, int quadrant,
|
||||
int dimension) {
|
||||
const uint32_t map32address[4] = {rom_.version_constants().kMap32TileTL,
|
||||
rom_.version_constants().kMap32TileTR,
|
||||
rom_.version_constants().kMap32TileBL,
|
||||
rom_.version_constants().kMap32TileBR};
|
||||
ASSIGN_OR_RETURN(auto arg1,
|
||||
rom_.ReadByte(map32address[dimension] + quadrant + (index)));
|
||||
ASSIGN_OR_RETURN(auto arg2, rom_.ReadWord(map32address[dimension] + (index) +
|
||||
(quadrant <= 1 ? 4 : 5)));
|
||||
return (uint16_t)(arg1 +
|
||||
(((arg2 >> (quadrant % 2 == 0 ? 4 : 0)) & 0x0F) * 256));
|
||||
}
|
||||
|
||||
constexpr int kMap32TilesLength = 0x33F0;
|
||||
|
||||
absl::Status Overworld::AssembleMap32Tiles() {
|
||||
// Loop through each 32x32 pixel tile in the rom
|
||||
for (int i = 0; i < 0x33F0; i += 6) {
|
||||
for (int i = 0; i < kMap32TilesLength; i += 6) {
|
||||
// Loop through each quadrant of the 32x32 pixel tile.
|
||||
for (int k = 0; k < 4; k++) {
|
||||
// Generate the 16-bit tile for the current quadrant of the current
|
||||
// 32x32 pixel tile.
|
||||
uint16_t tl = get_tile16_for_tile32(i, k, (int)Dimension::map32TilesTL);
|
||||
uint16_t tr = get_tile16_for_tile32(i, k, (int)Dimension::map32TilesTR);
|
||||
uint16_t bl = get_tile16_for_tile32(i, k, (int)Dimension::map32TilesBL);
|
||||
uint16_t br = get_tile16_for_tile32(i, k, (int)Dimension::map32TilesBR);
|
||||
ASSIGN_OR_RETURN(uint16_t tl,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesTL));
|
||||
ASSIGN_OR_RETURN(uint16_t tr,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesTR));
|
||||
ASSIGN_OR_RETURN(uint16_t bl,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesBL));
|
||||
ASSIGN_OR_RETURN(uint16_t br,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesBR));
|
||||
|
||||
// Add the generated 16-bit tiles to the tiles32 vector.
|
||||
tiles32_unique_.emplace_back(gfx::Tile32(tl, tr, bl, br));
|
||||
@@ -192,11 +199,13 @@ void Overworld::AssembleMap32Tiles() {
|
||||
map_tiles_.dark_world[i].resize(0x200);
|
||||
map_tiles_.special_world[i].resize(0x200);
|
||||
}
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
void Overworld::AssembleMap16Tiles() {
|
||||
int tpos = kMap16Tiles;
|
||||
for (int i = 0; i < 4096; i += 1) {
|
||||
for (int i = 0; i < kNumTile16Individual; i += 1) {
|
||||
gfx::TileInfo t0 = gfx::GetTilesInfo(rom()->toint16(tpos));
|
||||
tpos += 2;
|
||||
gfx::TileInfo t1 = gfx::GetTilesInfo(rom()->toint16(tpos));
|
||||
@@ -1515,7 +1524,7 @@ absl::Status Overworld::LoadPrototype(Rom &rom,
|
||||
const std::string &tilemap_filename) {
|
||||
rom_ = rom;
|
||||
|
||||
AssembleMap32Tiles();
|
||||
RETURN_IF_ERROR(AssembleMap32Tiles());
|
||||
AssembleMap16Tiles();
|
||||
RETURN_IF_ERROR(DecompressProtoMapTiles(tilemap_filename))
|
||||
|
||||
|
||||
@@ -431,6 +431,7 @@ constexpr int overworldCustomMosaicArray = 0x1301F0;
|
||||
|
||||
constexpr int kMap16Tiles = 0x78000;
|
||||
constexpr int kNumOverworldMaps = 160;
|
||||
constexpr int kNumTile16Individual = 4096;
|
||||
constexpr int Map32PerScreen = 256;
|
||||
constexpr int NumberOfMap16 = 3752; // 4096
|
||||
constexpr int LimitOfMap32 = 8864;
|
||||
@@ -550,7 +551,9 @@ class Overworld : public SharedRom, public core::ExperimentFlags {
|
||||
};
|
||||
|
||||
void FetchLargeMaps();
|
||||
void AssembleMap32Tiles();
|
||||
absl::StatusOr<uint16_t> GetTile16ForTile32(int index, int quadrant,
|
||||
int dimension);
|
||||
absl::Status AssembleMap32Tiles();
|
||||
void AssembleMap16Tiles();
|
||||
void AssignWorldTiles(int x, int y, int sx, int sy, int tpos,
|
||||
OWBlockset &world);
|
||||
|
||||
Reference in New Issue
Block a user