Refactor AssembleMap32Tiles to report errors
This commit is contained in:
@@ -970,7 +970,7 @@ void OverworldEditor::DrawOverworldSprites() {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto &sprite : *overworld_.mutable_sprites(game_state_)) {
|
for (auto &sprite : *overworld_.mutable_sprites(game_state_)) {
|
||||||
if (!sprite.deleted()) {
|
if (!sprite.deleted()) {
|
||||||
int map_id = sprite.map_id();
|
// int map_id = sprite.map_id();
|
||||||
// map x and map y are relative to the map
|
// map x and map y are relative to the map
|
||||||
// So we need to check if the map is large or small then add the offset
|
// So we need to check if the map is large or small then add the offset
|
||||||
|
|
||||||
@@ -1063,10 +1063,10 @@ absl::Status OverworldEditor::LoadGraphics() {
|
|||||||
|
|
||||||
// Copy the tile16 data into individual tiles.
|
// Copy the tile16 data into individual tiles.
|
||||||
auto tile16_data = overworld_.tile16_blockset_data();
|
auto tile16_data = overworld_.tile16_blockset_data();
|
||||||
tile16_individual_.reserve(kNumTile16Individual);
|
tile16_individual_.reserve(zelda3::overworld::kNumTile16Individual);
|
||||||
|
|
||||||
// Loop through the tiles and copy their pixel data into separate vectors
|
// Loop through the tiles and copy their pixel data into separate vectors
|
||||||
for (uint i = 0; i < kNumTile16Individual; i++) {
|
for (uint i = 0; i < zelda3::overworld::kNumTile16Individual; i++) {
|
||||||
std::vector<uint8_t> tile_data(kTile16Size * kTile16Size, 0x00);
|
std::vector<uint8_t> tile_data(kTile16Size * kTile16Size, 0x00);
|
||||||
|
|
||||||
// Copy the pixel data for the current tile into the vector
|
// Copy the pixel data for the current tile into the vector
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ constexpr uint kMessageIdSize = 5;
|
|||||||
constexpr uint kNumSheetsToLoad = 223;
|
constexpr uint kNumSheetsToLoad = 223;
|
||||||
constexpr uint kTile8DisplayHeight = 64;
|
constexpr uint kTile8DisplayHeight = 64;
|
||||||
constexpr uint kOverworldMapSize = 0x200;
|
constexpr uint kOverworldMapSize = 0x200;
|
||||||
constexpr uint kNumTile16Individual = 4096;
|
|
||||||
constexpr float kInputFieldSize = 30.f;
|
constexpr float kInputFieldSize = 30.f;
|
||||||
constexpr ImVec2 kOverworldCanvasSize(kOverworldMapSize * 8,
|
constexpr ImVec2 kOverworldCanvasSize(kOverworldMapSize * 8,
|
||||||
kOverworldMapSize * 8);
|
kOverworldMapSize * 8);
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ absl::Status OverworldEditor::RefreshTile16Blockset() {
|
|||||||
|
|
||||||
std::vector<std::future<void>> futures;
|
std::vector<std::future<void>> futures;
|
||||||
// Loop through the tiles and copy their pixel data into separate vectors
|
// Loop through the tiles and copy their pixel data into separate vectors
|
||||||
for (uint i = 0; i < kNumTile16Individual; i++) {
|
for (uint i = 0; i < zelda3::overworld::kNumTile16Individual; i++) {
|
||||||
futures.push_back(std::async(
|
futures.push_back(std::async(
|
||||||
std::launch::async,
|
std::launch::async,
|
||||||
[&](int index) {
|
[&](int index) {
|
||||||
@@ -141,7 +141,7 @@ absl::Status OverworldEditor::RefreshTile16Blockset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render the bitmaps of each tile.
|
// Render the bitmaps of each tile.
|
||||||
for (uint id = 0; id < kNumTile16Individual; id++) {
|
for (uint id = 0; id < zelda3::overworld::kNumTile16Individual; id++) {
|
||||||
RETURN_IF_ERROR(tile16_individual_[id].ApplyPalette(palette_));
|
RETURN_IF_ERROR(tile16_individual_[id].ApplyPalette(palette_));
|
||||||
Renderer::GetInstance().UpdateBitmap(&tile16_individual_[id]);
|
Renderer::GetInstance().UpdateBitmap(&tile16_individual_[id]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ absl::flat_hash_map<int, MapData> parseFile(const std::string &filename) {
|
|||||||
absl::Status Overworld::Load(Rom &rom) {
|
absl::Status Overworld::Load(Rom &rom) {
|
||||||
rom_ = rom;
|
rom_ = rom;
|
||||||
|
|
||||||
AssembleMap32Tiles();
|
RETURN_IF_ERROR(AssembleMap32Tiles());
|
||||||
AssembleMap16Tiles();
|
AssembleMap16Tiles();
|
||||||
RETURN_IF_ERROR(DecompressAllMapTiles())
|
RETURN_IF_ERROR(DecompressAllMapTiles())
|
||||||
|
|
||||||
@@ -154,30 +154,37 @@ void Overworld::FetchLargeMaps() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Overworld::AssembleMap32Tiles() {
|
absl::StatusOr<uint16_t> Overworld::GetTile16ForTile32(int index, int quadrant,
|
||||||
auto get_tile16_for_tile32 = [this](int index, int quadrant, int dimension) {
|
int dimension) {
|
||||||
const uint32_t map32address[4] = {rom()->version_constants().kMap32TileTL,
|
const uint32_t map32address[4] = {rom_.version_constants().kMap32TileTL,
|
||||||
rom()->version_constants().kMap32TileTR,
|
rom_.version_constants().kMap32TileTR,
|
||||||
rom()->version_constants().kMap32TileBL,
|
rom_.version_constants().kMap32TileBL,
|
||||||
rom()->version_constants().kMap32TileBR};
|
rom_.version_constants().kMap32TileBR};
|
||||||
return (uint16_t)(rom_[map32address[dimension] + quadrant + (index)] +
|
ASSIGN_OR_RETURN(auto arg1,
|
||||||
(((rom_[map32address[dimension] + (index) +
|
rom_.ReadByte(map32address[dimension] + quadrant + (index)));
|
||||||
(quadrant <= 1 ? 4 : 5)] >>
|
ASSIGN_OR_RETURN(auto arg2, rom_.ReadWord(map32address[dimension] + (index) +
|
||||||
(quadrant % 2 == 0 ? 4 : 0)) &
|
(quadrant <= 1 ? 4 : 5)));
|
||||||
0x0F) *
|
return (uint16_t)(arg1 +
|
||||||
256));
|
(((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
|
// 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.
|
// Loop through each quadrant of the 32x32 pixel tile.
|
||||||
for (int k = 0; k < 4; k++) {
|
for (int k = 0; k < 4; k++) {
|
||||||
// Generate the 16-bit tile for the current quadrant of the current
|
// Generate the 16-bit tile for the current quadrant of the current
|
||||||
// 32x32 pixel tile.
|
// 32x32 pixel tile.
|
||||||
uint16_t tl = get_tile16_for_tile32(i, k, (int)Dimension::map32TilesTL);
|
ASSIGN_OR_RETURN(uint16_t tl,
|
||||||
uint16_t tr = get_tile16_for_tile32(i, k, (int)Dimension::map32TilesTR);
|
GetTile16ForTile32(i, k, (int)Dimension::map32TilesTL));
|
||||||
uint16_t bl = get_tile16_for_tile32(i, k, (int)Dimension::map32TilesBL);
|
ASSIGN_OR_RETURN(uint16_t tr,
|
||||||
uint16_t br = get_tile16_for_tile32(i, k, (int)Dimension::map32TilesBR);
|
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.
|
// Add the generated 16-bit tiles to the tiles32 vector.
|
||||||
tiles32_unique_.emplace_back(gfx::Tile32(tl, tr, bl, br));
|
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_.dark_world[i].resize(0x200);
|
||||||
map_tiles_.special_world[i].resize(0x200);
|
map_tiles_.special_world[i].resize(0x200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Overworld::AssembleMap16Tiles() {
|
void Overworld::AssembleMap16Tiles() {
|
||||||
int tpos = kMap16Tiles;
|
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));
|
gfx::TileInfo t0 = gfx::GetTilesInfo(rom()->toint16(tpos));
|
||||||
tpos += 2;
|
tpos += 2;
|
||||||
gfx::TileInfo t1 = gfx::GetTilesInfo(rom()->toint16(tpos));
|
gfx::TileInfo t1 = gfx::GetTilesInfo(rom()->toint16(tpos));
|
||||||
@@ -1515,7 +1524,7 @@ absl::Status Overworld::LoadPrototype(Rom &rom,
|
|||||||
const std::string &tilemap_filename) {
|
const std::string &tilemap_filename) {
|
||||||
rom_ = rom;
|
rom_ = rom;
|
||||||
|
|
||||||
AssembleMap32Tiles();
|
RETURN_IF_ERROR(AssembleMap32Tiles());
|
||||||
AssembleMap16Tiles();
|
AssembleMap16Tiles();
|
||||||
RETURN_IF_ERROR(DecompressProtoMapTiles(tilemap_filename))
|
RETURN_IF_ERROR(DecompressProtoMapTiles(tilemap_filename))
|
||||||
|
|
||||||
|
|||||||
@@ -431,6 +431,7 @@ constexpr int overworldCustomMosaicArray = 0x1301F0;
|
|||||||
|
|
||||||
constexpr int kMap16Tiles = 0x78000;
|
constexpr int kMap16Tiles = 0x78000;
|
||||||
constexpr int kNumOverworldMaps = 160;
|
constexpr int kNumOverworldMaps = 160;
|
||||||
|
constexpr int kNumTile16Individual = 4096;
|
||||||
constexpr int Map32PerScreen = 256;
|
constexpr int Map32PerScreen = 256;
|
||||||
constexpr int NumberOfMap16 = 3752; // 4096
|
constexpr int NumberOfMap16 = 3752; // 4096
|
||||||
constexpr int LimitOfMap32 = 8864;
|
constexpr int LimitOfMap32 = 8864;
|
||||||
@@ -550,7 +551,9 @@ class Overworld : public SharedRom, public core::ExperimentFlags {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void FetchLargeMaps();
|
void FetchLargeMaps();
|
||||||
void AssembleMap32Tiles();
|
absl::StatusOr<uint16_t> GetTile16ForTile32(int index, int quadrant,
|
||||||
|
int dimension);
|
||||||
|
absl::Status AssembleMap32Tiles();
|
||||||
void AssembleMap16Tiles();
|
void AssembleMap16Tiles();
|
||||||
void AssignWorldTiles(int x, int y, int sx, int sy, int tpos,
|
void AssignWorldTiles(int x, int y, int sx, int sy, int tpos,
|
||||||
OWBlockset &world);
|
OWBlockset &world);
|
||||||
|
|||||||
Reference in New Issue
Block a user