1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! 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;
}