nightshade-api 0.47.0

Procedural high level API for the nightshade game engine
Documentation
//! The OS window and frame timing: title, size, cursor lock, and the per-frame
//! clock. Reads of the clock pair with [`delta_time`](crate::prelude::delta_time)
//! in the input module.

use nightshade::prelude::*;

/// Sets the OS window title.
pub fn set_window_title(world: &mut World, title: &str) {
    world.resources.window.title = title.to_string();
}

/// The window's current viewport size in physical pixels, if the window is up.
pub fn window_size(world: &World) -> Option<(u32, u32)> {
    world.resources.window.cached_viewport_size
}

/// Locks or unlocks the cursor to the window, hiding it while locked. Locking
/// drives mouselook in a first person camera; unlocking frees the cursor for the
/// retained UI and pauses the look. Toggle it to switch between walking and
/// clicking a panel.
pub fn lock_cursor(world: &mut World, locked: bool) {
    set_cursor_locked(world, locked);
    set_cursor_visible(world, !locked);
}

/// Whether the cursor is currently locked to the window.
pub fn cursor_locked(world: &World) -> bool {
    world.resources.window.cursor_locked
}

/// The current frames per second, as the engine measures it.
pub fn frames_per_second(world: &World) -> f32 {
    world.resources.window.timing.frames_per_second
}

/// The number of frames rendered since startup.
pub fn frame_count(world: &World) -> u32 {
    world.resources.window.timing.frame_counter
}

/// Milliseconds elapsed since startup.
pub fn uptime_milliseconds(world: &World) -> u64 {
    world.resources.window.timing.uptime_milliseconds
}

/// Asks the app to exit at the end of the current frame.
pub fn request_exit(world: &mut World) {
    world.resources.window.should_exit = true;
}