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
|
@ -13,7 +13,7 @@ use crate::{
|
|||
level::Level,
|
||||
marble_engine::{
|
||||
board::Board,
|
||||
pos::Pos,
|
||||
pos::{Pos, PosInt},
|
||||
tile::{Direction, GateType, MathOp, MirrorType, PTile, Tile, WireType},
|
||||
Machine,
|
||||
},
|
||||
|
@ -28,7 +28,7 @@ const HEADER_HEIGHT: i32 = 40;
|
|||
const FOOTER_HEIGHT: i32 = 95;
|
||||
const SIDEBAR_WIDTH: i32 = 200 + 32 * 2 + 5 * 4;
|
||||
const MAX_ZOOM_IN: i32 = 3;
|
||||
const BOARD_MARGIN: isize = 3;
|
||||
const BOARD_MARGIN: PosInt = 3;
|
||||
const MAX_SPEED_POWER: u8 = 16;
|
||||
const SPEED_DIGITS: u8 = 5;
|
||||
const MAX_FRAME_TIME_MICROS: u128 = 1_000_000 / 30;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -2,10 +2,12 @@ use std::ops::Add;
|
|||
|
||||
use raylib::prelude::*;
|
||||
|
||||
pub type PosInt = i16;
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq)]
|
||||
pub struct Pos {
|
||||
pub x: isize,
|
||||
pub y: isize,
|
||||
pub x: PosInt,
|
||||
pub y: PosInt,
|
||||
}
|
||||
|
||||
impl Pos {
|
||||
|
@ -34,8 +36,8 @@ impl Pos {
|
|||
impl From<(usize, usize)> for Pos {
|
||||
fn from(value: (usize, usize)) -> Self {
|
||||
Self {
|
||||
x: value.0 as isize,
|
||||
y: value.1 as isize,
|
||||
x: value.0 as PosInt,
|
||||
y: value.1 as PosInt,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,8 +45,8 @@ impl From<(usize, usize)> for Pos {
|
|||
impl From<(i32, i32)> for Pos {
|
||||
fn from(value: (i32, i32)) -> Self {
|
||||
Self {
|
||||
x: value.0 as isize,
|
||||
y: value.1 as isize,
|
||||
x: value.0 as PosInt,
|
||||
y: value.1 as PosInt,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,8 +54,8 @@ impl From<(i32, i32)> for Pos {
|
|||
impl From<Vector2> for Pos {
|
||||
fn from(vec: Vector2) -> Self {
|
||||
Self {
|
||||
x: vec.x as isize,
|
||||
y: vec.y as isize,
|
||||
x: vec.x as PosInt,
|
||||
y: vec.y as PosInt,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue