yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
draw_routine_types.cc
Go to the documentation of this file.
2
5
6namespace yaze {
7namespace zelda3 {
8namespace DrawRoutineUtils {
9
10namespace {
11struct TraceState {
12 TraceHookFn hook = nullptr;
13 void* user_data = nullptr;
14 bool trace_only = false;
15};
16
18} // namespace
19
20void SetTraceHook(TraceHookFn hook, void* user_data, bool trace_only) {
21 g_trace_state.hook = hook;
22 g_trace_state.user_data = user_data;
23 g_trace_state.trace_only = trace_only;
24}
25
27 g_trace_state = TraceState{};
28}
29
30void WriteTile8(gfx::BackgroundBuffer& bg, int tile_x, int tile_y,
31 const gfx::TileInfo& tile_info) {
32 if (!IsValidTilePosition(tile_x, tile_y)) {
33 return;
34 }
35 if (g_trace_state.hook) {
36 g_trace_state.hook(tile_x, tile_y, tile_info, g_trace_state.user_data);
37 if (g_trace_state.trace_only) {
38 return;
39 }
40 }
41 // Convert TileInfo to the 16-bit word format and store in tile buffer
42 uint16_t word = gfx::TileInfoToWord(tile_info);
43 bg.SetTileAt(tile_x, tile_y, word);
44}
45
46void DrawBlock2x2(gfx::BackgroundBuffer& bg, int tile_x, int tile_y,
47 std::span<const gfx::TileInfo> tiles, int offset) {
48 // Draw a 2x2 block (4 tiles) at the given position
49 // Layout: [0][1]
50 // [2][3]
51 if (offset + 3 >= static_cast<int>(tiles.size())) return;
52
53 WriteTile8(bg, tile_x, tile_y, tiles[offset]);
54 WriteTile8(bg, tile_x + 1, tile_y, tiles[offset + 1]);
55 WriteTile8(bg, tile_x, tile_y + 1, tiles[offset + 2]);
56 WriteTile8(bg, tile_x + 1, tile_y + 1, tiles[offset + 3]);
57}
58
59void DrawBlock2x4(gfx::BackgroundBuffer& bg, int tile_x, int tile_y,
60 std::span<const gfx::TileInfo> tiles, int offset) {
61 // Draw a 2x4 block (8 tiles) at the given position
62 // Layout: [0][1]
63 // [2][3]
64 // [4][5]
65 // [6][7]
66 if (offset + 7 >= static_cast<int>(tiles.size())) return;
67
68 for (int row = 0; row < 4; row++) {
69 WriteTile8(bg, tile_x, tile_y + row, tiles[offset + row * 2]);
70 WriteTile8(bg, tile_x + 1, tile_y + row, tiles[offset + row * 2 + 1]);
71 }
72}
73
74void DrawBlock4x2(gfx::BackgroundBuffer& bg, int tile_x, int tile_y,
75 std::span<const gfx::TileInfo> tiles, int offset) {
76 // Draw a 4x2 block (8 tiles) at the given position
77 // Layout: [0][1][2][3]
78 // [4][5][6][7]
79 if (offset + 7 >= static_cast<int>(tiles.size())) return;
80
81 for (int col = 0; col < 4; col++) {
82 WriteTile8(bg, tile_x + col, tile_y, tiles[offset + col]);
83 WriteTile8(bg, tile_x + col, tile_y + 1, tiles[offset + 4 + col]);
84 }
85}
86
87void DrawBlock4x4(gfx::BackgroundBuffer& bg, int tile_x, int tile_y,
88 std::span<const gfx::TileInfo> tiles, int offset) {
89 // Draw a 4x4 block (16 tiles) at the given position
90 // Layout: [0 ][1 ][2 ][3 ]
91 // [4 ][5 ][6 ][7 ]
92 // [8 ][9 ][10][11]
93 // [12][13][14][15]
94 if (offset + 15 >= static_cast<int>(tiles.size())) return;
95
96 for (int row = 0; row < 4; row++) {
97 for (int col = 0; col < 4; col++) {
98 WriteTile8(bg, tile_x + col, tile_y + row, tiles[offset + row * 4 + col]);
99 }
100 }
101}
102
103} // namespace DrawRoutineUtils
104} // namespace zelda3
105} // namespace yaze
void SetTileAt(int x, int y, uint16_t value)
SNES 16-bit tile metadata container.
Definition snes_tile.h:52
uint16_t TileInfoToWord(TileInfo tile_info)
Definition snes_tile.cc:361
void DrawBlock2x2(gfx::BackgroundBuffer &bg, int tile_x, int tile_y, std::span< const gfx::TileInfo > tiles, int offset)
Draw a 2x2 block of tiles (16x16 pixels)
void DrawBlock2x4(gfx::BackgroundBuffer &bg, int tile_x, int tile_y, std::span< const gfx::TileInfo > tiles, int offset)
Draw a 2x4 block of tiles (16x32 pixels)
void SetTraceHook(TraceHookFn hook, void *user_data, bool trace_only)
void DrawBlock4x2(gfx::BackgroundBuffer &bg, int tile_x, int tile_y, std::span< const gfx::TileInfo > tiles, int offset)
Draw a 4x2 block of tiles (32x16 pixels)
void(*)(int tile_x, int tile_y, const gfx::TileInfo &tile_info, void *user_data) TraceHookFn
bool IsValidTilePosition(int tile_x, int tile_y)
Check if tile position is within canvas bounds.
void WriteTile8(gfx::BackgroundBuffer &bg, int tile_x, int tile_y, const gfx::TileInfo &tile_info)
Write an 8x8 tile to the background buffer.
void DrawBlock4x4(gfx::BackgroundBuffer &bg, int tile_x, int tile_y, std::span< const gfx::TileInfo > tiles, int offset)
Draw a 4x4 block of tiles (32x32 pixels)