graphic_utils refactors - renamed functions, optimized some code, used Tonc defines

This commit is contained in:
MeirGavish
2025-08-19 18:33:47 +03:00
parent 065d846ac7
commit 5a70b002a9
3 changed files with 18 additions and 20 deletions
+4 -4
View File
@@ -68,11 +68,11 @@
// When making this, missed that it already exists in tonc_math.h
typedef RECT Rect;
/* Gets the screenblock tile for the given coordinates (x, y).
/* Gets the screenblock entry for the given coordinates (x, y).
* x and y are in number of tiles.
* Returns the screenblock tile.
* Returns the screenblock entry.
*/
u16 main_bg_se_get_tile(BG_POINT pos);
SE main_bg_se_get_se(BG_POINT pos);
INLINE int rect_width(const Rect* rect)
{
@@ -108,7 +108,7 @@ void main_bg_se_copy_rect(Rect se_rect, BG_POINT pos);
* se_rect dimensions are in number of tiles.
* The tile is copied to the top left corner of the rect.
*/
void main_bg_se_copy_tile_to_rect(u16 tile, Rect se_rect);
void main_bg_se_fill_rect_with_se(u16 tile, Rect se_rect);
/* Moves a rect in the main background vertically in direction by a single tile.
* Note that tiles in the previous location will be transparent (0x000)
* so maybe copy would be a better choice if you don't want to delete things
+3 -3
View File
@@ -2127,15 +2127,15 @@ void game_round_end()
Rect top_rect = {11, 8, 22, 8};
BG_POINT top_point = {6, 29};
main_bg_se_copy_tile_to_rect(main_bg_se_get_tile(top_point), top_rect);
main_bg_se_fill_rect_with_se(main_bg_se_get_se(top_point), top_rect);
Rect middle_rect = {11, 9, 22, 9};
BG_POINT middle_point = {6, 30};
main_bg_se_copy_tile_to_rect(main_bg_se_get_tile(middle_point), middle_rect);
main_bg_se_fill_rect_with_se(main_bg_se_get_se(middle_point), middle_rect);
Rect bottom_rect = {11, 10, 22, 10};
BG_POINT bottom_point = {6, 31};
main_bg_se_copy_tile_to_rect(main_bg_se_get_tile(bottom_point), bottom_rect);
main_bg_se_fill_rect_with_se(main_bg_se_get_se(bottom_point), bottom_rect);
tte_printf("#{P:%d, %d; cx:0x%X000}Cash Out: $%d", CASHOUT_RECT.left, CASHOUT_RECT.top, TTE_WHITE_PB, hands + blind_get_reward(current_blind)); // Print the cash out amount
}
+9 -11
View File
@@ -24,7 +24,7 @@ static void clip_se_rect_to_screenblock(Rect* rect)
clip_se_rect_to_bounding_rect(rect, &FULL_SCREENBLOCK_RECT);
}
u16 main_bg_se_get_tile(BG_POINT pos)
SE main_bg_se_get_se(BG_POINT pos)
{
return se_mat[MAIN_BG_SBB][pos.y][pos.x];
}
@@ -108,20 +108,18 @@ void main_bg_se_copy_rect(Rect se_rect, BG_POINT pos)
int width = rect_width(&se_rect);
int height = rect_height(&se_rect);
u16 tile_map[height][width];
SE tile_map[height][width];
// Copy the rect to the tile map
for (int sy = 0; sy < height; sy++)
{
for (int sx = 0; sx < width; sx++)
{
BG_POINT pt;
pt.x = se_rect.left + sx;
pt.y = se_rect.top + sy;
tile_map[sy][sx] = main_bg_se_get_tile(pt);
}
memcpy16(&tile_map[sy][0],
&se_mat[MAIN_BG_SBB][se_rect.top + sy][se_rect.left],
width);
}
// TODO: Avoid overflow
// Copy the tilemap to the new rect position
for (int sy = 0; sy < height; sy++)
{
memcpy16(&se_mat[MAIN_BG_SBB][pos.y + sy][pos.x],
@@ -130,7 +128,7 @@ void main_bg_se_copy_rect(Rect se_rect, BG_POINT pos)
}
}
void main_bg_se_copy_tile_to_rect(u16 tile, Rect se_rect)
void main_bg_se_fill_rect_with_se(SE se, Rect se_rect)
{
if (se_rect.left > se_rect.right || se_rect.top > se_rect.bottom)
return;
@@ -143,7 +141,7 @@ void main_bg_se_copy_tile_to_rect(u16 tile, Rect se_rect)
for (int sy = 0; sy < height; sy++)
{
memset16(&se_mat[MAIN_BG_SBB][se_rect.top + sy][se_rect.left], tile, width);
memset16(&se_mat[MAIN_BG_SBB][se_rect.top + sy][se_rect.left], se, width);
}
}