1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Simulation-wide typed parameter store.
//!
//! The `environment` module provides [`Environment`]: a named, typed key-value
//! store for parameters that are shared across all agents and systems in a
//! simulation. It is the idiomatic equivalent of FLAME GPU's `Environment`
//! object.
//!
//! ## Typical uses
//!
//! - Interest rates, tax rates, reproduction probabilities
//! - World dimensions, grid resolution, time-step size
//! - Any scalar or small struct that every system needs to read
//!
//! ## Enabling
//!
//! Add `--features environment` to your `cargo` invocation. The module is a
//! strict no-op (zero compile cost) when the feature is absent.
//!
//! ## Quick-start
//!
//! ```text
//! use std::sync::Arc;
//! use syren::environment::{Environment, EnvironmentBuilder, EnvironmentSystem};
//! use syren::{AccessSets, Scheduler, Stage};
//!
//! // 1. Declare parameters.
//! let env: Arc<Environment> = EnvironmentBuilder::new()
//! .register::<f32>("interest_rate", 0.05)
//! .register::<u32>("world_width", 100)
//! .build();
//!
//! // 2. Optionally wrap mutation logic as a schedulable system.
//! let interest_sys = EnvironmentSystem::new(
//! 42u16,
//! "CompoundInterest",
//! AccessSets::default(),
//! Arc::clone(&env),
//! |e, _ecs| {
//! let r: f32 = e.get("interest_rate")?;
//! e.set("interest_rate", r * 1.001)?;
//! Ok(())
//! },
//! );
//!
//! // 3. Register with the scheduler.
//! // scheduler.add_system(Stage::Update, Box::new(interest_sys));
//! ```
//!
//! ## GPU uniform buffers
//!
//! When `--features gpu` is also active, any subset of `Pod` parameters can be
//! packed into a `wgpu` uniform buffer:
//!
//! ```text
//! use syren::environment::uniform::EnvUniformBuffer;
//!
//! let ubuf = EnvUniformBuffer::builder(Arc::clone(&env))
//! .include::<f32>("interest_rate")?
//! .include::<u32>("world_width")?
//! .build();
//! ```
//!
//! ## Design notes
//!
//! * Schema is **frozen** after `EnvironmentBuilder::build()` - no new keys.
//! * Values can be updated at any point via `Environment::set`.
//! * Thread-safe: each key has its own `RwLock`.
//! * Dirty tracking powers GPU upload without full buffer re-scan.
pub use EnvironmentBoundary;
pub use EnvironmentBuilder;
pub use ;
pub use EnvKey;
pub use Environment;
pub use EnvironmentSystem;
pub use ;