nightshade_api/lib.rs
1//! # nightshade-api
2//!
3//! A procedural high level API over the nightshade engine. Write a full 3d
4//! scene or a small game as straight-line code with free functions and plain
5//! data. No trait to implement, no callbacks to wire up, no ECS knowledge
6//! required to get started.
7//!
8//! A spinning cube is the whole pitch:
9//!
10//! ```ignore
11//! use nightshade_api::prelude::*;
12//!
13//! fn main() {
14//! let mut app = open();
15//! let cube = spawn_cube(&mut app.world, vec3(0.0, 0.5, 0.0));
16//! while frame(&mut app) {
17//! let step = delta_time(&app.world);
18//! rotate(&mut app.world, cube, Vec3::y(), step);
19//! }
20//! }
21//! ```
22//!
23//! Add to Cargo.toml:
24//!
25//! ```toml
26//! nightshade-api = "0.40"
27//! ```
28//!
29//! ## What you get for free
30//!
31//! [`prelude::open`] gives you a window with a sky, a sun with shadows, a
32//! reference grid, an orbit camera focused on the origin, prototype textures
33//! like `"checkerboard"`, and escape to exit. Every program starts from a lit,
34//! navigable scene. Override any of it with one call: [`prelude::set_background`],
35//! [`prelude::show_grid`], [`prelude::fly_camera`], [`prelude::set_sun`].
36//!
37//! ## The two entry points
38//!
39//! Own the loop (native only). Setup is ordinary code before the loop, state
40//! is ordinary locals across loop iterations:
41//!
42//! ```ignore
43//! let mut app = open();
44//! let mut score = 0;
45//! while frame(&mut app) {
46//! score += 1;
47//! }
48//! ```
49//!
50//! Or hand the engine the loop with [`prelude::run`], which also works on
51//! wasm. Setup returns your state, the update closure receives it back every
52//! frame:
53//!
54//! ```ignore
55//! run(
56//! |world| spawn_cube(world, vec3(0.0, 0.5, 0.0)),
57//! |world, cube| {
58//! let step = delta_time(world);
59//! rotate(world, *cube, Vec3::y(), step);
60//! },
61//! )
62//! .unwrap();
63//! ```
64//!
65//! ## Vocabulary
66//!
67//! Two verbs carry the lifetime rules. `spawn_` is retained: the thing exists
68//! until you [`prelude::despawn`] it. `draw_` is immediate: visible for
69//! exactly one frame, redraw it every frame you want it on screen.
70//!
71//! - Scene content: [`prelude::spawn_cube`], [`prelude::spawn_sphere`],
72//! [`prelude::spawn_floor`], [`prelude::spawn_model`], [`prelude::spawn_object`]
73//! - Crowds: [`prelude::spawn_objects`], [`prelude::spawn_instanced`]
74//! - Tags: [`prelude::tag`], [`prelude::tagged`], [`prelude::for_each_tagged`]
75//! - Looks: [`prelude::set_color`], [`prelude::set_metallic_roughness`],
76//! [`prelude::set_emissive`], [`prelude::set_texture`]
77//! - Placement: [`prelude::set_position`], [`prelude::rotate`], [`prelude::set_scale`],
78//! [`prelude::set_parent`]
79//! - Cameras: [`prelude::orbit_camera`], [`prelude::fly_camera`],
80//! [`prelude::first_person`], [`prelude::fixed_camera`]
81//! - Input: [`prelude::key_down`], [`prelude::wasd`], [`prelude::mouse_clicked`],
82//! [`prelude::clicked_entity`]
83//! - Immediate drawing: [`prelude::draw_cube`], [`prelude::draw_sphere`],
84//! [`prelude::draw_line`]
85//! - Text: [`prelude::spawn_text`], [`prelude::set_text`], [`prelude::spawn_label`]
86//!
87//! ## Dropping down to the engine
88//!
89//! Every function here takes the real engine [`prelude::World`] and bottoms
90//! out in normal nightshade calls. Nothing is hidden behind a wrapper type,
91//! so when a program outgrows the facade you replace one call site at a time.
92//! The full engine is re-exported at [`nightshade`], one path away:
93//!
94//! ```ignore
95//! use nightshade_api::nightshade::prelude::*;
96//! ```
97//!
98//! ## Examples
99//!
100//! The `examples/` directory is the tour. Run one with
101//! `just run-example solar_system` from the repo root, or
102//! `cargo run -r -p nightshade-api --example solar_system`.
103
104pub use nightshade;
105
106mod animate;
107#[cfg(not(target_arch = "wasm32"))]
108mod app;
109mod appearance;
110#[cfg(feature = "audio")]
111mod audio;
112mod camera;
113mod decals;
114mod draw;
115mod effects;
116mod environment;
117mod groups;
118mod input;
119mod lighting;
120#[cfg(feature = "navmesh")]
121mod navigation;
122mod palette;
123#[cfg(feature = "physics")]
124mod physics;
125#[cfg(feature = "picking")]
126mod picking;
127mod placement;
128mod runner;
129mod scene;
130mod text;
131
132/// Everything in one import.
133///
134/// ```ignore
135/// use nightshade_api::prelude::*;
136/// ```
137///
138/// Pulls in the full api surface plus the engine types it hands you:
139/// [`World`], [`Entity`], the math types, [`KeyCode`], and [`MouseButton`].
140pub mod prelude {
141 pub use crate::animate::*;
142 #[cfg(not(target_arch = "wasm32"))]
143 pub use crate::app::{App, Window, frame, open, open_with, render_image};
144 pub use crate::appearance::*;
145 #[cfg(feature = "audio")]
146 pub use crate::audio::*;
147 pub use crate::camera::*;
148 pub use crate::decals::*;
149 pub use crate::draw::*;
150 pub use crate::effects::*;
151 pub use crate::environment::*;
152 pub use crate::groups::*;
153 pub use crate::input::*;
154 pub use crate::lighting::*;
155 #[cfg(feature = "navmesh")]
156 pub use crate::navigation::*;
157 pub use crate::palette::*;
158 #[cfg(feature = "physics")]
159 pub use crate::physics::*;
160 #[cfg(feature = "picking")]
161 pub use crate::picking::*;
162 pub use crate::placement::*;
163 pub use crate::runner::{run, run_scene};
164 pub use crate::scene::*;
165 pub use crate::text::*;
166
167 pub use nightshade::ecs::graphics::resources::DepthOfField;
168 #[cfg(feature = "physics")]
169 pub use nightshade::ecs::physics::joints::{
170 FixedJoint, JointAxisDirection, JointHandle, RevoluteJoint, RopeJoint, SpringJoint,
171 };
172 #[cfg(feature = "physics")]
173 pub use nightshade::prelude::{CollisionEvent, RaycastHit};
174 pub use nightshade::prelude::{
175 EasingFunction, Entity, Fog, InstanceTransform, KeyCode, Line, MouseButton, Vec2, Vec3,
176 Vec4, World, nalgebra_glm, vec2, vec3, vec4,
177 };
178}