void r_render_update_visible_tiles(void) {
i32 x, y;
- struct u_vec2 t, tt, tl, tb;
+ struct u_vec2 t0, t1, t2, t3;
struct t_camera *c = &t_main_camera;
r_render_state.start_tile.x = t_map.width;
r_render_state.start_tile.y = t_map.height;
+ r_render_state.end_tile.x = 0;
+ r_render_state.end_tile.y = 0;
for (x = 0; x < t_map.width; x++) {
for (y = 0; y < t_map.height; y++) {
- t = t_camera_zoom_vec2(c, u_tile_to_screen(x, y));
- tt = t_camera_zoom_vec2(c, u_tile_to_screen(x+1, y+1));
- tl = t_camera_zoom_vec2(c, u_tile_to_screen(x+2, y));
- tb = t_camera_zoom_vec2(c, u_tile_to_screen(x+2, y-2));
+ t0 = t_camera_zoom_vec2(c, u_tile_to_screen(x, y));
+ t1 = t_camera_zoom_vec2(c, u_tile_to_screen(x+1, y+1));
+ t2 = t_camera_zoom_vec2(c, u_tile_to_screen(x+2, y));
+ t3 = t_camera_zoom_vec2(c, u_tile_to_screen(x+2, y-2));
/* do not draw if tile is not visible at all
* also include a few points outside the camera to avoid tiles
* popping in
*/
- if (t_camera_is_visible_screen(&t_main_camera, t.x, t.y)
- || t_camera_is_visible_screen(&t_main_camera, tt.x, tt.y)
- || t_camera_is_visible_screen(&t_main_camera, tb.x, tb.y)
- || t_camera_is_visible_screen(&t_main_camera, tl.x, tl.y)) {
+ if (t_camera_is_visible_screen(&t_main_camera, t0.x, t0.y)
+ || t_camera_is_visible_screen(&t_main_camera, t1.x, t1.y)
+ || t_camera_is_visible_screen(&t_main_camera, t2.x, t2.y)
+ || t_camera_is_visible_screen(&t_main_camera, t3.x, t3.y)) {
if (r_render_state.end_tile.x < x) {
r_render_state.end_tile.x = x;
}
}
}
+
+ r_render_state.end_tile.x += 1;
+ U_CLAMP(r_render_state.end_tile.x, 0, t_map.width);
}