update z3_dungeon_room public data type internals
This commit is contained in:
104
incl/dungeon.h
104
incl/dungeon.h
@@ -8,60 +8,64 @@ extern "C" {
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct z3_object_door {
|
||||
short id;
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t size;
|
||||
uint8_t type;
|
||||
uint8_t layer;
|
||||
} z3_object_door;
|
||||
|
||||
typedef struct z3_dungeon_destination {
|
||||
uint8_t index;
|
||||
uint8_t target;
|
||||
uint8_t target_layer;
|
||||
} z3_dungeon_destination;
|
||||
|
||||
typedef struct z3_staircase {
|
||||
uint8_t id;
|
||||
uint8_t room;
|
||||
const char *label;
|
||||
} z3_staircase;
|
||||
|
||||
typedef struct z3_chest {
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t item;
|
||||
bool picker;
|
||||
bool big_chest;
|
||||
} z3_chest;
|
||||
|
||||
typedef struct z3_chest_data {
|
||||
uint8_t id;
|
||||
bool size;
|
||||
} z3_chest_data;
|
||||
|
||||
typedef enum z3_dungeon_background2 {
|
||||
Off,
|
||||
Parallax,
|
||||
Dark,
|
||||
OnTop,
|
||||
Translucent,
|
||||
Addition,
|
||||
Normal,
|
||||
Transparent,
|
||||
DarkRoom
|
||||
} z3_dungeon_background2;
|
||||
|
||||
typedef struct z3_dungeon_room {
|
||||
z3_dungeon_background2 bg2;
|
||||
z3_dungeon_destination pits;
|
||||
z3_dungeon_destination stairs[4];
|
||||
typedef struct object_door {
|
||||
short id;
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t size;
|
||||
uint8_t type;
|
||||
uint8_t layer;
|
||||
} object_door;
|
||||
object_door* doors;
|
||||
|
||||
typedef struct staircase {
|
||||
uint8_t id;
|
||||
uint8_t room;
|
||||
const char* label;
|
||||
} staircase;
|
||||
staircase* staircases;
|
||||
|
||||
typedef struct chest {
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t item;
|
||||
bool picker;
|
||||
bool big_chest;
|
||||
} chest;
|
||||
chest* chests;
|
||||
|
||||
typedef struct chest_data {
|
||||
uint8_t id;
|
||||
bool size;
|
||||
} chest_data;
|
||||
chest_data* chests;
|
||||
|
||||
typedef enum background2 {
|
||||
Off,
|
||||
Parallax,
|
||||
Dark,
|
||||
OnTop,
|
||||
Translucent,
|
||||
Addition,
|
||||
Normal,
|
||||
Transparent,
|
||||
DarkRoom
|
||||
} background2;
|
||||
background2 bg2;
|
||||
|
||||
typedef struct destination {
|
||||
uint8_t index;
|
||||
uint8_t target;
|
||||
uint8_t target_layer;
|
||||
} destination;
|
||||
|
||||
destination pits;
|
||||
destination stairs[4];
|
||||
} z3_dungeon_room;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // YAZE_BASE_DUNGEON_H_
|
||||
#endif // YAZE_BASE_DUNGEON_H_
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "rom.h"
|
||||
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@@ -54,10 +54,11 @@ absl::StatusOr<std::vector<uint8_t>> Load2BppGraphics(const Rom &rom) {
|
||||
return sheet;
|
||||
}
|
||||
|
||||
absl::StatusOr<std::array<gfx::Bitmap, kNumLinkSheets>> LoadLinkGraphics(const Rom& rom) {
|
||||
absl::StatusOr<std::array<gfx::Bitmap, kNumLinkSheets>> LoadLinkGraphics(
|
||||
const Rom &rom) {
|
||||
const uint32_t kLinkGfxOffset = 0x80000; // $10:8000
|
||||
const uint16_t kLinkGfxLength = 0x800; // 0x4000 or 0x7000?
|
||||
std::array<gfx::Bitmap, kNumLinkSheets> link_graphics;
|
||||
std::array<gfx::Bitmap, kNumLinkSheets> link_graphics;
|
||||
for (uint32_t i = 0; i < kNumLinkSheets; i++) {
|
||||
ASSIGN_OR_RETURN(
|
||||
auto link_sheet_data,
|
||||
@@ -65,45 +66,45 @@ absl::StatusOr<std::array<gfx::Bitmap, kNumLinkSheets>> LoadLinkGraphics(const R
|
||||
/*length=*/kLinkGfxLength))
|
||||
auto link_sheet_8bpp = gfx::SnesTo8bppSheet(link_sheet_data, /*bpp=*/4);
|
||||
link_graphics[i].Create(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
|
||||
gfx::kTilesheetDepth, link_sheet_8bpp);
|
||||
RETURN_IF_ERROR(link_graphics[i].ApplyPalette(rom.palette_group().armors[0]);)
|
||||
gfx::kTilesheetDepth, link_sheet_8bpp);
|
||||
RETURN_IF_ERROR(
|
||||
link_graphics[i].ApplyPalette(rom.palette_group().armors[0]);)
|
||||
Renderer::GetInstance().RenderBitmap(&link_graphics[i]);
|
||||
}
|
||||
return link_graphics;
|
||||
}
|
||||
|
||||
absl::StatusOr<std::array<gfx::Bitmap, kNumGfxSheets>>
|
||||
LoadAllGraphicsData(Rom& rom, bool defer_render) {
|
||||
std::array<gfx::Bitmap, kNumGfxSheets> graphics_sheets;
|
||||
absl::StatusOr<std::array<gfx::Bitmap, kNumGfxSheets>> LoadAllGraphicsData(
|
||||
Rom &rom, bool defer_render) {
|
||||
std::array<gfx::Bitmap, kNumGfxSheets> graphics_sheets;
|
||||
std::vector<uint8_t> sheet;
|
||||
bool bpp3 = false;
|
||||
|
||||
for (uint32_t i = 0; i < kNumGfxSheets; i++) {
|
||||
if (i >= 115 && i <= 126) { // uncompressed sheets
|
||||
sheet.resize(Uncompressed3BPPSize);
|
||||
auto offset =
|
||||
GetGraphicsAddress(rom.data(), i, rom.version_constants().kOverworldGfxPtr1,
|
||||
rom.version_constants().kOverworldGfxPtr2,
|
||||
rom.version_constants().kOverworldGfxPtr3);
|
||||
std::copy(rom.data() + offset, rom.data() + offset + Uncompressed3BPPSize,
|
||||
sheet.begin());
|
||||
auto offset = GetGraphicsAddress(
|
||||
rom.data(), i, rom.version_constants().kOverworldGfxPtr1,
|
||||
rom.version_constants().kOverworldGfxPtr2,
|
||||
rom.version_constants().kOverworldGfxPtr3);
|
||||
std::copy(rom.data() + offset, rom.data() + offset + Uncompressed3BPPSize,
|
||||
sheet.begin());
|
||||
bpp3 = true;
|
||||
} else if (i == 113 || i == 114 || i >= 218) {
|
||||
bpp3 = false;
|
||||
} else {
|
||||
auto offset =
|
||||
GetGraphicsAddress(rom.data(), i, rom.version_constants().kOverworldGfxPtr1,
|
||||
rom.version_constants().kOverworldGfxPtr2,
|
||||
rom.version_constants().kOverworldGfxPtr3);
|
||||
ASSIGN_OR_RETURN(sheet,
|
||||
gfx::lc_lz2::DecompressV2(rom.data(), offset))
|
||||
auto offset = GetGraphicsAddress(
|
||||
rom.data(), i, rom.version_constants().kOverworldGfxPtr1,
|
||||
rom.version_constants().kOverworldGfxPtr2,
|
||||
rom.version_constants().kOverworldGfxPtr3);
|
||||
ASSIGN_OR_RETURN(sheet, gfx::lc_lz2::DecompressV2(rom.data(), offset))
|
||||
bpp3 = true;
|
||||
}
|
||||
|
||||
if (bpp3) {
|
||||
auto converted_sheet = gfx::SnesTo8bppSheet(sheet, 3);
|
||||
graphics_sheets[i].Create(gfx::kTilesheetWidth, gfx::kTilesheetHeight,
|
||||
gfx::kTilesheetDepth, converted_sheet);
|
||||
gfx::kTilesheetDepth, converted_sheet);
|
||||
if (graphics_sheets[i].is_active()) {
|
||||
if (i > 115) {
|
||||
// Apply sprites palette
|
||||
@@ -132,8 +133,8 @@ LoadAllGraphicsData(Rom& rom, bool defer_render) {
|
||||
return graphics_sheets;
|
||||
}
|
||||
|
||||
absl::Status
|
||||
SaveAllGraphicsData(Rom& rom, std::array<gfx::Bitmap, kNumGfxSheets>& gfx_sheets) {
|
||||
absl::Status SaveAllGraphicsData(
|
||||
Rom &rom, std::array<gfx::Bitmap, kNumGfxSheets> &gfx_sheets) {
|
||||
for (int i = 0; i < kNumGfxSheets; i++) {
|
||||
if (gfx_sheets[i].is_active()) {
|
||||
int to_bpp = 3;
|
||||
@@ -158,10 +159,10 @@ SaveAllGraphicsData(Rom& rom, std::array<gfx::Bitmap, kNumGfxSheets>& gfx_sheets
|
||||
sheet_data[j] = compressed_data[j];
|
||||
}
|
||||
}
|
||||
auto offset =
|
||||
GetGraphicsAddress(rom.data(), i, rom.version_constants().kOverworldGfxPtr1,
|
||||
rom.version_constants().kOverworldGfxPtr2,
|
||||
rom.version_constants().kOverworldGfxPtr3);
|
||||
auto offset = GetGraphicsAddress(
|
||||
rom.data(), i, rom.version_constants().kOverworldGfxPtr1,
|
||||
rom.version_constants().kOverworldGfxPtr2,
|
||||
rom.version_constants().kOverworldGfxPtr3);
|
||||
std::copy(final_data.begin(), final_data.end(), rom.begin() + offset);
|
||||
}
|
||||
}
|
||||
@@ -231,10 +232,10 @@ absl::Status Rom::LoadFromPointer(uchar *data, size_t length, bool z3_load) {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status Rom::LoadFromBytes(const std::vector<uint8_t>& data) {
|
||||
absl::Status Rom::LoadFromBytes(const std::vector<uint8_t> &data) {
|
||||
if (data.empty()) {
|
||||
return absl::InvalidArgumentError(
|
||||
"Could not load ROM: parameter `data` is empty.");
|
||||
"Could not load ROM: parameter `data` is empty.");
|
||||
}
|
||||
rom_data_ = data;
|
||||
size_ = data.size();
|
||||
|
||||
@@ -129,7 +129,6 @@ static const std::map<Z3_Version, VersionConstants> kVersionConstantsMap = {
|
||||
{Z3_Version::RANDO, {}},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Rom class is used to load, save, and modify Rom data.
|
||||
*/
|
||||
@@ -251,7 +250,7 @@ class Rom {
|
||||
absl::StatusOr<gfx::Tile16> ReadTile16(uint32_t tile16_id) {
|
||||
// Skip 8 bytes per tile.
|
||||
auto tpos = kTile16Ptr + (tile16_id * 0x08);
|
||||
gfx::Tile16 tile16 = {};
|
||||
gfx::Tile16 tile16 = {};
|
||||
ASSIGN_OR_RETURN(auto new_tile0, ReadWord(tpos))
|
||||
tile16.tile0_ = gfx::WordToTileInfo(new_tile0);
|
||||
tpos += 2;
|
||||
@@ -378,7 +377,7 @@ class Rom {
|
||||
|
||||
uint8_t& operator[](unsigned long i) {
|
||||
if (i > size_) {
|
||||
throw std::out_of_range("Rom index out of range");
|
||||
throw std::out_of_range("Rom index out of range");
|
||||
}
|
||||
return rom_data_[i];
|
||||
}
|
||||
@@ -499,18 +498,19 @@ class Rom {
|
||||
};
|
||||
|
||||
class GraphicsSheetManager {
|
||||
public:
|
||||
static GraphicsSheetManager& GetInstance() {
|
||||
static GraphicsSheetManager instance;
|
||||
return instance;
|
||||
}
|
||||
public:
|
||||
static GraphicsSheetManager& GetInstance() {
|
||||
static GraphicsSheetManager instance;
|
||||
return instance;
|
||||
}
|
||||
GraphicsSheetManager() = default;
|
||||
virtual ~GraphicsSheetManager() = default;
|
||||
std::array<gfx::Bitmap, kNumGfxSheets>& gfx_sheets() { return gfx_sheets_; }
|
||||
auto gfx_sheet(int i) { return gfx_sheets_[i]; }
|
||||
auto mutable_gfx_sheet(int i) { return &gfx_sheets_[i]; }
|
||||
auto mutable_gfx_sheets() { return &gfx_sheets_; }
|
||||
private:
|
||||
auto mutable_gfx_sheets() { return &gfx_sheets_; }
|
||||
|
||||
private:
|
||||
std::array<gfx::Bitmap, kNumGfxSheets> gfx_sheets_;
|
||||
};
|
||||
|
||||
@@ -532,9 +532,11 @@ private:
|
||||
* | 218-222 | Compressed 2bpp | 0x800 chars | Decompressed each |
|
||||
*
|
||||
*/
|
||||
absl::StatusOr<std::array<gfx::Bitmap, kNumGfxSheets>> LoadAllGraphicsData(Rom& rom, bool defer_render = false);
|
||||
absl::StatusOr<std::array<gfx::Bitmap, kNumGfxSheets>> LoadAllGraphicsData(
|
||||
Rom& rom, bool defer_render = false);
|
||||
|
||||
absl::Status SaveAllGraphicsData(Rom& rom, std::array<gfx::Bitmap, kNumGfxSheets>& gfx_sheets);
|
||||
absl::Status SaveAllGraphicsData(
|
||||
Rom& rom, std::array<gfx::Bitmap, kNumGfxSheets>& gfx_sheets);
|
||||
|
||||
/**
|
||||
* @brief Loads 2bpp graphics from Rom data.
|
||||
@@ -549,7 +551,8 @@ absl::StatusOr<std::vector<uint8_t>> Load2BppGraphics(const Rom& rom);
|
||||
/**
|
||||
* @brief Loads the players 4bpp graphics sheet from Rom data.
|
||||
*/
|
||||
absl::StatusOr<std::array<gfx::Bitmap, kNumLinkSheets>> LoadLinkGraphics(const Rom& rom);
|
||||
absl::StatusOr<std::array<gfx::Bitmap, kNumLinkSheets>> LoadLinkGraphics(
|
||||
const Rom& rom);
|
||||
|
||||
/**
|
||||
* @brief A class to hold a shared pointer to a Rom object.
|
||||
|
||||
@@ -27,12 +27,13 @@ void Room::LoadHeader() {
|
||||
|
||||
auto header_location = core::SnesToPc(address);
|
||||
|
||||
bg2_ = (z3_dungeon_background2)((rom()->data()[header_location] >> 5) & 0x07);
|
||||
bg2_ = (z3_dungeon_room::background2)((rom()->data()[header_location] >> 5) &
|
||||
0x07);
|
||||
collision_ = (CollisionKey)((rom()->data()[header_location] >> 2) & 0x07);
|
||||
is_light_ = ((rom()->data()[header_location]) & 0x01) == 1;
|
||||
|
||||
if (is_light_) {
|
||||
bg2_ = z3_dungeon_background2::DarkRoom;
|
||||
bg2_ = z3_dungeon_room::background2::DarkRoom;
|
||||
}
|
||||
|
||||
palette = ((rom()->data()[header_location + 1] & 0x3F));
|
||||
@@ -373,7 +374,7 @@ void Room::LoadObjects() {
|
||||
if (nbr_of_staircase < 4) {
|
||||
tile_objects_.back().set_options(ObjectOption::Stairs |
|
||||
tile_objects_.back().options());
|
||||
z3_staircases_.push_back(z3_staircase(
|
||||
z3_staircases_.push_back(z3_dungeon_room::staircase(
|
||||
posX, posY,
|
||||
absl::StrCat("To ", staircase_rooms_[nbr_of_staircase])
|
||||
.data()));
|
||||
@@ -381,7 +382,8 @@ void Room::LoadObjects() {
|
||||
} else {
|
||||
tile_objects_.back().set_options(ObjectOption::Stairs |
|
||||
tile_objects_.back().options());
|
||||
z3_staircases_.push_back(z3_staircase(posX, posY, "To ???"));
|
||||
z3_staircases_.push_back(
|
||||
z3_dungeon_room::staircase(posX, posY, "To ???"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -391,7 +393,7 @@ void Room::LoadObjects() {
|
||||
tile_objects_.back().set_options(ObjectOption::Chest |
|
||||
tile_objects_.back().options());
|
||||
// chest_list_.push_back(
|
||||
// Chest(posX, posY, chests_in_room_.front().itemIn, false));
|
||||
// z3_chest(posX, posY, chests_in_room_.front().itemIn, false));
|
||||
chests_in_room_.erase(chests_in_room_.begin());
|
||||
}
|
||||
} else if (oid == 0xFB1) {
|
||||
@@ -399,14 +401,14 @@ void Room::LoadObjects() {
|
||||
tile_objects_.back().set_options(ObjectOption::Chest |
|
||||
tile_objects_.back().options());
|
||||
// chest_list_.push_back(
|
||||
// Chest(posX + 1, posY, chests_in_room_.front().item_in, true));
|
||||
// z3_chest(posX + 1, posY, chests_in_room_.front().item_in, true));
|
||||
chests_in_room_.erase(chests_in_room_.begin());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// tile_objects_.push_back(object_door(static_cast<short>((b2 << 8) + b1),
|
||||
// 0,
|
||||
// 0, 0, static_cast<uint8_t>(layer)));
|
||||
// tile_objects_.push_back(z3_object_door(static_cast<short>((b2 << 8) + b1),
|
||||
// 0, 0, 0,
|
||||
// static_cast<uint8_t>(layer)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -477,7 +479,7 @@ void Room::LoadChests() {
|
||||
}
|
||||
|
||||
chests_in_room_.emplace_back(
|
||||
z3_chest_data(rom_data[cpos + (i * 3) + 2], big));
|
||||
z3_dungeon_room::chest_data(rom_data[cpos + (i * 3) + 2], big));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,13 +177,13 @@ class Room : public SharedRom {
|
||||
int64_t room_size_pointer_;
|
||||
|
||||
std::array<uint8_t, 16> blocks_;
|
||||
std::array<uchar, 16> chest_list_;
|
||||
std::array<z3_chest, 16> chest_list_;
|
||||
|
||||
std::array<gfx::Bitmap, 3> background_bmps_;
|
||||
std::vector<RoomObject> tile_objects_;
|
||||
std::vector<zelda3::Sprite> sprites_;
|
||||
std::vector<z3_staircase> z3_staircases_;
|
||||
std::vector<z3_chest_data> chests_in_room_;
|
||||
std::vector<z3_dungeon_room::staircase> z3_staircases_;
|
||||
std::vector<z3_dungeon_room::chest_data> chests_in_room_;
|
||||
|
||||
LayerMergeType layer_merging_;
|
||||
CollisionKey collision_;
|
||||
@@ -191,12 +191,12 @@ class Room : public SharedRom {
|
||||
TagKey tag1_;
|
||||
TagKey tag2_;
|
||||
|
||||
z3_dungeon_background2 bg2_;
|
||||
z3_dungeon_destination pits_;
|
||||
z3_dungeon_destination stair1_;
|
||||
z3_dungeon_destination stair2_;
|
||||
z3_dungeon_destination stair3_;
|
||||
z3_dungeon_destination stair4_;
|
||||
z3_dungeon_room::background2 bg2_;
|
||||
z3_dungeon_room::destination pits_;
|
||||
z3_dungeon_room::destination stair1_;
|
||||
z3_dungeon_room::destination stair2_;
|
||||
z3_dungeon_room::destination stair3_;
|
||||
z3_dungeon_room::destination stair4_;
|
||||
};
|
||||
|
||||
constexpr std::string_view kRoomNames[] = {
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
namespace yaze {
|
||||
namespace zelda3 {
|
||||
|
||||
|
||||
struct SubtypeInfo {
|
||||
uint32_t subtype_ptr;
|
||||
uint32_t routine_ptr;
|
||||
|
||||
Reference in New Issue
Block a user