From b69020b68edc3d9ba0e0c9254391ddfd5844dcbf Mon Sep 17 00:00:00 2001 From: Joshua Yanovski Date: Fri, 23 Aug 2019 01:08:47 +0200 Subject: [PATCH 1/2] Fine, removing box syntax. --- world/src/lib.rs | 1 - world/src/sim/util.rs | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/world/src/lib.rs b/world/src/lib.rs index 65a0283e75..5a58627c9c 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -1,6 +1,5 @@ #![deny(unsafe_code)] #![feature( - box_syntax, const_generics, euclidean_division, bind_by_move_pattern_guards, diff --git a/world/src/sim/util.rs b/world/src/sim/util.rs index 2c90a2e659..4e27ee20a4 100644 --- a/world/src/sim/util.rs +++ b/world/src/sim/util.rs @@ -92,7 +92,9 @@ pub fn cdf_irwin_hall(weights: &[f32; N], samples: [f32; N]) -> /// index (i.e. its position in a sorted list of value returned by the noise function applied to /// every chunk in the game). Second component is the cached value of the noise function that /// generated the index. -pub type InverseCdf = Box<[(f32, f32); WORLD_SIZE.x * WORLD_SIZE.y]>; +/// +/// NOTE: Length should always be WORLD_SIZE.x * WORLD_SIZE.y. +pub type InverseCdf = Box<[(f32, f32)]>; /// Computes the position Vec2 of a SimChunk from an index, where the index was generated by /// uniform_noise. @@ -156,7 +158,7 @@ pub fn uniform_noise(f: impl Fn(usize, Vec2) -> f32) -> InverseCdf { // NOTE: Currently there doesn't seem to be a way to create a large fixed-size // array on the heap without overflowing the stack unless you use placement box (at least on // debug mode). So I want to keep using this until a better alternative is made available. - let mut uniform_noise = box [(0.0, 0.0); WORLD_SIZE.x * WORLD_SIZE.y]; + let mut uniform_noise = vec![(0.0, 0.0); WORLD_SIZE.x * WORLD_SIZE.y].into_boxed_slice(); let total = (WORLD_SIZE.x * WORLD_SIZE.y) as f32; for (noise_idx, (chunk_idx, noise_val)) in noise.into_iter().enumerate() { uniform_noise[chunk_idx] = ((1 + noise_idx) as f32 / total, noise_val); From f687c591ca8ba89aea15565d5a8979af87e33350 Mon Sep 17 00:00:00 2001 From: Joshua Yanovski Date: Fri, 23 Aug 2019 01:16:15 +0200 Subject: [PATCH 2/2] Remove out of date comment. --- world/src/sim/util.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/world/src/sim/util.rs b/world/src/sim/util.rs index 4e27ee20a4..9b6da7a41d 100644 --- a/world/src/sim/util.rs +++ b/world/src/sim/util.rs @@ -154,10 +154,6 @@ pub fn uniform_noise(f: impl Fn(usize, Vec2) -> f32) -> InverseCdf { // Construct a vector that associates each chunk position with the 1-indexed // position of the noise in the sorted vector (divided by the vector length). // This guarantees a uniform distribution among the samples. - // - // NOTE: Currently there doesn't seem to be a way to create a large fixed-size - // array on the heap without overflowing the stack unless you use placement box (at least on - // debug mode). So I want to keep using this until a better alternative is made available. let mut uniform_noise = vec![(0.0, 0.0); WORLD_SIZE.x * WORLD_SIZE.y].into_boxed_slice(); let total = (WORLD_SIZE.x * WORLD_SIZE.y) as f32; for (noise_idx, (chunk_idx, noise_val)) in noise.into_iter().enumerate() {