yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
diggable_tiles.cc
Go to the documentation of this file.
2
3#include <cstring>
4
5namespace yaze::zelda3 {
6
7bool DiggableTiles::IsDiggable(uint16_t tile_id) const {
8 if (tile_id >= kMaxDiggableTileId) {
9 return false;
10 }
11 int byte_index = tile_id / 8;
12 int bit_index = tile_id % 8;
13 return (bitfield_[byte_index] & (1 << bit_index)) != 0;
14}
15
16void DiggableTiles::SetDiggable(uint16_t tile_id, bool diggable) {
17 if (tile_id >= kMaxDiggableTileId) {
18 return;
19 }
20 int byte_index = tile_id / 8;
21 int bit_index = tile_id % 8;
22 if (diggable) {
23 bitfield_[byte_index] |= (1 << bit_index);
24 } else {
25 bitfield_[byte_index] &= ~(1 << bit_index);
26 }
27}
28
30 bitfield_.fill(0);
31}
32
34 Clear();
35 for (int i = 0; i < kNumVanillaDiggableTiles; ++i) {
37 }
38}
39
40std::vector<uint16_t> DiggableTiles::GetAllDiggableTileIds() const {
41 std::vector<uint16_t> result;
42 for (uint16_t tile_id = 0; tile_id < kMaxDiggableTileId; ++tile_id) {
43 if (IsDiggable(tile_id)) {
44 result.push_back(tile_id);
45 }
46 }
47 return result;
48}
49
51 int count = 0;
52 for (uint16_t tile_id = 0; tile_id < kMaxDiggableTileId; ++tile_id) {
53 if (IsDiggable(tile_id)) {
54 ++count;
55 }
56 }
57 return count;
58}
59
60void DiggableTiles::FromBytes(const uint8_t* data) {
61 std::memcpy(bitfield_.data(), data, kDiggableTilesBitfieldSize);
62}
63
64void DiggableTiles::ToBytes(uint8_t* data) const {
65 std::memcpy(data, bitfield_.data(), kDiggableTilesBitfieldSize);
66}
67
69 const gfx::Tile16& tile16,
70 const std::array<uint8_t, 0x200>& all_tiles_types) {
71 // Check all 4 component tiles
72 // A Tile16 is diggable only if ALL components are diggable types
73 auto is_tile_diggable = [&all_tiles_types](const gfx::TileInfo& tile_info) {
74 uint16_t tile_id = tile_info.id_;
75 if (tile_id >= all_tiles_types.size()) {
76 return false;
77 }
78 uint8_t tile_type = all_tiles_types[tile_id];
79 return tile_type == kTileTypeDiggable1 || tile_type == kTileTypeDiggable2;
80 };
81
82 return is_tile_diggable(tile16.tile0_) &&
83 is_tile_diggable(tile16.tile1_) &&
84 is_tile_diggable(tile16.tile2_) &&
85 is_tile_diggable(tile16.tile3_);
86}
87
88} // namespace yaze::zelda3
Tile composition of four 8x8 tiles.
Definition snes_tile.h:140
SNES 16-bit tile metadata container.
Definition snes_tile.h:50
void ToBytes(uint8_t *data) const
Write bitfield to raw bytes (64 bytes).
int GetDiggableCount() const
Get the count of tiles marked as diggable.
void SetVanillaDefaults()
Reset to vanilla diggable tiles.
void FromBytes(const uint8_t *data)
Load bitfield from raw bytes (64 bytes).
void SetDiggable(uint16_t tile_id, bool diggable)
Set or clear the diggable bit for a Map16 tile ID.
static bool IsTile16Diggable(const gfx::Tile16 &tile16, const std::array< uint8_t, 0x200 > &all_tiles_types)
Check if a Tile16 should be diggable based on its component tiles.
std::vector< uint16_t > GetAllDiggableTileIds() const
Get all tile IDs that are currently marked as diggable.
bool IsDiggable(uint16_t tile_id) const
Check if a Map16 tile ID is marked as diggable.
std::array< uint8_t, kDiggableTilesBitfieldSize > bitfield_
void Clear()
Clear all diggable bits.
Zelda 3 specific classes and functions.
Definition editor.h:35
constexpr int kDiggableTilesBitfieldSize
constexpr uint8_t kTileTypeDiggable1
constexpr uint8_t kTileTypeDiggable2
constexpr int kNumVanillaDiggableTiles
constexpr int kMaxDiggableTileId
constexpr uint16_t kVanillaDiggableTiles[]