culled board rendering, much better performance with enormous boards
This commit is contained in:
parent
ae226026dd
commit
b13d7aaf6d
1 changed files with 26 additions and 15 deletions
|
@ -214,17 +214,27 @@ impl Board {
|
|||
|
||||
pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, offset: Vector2, zoom: i32) {
|
||||
let tile_size = 16 << zoom;
|
||||
for x in 0..self.width {
|
||||
for y in 0..self.height {
|
||||
let tile = self.rows[y][x];
|
||||
let px =
|
||||
(x as i32 - self.offset_x as i32) * tile_size + offset.x as i32 + tile_size / 2;
|
||||
let py =
|
||||
(y as i32 - self.offset_y as i32) * tile_size + offset.y as i32 + tile_size / 2;
|
||||
|
||||
let start_x = (-offset.x as i32) / tile_size + self.offset_x as i32 - 1;
|
||||
let tile_width = d.get_screen_width() / tile_size + 2;
|
||||
let start_y = (-offset.y as i32) / tile_size + self.offset_y as i32 - 1;
|
||||
let tile_height = d.get_screen_height() / tile_size + 2;
|
||||
|
||||
for x in start_x..(start_x + tile_width) {
|
||||
for y in start_y..(start_y + tile_height) {
|
||||
if self.in_bounds(Pos {
|
||||
x: x as isize,
|
||||
y: y as isize,
|
||||
}) {
|
||||
let tx = x as usize;
|
||||
let ty = y as usize;
|
||||
let tile = self.rows[ty][tx];
|
||||
let px = (x - self.offset_x as i32) * tile_size + offset.x as i32;
|
||||
let py = (y - self.offset_y as i32) * tile_size + offset.y as i32;
|
||||
let texture = textures.get(&tile.texture());
|
||||
d.draw_texture_ex(
|
||||
texture,
|
||||
Vector2::new((px - tile_size / 2) as f32, (py - tile_size / 2) as f32),
|
||||
Vector2::new(px as f32, py as f32),
|
||||
0.0,
|
||||
(1 << zoom) as f32,
|
||||
Color::WHITE,
|
||||
|
@ -233,3 +243,4 @@ impl Board {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue