proc-relief: drainage global grossier opt-in (regions 4 km, marge 2 km, grille 32 m)
Comblement des grandes cuvettes au-dela de la marge des tuiles, raccord par partition de l unite. Champ drainage_global absent = desactive. atlas_calage: filtre ATLAS_BIOMES, bornes force/pente_min. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
c5b67af2a8
révision
afb622561a
4 fichiers modifiés
+158
-3
Aucun fichier ne correspond à votre recherche
@@ -39,6 +39,7 @@ pub fn params_initiaux(b: BiomeRelief) -> ParamsRelief {
|
||||
glaciaire: None,
|
||||
erosion: ero(20_000, 10, 35.0),
|
||||
combler_cuvettes: true,
|
||||
drainage_global: None,
|
||||
};
|
||||
match b {
|
||||
// 400-2400 m, falaises étagées (Urgonien / Tithonique), hauts plateaux lapiazés
|
||||
|
||||
@@ -30,6 +30,19 @@ pub struct ParamsRelief {
|
||||
/// dolines du karst. Absent des anciens JSON : valeur `true`.
|
||||
#[serde(default = "vrai")]
|
||||
pub combler_cuvettes: bool,
|
||||
/// Drainage global grossier (comblement des grandes cuvettes sur des régions de 4 km
|
||||
/// avec 2 km de marge). Opt-in : absent = désactivé.
|
||||
#[serde(default)]
|
||||
pub drainage_global: Option<DrainageGlobal>,
|
||||
}
|
||||
|
||||
/// Comblement grossier des grandes dépressions (au-delà de la marge des tuiles d'érosion).
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct DrainageGlobal {
|
||||
/// Pente minimale imposée (m par m) dans les zones comblées.
|
||||
pub pente_min: f32,
|
||||
/// 0..1 : part du comblement appliquée (1 = cuvette entièrement comblée).
|
||||
pub force: f32,
|
||||
}
|
||||
|
||||
fn vrai() -> bool {
|
||||
|
||||
@@ -93,12 +93,60 @@ impl TileCache {
|
||||
}
|
||||
}
|
||||
|
||||
/// Régions du drainage global : 4096 m, marge 2048 m, grille de 32 m, raccord 1024 m.
|
||||
pub const REGION_M: f64 = 4096.0;
|
||||
pub const MARGE_REGION_M: f64 = 2048.0;
|
||||
pub const PAS_REGION_M: f64 = 32.0;
|
||||
pub const DEMI_BANDE_REGION_M: f64 = 512.0;
|
||||
pub const N_REGION: usize = ((REGION_M + 2.0 * MARGE_REGION_M) / PAS_REGION_M) as usize + 1;
|
||||
|
||||
/// Comblement grossier d'une région élargie (comblé − brut, N_REGION², m).
|
||||
type DeltaRegion = Arc<Vec<f32>>;
|
||||
|
||||
/// Cache des régions de drainage (petit, une entrée = 260 Ko).
|
||||
pub struct RegionCache {
|
||||
m: Mutex<HashMap<(i32, i32), (Arc<OnceLock<DeltaRegion>>, u64)>>,
|
||||
horloge: AtomicU64,
|
||||
}
|
||||
|
||||
impl RegionCache {
|
||||
fn new() -> Self {
|
||||
RegionCache { m: Mutex::new(HashMap::new()), horloge: AtomicU64::new(0) }
|
||||
}
|
||||
fn get_or_gen(&self, k: (i32, i32), f: impl FnOnce() -> Vec<f32>) -> DeltaRegion {
|
||||
let t = self.horloge.fetch_add(1, Ordering::Relaxed);
|
||||
let cell = {
|
||||
let mut m = self.m.lock().unwrap();
|
||||
let c = {
|
||||
let e = m.entry(k).or_insert_with(|| (Arc::new(OnceLock::new()), t));
|
||||
e.1 = t;
|
||||
e.0.clone()
|
||||
};
|
||||
if m.len() > 64 {
|
||||
if let Some(vieux) = m.iter().filter(|(k2, _)| **k2 != k).min_by_key(|(_, v)| v.1).map(|(k2, _)| *k2) {
|
||||
m.remove(&vieux);
|
||||
}
|
||||
}
|
||||
c
|
||||
};
|
||||
cell.get_or_init(|| Arc::new(f())).clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn trapeze_region(l: f64) -> f64 {
|
||||
let b = DEMI_BANDE_REGION_M;
|
||||
((l + b) / (2.0 * b)).clamp(0.0, 1.0) * ((REGION_M + b - l) / (2.0 * b)).clamp(0.0, 1.0)
|
||||
}
|
||||
|
||||
/// Générateur complet : carte de poids + paramètres par biome + graine + cache.
|
||||
pub struct Generateur {
|
||||
pub seed: u64,
|
||||
pub monde: Arc<dyn SourcePoids>,
|
||||
pub params: Vec<ParamsRelief>,
|
||||
pub cache: TileCache,
|
||||
pub regions: RegionCache,
|
||||
drainage_actif: bool,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -110,7 +158,8 @@ fn trapeze(l: f64) -> f64 {
|
||||
impl Generateur {
|
||||
pub fn new(seed: u64, monde: Arc<dyn SourcePoids>, params: Vec<ParamsRelief>) -> Self {
|
||||
assert_eq!(params.len(), BiomeRelief::TOUS.len());
|
||||
Generateur { seed, monde, params, cache: TileCache::new(256) }
|
||||
let drainage_actif = params.iter().any(|p| p.drainage_global.is_some());
|
||||
Generateur { seed, monde, params, cache: TileCache::new(256), regions: RegionCache::new(), drainage_actif }
|
||||
}
|
||||
|
||||
pub fn biome_unique(seed: u64, b: BiomeRelief) -> Self {
|
||||
@@ -121,7 +170,91 @@ impl Generateur {
|
||||
#[inline]
|
||||
pub fn brut(&self, x: f64, z: f64, lod_m: f32) -> f32 {
|
||||
let w = self.monde.poids(x, z);
|
||||
self.brut_poids(&w, x, z, lod_m)
|
||||
let h = self.brut_poids(&w, x, z, lod_m);
|
||||
if !self.drainage_actif {
|
||||
return h;
|
||||
}
|
||||
h + self.drainage_poids(&w, x, z)
|
||||
}
|
||||
|
||||
/// Comblement grossier en (x, z), pondéré par les biomes qui le demandent.
|
||||
fn drainage_poids(&self, w: &PoidsBiomes, x: f64, z: f64) -> f32 {
|
||||
let (mut f, mut s) = (0.0f32, 0.0f32);
|
||||
for &(b, p) in &w.b {
|
||||
if p > 0.0 {
|
||||
s += p;
|
||||
if let Some(d) = self.params[b.index()].drainage_global {
|
||||
f += p * d.force;
|
||||
}
|
||||
}
|
||||
}
|
||||
if f <= 0.0 {
|
||||
return 0.0;
|
||||
}
|
||||
(f / s.max(1e-6)) * self.drainage(x, z)
|
||||
}
|
||||
|
||||
/// Pente minimale du comblement grossier : moyenne des biomes qui le demandent au centre de la région.
|
||||
fn pente_region(&self, rx: i32, rz: i32) -> f32 {
|
||||
let w = self.monde.poids((rx as f64 + 0.5) * REGION_M, (rz as f64 + 0.5) * REGION_M);
|
||||
let (mut e, mut s) = (0.0f32, 0.0f32);
|
||||
for &(b, p) in &w.b {
|
||||
if let (true, Some(d)) = (p > 0.0, self.params[b.index()].drainage_global) {
|
||||
e += p * d.pente_min;
|
||||
s += p;
|
||||
}
|
||||
}
|
||||
if s > 0.0 { e / s } else { 0.002 }
|
||||
}
|
||||
|
||||
/// Calcule le comblement grossier d'une région élargie (brut sans drainage, détail 64 m).
|
||||
fn delta_region(&self, rx: i32, rz: i32) -> Vec<f32> {
|
||||
let n = N_REGION;
|
||||
let ox = rx as f64 * REGION_M - MARGE_REGION_M;
|
||||
let oz = rz as f64 * REGION_M - MARGE_REGION_M;
|
||||
let mut h = vec![0.0f32; n * n];
|
||||
for j in 0..n {
|
||||
let z = oz + j as f64 * PAS_REGION_M;
|
||||
for i in 0..n {
|
||||
let x = ox + i as f64 * PAS_REGION_M;
|
||||
let w = self.monde.poids(x, z);
|
||||
h[j * n + i] = self.brut_poids(&w, x, z, 2.0 * PAS_REGION_M as f32);
|
||||
}
|
||||
}
|
||||
let brut = h.clone();
|
||||
let eps = self.pente_region(rx, rz) * PAS_REGION_M as f32;
|
||||
erosion::combler_cuvettes(&mut h, n, eps, 0.0);
|
||||
h.iter().zip(&brut).map(|(a, b)| a - b).collect()
|
||||
}
|
||||
|
||||
/// Comblement grossier raccordé (partition de l'unité sur les régions).
|
||||
pub fn drainage(&self, x: f64, z: f64) -> f32 {
|
||||
let b = DEMI_BANDE_REGION_M;
|
||||
let (rx0, rx1) = (((x - b) / REGION_M).floor() as i32, ((x + b) / REGION_M).floor() as i32);
|
||||
let (rz0, rz1) = (((z - b) / REGION_M).floor() as i32, ((z + b) / REGION_M).floor() as i32);
|
||||
let mut c = 0.0f32;
|
||||
for rz in rz0..=rz1 {
|
||||
let wz = trapeze_region(z - rz as f64 * REGION_M);
|
||||
if wz <= 0.0 {
|
||||
continue;
|
||||
}
|
||||
for rx in rx0..=rx1 {
|
||||
let wx = trapeze_region(x - rx as f64 * REGION_M);
|
||||
if wx <= 0.0 {
|
||||
continue;
|
||||
}
|
||||
let d = self.regions.get_or_gen((rx, rz), || self.delta_region(rx, rz));
|
||||
let n = N_REGION;
|
||||
let gx = ((x - (rx as f64 * REGION_M - MARGE_REGION_M)) / PAS_REGION_M).clamp(0.0, (n - 1) as f64 - 1e-6);
|
||||
let gz = ((z - (rz as f64 * REGION_M - MARGE_REGION_M)) / PAS_REGION_M).clamp(0.0, (n - 1) as f64 - 1e-6);
|
||||
let (ix, iz) = (gx as usize, gz as usize);
|
||||
let (fx, fz) = ((gx - ix as f64) as f32, (gz - iz as f64) as f32);
|
||||
let i = iz * n + ix;
|
||||
let v = d[i] * (1.0 - fx) * (1.0 - fz) + d[i + 1] * fx * (1.0 - fz) + d[i + n] * (1.0 - fx) * fz + d[i + n + 1] * fx * fz;
|
||||
c += (wx * wz) as f32 * v;
|
||||
}
|
||||
}
|
||||
c
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur