Skip to main content

WorldConfig

Struct WorldConfig 

Source
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:

§Field defaults (when world.toml is absent)

FieldDefault
world_name"world"
seed42
spawn_position[0.0, 0.0, 0.0]
load_distance150.0
unload_distance200.0
asteroidssee AsteroidConfigToml::default
lightingsee LightingConfig::default
skyboxsee 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: String

Which example game to run when launched via examples/voxel.rs.

Recognized values: "basic_world", "minetest". Default: "basic_world".

§world_name: String

Name 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: u64

Global 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: f32

Radius in world units within which chunks are loaded. Default: 150.0.

Copied into ChunkManager::load_distance by WorldConfigPlugin.

§unload_distance: f32

Radius 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: AsteroidConfigToml

Asteroid generation parameters from the [asteroids] section.

§lighting: LightingConfig

Scene lighting parameters from the [lighting] section.

§skybox: SkyboxConfigToml

Skybox configuration from the [skybox] section. Defaults to a starfield when the section is absent.

Implementations§

Source§

impl WorldConfig

Source

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
}
Source

pub fn build_skybox_config(&self) -> SkyboxConfig

Converts SkyboxConfigToml into a SkyboxConfig runtime resource.

  • "starfield" → SkyboxMode::Starfield using star_count and star_radius.
  • "color" → SkyboxMode::Color using background_color (falls back to black).
  • Any other value falls back to the default starfield.
Source

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.

Source

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();
Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WorldConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WorldConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for WorldConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Resource for WorldConfig
where Self: Send + Sync + 'static,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more