nightshade-api 0.45.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.resources.terrain` after enabling.
#[cfg(feature = "terrain")]
pub fn enable_terrain(world: &mut World, seed: u32) {
    world.resources.terrain.enabled = true;
    world.resources.terrain.seed = seed;
    world.resources.terrain.revision += 1;
}

/// Turns the procedural terrain off.
#[cfg(feature = "terrain")]
pub fn disable_terrain(world: &mut World) {
    world.resources.terrain.enabled = false;
    world.resources.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) {
    world.resources.terrain.height_min = min;
    world.resources.terrain.height_max = max;
    world.resources.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) {
    world.resources.terrain.snow_height = height;
    world.resources.terrain.revision += 1;
}

/// Enables a GPU grass field with a default meadow look. Configure or replace
/// the grass types on `world.resources.grass.types` after enabling.
#[cfg(feature = "grass")]
pub fn enable_grass(world: &mut World) {
    use nightshade::ecs::grass::GrassTypeParams;
    world.resources.grass.enabled = true;
    if world.resources.grass.types.is_empty() {
        world.resources.grass.types = vec![GrassTypeParams::meadow()];
        world.resources.grass.types_revision += 1;
    }
}

/// Turns the grass field off.
#[cfg(feature = "grass")]
pub fn disable_grass(world: &mut World) {
    world.resources.grass.enabled = false;
}