pub struct WorldConfig {
pub example: String,
pub world_name: String,
pub seed: u64,
pub spawn_position: [f32; 3],
pub load_distance: f32,
pub unload_distance: f32,
pub asteroids: AsteroidConfigToml,
pub lighting: LightingConfig,
pub skybox: SkyboxConfigToml,
}Expand description
Top-level world configuration loaded from world.toml.
Inserted as a Bevy Resource by WorldConfigPlugin during the
Startup schedule. If world.toml is absent or malformed,
WorldConfig::default is used and an error is printed to stderr — no
panic occurs. See the module docs for the full fallback and
application flow.
After loading, call the builder helpers to construct runtime types:
build_asteroid_generator→crate::generator::asteroid::AsteroidGeneratorbuild_skybox_config→crate::skybox::SkyboxConfig
§Field defaults (when world.toml is absent)
| Field | Default |
|---|---|
world_name | "world" |
seed | 42 |
spawn_position | [0.0, 0.0, 0.0] |
load_distance | 150.0 |
unload_distance | 200.0 |
asteroids | see AsteroidConfigToml::default |
lighting | see LightingConfig::default |
skybox | see SkyboxConfigToml::default |
§Example
use voxel_framework::world::WorldConfig;
let config = WorldConfig::from_file("world.toml").unwrap_or_default();
println!("world = {}", config.world_name);
println!("seed = {}", config.seed);Fields§
§example: StringWhich example game to run when launched via examples/voxel.rs.
Recognized values: "basic_world", "minetest". Default: "basic_world".
world_name: StringName of this world, used as the folder under worlds/ for chunk and
player data storage. Default: "world".
Set in the world TOML as world_name = "survival". The framework stores
all data for this world under ./worlds/{world_name}/.
seed: u64Global world seed used for all deterministic generation. Default: 42.
spawn_position: [f32; 3]Player/viewer spawn position in world space as [x, y, z]. Default: [0.0, 0.0, 0.0].
load_distance: f32Radius in world units within which chunks are loaded. Default: 150.0.
Copied into ChunkManager::load_distance by WorldConfigPlugin.
unload_distance: f32Radius in world units beyond which chunks are unloaded. Default: 200.0.
Must be greater than load_distance to
maintain the hysteresis band. Copied into
ChunkManager::unload_distance by WorldConfigPlugin.
asteroids: AsteroidConfigTomlAsteroid generation parameters from the [asteroids] section.
lighting: LightingConfigScene lighting parameters from the [lighting] section.
skybox: SkyboxConfigTomlSkybox configuration from the [skybox] section. Defaults to a
starfield when the section is absent.
Implementations§
Source§impl WorldConfig
impl WorldConfig
Sourcepub fn build_asteroid_generator(&self) -> AsteroidGenerator
pub fn build_asteroid_generator(&self) -> AsteroidGenerator
Constructs an AsteroidGenerator from the [asteroids] configuration.
Bridges the TOML-friendly AsteroidConfigToml (which uses u64 for
the seed and u32 for the count) to the runtime
crate::generator::asteroid::AsteroidConfig type (which uses u32
and usize respectively). The seed is truncated — values above
u32::MAX wrap silently.
Fields not present in AsteroidConfigToml (e.g. noise octaves) are
filled from crate::generator::asteroid::AsteroidConfig::default.
Call this once during startup, typically inside the system that sets up the world generator:
use bevy::prelude::*;
use voxel_framework::world::WorldConfig;
fn setup(config: Res<WorldConfig>) {
let generator = config.build_asteroid_generator();
// hand `generator` to your chunk generation system
}Sourcepub fn build_skybox_config(&self) -> SkyboxConfig
pub fn build_skybox_config(&self) -> SkyboxConfig
Converts SkyboxConfigToml into a SkyboxConfig runtime resource.
"starfield"→SkyboxMode::Starfieldusingstar_countandstar_radius."color"→SkyboxMode::Colorusingbackground_color(falls back to black).- Any other value falls back to the default starfield.
Sourcepub fn world_data_dir(&self) -> String
pub fn world_data_dir(&self) -> String
Returns the base data directory for this world: ./worlds/{world_name}.
All world-specific files (chunks, player data) are stored under this path.
Sourcepub fn from_file(path: &str) -> Result<Self, Box<dyn Error>>
pub fn from_file(path: &str) -> Result<Self, Box<dyn Error>>
Loads a WorldConfig from a TOML file at path.
§Errors
Returns an error in either of these two situations:
- I/O failure — the file does not exist, is not readable, or the process lacks permission to open it.
- Parse failure — the file content is not valid TOML, or a required
top-level field (
seed,spawn_position,load_distance,unload_distance,asteroids,lighting) is missing.
The typical usage pattern is to fall back to Default on any error:
use voxel_framework::world::WorldConfig;
let config = WorldConfig::from_file("world.toml").unwrap_or_default();Sourcepub fn from_toml_str(s: &str) -> Result<Self, Box<dyn Error>>
pub fn from_toml_str(s: &str) -> Result<Self, Box<dyn Error>>
Parses a WorldConfig from a TOML string.
Returns an error if the TOML is invalid or missing required fields.
Sourcepub fn from_world_dir(world_name: &str) -> Self
pub fn from_world_dir(world_name: &str) -> Self
Loads WorldConfig from a world directory’s world.json manifest.
Reads worlds/{world_name}/world.json and extracts the fields that are
stored there (seed, spawn_position, load_distance,
unload_distance). All other fields keep their Default values.
Returns defaults (with world_name set) if the file is missing or
cannot be parsed — no panic occurs.
§Example
use voxel_framework::world::WorldConfig;
// First run: world.json does not exist yet → defaults.
// Subsequent runs: world.json was written by WorldManifestPlugin → loaded.
let config = WorldConfig::from_world_dir("survival");
println!("seed = {}", config.seed);Trait Implementations§
Source§impl Clone for WorldConfig
impl Clone for WorldConfig
Source§impl Debug for WorldConfig
impl Debug for WorldConfig
Source§impl Default for WorldConfig
impl Default for WorldConfig
Source§impl<'de> Deserialize<'de> for WorldConfig
impl<'de> Deserialize<'de> for WorldConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Resource for WorldConfig
Auto Trait Implementations§
impl Forget for WorldConfig
impl Freeze for WorldConfig
impl Move for WorldConfig
impl RefUnwindSafe for WorldConfig
impl Send for WorldConfig
impl Sync for WorldConfig
impl Unpin for WorldConfig
impl UnsafeUnpin for WorldConfig
impl UnwindSafe for WorldConfig
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more