use i16 for coordinates instead of isize, yielding better cache locality etc
This commit is contained in:
parent
28213da9f3
commit
42a355d387
3 changed files with 18 additions and 15 deletions
|
@ -2,6 +2,7 @@ use crate::{draw_scaled_texture, Textures};
|
|||
|
||||
use super::tile::*;
|
||||
use super::Pos;
|
||||
use super::PosInt;
|
||||
use raylib::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -73,7 +74,7 @@ impl Board {
|
|||
}
|
||||
|
||||
fn in_bounds(&self, p: Pos) -> bool {
|
||||
p.x >= 0 && p.y >= 0 && p.x < self.width as isize && p.y < self.height as isize
|
||||
p.x >= 0 && p.y >= 0 && p.x < self.width as PosInt && p.y < self.height as PosInt
|
||||
}
|
||||
|
||||
pub fn get(&self, p: Pos) -> Option<Tile> {
|
||||
|
@ -116,11 +117,11 @@ impl Board {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn grow_to_include(&mut self, p: Pos) -> (isize, isize) {
|
||||
pub fn grow_to_include(&mut self, p: Pos) -> (PosInt,PosInt) {
|
||||
let mut offset_x = 0;
|
||||
let mut offset_y = 0;
|
||||
if p.x < 0 {
|
||||
let len = p.x.unsigned_abs();
|
||||
let len = p.x.unsigned_abs() as usize;
|
||||
for row in &mut self.rows {
|
||||
let mut new_row = vec![Tile::Blank; len];
|
||||
new_row.append(row);
|
||||
|
@ -137,7 +138,7 @@ impl Board {
|
|||
}
|
||||
|
||||
if p.y < 0 {
|
||||
let len = p.y.unsigned_abs();
|
||||
let len = p.y.unsigned_abs() as usize;
|
||||
let mut new_rows = vec![vec![Tile::Blank; self.width]; len];
|
||||
new_rows.append(&mut self.rows);
|
||||
self.rows = new_rows;
|
||||
|
@ -148,7 +149,7 @@ impl Board {
|
|||
self.rows.resize(new_height, vec![Tile::Blank; self.width]);
|
||||
self.height = new_height;
|
||||
}
|
||||
(offset_x as isize, offset_y as isize)
|
||||
(offset_x as PosInt, offset_y as PosInt)
|
||||
}
|
||||
|
||||
pub fn trim_size(&mut self, margin: usize) -> (usize, usize) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue