From d81218a11496610bc6b7888cdbe1967c0a3e42c3 Mon Sep 17 00:00:00 2001 From: Joshua Yanovski Date: Mon, 20 Jan 2020 02:59:28 +0100 Subject: [PATCH] Fixes to enable loading (relatively) large maps. With these changes, we can successfully open, map, and play maps thare are 16x the size of a standard (1024 x 1024 chunk) map, 4x larger in each direction. --- common/src/net/post.rs | 2 +- common/src/net/post2.rs | 2 +- world/src/sim/erosion.rs | 15 +++++++++++---- world/src/sim/map.rs | 5 ++--- world/src/sim/mod.rs | 19 ++++++++++++++++++- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/common/src/net/post.rs b/common/src/net/post.rs index 8f0eceed1d..2dd7620c05 100644 --- a/common/src/net/post.rs +++ b/common/src/net/post.rs @@ -67,7 +67,7 @@ const SEND_TOK: Token = Token(3); const RECV_TOK: Token = Token(4); const MIDDLEMAN_TOK: Token = Token(5); -const MAX_MSG_BYTES: usize = 1 << 24; +const MAX_MSG_BYTES: usize = 1 << 28; enum CtrlMsg { Shutdown, diff --git a/common/src/net/post2.rs b/common/src/net/post2.rs index 3ed9c5c0cb..e06c8802ff 100644 --- a/common/src/net/post2.rs +++ b/common/src/net/post2.rs @@ -43,7 +43,7 @@ impl From for Error { pub trait PostMsg = Serialize + DeserializeOwned + 'static + Send; -const MAX_MSG_SIZE: usize = 1 << 24; +const MAX_MSG_SIZE: usize = 1 << 28; pub struct PostOffice { listener: TcpListener, diff --git a/world/src/sim/erosion.rs b/world/src/sim/erosion.rs index 12da4b279e..590d917cc9 100644 --- a/world/src/sim/erosion.rs +++ b/world/src/sim/erosion.rs @@ -232,8 +232,8 @@ pub fn get_rivers, G: Float + Into>( let mut rivers = vec![RiverData::default(); WORLD_SIZE.x * WORLD_SIZE.y].into_boxed_slice(); let neighbor_coef = TerrainChunkSize::RECT_SIZE.map(|e| e as f64); // (Roughly) area of a chunk, times minutes per second. - let mins_per_sec = /*64.0*/1.0/*1.0 / 16.0*/; - let chunk_area_factor = neighbor_coef.x * neighbor_coef.y / mins_per_sec; + let mins_per_sec = /*16.0*/1.0/*1.0 / 16.0*//*1.0 / 64.0*/; + let chunk_area_factor = neighbor_coef.x * neighbor_coef.y * mins_per_sec; // NOTE: This technically makes us discontinuous, so we should be cautious about using this. let derivative_divisor = 1.0; let height_scale = 1.0; // 1.0 / CONFIG.mountain_scale as f64; @@ -944,14 +944,21 @@ fn erode( let old_b_i = b[posi]; let sed = (h_t[posi] - old_b_i) as f64; let n = n_f(posi); + // Higher rock strength tends to lead to higher erodibility? + // let max_slope = max_slopes[posi]/*mid_slope*/; + let kd_factor = + 1.0; + // (/*1.0 / */(max_slope / mid_slope/*.sqrt()*//*.powf(0.03125)*/).powf(/*2.0*/2.0/* * m*/))/*.min(kdsed)*/; + let k_fs = kf(posi) / kd_factor; + let k = if sed > sediment_thickness(n) { // Sediment // k_fs - k_fs_mult_sed * kf(posi) + k_fs_mult_sed * k_fs } else { // Bedrock // k_fb - kf(posi) + k_fs } * dt; let n = n as f64; let m = m_f(posi) as f64; diff --git a/world/src/sim/map.rs b/world/src/sim/map.rs index 672de33b93..d43c789f48 100644 --- a/world/src/sim/map.rs +++ b/world/src/sim/map.rs @@ -133,9 +133,8 @@ impl MapConfig { (0..dimensions.y * dimensions.x) .into_iter() .for_each(|chunk_idx| { - let pos = uniform_idx_as_vec2(chunk_idx); - let i = pos.x as usize; - let j = pos.y as usize; + let i = chunk_idx % dimensions.x as usize; + let j = chunk_idx / dimensions.x as usize; let pos = (focus_rect + Vec2::new(i as f64, j as f64) * scale).map(|e: f64| e as i32); diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 97d5e2b3cd..5dbe49791a 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -386,7 +386,7 @@ impl WorldSim { // (0.5^(-(1.0-0.9)))^1/256/32*2^4*256*4 // (2^(-(1.0-0.9)))^4 // 16.0 - .set_frequency(/*0.9*/ /*Fbm*//*HybridMulti_::DEFAULT_FREQUENCY*/1.0 / (2.0/*8.0*//*256.0*//*1.0*//*16.0*/ * TerrainChunkSize::RECT_SIZE.x as f64/*4.0*//* TerrainChunkSize::RECT_SIZE.x as f64 */ * 2.0.powi(10 - 1))) + .set_frequency(/*0.9*/ /*Fbm*//*HybridMulti_::DEFAULT_FREQUENCY*/1.0 * (5_000.0 / continent_scale) / (2.0/*8.0*//*256.0*//*1.0*//*16.0*/ * TerrainChunkSize::RECT_SIZE.x as f64/*4.0*//* TerrainChunkSize::RECT_SIZE.x as f64 */ * 2.0.powi(10 - 1))) // .set_frequency(/*0.9*/ /*Fbm*//*HybridMulti_::DEFAULT_FREQUENCY*/1.0 / (8.0/*8.0*//*256.0*//*1.0*//*16.0*/ * 32.0/*4.0*//* TerrainChunkSize::RECT_SIZE.x as f64 */ * 2.0.powi(10 - 1))) // .set_persistence(/*0.9*/ /*2.0*/0.67) // .set_frequency(/*0.9*/ Fbm::DEFAULT_FREQUENCY / (2.0 * 32.0)) @@ -711,6 +711,7 @@ impl WorldSim { let wposf = (uniform_idx_as_vec2(posi) * TerrainChunkSize::RECT_SIZE.map(|e| e as i32)) .map(|e| e as f64); let turb_wposf = wposf + .mul(5_000.0 / continent_scale) .div(TerrainChunkSize::RECT_SIZE.map(|e| e as f64)) .div(turb_wposf_div); let turb = Vec2::new( @@ -721,6 +722,7 @@ impl WorldSim { // let turb = Vec2::zero(); let turb_wposf = wposf + turb; let turb_wposi = turb_wposf + .div(5_000.0 / continent_scale) .map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as f64) .map2(WORLD_SIZE, |e, f| (e as i32).max(f as i32 - 1).min(0)); let turb_posi = vec2_as_uniform_idx(turb_wposi); @@ -762,6 +764,7 @@ impl WorldSim { None } else { let turb_wposf = wposf + .mul(5_000.0 / continent_scale) .div(TerrainChunkSize::RECT_SIZE.map(|e| e as f64)) .div(turb_wposf_div); let turb = Vec2::new( @@ -772,6 +775,7 @@ impl WorldSim { // let turb = Vec2::zero(); let turb_wposf = wposf + turb; let turb_wposi = turb_wposf + .div(5_000.0 / continent_scale) .map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as f64) .map2(WORLD_SIZE, |e, f| (e as i32).max(f as i32 - 1).min(0)); let turb_posi = vec2_as_uniform_idx(turb_wposi); @@ -918,6 +922,7 @@ impl WorldSim { * TerrainChunkSize::RECT_SIZE.map(|e| e as i32)) .map(|e| e as f64); let turb_wposf = wposf + .mul(5_000.0 / continent_scale) .div(TerrainChunkSize::RECT_SIZE.map(|e| e as f64)) .div(turb_wposf_div); let turb = Vec2::new( @@ -928,6 +933,7 @@ impl WorldSim { // let turb = Vec2::zero(); let turb_wposf = wposf + turb; let turb_wposi = turb_wposf + .div(5_000.0 / continent_scale) .map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as f64) .map2(WORLD_SIZE, |e, f| (e as i32).max(f as i32 - 1).min(0)); let turb_posi = vec2_as_uniform_idx(turb_wposi); @@ -977,6 +983,8 @@ impl WorldSim { // multiplied by height_scale^(2m) to account for change in area. // 2.5e-6/* / time_scale*//* / 4.0 * 0.25 *//* * 4.0*/ 1.0e-6 + // 2.0e-5 // 1.8e-4 to 2.2e-6 + // 1.0e-5 // 9.0e-5 to 1.1e-6 // 2.0e-6 // 2.9e-10 // ((1.0 - uheight) * (5e-5 - 2.9e-10) + 2.9e-10) @@ -1000,6 +1008,7 @@ impl WorldSim { * TerrainChunkSize::RECT_SIZE.map(|e| e as i32)) .map(|e| e as f64); let turb_wposf = wposf + .mul(5_000.0 / continent_scale) .div(TerrainChunkSize::RECT_SIZE.map(|e| e as f64)) .div(turb_wposf_div); let turb = Vec2::new( @@ -1010,6 +1019,7 @@ impl WorldSim { // let turb = Vec2::zero(); let turb_wposf = wposf + turb; let turb_wposi = turb_wposf + .div(5_000.0 / continent_scale) .map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as f64) .map2(WORLD_SIZE, |e, f| (e as i32).max(f as i32 - 1).min(0)); let turb_posi = vec2_as_uniform_idx(turb_wposi); @@ -1053,6 +1063,7 @@ impl WorldSim { let wposf = (uniform_idx_as_vec2(posi) * TerrainChunkSize::RECT_SIZE.map(|e| e as i32)) .map(|e| e as f64); let turb_wposf = wposf + .mul(5_000.0 / continent_scale) .div(TerrainChunkSize::RECT_SIZE.map(|e| e as f64)) .div(turb_wposf_div); let turb = Vec2::new( @@ -1063,6 +1074,7 @@ impl WorldSim { // let turb = Vec2::zero(); let turb_wposf = wposf + turb; let turb_wposi = turb_wposf + .div(5_000.0 / continent_scale) .map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as f64) .map2(WORLD_SIZE, |e, f| (e as i32).max(f as i32 - 1).min(0)); let turb_posi = vec2_as_uniform_idx(turb_wposi); @@ -1149,6 +1161,7 @@ impl WorldSim { let wposf = (uniform_idx_as_vec2(posi) * TerrainChunkSize::RECT_SIZE.map(|e| e as i32)) .map(|e| e as f64); let turb_wposf = wposf + .mul(5_000.0 / continent_scale) .div(TerrainChunkSize::RECT_SIZE.map(|e| e as f64)) .div(turb_wposf_div); let turb = Vec2::new( @@ -1159,6 +1172,7 @@ impl WorldSim { // let turb = Vec2::zero(); let turb_wposf = wposf + turb; let turb_wposi = turb_wposf + .div(5_000.0 / continent_scale) .map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as f64) .map2(WORLD_SIZE, |e, f| (e as i32).max(f as i32 - 1).min(0)); let turb_posi = vec2_as_uniform_idx(turb_wposi); @@ -1230,6 +1244,7 @@ impl WorldSim { let wposf = (uniform_idx_as_vec2(posi) * TerrainChunkSize::RECT_SIZE.map(|e| e as i32)) .map(|e| e as f64); let turb_wposf = wposf + .mul(5_000.0 / continent_scale) .div(TerrainChunkSize::RECT_SIZE.map(|e| e as f64)) .div(turb_wposf_div); let turb = Vec2::new( @@ -1240,6 +1255,7 @@ impl WorldSim { // let turb = Vec2::zero(); let turb_wposf = wposf + turb; let turb_wposi = turb_wposf + .div(5_000.0 / continent_scale) .map2(TerrainChunkSize::RECT_SIZE, |e, f| e / f as f64) .map2(WORLD_SIZE, |e, f| (e as i32).max(f as i32 - 1).min(0)); let turb_posi = vec2_as_uniform_idx(turb_wposi); @@ -1383,6 +1399,7 @@ impl WorldSim { // tan(54/360*2*pi)*32 // let height = 1.0f64; let turb_wposf = wposf + .mul(5_000.0 / continent_scale) .div(TerrainChunkSize::RECT_SIZE.map(|e| e as f64)) .div(turb_wposf_div); let turb = Vec2::new(