nightshade-api 0.54.0

Procedural high level API for the nightshade game engine
Documentation
//! Procedural terrain and grass: the engine's GPU clipmap world that tiles out
//! around the camera, and a GPU grass field over it. Both are configured through
//! engine resources, so enabling them is a flag and a few knobs.

use nightshade::prelude::*;

/// Enables the procedural terrain with height `seed`. It renders as a clipmap
/// that follows the camera. Tune amplitude, colors, and the snow line on
/// `world.plugin_resource_mut::<TerrainSettings>()` after enabling.
#[cfg(feature = "terrain")]
pub fn enable_terrain(world: &mut World, seed: u32) {
    let terrain = world.plugin_resource_mut::<TerrainSettings>();
    terrain.enabled = true;
    terrain.seed = seed;
    terrain.revision += 1;
}

/// Turns the procedural terrain off.
#[cfg(feature = "terrain")]
pub fn disable_terrain(world: &mut World) {
    let terrain = world.plugin_resource_mut::<TerrainSettings>();
    terrain.enabled = false;
    terrain.revision += 1;
}

/// Sets the terrain's lowest and highest elevation in world units.
#[cfg(feature = "terrain")]
pub fn set_terrain_height_range(world: &mut World, min: f32, max: f32) {
    let terrain = world.plugin_resource_mut::<TerrainSettings>();
    terrain.height_min = min;
    terrain.height_max = max;
    terrain.revision += 1;
}

/// Sets the elevation above which terrain turns to snow.
#[cfg(feature = "terrain")]
pub fn set_terrain_snow_height(world: &mut World, height: f32) {
    let terrain = world.plugin_resource_mut::<TerrainSettings>();
    terrain.snow_height = height;
    terrain.revision += 1;
}

/// Enables a GPU grass field with a default meadow look. Configure or replace
/// the grass types on the `GrassSettings` resource after enabling.
#[cfg(feature = "grass")]
pub fn enable_grass(world: &mut World) {
    use nightshade::render::grass_config::{GrassDomain, GrassSettings, GrassTypeParams};
    let grass = world.res::<GrassSettings>();
    grass.enabled = true;
    grass.domain = GrassDomain::Infinite;
    if grass.types.is_empty() {
        grass.types = vec![GrassTypeParams::meadow()];
        grass.types_revision += 1;
    }
}

/// Turns the grass field off.
#[cfg(feature = "grass")]
pub fn disable_grass(world: &mut World) {
    world
        .res::<nightshade::render::grass_config::GrassSettings>()
        .enabled = false;
}