mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added ability to toggle world features
This commit is contained in:
12
assets/world/features.ron
Normal file
12
assets/world/features.ron
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#![enable(unwrap_newtypes)]
|
||||||
|
#![enable(implicit_some)]
|
||||||
|
|
||||||
|
(
|
||||||
|
caverns: false, // TODO: Disabled by default until cave overhaul
|
||||||
|
caves: true,
|
||||||
|
shrubs: true,
|
||||||
|
trees: true,
|
||||||
|
scatter: true,
|
||||||
|
paths: true,
|
||||||
|
spots: true,
|
||||||
|
)
|
@ -851,7 +851,7 @@ impl Server {
|
|||||||
let ecs = self.state.ecs_mut();
|
let ecs = self.state.ecs_mut();
|
||||||
let slow_jobs = ecs.write_resource::<SlowJobPool>();
|
let slow_jobs = ecs.write_resource::<SlowJobPool>();
|
||||||
|
|
||||||
index.reload_colors_if_changed(|index| {
|
index.reload_if_changed(|index| {
|
||||||
let mut chunk_generator = ecs.write_resource::<ChunkGenerator>();
|
let mut chunk_generator = ecs.write_resource::<ChunkGenerator>();
|
||||||
let client = ecs.read_storage::<Client>();
|
let client = ecs.read_storage::<Client>();
|
||||||
let mut terrain = ecs.write_resource::<common::terrain::TerrainGrid>();
|
let mut terrain = ecs.write_resource::<common::terrain::TerrainGrid>();
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
use common::assets;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub sea_level: f32,
|
pub sea_level: f32,
|
||||||
pub mountain_scale: f32,
|
pub mountain_scale: f32,
|
||||||
@ -69,3 +72,20 @@ pub const CONFIG: Config = Config {
|
|||||||
river_min_height: 0.25,
|
river_min_height: 0.25,
|
||||||
river_width_to_depth: 8.0,
|
river_width_to_depth: 8.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct Features {
|
||||||
|
pub caverns: bool,
|
||||||
|
pub caves: bool,
|
||||||
|
pub shrubs: bool,
|
||||||
|
pub trees: bool,
|
||||||
|
pub scatter: bool,
|
||||||
|
pub paths: bool,
|
||||||
|
pub spots: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl assets::Asset for Features {
|
||||||
|
type Loader = assets::RonLoader;
|
||||||
|
|
||||||
|
const EXTENSION: &'static str = "ron";
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
layer::wildlife::{self, DensityFn, SpawnEntry},
|
layer::wildlife::{self, DensityFn, SpawnEntry},
|
||||||
site::{economy::TradeInformation, Site},
|
site::{economy::TradeInformation, Site},
|
||||||
Colors,
|
Colors, Features,
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
assets::{AssetExt, AssetHandle},
|
assets::{AssetExt, AssetHandle},
|
||||||
@ -13,6 +13,7 @@ use noise::{Seedable, SuperSimplex};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
const WORLD_COLORS_MANIFEST: &str = "world.style.colors";
|
const WORLD_COLORS_MANIFEST: &str = "world.style.colors";
|
||||||
|
const WORLD_FEATURES_MANIFEST: &str = "world.features";
|
||||||
|
|
||||||
pub struct Index {
|
pub struct Index {
|
||||||
pub seed: u32,
|
pub seed: u32,
|
||||||
@ -22,6 +23,7 @@ pub struct Index {
|
|||||||
pub trade: TradeInformation,
|
pub trade: TradeInformation,
|
||||||
pub wildlife_spawns: Vec<(AssetHandle<SpawnEntry>, DensityFn)>,
|
pub wildlife_spawns: Vec<(AssetHandle<SpawnEntry>, DensityFn)>,
|
||||||
colors: AssetHandle<Arc<Colors>>,
|
colors: AssetHandle<Arc<Colors>>,
|
||||||
|
features: AssetHandle<Arc<Features>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An owned reference to indexed data.
|
/// An owned reference to indexed data.
|
||||||
@ -32,6 +34,7 @@ pub struct Index {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct IndexOwned {
|
pub struct IndexOwned {
|
||||||
colors: Arc<Colors>,
|
colors: Arc<Colors>,
|
||||||
|
features: Arc<Features>,
|
||||||
index: Arc<Index>,
|
index: Arc<Index>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +50,7 @@ impl Deref for IndexOwned {
|
|||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct IndexRef<'a> {
|
pub struct IndexRef<'a> {
|
||||||
pub colors: &'a Colors,
|
pub colors: &'a Colors,
|
||||||
|
pub features: &'a Features,
|
||||||
pub index: &'a Index,
|
pub index: &'a Index,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +64,7 @@ impl Index {
|
|||||||
/// NOTE: Panics if the color manifest cannot be loaded.
|
/// NOTE: Panics if the color manifest cannot be loaded.
|
||||||
pub fn new(seed: u32) -> Self {
|
pub fn new(seed: u32) -> Self {
|
||||||
let colors = Arc::<Colors>::load_expect(WORLD_COLORS_MANIFEST);
|
let colors = Arc::<Colors>::load_expect(WORLD_COLORS_MANIFEST);
|
||||||
|
let features = Arc::<Features>::load_expect(WORLD_FEATURES_MANIFEST);
|
||||||
let wildlife_spawns = wildlife::spawn_manifest()
|
let wildlife_spawns = wildlife::spawn_manifest()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(e, f)| (SpawnEntry::load_expect(e), f))
|
.map(|(e, f)| (SpawnEntry::load_expect(e), f))
|
||||||
@ -73,6 +78,7 @@ impl Index {
|
|||||||
trade: Default::default(),
|
trade: Default::default(),
|
||||||
wildlife_spawns,
|
wildlife_spawns,
|
||||||
colors,
|
colors,
|
||||||
|
features,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,10 +95,12 @@ impl Index {
|
|||||||
impl IndexOwned {
|
impl IndexOwned {
|
||||||
pub fn new(index: Index) -> Self {
|
pub fn new(index: Index) -> Self {
|
||||||
let colors = index.colors.cloned();
|
let colors = index.colors.cloned();
|
||||||
|
let features = index.features.cloned();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
index: Arc::new(index),
|
index: Arc::new(index),
|
||||||
colors,
|
colors,
|
||||||
|
features,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,13 +111,12 @@ impl IndexOwned {
|
|||||||
/// solution.
|
/// solution.
|
||||||
///
|
///
|
||||||
/// Ideally, this should be called about once per tick.
|
/// Ideally, this should be called about once per tick.
|
||||||
pub fn reload_colors_if_changed<R>(
|
pub fn reload_if_changed<R>(&mut self, reload: impl FnOnce(&mut Self) -> R) -> Option<R> {
|
||||||
&mut self,
|
let reloaded = self.index.colors.reloaded_global() || self.index.features.reloaded_global();
|
||||||
reload: impl FnOnce(&mut Self) -> R,
|
reloaded.then(move || {
|
||||||
) -> Option<R> {
|
// Reload the fields from the asset handle, which is updated automatically
|
||||||
self.index.colors.reloaded_global().then(move || {
|
|
||||||
// Reload the color from the asset handle, which is updated automatically
|
|
||||||
self.colors = self.index.colors.cloned();
|
self.colors = self.index.colors.cloned();
|
||||||
|
self.features = self.index.features.cloned();
|
||||||
reload(self)
|
reload(self)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -117,6 +124,7 @@ impl IndexOwned {
|
|||||||
pub fn as_index_ref(&self) -> IndexRef {
|
pub fn as_index_ref(&self) -> IndexRef {
|
||||||
IndexRef {
|
IndexRef {
|
||||||
colors: &self.colors,
|
colors: &self.colors,
|
||||||
|
features: &self.features,
|
||||||
index: &self.index,
|
index: &self.index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ pub mod util;
|
|||||||
// Reexports
|
// Reexports
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
canvas::{Canvas, CanvasInfo},
|
canvas::{Canvas, CanvasInfo},
|
||||||
config::CONFIG,
|
config::{Features, CONFIG},
|
||||||
land::Land,
|
land::Land,
|
||||||
};
|
};
|
||||||
pub use block::BlockGen;
|
pub use block::BlockGen;
|
||||||
@ -347,13 +347,27 @@ impl World {
|
|||||||
entities: Vec::new(),
|
entities: Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if index.features.caverns {
|
||||||
layer::apply_caverns_to(&mut canvas, &mut dynamic_rng);
|
layer::apply_caverns_to(&mut canvas, &mut dynamic_rng);
|
||||||
|
}
|
||||||
|
if index.features.caves {
|
||||||
layer::apply_caves_to(&mut canvas, &mut dynamic_rng);
|
layer::apply_caves_to(&mut canvas, &mut dynamic_rng);
|
||||||
|
}
|
||||||
|
if index.features.shrubs {
|
||||||
layer::apply_shrubs_to(&mut canvas, &mut dynamic_rng);
|
layer::apply_shrubs_to(&mut canvas, &mut dynamic_rng);
|
||||||
|
}
|
||||||
|
if index.features.trees {
|
||||||
layer::apply_trees_to(&mut canvas, &mut dynamic_rng);
|
layer::apply_trees_to(&mut canvas, &mut dynamic_rng);
|
||||||
|
}
|
||||||
|
if index.features.scatter {
|
||||||
layer::apply_scatter_to(&mut canvas, &mut dynamic_rng);
|
layer::apply_scatter_to(&mut canvas, &mut dynamic_rng);
|
||||||
|
}
|
||||||
|
if index.features.paths {
|
||||||
layer::apply_paths_to(&mut canvas);
|
layer::apply_paths_to(&mut canvas);
|
||||||
|
}
|
||||||
|
if index.features.spots {
|
||||||
layer::apply_spots_to(&mut canvas, &mut dynamic_rng);
|
layer::apply_spots_to(&mut canvas, &mut dynamic_rng);
|
||||||
|
}
|
||||||
// layer::apply_coral_to(&mut canvas);
|
// layer::apply_coral_to(&mut canvas);
|
||||||
|
|
||||||
// Apply site generation
|
// Apply site generation
|
||||||
|
Reference in New Issue
Block a user