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) {
|
pub fn draw(&self, d: &mut RaylibDrawHandle, textures: &Textures, offset: Vector2, zoom: i32) {
|
||||||
let tile_size = 16 << zoom;
|
let tile_size = 16 << zoom;
|
||||||
for x in 0..self.width {
|
|
||||||
for y in 0..self.height {
|
let start_x = (-offset.x as i32) / tile_size + self.offset_x as i32 - 1;
|
||||||
let tile = self.rows[y][x];
|
let tile_width = d.get_screen_width() / tile_size + 2;
|
||||||
let px =
|
let start_y = (-offset.y as i32) / tile_size + self.offset_y as i32 - 1;
|
||||||
(x as i32 - self.offset_x as i32) * tile_size + offset.x as i32 + tile_size / 2;
|
let tile_height = d.get_screen_height() / tile_size + 2;
|
||||||
let py =
|
|
||||||
(y as i32 - self.offset_y as i32) * tile_size + offset.y as i32 + 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());
|
let texture = textures.get(&tile.texture());
|
||||||
d.draw_texture_ex(
|
d.draw_texture_ex(
|
||||||
texture,
|
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,
|
0.0,
|
||||||
(1 << zoom) as f32,
|
(1 << zoom) as f32,
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
|
@ -232,4 +242,5 @@ impl Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue