Refactor Overworld blockset types and update related function signatures
This commit is contained in:
@@ -1,32 +1,18 @@
|
||||
#ifndef YAZE_APP_ZELDA3_COMMON_H
|
||||
#define YAZE_APP_ZELDA3_COMMON_H
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace yaze {
|
||||
|
||||
/**
|
||||
* @namespace yaze::zelda3
|
||||
* @brief Zelda 3 specific classes and functions.
|
||||
*/
|
||||
namespace zelda3 {
|
||||
|
||||
/**
|
||||
* @brief Represents tile32 data for the overworld.
|
||||
*/
|
||||
using OWBlockset = std::vector<std::vector<uint16_t>>;
|
||||
|
||||
/**
|
||||
* @brief Overworld map tile32 data.
|
||||
*/
|
||||
struct OWMapTiles {
|
||||
OWBlockset light_world; // 64 maps
|
||||
OWBlockset dark_world; // 64 maps
|
||||
OWBlockset special_world; // 32 maps
|
||||
};
|
||||
using OWMapTiles = struct OWMapTiles;
|
||||
|
||||
/**
|
||||
* @class GameEntity
|
||||
* @brief Base class for all overworld and dungeon entities.
|
||||
|
||||
@@ -124,18 +124,18 @@ absl::Status Overworld::AssembleMap32Tiles() {
|
||||
for (int k = 0; k < 4; k++) {
|
||||
// Generate the 16-bit tile for the current quadrant of the current
|
||||
// 32x32 pixel tile.
|
||||
ASSIGN_OR_RETURN(uint16_t tl,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesTL,
|
||||
map32address));
|
||||
ASSIGN_OR_RETURN(uint16_t tr,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesTR,
|
||||
map32address));
|
||||
ASSIGN_OR_RETURN(uint16_t bl,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesBL,
|
||||
map32address));
|
||||
ASSIGN_OR_RETURN(uint16_t br,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesBR,
|
||||
map32address));
|
||||
ASSIGN_OR_RETURN(
|
||||
uint16_t tl,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesTL, map32address));
|
||||
ASSIGN_OR_RETURN(
|
||||
uint16_t tr,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesTR, map32address));
|
||||
ASSIGN_OR_RETURN(
|
||||
uint16_t bl,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesBL, map32address));
|
||||
ASSIGN_OR_RETURN(
|
||||
uint16_t br,
|
||||
GetTile16ForTile32(i, k, (int)Dimension::map32TilesBR, map32address));
|
||||
|
||||
// Add the generated 16-bit tiles to the tiles32 vector.
|
||||
tiles32_unique_.emplace_back(gfx::Tile32(tl, tr, bl, br));
|
||||
@@ -177,7 +177,7 @@ void Overworld::AssembleMap16Tiles() {
|
||||
}
|
||||
|
||||
void Overworld::AssignWorldTiles(int x, int y, int sx, int sy, int tpos,
|
||||
OWBlockset &world) {
|
||||
OverworldBlockset &world) {
|
||||
int position_x1 = (x * 2) + (sx * 32);
|
||||
int position_y1 = (y * 2) + (sy * 32);
|
||||
int position_x2 = (x * 2) + 1 + (sx * 32);
|
||||
@@ -572,8 +572,7 @@ absl::Status Overworld::SaveOverworldMaps() {
|
||||
|
||||
if ((pos + size_a) >= 0x6411F && (pos + size_a) <= 0x70000) {
|
||||
core::Logger::log("Pos set to overflow region for map " +
|
||||
std::to_string(i) + " at " +
|
||||
core::HexLong(pos));
|
||||
std::to_string(i) + " at " + core::HexLong(pos));
|
||||
pos = OverworldMapDataOverflow; // 0x0F8780;
|
||||
}
|
||||
|
||||
@@ -610,8 +609,7 @@ absl::Status Overworld::SaveOverworldMaps() {
|
||||
int snes_pos = core::PcToSnes(pos);
|
||||
map_pointers1[i] = snes_pos;
|
||||
core::Logger::log("Saving map pointers1 and compressed data for map " +
|
||||
core::HexByte(i) + " at " +
|
||||
core::HexLong(snes_pos));
|
||||
core::HexByte(i) + " at " + core::HexLong(snes_pos));
|
||||
RETURN_IF_ERROR(rom()->WriteLong(
|
||||
rom()->version_constants().kCompressedAllMap32PointersLow + (3 * i),
|
||||
snes_pos));
|
||||
@@ -620,9 +618,8 @@ absl::Status Overworld::SaveOverworldMaps() {
|
||||
} else {
|
||||
// Save pointer for map1
|
||||
int snes_pos = map_pointers1[map_pointers1_id[i]];
|
||||
core::Logger::log("Saving map pointers1 for map " +
|
||||
core::HexByte(i) + " at " +
|
||||
core::HexLong(snes_pos));
|
||||
core::Logger::log("Saving map pointers1 for map " + core::HexByte(i) +
|
||||
" at " + core::HexLong(snes_pos));
|
||||
RETURN_IF_ERROR(rom()->WriteLong(
|
||||
rom()->version_constants().kCompressedAllMap32PointersLow + (3 * i),
|
||||
snes_pos));
|
||||
@@ -634,8 +631,7 @@ absl::Status Overworld::SaveOverworldMaps() {
|
||||
|
||||
if ((pos + b.size()) >= 0x6411F && (pos + b.size()) <= 0x70000) {
|
||||
core::Logger::log("Pos set to overflow region for map " +
|
||||
core::HexByte(i) + " at " +
|
||||
core::HexLong(pos));
|
||||
core::HexByte(i) + " at " + core::HexLong(pos));
|
||||
pos = OverworldMapDataOverflow;
|
||||
}
|
||||
|
||||
@@ -645,8 +641,7 @@ absl::Status Overworld::SaveOverworldMaps() {
|
||||
int snes_pos = core::PcToSnes(pos);
|
||||
map_pointers2[i] = snes_pos;
|
||||
core::Logger::log("Saving map pointers2 and compressed data for map " +
|
||||
core::HexByte(i) + " at " +
|
||||
core::HexLong(snes_pos));
|
||||
core::HexByte(i) + " at " + core::HexLong(snes_pos));
|
||||
RETURN_IF_ERROR(rom()->WriteLong(
|
||||
rom()->version_constants().kCompressedAllMap32PointersHigh + (3 * i),
|
||||
snes_pos));
|
||||
@@ -655,9 +650,8 @@ absl::Status Overworld::SaveOverworldMaps() {
|
||||
} else {
|
||||
// Save pointer for map2
|
||||
int snes_pos = map_pointers2[map_pointers2_id[i]];
|
||||
core::Logger::log("Saving map pointers2 for map " +
|
||||
core::HexByte(i) + " at " +
|
||||
core::HexLong(snes_pos));
|
||||
core::Logger::log("Saving map pointers2 for map " + core::HexByte(i) +
|
||||
" at " + core::HexLong(snes_pos));
|
||||
RETURN_IF_ERROR(rom()->WriteLong(
|
||||
rom()->version_constants().kCompressedAllMap32PointersHigh + (3 * i),
|
||||
snes_pos));
|
||||
@@ -989,13 +983,13 @@ absl::Status Overworld::SaveLargeMaps() {
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::vector<uint64_t> GetAllTile16(OWMapTiles &map_tiles_) {
|
||||
std::vector<uint64_t> GetAllTile16(OverworldMapTiles &map_tiles_) {
|
||||
std::vector<uint64_t> all_tile_16; // Ensure it's 64 bits
|
||||
|
||||
int sx = 0;
|
||||
int sy = 0;
|
||||
int c = 0;
|
||||
OWBlockset tiles_used;
|
||||
OverworldBlockset tiles_used;
|
||||
for (int i = 0; i < kNumOverworldMaps; i++) {
|
||||
if (i < 64) {
|
||||
tiles_used = map_tiles_.light_world;
|
||||
|
||||
@@ -19,17 +19,17 @@
|
||||
namespace yaze {
|
||||
namespace zelda3 {
|
||||
|
||||
constexpr int GravesYTilePos = 0x49968; // short (0x0F entries)
|
||||
constexpr int GravesXTilePos = 0x49986; // short (0x0F entries)
|
||||
constexpr int GravesTilemapPos = 0x499A4; // short (0x0F entries)
|
||||
constexpr int GravesGFX = 0x499C2; // short (0x0F entries)
|
||||
constexpr int GravesYTilePos = 0x49968; // short (0x0F entries)
|
||||
constexpr int GravesXTilePos = 0x49986; // short (0x0F entries)
|
||||
constexpr int GravesTilemapPos = 0x499A4; // short (0x0F entries)
|
||||
constexpr int GravesGFX = 0x499C2; // short (0x0F entries)
|
||||
|
||||
constexpr int GravesXPos = 0x4994A; // short (0x0F entries)
|
||||
constexpr int GravesYLine = 0x4993A; // short (0x08 entries)
|
||||
constexpr int GravesCountOnY = 0x499E0; // Byte 0x09 entries
|
||||
constexpr int GravesXPos = 0x4994A; // short (0x0F entries)
|
||||
constexpr int GravesYLine = 0x4993A; // short (0x08 entries)
|
||||
constexpr int GravesCountOnY = 0x499E0; // Byte 0x09 entries
|
||||
|
||||
constexpr int GraveLinkSpecialHole = 0x46DD9; // short
|
||||
constexpr int GraveLinkSpecialStairs = 0x46DE0; // short
|
||||
constexpr int GraveLinkSpecialHole = 0x46DD9; // short
|
||||
constexpr int GraveLinkSpecialStairs = 0x46DE0; // short
|
||||
constexpr int kOverworldMapPaletteIds = 0x7D1C;
|
||||
constexpr int kOverworldSpritePaletteIds = 0x7B41;
|
||||
constexpr int overworldMapPaletteGroup = 0x75504;
|
||||
@@ -94,8 +94,8 @@ constexpr int kMap16Tiles = 0x78000;
|
||||
constexpr int kNumOverworldMaps = 160;
|
||||
constexpr int kNumTile16Individual = 4096;
|
||||
constexpr int Map32PerScreen = 256;
|
||||
constexpr int NumberOfMap16 = 3752; // 4096
|
||||
constexpr int NumberOfMap16Ex = 4096; // 4096
|
||||
constexpr int NumberOfMap16 = 3752; // 4096
|
||||
constexpr int NumberOfMap16Ex = 4096; // 4096
|
||||
constexpr int LimitOfMap32 = 8864;
|
||||
constexpr int NumberOfOWSprites = 352;
|
||||
constexpr int NumberOfMap32 = Map32PerScreen * kNumOverworldMaps;
|
||||
@@ -107,7 +107,7 @@ constexpr int NumberOfMap32 = Map32PerScreen * kNumOverworldMaps;
|
||||
* as well as creating the tilesets and tilemaps for the overworld.
|
||||
*/
|
||||
class Overworld : public SharedRom, public core::ExperimentFlags {
|
||||
public:
|
||||
public:
|
||||
absl::Status Load(Rom &rom);
|
||||
absl::Status LoadOverworldMaps();
|
||||
void LoadTileTypes();
|
||||
@@ -156,16 +156,16 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
OWBlockset &GetMapTiles(int world_type) {
|
||||
OverworldBlockset &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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ public:
|
||||
auto all_tiles_types() const { return all_tiles_types_; }
|
||||
auto mutable_all_tiles_types() { return &all_tiles_types_; }
|
||||
|
||||
private:
|
||||
private:
|
||||
enum Dimension {
|
||||
map32TilesTL = 0,
|
||||
map32TilesTR = 1,
|
||||
@@ -220,12 +220,14 @@ private:
|
||||
absl::Status AssembleMap32Tiles();
|
||||
void AssembleMap16Tiles();
|
||||
void AssignWorldTiles(int x, int y, int sx, int sy, int tpos,
|
||||
OWBlockset &world);
|
||||
OverworldBlockset &world);
|
||||
void OrganizeMapTiles(std::vector<uint8_t> &bytes,
|
||||
std::vector<uint8_t> &bytes2, int i, int sx, int sy,
|
||||
int &ttpos);
|
||||
absl::Status DecompressAllMapTiles();
|
||||
|
||||
Rom rom_;
|
||||
|
||||
bool is_loaded_ = false;
|
||||
bool expanded_tile16_ = false;
|
||||
bool expanded_tile32_ = false;
|
||||
@@ -234,13 +236,11 @@ private:
|
||||
int game_state_ = 0;
|
||||
int current_map_ = 0;
|
||||
int current_world_ = 0;
|
||||
uchar map_parent_[160];
|
||||
|
||||
Rom rom_;
|
||||
OWMapTiles map_tiles_;
|
||||
|
||||
uint8_t all_tiles_types_[0x200];
|
||||
OverworldMapTiles map_tiles_;
|
||||
|
||||
std::array<uint8_t, 160> map_parent_;
|
||||
std::array<uint8_t, 0x200> all_tiles_types_;
|
||||
std::vector<gfx::Tile16> tiles16_;
|
||||
std::vector<gfx::Tile32> tiles32_;
|
||||
std::vector<uint16_t> tiles32_list_;
|
||||
@@ -251,7 +251,6 @@ private:
|
||||
std::vector<OverworldExit> all_exits_;
|
||||
std::vector<OverworldItem> all_items_;
|
||||
std::vector<std::vector<Sprite>> all_sprites_;
|
||||
|
||||
std::vector<uint64_t> deleted_entrances_;
|
||||
|
||||
std::vector<std::vector<uint8_t>> map_data_p1 =
|
||||
@@ -268,7 +267,7 @@ private:
|
||||
std::vector<absl::flat_hash_map<uint16_t, int>> usage_stats_;
|
||||
};
|
||||
|
||||
} // namespace zelda3
|
||||
} // namespace yaze
|
||||
} // namespace zelda3
|
||||
} // namespace yaze
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,7 +30,7 @@ OverworldMap::OverworldMap(int index, Rom& rom, bool load_custom_data)
|
||||
|
||||
absl::Status OverworldMap::BuildMap(int count, int game_state, int world,
|
||||
std::vector<gfx::Tile16>& tiles16,
|
||||
OWBlockset& world_blockset) {
|
||||
OverworldBlockset& world_blockset) {
|
||||
game_state_ = game_state;
|
||||
world_ = world;
|
||||
if (large_map_) {
|
||||
@@ -718,7 +718,7 @@ absl::Status OverworldMap::BuildTiles16Gfx(std::vector<gfx::Tile16>& tiles16,
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status OverworldMap::BuildBitmap(OWBlockset& world_blockset) {
|
||||
absl::Status OverworldMap::BuildBitmap(OverworldBlockset& world_blockset) {
|
||||
if (bitmap_data_.size() != 0) {
|
||||
bitmap_data_.clear();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef YAZE_APP_ZELDA3_OVERWORLD_MAP_H
|
||||
#define YAZE_APP_ZELDA3_OVERWORLD_MAP_H
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
@@ -54,6 +55,20 @@ constexpr int OverworldCustomTileGFXGroupArray = 0x140480;
|
||||
// 1 byte, not 0 if enabled
|
||||
constexpr int OverworldCustomTileGFXGroupEnabled = 0x140148;
|
||||
|
||||
/**
|
||||
* @brief Represents tile32 data for the overworld.
|
||||
*/
|
||||
using OverworldBlockset = std::vector<std::vector<uint16_t>>;
|
||||
|
||||
/**
|
||||
* @brief Overworld map tile32 data.
|
||||
*/
|
||||
typedef struct OverworldMapTiles {
|
||||
OverworldBlockset light_world; // 64 maps
|
||||
OverworldBlockset dark_world; // 64 maps
|
||||
OverworldBlockset special_world; // 32 maps
|
||||
} OverworldMapTiles;
|
||||
|
||||
/**
|
||||
* @brief Represents a single Overworld map screen.
|
||||
*/
|
||||
@@ -64,13 +79,13 @@ class OverworldMap : public gfx::GfxContext {
|
||||
|
||||
absl::Status BuildMap(int count, int game_state, int world,
|
||||
std::vector<gfx::Tile16>& tiles16,
|
||||
OWBlockset& world_blockset);
|
||||
OverworldBlockset& world_blockset);
|
||||
|
||||
void LoadAreaGraphics();
|
||||
absl::Status LoadPalette();
|
||||
absl::Status BuildTileset();
|
||||
absl::Status BuildTiles16Gfx(std::vector<gfx::Tile16>& tiles16, int count);
|
||||
absl::Status BuildBitmap(OWBlockset& world_blockset);
|
||||
absl::Status BuildBitmap(OverworldBlockset& world_blockset);
|
||||
|
||||
void DrawAnimatedTiles();
|
||||
|
||||
@@ -148,6 +163,8 @@ class OverworldMap : public gfx::GfxContext {
|
||||
int index, int previous_index,
|
||||
int limit);
|
||||
|
||||
Rom rom_;
|
||||
|
||||
bool built_ = false;
|
||||
bool large_map_ = false;
|
||||
bool initialized_ = false;
|
||||
@@ -167,19 +184,18 @@ class OverworldMap : public gfx::GfxContext {
|
||||
uint8_t animated_gfx_ = 0; // Custom Overworld Animated ID
|
||||
uint16_t subscreen_overlay_ = 0; // Custom Overworld Subscreen Overlay ID
|
||||
|
||||
uint8_t custom_gfx_ids_[8];
|
||||
uchar sprite_graphics_[3];
|
||||
uchar sprite_palette_[3];
|
||||
uchar area_music_[4];
|
||||
uchar static_graphics_[16];
|
||||
std::array<uint8_t, 8> custom_gfx_ids_;
|
||||
std::array<uint8_t, 3> sprite_graphics_;
|
||||
std::array<uint8_t, 3> sprite_palette_;
|
||||
std::array<uint8_t, 4> area_music_;
|
||||
std::array<uint8_t, 16> static_graphics_;
|
||||
|
||||
Rom rom_;
|
||||
std::vector<uint8_t> all_gfx_;
|
||||
std::vector<uint8_t> current_blockset_;
|
||||
std::vector<uint8_t> current_gfx_;
|
||||
std::vector<uint8_t> bitmap_data_;
|
||||
OWMapTiles map_tiles_;
|
||||
|
||||
OverworldMapTiles map_tiles_;
|
||||
gfx::SnesPalette current_palette_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user