nightshade-api 0.51.0

Procedural high level API for the nightshade game engine
Documentation
// Scalar helpers that round out the built-in arithmetic. Import with:
// import "std/math" as math; then call math::clamp01(x), math::remap(...), etc.
fn clamp01(x) {
    if x < 0.0 { 0.0 } else if x > 1.0 { 1.0 } else { x }
}

fn clamp(x, lo, hi) {
    if x < lo { lo } else if x > hi { hi } else { x }
}

fn sign(x) {
    if x > 0.0 { 1.0 } else if x < 0.0 { -1.0 } else { 0.0 }
}

// Maps x from the input range onto the output range, linearly.
fn remap(x, in_lo, in_hi, out_lo, out_hi) {
    out_lo + (x - in_lo) / (in_hi - in_lo) * (out_hi - out_lo)
}

// Moves current toward target by at most step, without overshooting. Good for
// framerate-independent easing when scaled by dt.
fn approach(current, target, step) {
    if current < target {
        let next = current + step;
        if next > target { target } else { next }
    } else {
        let next = current - step;
        if next < target { target } else { next }
    }
}