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(&bg, 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()))
52 return;
53
54 WriteTile8(bg, tile_x, tile_y, tiles[offset]);
55 WriteTile8(bg, tile_x + 1, tile_y, tiles[offset + 1]);
56 WriteTile8(bg, tile_x, tile_y + 1, tiles[offset + 2]);
57 WriteTile8(bg, tile_x + 1, tile_y + 1, tiles[offset + 3]);
58}
59
60void DrawBlock2x4(gfx::BackgroundBuffer& bg, int tile_x, int tile_y,
61 std::span<const gfx::TileInfo> tiles, int offset) {
62 // Draw a 2x4 block (8 tiles) at the given position
63 // Layout: [0][1]
64 // [2][3]
65 // [4][5]
66 // [6][7]
67 if (offset + 7 >= static_cast<int>(tiles.size()))
68 return;
69
70 for (int row = 0; row < 4; row++) {
71 WriteTile8(bg, tile_x, tile_y + row, tiles[offset + row * 2]);
72 WriteTile8(bg, tile_x + 1, tile_y + row, tiles[offset + row * 2 + 1]);
73 }
74}
75
76void DrawBlock4x2(gfx::BackgroundBuffer& bg, int tile_x, int tile_y,
77 std::span<const gfx::TileInfo> tiles, int offset) {
78 // Draw a 4x2 block (8 tiles) at the given position
79 // Layout: [0][1][2][3]
80 // [4][5][6][7]
81 if (offset + 7 >= static_cast<int>(tiles.size()))
82 return;
83
84 for (int col = 0; col < 4; col++) {
85 WriteTile8(bg, tile_x + col, tile_y, tiles[offset + col]);
86 WriteTile8(bg, tile_x + col, tile_y + 1, tiles[offset + 4 + col]);
87 }
88}
89
90void DrawBlock4x4(gfx::BackgroundBuffer& bg, int tile_x, int tile_y,
91 std::span<const gfx::TileInfo> tiles, int offset) {
92 // Draw a 4x4 block (16 tiles) at the given position
93 // Layout: [0 ][1 ][2 ][3 ]
94 // [4 ][5 ][6 ][7 ]
95 // [8 ][9 ][10][11]
96 // [12][13][14][15]
97 if (offset + 15 >= static_cast<int>(tiles.size()))
98 return;
99
100 for (int row = 0; row < 4; row++) {
101 for (int col = 0; col < 4; col++) {
102 WriteTile8(bg, tile_x + col, tile_y + row, tiles[offset + row * 4 + col]);
103 }
104 }
105}
106
107} // namespace DrawRoutineUtils
108} // namespace zelda3
109} // 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)
bool IsValidTilePosition(int tile_x, int tile_y)
Check if tile position is within canvas bounds.
void(*)(gfx::BackgroundBuffer *bg, int tile_x, int tile_y, const gfx::TileInfo &tile_info, void *user_data) TraceHookFn
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)