diff --git a/include/graphic_utils.h b/include/graphic_utils.h index 70cb379..979e9f5 100644 --- a/include/graphic_utils.h +++ b/include/graphic_utils.h @@ -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 diff --git a/source/game.c b/source/game.c index b972527..fc83856 100644 --- a/source/game.c +++ b/source/game.c @@ -981,7 +981,7 @@ void game_lose_init() { // Using the text color to match the "Game Over" text, another shade of red could work better affine_background_set_color(TEXT_CLR_RED); - + } void init_game_state(enum GameState game_state_to_init) @@ -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 } diff --git a/source/graphic_utils.c b/source/graphic_utils.c index b568442..8c574e0 100644 --- a/source/graphic_utils.c +++ b/source/graphic_utils.c @@ -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); } }