Cleanup Overworld stuff

This commit is contained in:
scawful
2023-11-10 23:23:20 -05:00
parent dbcd47ba68
commit aaccbe08af
4 changed files with 36 additions and 55 deletions

View File

@@ -426,9 +426,9 @@ void ROM::SavePalette(int index, const std::string& group_name,
for (size_t j = 0; j < palette.size(); ++j) { for (size_t j = 0; j < palette.size(); ++j) {
gfx::SNESColor color = palette[j]; gfx::SNESColor color = palette[j];
// If the color is modified, save the color to the ROM // 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); 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()) { if (colorIndex < palette_groups_[groupName][paletteIndex].size()) {
// Update the color value in the palette // Update the color value in the palette
palette_groups_[groupName][paletteIndex][colorIndex] = newColor; palette_groups_[groupName][paletteIndex][colorIndex] = newColor;
palette_groups_[groupName][paletteIndex][colorIndex].setModified(true); palette_groups_[groupName][paletteIndex][colorIndex].SetModified(true);
} else { } else {
return absl::AbortedError( return absl::AbortedError(
"Error: Invalid color index in UpdatePaletteColor."); "Error: Invalid color index in UpdatePaletteColor.");

View File

@@ -139,21 +139,40 @@ absl::Status Overworld::Load(ROM &rom) {
FetchLargeMaps(); FetchLargeMaps();
LoadEntrances(); 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(); auto size = tiles16.size();
std::vector<std::future<absl::Status>> futures; std::vector<std::future<absl::Status>> futures;
for (int i = 0; i < kNumOverworldMaps; ++i) { for (int i = 0; i < kNumOverworldMaps; ++i) {
futures.push_back(std::async(std::launch::async, [this, i, size]() { int world_type = 0;
if (i < 64) { if (i >= 64 && i < 0x80) {
return overworld_maps_[i].BuildMap(size, game_state_, 0, map_parent_, world_type = 1;
map_tiles_.light_world); } else if (i >= 0x80) {
} else if (i < 0x80 && i >= 0x40) { world_type = 2;
return overworld_maps_[i].BuildMap(size, game_state_, 1, map_parent_, }
map_tiles_.dark_world); futures.push_back(std::async(std::launch::async, [this, i, size,
} else { world_type]() {
return overworld_maps_[i].BuildMap(size, game_state_, 2, map_parent_, return overworld_maps_[i].BuildMap(size, game_state_, world_type,
map_tiles_.special_world); map_parent_, GetMapTiles(world_type));
}
})); }));
} }
@@ -164,10 +183,6 @@ absl::Status Overworld::Load(ROM &rom) {
return status; return status;
} }
} }
// LoadSprites();
is_loaded_ = true;
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -274,8 +289,6 @@ absl::Status Overworld::SaveOverworldMaps() {
return absl::OkStatus(); return absl::OkStatus();
} }
// ----------------------------------------------------------------------------
absl::Status Overworld::SaveLargeMaps() { absl::Status Overworld::SaveLargeMaps() {
for (int i = 0; i < 0x40; i++) { for (int i = 0; i < 0x40; i++) {
int yPos = i / 8; int yPos = i / 8;
@@ -469,8 +482,6 @@ absl::Status Overworld::SaveLargeMaps() {
return absl::OkStatus(); return absl::OkStatus();
} }
// ----------------------------------------------------------------------------
bool Overworld::CreateTile32Tilemap(bool only_show) { bool Overworld::CreateTile32Tilemap(bool only_show) {
tiles32_unique_.clear(); tiles32_unique_.clear();
tiles32.clear(); tiles32.clear();
@@ -539,8 +550,6 @@ bool Overworld::CreateTile32Tilemap(bool only_show) {
return false; return false;
} }
// ----------------------------------------------------------------------------
absl::Status Overworld::SaveMap16Tiles() { absl::Status Overworld::SaveMap16Tiles() {
int tpos = kMap16Tiles; int tpos = kMap16Tiles;
// 3760 // 3760
@@ -557,8 +566,6 @@ absl::Status Overworld::SaveMap16Tiles() {
return absl::OkStatus(); return absl::OkStatus();
} }
// ----------------------------------------------------------------------------
absl::Status Overworld::SaveMap32Tiles() { absl::Status Overworld::SaveMap32Tiles() {
constexpr int kMaxUniqueTiles = 0x4540; constexpr int kMaxUniqueTiles = 0x4540;
constexpr int kTilesPer32x32Tile = 6; constexpr int kTilesPer32x32Tile = 6;
@@ -618,8 +625,6 @@ absl::Status Overworld::SaveMap32Tiles() {
return absl::OkStatus(); return absl::OkStatus();
} }
// ----------------------------------------------------------------------------
uint16_t Overworld::GenerateTile32(int index, int quadrant, int dimension) { uint16_t Overworld::GenerateTile32(int index, int quadrant, int dimension) {
// The addresses of the four 32x32 pixel tiles in the ROM. // The addresses of the four 32x32 pixel tiles in the ROM.
const uint32_t map32address[4] = {rom()->GetVersionConstants().kMap32TileTL, const uint32_t map32address[4] = {rom()->GetVersionConstants().kMap32TileTL,
@@ -635,8 +640,6 @@ uint16_t Overworld::GenerateTile32(int index, int quadrant, int dimension) {
256)); 256));
} }
// ----------------------------------------------------------------------------
void Overworld::AssembleMap32Tiles() { void 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 < 0x33F0; i += 6) {
@@ -666,8 +669,6 @@ void Overworld::AssembleMap32Tiles() {
} }
} }
// ----------------------------------------------------------------------------
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 < 4096; i += 1) {
@@ -683,8 +684,6 @@ void Overworld::AssembleMap16Tiles() {
} }
} }
// ----------------------------------------------------------------------------
void Overworld::AssignWorldTiles(int x, int y, int sx, int sy, int tpos, void Overworld::AssignWorldTiles(int x, int y, int sx, int sy, int tpos,
OWBlockset &world) { OWBlockset &world) {
int position_x1 = (x * 2) + (sx * 32); 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_; world[position_x2][position_y2] = tiles32[tpos].tile3_;
} }
// ----------------------------------------------------------------------------
void Overworld::OrganizeMapTiles(Bytes &bytes, Bytes &bytes2, int i, int sx, void Overworld::OrganizeMapTiles(Bytes &bytes, Bytes &bytes2, int i, int sx,
int sy, int &ttpos) { int sy, int &ttpos) {
for (int y = 0; y < 16; y++) { 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() { absl::Status Overworld::DecompressAllMapTiles() {
int lowest = 0x0FFFFF; int lowest = 0x0FFFFF;
int highest = 0x0F8000; int highest = 0x0F8000;
@@ -768,9 +763,6 @@ absl::Status Overworld::DecompressAllMapTiles() {
c = 0; c = 0;
} }
} }
std::cout << "MapPointers(lowest) : " << lowest << std::endl;
std::cout << "MapPointers(highest) : " << highest << std::endl;
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -807,8 +799,6 @@ absl::Status Overworld::DecompressProtoMapTiles(const std::string &filename) {
return absl::OkStatus(); return absl::OkStatus();
} }
// ----------------------------------------------------------------------------
void Overworld::FetchLargeMaps() { void Overworld::FetchLargeMaps() {
for (int i = 128; i < 145; i++) { for (int i = 128; i < 145; i++) {
map_parent_[i] = 0; map_parent_[i] = 0;
@@ -866,8 +856,6 @@ void Overworld::FetchLargeMaps() {
} }
} }
// ----------------------------------------------------------------------------
void Overworld::LoadEntrances() { void Overworld::LoadEntrances() {
for (int i = 0; i < 129; i++) { for (int i = 0; i < 129; i++) {
short mapId = rom()->toint16(OWEntranceMap + (i * 2)); short mapId = rom()->toint16(OWEntranceMap + (i * 2));
@@ -902,8 +890,6 @@ void Overworld::LoadEntrances() {
} }
} }
// ----------------------------------------------------------------------------
void Overworld::LoadSprites() { void Overworld::LoadSprites() {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
all_sprites_.emplace_back(); all_sprites_.emplace_back();
@@ -926,8 +912,6 @@ void Overworld::LoadSprites() {
LoadSpritesFromMap(overworldSpritesAgahnim, 144, 2); LoadSpritesFromMap(overworldSpritesAgahnim, 144, 2);
} }
// ----------------------------------------------------------------------------
void Overworld::LoadSpritesFromMap(int spriteStart, int spriteCount, void Overworld::LoadSpritesFromMap(int spriteStart, int spriteCount,
int spriteIndex) { int spriteIndex) {
for (int i = 0; i < spriteCount; i++) { for (int i = 0; i < spriteCount; i++) {

View File

@@ -181,7 +181,8 @@ struct MapData {
class Overworld : public SharedROM { class Overworld : public SharedROM {
public: public:
absl::Status Load(ROM &rom); absl::Status Load(ROM &rom);
OWBlockset& GetMapTiles(int world_type);
absl::Status LoadOverworldMaps();
absl::Status SaveOverworldMaps(); absl::Status SaveOverworldMaps();
absl::Status SaveLargeMaps(); absl::Status SaveLargeMaps();
@@ -189,9 +190,6 @@ class Overworld : public SharedROM {
absl::Status SaveMap16Tiles(); absl::Status SaveMap16Tiles();
absl::Status SaveMap32Tiles(); 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 Sprites(int state) const { return all_sprites_[state]; }
auto AreaGraphics() const { auto AreaGraphics() const {
return overworld_maps_[current_map_].AreaGraphics(); return overworld_maps_[current_map_].AreaGraphics();
@@ -207,7 +205,6 @@ class Overworld : public SharedROM {
auto Tile16Blockset() const { auto Tile16Blockset() const {
return overworld_maps_[current_map_].Tile16Blockset(); return overworld_maps_[current_map_].Tile16Blockset();
} }
auto GameState() const { return game_state_; }
auto isLoaded() const { return is_loaded_; } auto isLoaded() const { return is_loaded_; }
void SetCurrentMap(int i) { current_map_ = i; } void SetCurrentMap(int i) { current_map_ = i; }

View File

@@ -144,7 +144,7 @@ void SetColorsPalette(ROM& rom, int index, gfx::SNESPalette& current,
current.Create(new_palette); current.Create(new_palette);
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
current[(i / 16) * 16].setTransparent(true); current[(i / 16) * 16].SetTransparent(true);
} }
} }