yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
tile16_usage_index.cc
Go to the documentation of this file.
2
3namespace yaze::zelda3 {
4
5namespace {
6
7const gfx::TileInfo& TileInfoForQuadrant(const gfx::Tile16& tile, int quadrant) {
8 switch (quadrant) {
9 case 0:
10 return tile.tile0_;
11 case 1:
12 return tile.tile1_;
13 case 2:
14 return tile.tile2_;
15 default:
16 return tile.tile3_;
17 }
18}
19
20} // namespace
21
23 if (!usage_index) {
24 return;
25 }
26 for (auto& hits : *usage_index) {
27 hits.clear();
28 }
29}
30
31void AddTile16ToUsageIndex(const gfx::Tile16& tile_data, int tile16_id,
32 Tile8UsageIndex* usage_index) {
33 if (!usage_index) {
34 return;
35 }
36
37 for (int quadrant = 0; quadrant < 4; ++quadrant) {
38 const int tile8_id = TileInfoForQuadrant(tile_data, quadrant).id_;
39 if (tile8_id < 0 || tile8_id >= kMaxTile8UsageId) {
40 continue;
41 }
42 (*usage_index)[tile8_id].push_back({tile16_id, quadrant});
43 }
44}
45
47 int total_tiles,
48 const std::function<absl::StatusOr<gfx::Tile16>(int)>& tile_provider,
49 Tile8UsageIndex* usage_index) {
50 if (!usage_index) {
51 return absl::InvalidArgumentError("Usage index pointer is null");
52 }
53 if (!tile_provider) {
54 return absl::InvalidArgumentError("Tile provider callback is not set");
55 }
56 if (total_tiles < 0) {
57 return absl::InvalidArgumentError("Total tiles cannot be negative");
58 }
59
60 ClearTile8UsageIndex(usage_index);
61 for (int tile_id = 0; tile_id < total_tiles; ++tile_id) {
62 auto tile_result = tile_provider(tile_id);
63 if (!tile_result.ok()) {
64 continue;
65 }
66 AddTile16ToUsageIndex(*tile_result, tile_id, usage_index);
67 }
68 return absl::OkStatus();
69}
70
71} // namespace yaze::zelda3
Tile composition of four 8x8 tiles.
Definition snes_tile.h:142
SNES 16-bit tile metadata container.
Definition snes_tile.h:52
Zelda 3 specific classes and functions.
std::array< std::vector< Tile8UsageHit >, kMaxTile8UsageId > Tile8UsageIndex
void ClearTile8UsageIndex(Tile8UsageIndex *usage_index)
absl::Status BuildTile8UsageIndex(int total_tiles, const std::function< absl::StatusOr< gfx::Tile16 >(int)> &tile_provider, Tile8UsageIndex *usage_index)
constexpr int kMaxTile8UsageId
void AddTile16ToUsageIndex(const gfx::Tile16 &tile_data, int tile16_id, Tile8UsageIndex *usage_index)