Merge branch 'qutrin/ez-optimisation' into 'master'

Improvement: Replace all '..=b' with '..b + 1'

See merge request veloren/veloren!718
This commit is contained in:
Acrimon 2020-01-12 15:05:45 +00:00
commit 3405d42ef1
9 changed files with 18 additions and 16 deletions

View File

@ -411,7 +411,7 @@ impl Client {
// Request chunks from the server. // Request chunks from the server.
let mut all_loaded = true; let mut all_loaded = true;
'outer: for dist in 0..=view_distance as i32 { 'outer: for dist in 0..(view_distance as i32) + 1 {
// Only iterate through chunks that need to be loaded for circular vd // Only iterate through chunks that need to be loaded for circular vd
// The (dist - 2) explained: // The (dist - 2) explained:
// -0.5 because a chunk is visible if its corner is within the view distance // -0.5 because a chunk is visible if its corner is within the view distance
@ -428,7 +428,7 @@ impl Client {
dist dist
}; };
for i in -top..=top { for i in -top..top + 1 {
let keys = [ let keys = [
chunk_pos + Vec2::new(dist, i), chunk_pos + Vec2::new(dist, i),
chunk_pos + Vec2::new(i, dist), chunk_pos + Vec2::new(i, dist),

View File

@ -372,8 +372,8 @@ pub fn regions_in_vd(pos: Vec3<f32>, vd: f32) -> HashSet<Vec2<i32>> {
let max = RegionMap::pos_key(pos_xy.map(|e| (e + vd_extended) as i32)); let max = RegionMap::pos_key(pos_xy.map(|e| (e + vd_extended) as i32));
let min = RegionMap::pos_key(pos_xy.map(|e| (e - vd_extended) as i32)); let min = RegionMap::pos_key(pos_xy.map(|e| (e - vd_extended) as i32));
for x in min.x..=max.x { for x in min.x..max.x + 1 {
for y in min.y..=max.y { for y in min.y..max.y + 1 {
let key = Vec2::new(x, y); let key = Vec2::new(x, y);
if region_in_vd(key, pos, vd) { if region_in_vd(key, pos, vd) {

View File

@ -110,8 +110,10 @@ impl<'a> System<'a> for Sys {
let hdist = player_rad.ceil() as i32; let hdist = player_rad.ceil() as i32;
let vdist = player_height.ceil() as i32; let vdist = player_height.ceil() as i32;
// Neighbouring blocks iterator // Neighbouring blocks iterator
let near_iter = (-hdist..=hdist) let near_iter = (-hdist..hdist + 1)
.map(move |i| (-hdist..=hdist).map(move |j| (0..=vdist).map(move |k| (i, j, k)))) .map(move |i| {
(-hdist..hdist + 1).map(move |j| (0..vdist + 1).map(move |k| (i, j, k)))
})
.flatten() .flatten()
.flatten(); .flatten();

View File

@ -69,8 +69,8 @@ impl<I: Into<Aabr<i32>>, V: RectRasterableVol + ReadVol + Debug> SampleVol<I> fo
let mut sample = VolGrid2d::new()?; let mut sample = VolGrid2d::new()?;
let chunk_min = Self::chunk_key(range.min); let chunk_min = Self::chunk_key(range.min);
let chunk_max = Self::chunk_key(range.max); let chunk_max = Self::chunk_key(range.max);
for x in chunk_min.x..=chunk_max.x { for x in chunk_min.x..chunk_max.x + 1 {
for y in chunk_min.y..=chunk_max.y { for y in chunk_min.y..chunk_max.y + 1 {
let chunk_key = Vec2::new(x, y); let chunk_key = Vec2::new(x, y);
let chunk = self.get_key_arc(chunk_key).cloned(); let chunk = self.get_key_arc(chunk_key).cloned();

View File

@ -73,9 +73,9 @@ impl<I: Into<Aabb<i32>>, V: RasterableVol + ReadVol + Debug> SampleVol<I> for Vo
let mut sample = VolGrid3d::new()?; let mut sample = VolGrid3d::new()?;
let chunk_min = Self::chunk_key(range.min); let chunk_min = Self::chunk_key(range.min);
let chunk_max = Self::chunk_key(range.max); let chunk_max = Self::chunk_key(range.max);
for x in chunk_min.x..=chunk_max.x { for x in chunk_min.x..chunk_max.x + 1 {
for y in chunk_min.y..=chunk_max.y { for y in chunk_min.y..chunk_max.y + 1 {
for z in chunk_min.z..=chunk_max.z { for z in chunk_min.z..chunk_max.z + 1 {
let chunk_key = Vec3::new(x, y, z); let chunk_key = Vec3::new(x, y, z);
let chunk = self.get_key_arc(chunk_key).cloned(); let chunk = self.get_key_arc(chunk_key).cloned();

View File

@ -132,7 +132,7 @@ impl Server {
// until the first air block is found // until the first air block is found
// (up to max_z + 1, because max_z could still be a soild block) // (up to max_z + 1, because max_z could still be a soild block)
// if no air block is found default to max_z + 1 // if no air block is found default to max_z + 1
let z = (min_z..=max_z + 1) let z = (min_z..(max_z + 1) + 1)
.find(|z| { .find(|z| {
block_sampler block_sampler
.get_with_z_cache( .get_with_z_cache(

View File

@ -51,7 +51,7 @@ impl ClientInit {
let mut last_err = None; let mut last_err = None;
'tries: for _ in 0..=60 { 'tries: for _ in 0..60 + 1 {
// 300 Seconds // 300 Seconds
if cancel2.load(Ordering::Relaxed) { if cancel2.load(Ordering::Relaxed) {
break; break;

View File

@ -454,8 +454,8 @@ impl WorldSim {
_ => {} _ => {}
} */ } */
let pos = uniform_idx_as_vec2(posi); let pos = uniform_idx_as_vec2(posi);
for x in pos.x - 1..=pos.x + 1 { for x in pos.x - 1..(pos.x + 1) + 1 {
for y in pos.y - 1..=pos.y + 1 { for y in pos.y - 1..(pos.y + 1) + 1 {
if x >= 0 && y >= 0 && x < WORLD_SIZE.x as i32 && y < WORLD_SIZE.y as i32 { if x >= 0 && y >= 0 && x < WORLD_SIZE.x as i32 && y < WORLD_SIZE.y as i32 {
let posi = vec2_as_uniform_idx(Vec2::new(x, y)); let posi = vec2_as_uniform_idx(Vec2::new(x, y));
if !is_underwater(posi) { if !is_underwater(posi) {

View File

@ -101,7 +101,7 @@ pub fn cdf_irwin_hall<const N: usize>(weights: &[f32; N], samples: [f32; N]) ->
y /= weights.iter().product::<f32>(); y /= weights.iter().product::<f32>();
// Remember to multiply by 1 / N! at the end. // Remember to multiply by 1 / N! at the end.
y / (1..=N as i32).product::<i32>() as f32 y / (1..(N as i32) + 1).product::<i32>() as f32
} }
/// First component of each element of the vector is the computed CDF of the noise function at this /// First component of each element of the vector is the computed CDF of the noise function at this