Skip to main content

nadir/
lib.rs

1// Copyright 2026 Joseph Anthony Abbott III
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! The Nadir game engine: [`App`] and its main loop, the engine's
16//! components and systems, and the subsystems a game uses.
17//!
18//! [Nadir](https://github.com/jabbott-iii/Nadir) is a 2D engine for
19//! top-down games on Windows, macOS and Linux, written in Rust with no
20//! third-party crates. This crate is its facade, the one a game depends on:
21//! its package is `nadir_engine`, and code names it `nadir`. It re-exports
22//! the subsystems as modules, and [`prelude`] holds what most games use. A
23//! game needs only this crate:
24//!
25//! ```no_run
26//! use nadir::prelude::*;
27//!
28//! fn main() -> Result<(), nadir::Error> {
29//!     App::new(Config::default())
30//!         .add_fixed_system(FixedStage::Gameplay, "hello", |_, tick| {
31//!             if tick.index == 0 {
32//!                 nadir::log::info!("the first tick");
33//!             }
34//!         })
35//!         .run()
36//! }
37//! ```
38//!
39//! This is version 0.4, and the API will change before 1.0. The engine
40//! draws and plays sound on Linux (X11, ALSA). On Windows and macOS a game
41//! runs, but its window stays empty until roadmap tasks M2.6 and M2.7, and
42//! it plays no sound until M6.4 and M6.5. Text is drawn in the world
43//! (`nadir::render::Font`, `RenderFrame::texts`), and on the window with
44//! the UI's sprites (`RenderFrame::ui`); development builds show a
45//! [debug UI](#the-debug-ui) of the game's own windows and the engine's
46//! debug tools; gamepads and saves are not built yet. The
47//! [README](https://github.com/jabbott-iii/Nadir/blob/main/crates/engine/README.md)
48//! is a guide to how the parts fit together, with a game that walks a hero
49//! about a tile map.
50//!
51//! # The app and the main loop
52//!
53//! [`App`] holds the game's [`Config`], its world and its systems. A game
54//! adds resources, actions and systems with its builder methods, sets its
55//! world up through [`App::world_mut`], and calls [`App::run`], which opens
56//! the log file, the window and the audio output and runs the main loop
57//! until the window is closed. Each frame, the loop:
58//!
59//! 1. hands the window's [`Event`]s to [`Input`](input::Input);
60//! 2. runs the ticks that are due, [`TICK_HZ`] a second however fast the
61//!    frames come: each latches the game's actions, then runs the tick
62//!    stages;
63//! 3. sets [`TickStats`], and runs the frame stages, which fill the
64//!    [`RenderFrame`](render::RenderFrame);
65//! 4. draws it, and makes the assets that the workers have loaded.
66//!
67//! A frame counts for at most 250 ms: after a stall the simulation falls
68//! behind real time rather than running a burst of ticks.
69//!
70//! - [`App::update`] runs steps 1 to 3 without a window: tests, benchmarks
71//!   and headless runs call it themselves.
72//! - [`App::offscreen`] draws frames with no window: [`Offscreen::frame`]
73//!   returns each frame's pixels, for recordings.
74//! - [`Error`] is what ends [`App::run`].
75//!
76//! # The world, systems and stages
77//!
78//! The game's state is a [`World`](ecs::World) of entities, components and
79//! resources, from [`ecs`]. Systems are plain functions: a
80//! [`FixedSystem`](ecs::FixedSystem), `fn(&World, &Tick)`, runs in a
81//! [`FixedStage`](ecs::FixedStage) of each tick, added with
82//! [`App::add_fixed_system`]; a [`FrameSystem`](ecs::FrameSystem),
83//! `fn(&World, &Frame)`, in a [`FrameStage`](ecs::FrameStage) of each
84//! frame, added with [`App::add_frame_system`]. They run in stage order,
85//! then in the order they were added, after the engine's own, which
86//! [`App`] lists with the resources the engine adds.
87//!
88//! - [`App::insert_resource`] adds a resource; systems read it with
89//!   [`World::resource`](ecs::World::resource) and write it with
90//!   [`World::resource_mut`](ecs::World::resource_mut).
91//! - A component implements [`Component`](ecs::Component), and is
92//!   registered before use: with [`App::register_component`] if it is
93//!   reflected (defined with [`scene::reflect_struct!`] and its siblings),
94//!   or with [`World::register`](ecs::World::register).
95//! - Systems spawn, despawn, add and remove through
96//!   [`Commands`](ecs::Commands), which apply after the tick's stages or the
97//!   frame's.
98//! - [`App::add_event`] adds an event type, the resource
99//!   [`Events`](ecs::Events): tick systems read a tick's events, and frame
100//!   systems all those since the last frame.
101//!
102//! # The engine's components
103//!
104//! | Component | What it is |
105//! | :- | :- |
106//! | [`Transform`] | Where an entity is, in world pixels, +Y down |
107//! | [`Velocity`] | How fast it moves, in pixels a second: the engine moves it each tick |
108//! | [`Collider`] | What it collides with, solid or a trigger |
109//! | [`Sprite`] | What it looks like, drawn at its `Transform` |
110//! | [`Animator`] | Plays a [`Clip`] on its `Sprite` |
111//! | [`Facing`] | Which way it faces: facing left mirrors its `Sprite` |
112//! | [`Parent`] | Puts it at another entity's position, plus an offset |
113//! | [`Player`] | A tag for the entity the player controls |
114//! | [`SaveId`] | Its id in saves, which come with roadmap M9.4 |
115//! | [`PrevTransform`] | Where it was at the start of the last tick, for drawing between ticks: the engine keeps it |
116//! | [`AudioListener`] | Where the game hears from, in place of the camera |
117//! | [`AudioEmitter`] | A sound that plays at it, and follows it |
118//! | [`MusicArea`] | A box whose music plays while the listener is in it |
119//!
120//! [`Transform`], [`Velocity`], [`Player`], [`SaveId`], [`Facing`],
121//! [`Sprite`], [`Collider`] and [`Animator`] are reflected, so prefabs and
122//! levels can give them; [`Parent`], [`AudioListener`], [`AudioEmitter`]
123//! and [`MusicArea`] are not yet (M9.4 brings `Parent`), and
124//! [`PrevTransform`] is the engine's own, and is never in data. A
125//! [`Sprite`] is written with its texture's path, and a prefab may name a
126//! frame of a cooked atlas instead, `{"atlas": "atlas/sprites.kbj",
127//! "sprite": "sprites/hero", "frame": 0}`; a [`Collider`]'s layers by the
128//! names [`App::collision_layers`] gives them, `["World", "People"]`; an
129//! [`Animator`] as its clip's name in the [`Clips`]. The world hash leaves
130//! out what `nadir::animate` writes: a sprite's texture, uv, size, pivot
131//! and `flip.x` (ADR-0038).
132//!
133//! # Prefabs
134//!
135//! A prefab is a set of component values, cooked from
136//! `assets/data/prefabs/<name>.jsonc` to `data/prefabs/<name>.kbj`, that
137//! may extend another. The [`PrefabLibrary`](scene::PrefabLibrary)
138//! resource loads prefabs and their bases, and spawns entities of them;
139//! [`loading_context`] gives it a reflect context with what the engine's
140//! components need, the asset server, the clips and the collision layers,
141//! and [`reflect_context`] one for writing them, as a hash or a save
142//! does.
143//!
144//! # Levels
145//!
146//! The cook makes a level file, `levels/<name>.klvl`, of each level of an
147//! LDtk project. [`App::load_level`] (or [`load_level`] on a world) loads
148//! one in place of the last: its prefabs are read and checked before it
149//! returns, its assets load in `Scope::Level`, its tall tiles and entities
150//! spawn, its tile layers go into the [`TileLayers`](render::TileLayers)
151//! and its grid into the [`Collisions`], and the engine draws its tile
152//! layers each frame, its background the clear colour. [`CurrentLevel`]
153//! says what it made, and the next load removes it whole; a
154//! [`LevelError`] says why one did not load (ADR-0038).
155//!
156//! # Collision
157//!
158//! [`Collisions`] is the resource of the colliders, which the engine
159//! rebuilds and moves each tick: systems query its
160//! [`world`](Collisions::world), a [`CollisionWorld`](collision::CollisionWorld),
161//! and turn the collider indices it gives into entities with
162//! [`Collisions::entity`]. Its tile grid, [`Collisions::set_grid`], is how
163//! tiles collide. [`TriggerEnter`] and [`TriggerExit`] are the events of
164//! colliders that start and stop overlapping a trigger. [`collision`] has
165//! the shapes, the layers and the queries.
166//!
167//! # Animation
168//!
169//! A [`Clip`] is a list of [`ClipFrame`]s, each a region of a texture shown
170//! for a time, maybe with its own [`Placement`]. It loops or plays once
171//! ([`Playback`]). The resource [`Clips`] keeps the clips by handle and
172//! name, and [`Clips::add_atlas`] adds a cooked atlas's, from Aseprite's
173//! tags. An [`Animator`] plays one on its entity's [`Sprite`], and sends
174//! [`AnimationFinished`] when a clip that plays once ends. [`ClipError`]
175//! says why a clip could not be made or added.
176//!
177//! # Sound
178//!
179//! The resource [`Audio`](audio::Audio), from [`audio`], is the game's
180//! handle on the mixer: it plays a [`Sound`](audio::Sound), cooked to a
181//! `.kpcm` or `.qoa` file, on a [`Bus`](audio::Bus), at a position in the
182//! world or not, and crossfades from one [`Music`](audio::Music) track to
183//! another. [`Config::volumes`] sets each bus's volume as the game starts
184//! ([`Volumes`]). [`App::run`] opens the audio output with it, while
185//! [`App::update`] and [`App::offscreen`] play nothing, and
186//! [`App::take_mixer`] hands a test the mixer to render itself.
187//!
188//! The engine's `nadir::sound` plays the world's sound each frame. An
189//! [`AudioEmitter`] plays its sound at its entity, panned and fading by
190//! where it is from the listener: the first [`AudioListener`], or else the
191//! camera. When the listener comes into a [`MusicArea`], the music
192//! crossfades to its track, and [`AudioState`] says whose track was sent
193//! last. An emitter and an area wait for what they play to load; a sound
194//! played once as something happens, a footstep say, is lost if it has
195//! not loaded, so load it first with
196//! [`AssetServer::load_now`](assets::AssetServer::load_now).
197//!
198//! # Input, drawing and assets
199//!
200//! - [`input`]: the game's actions. An [`ActionSet`](input::ActionSet)
201//!   names them, an [`ActionMap`](input::ActionMap) binds keys and mouse
202//!   buttons to them, and [`App::add_actions`] adds both; tick systems read
203//!   the resource [`ActionState`](input::ActionState).
204//! - [`render`]: the resource [`RenderFrame`](render::RenderFrame), with
205//!   its [`Camera2D`](render::Camera2D), which frame systems fill and the
206//!   loop draws; the resource [`TileLayers`](render::TileLayers), whose
207//!   layers a frame names in [`RenderFrame::tile_layers`](render::RenderFrame::tile_layers);
208//!   the texts a frame draws in the world, in
209//!   [`RenderFrame::texts`](render::RenderFrame::texts); the UI it draws on
210//!   the window, in [`RenderFrame::ui`](render::RenderFrame::ui); and the
211//!   [`Texture`](render::Texture), [`Atlas`](render::Atlas) and
212//!   [`Font`](render::Font) assets.
213//! - [`assets`]: the resource [`AssetServer`](assets::AssetServer), which
214//!   loads from [`Config::assets`] on worker threads, and frees assets by
215//!   [`Scope`](assets::Scope).
216//!
217//! # Hot reload
218//!
219//! With the `dev` feature, [`App::run`] reloads the files that change while
220//! the game runs, such as those `cargo xtask cook --watch` cooks again, and
221//! nadir-render's shaders, from its `shaders/` folder
222//! ([`SHADER_DIR`](render::SHADER_DIR)). Watchers look at the files' times
223//! of change every 250 ms, and an edit is drawn a frame or two after it is
224//! seen; a shader edited before the loop starts is seen at its next save.
225//! The handles the game holds stay good (ADR-0043):
226//!
227//! - a texture's handle draws its new texels;
228//! - an atlas's clips are replaced by name under their handles, so its
229//!   animators play the new frames on from their time;
230//! - a prefab is replaced in the [`PrefabLibrary`](scene::PrefabLibrary)
231//!   under its name;
232//! - the current level is made again from its files, behind the handles of
233//!   its assets, tile layers and clips, once its file, an atlas or a prefab
234//!   changed; its entities are spawned anew;
235//! - a program is rebuilt from its shader files.
236//!
237//! A file that fails to load, a level that cannot be made again, or shaders
238//! that do not compile or fit their program are logged, and what they
239//! would replace stays. Each reload is logged with its time. What the game
240//! copied out of an asset, such as an atlas's regions into its own sprites,
241//! and the entities it spawned of prefabs itself, do not change.
242//! [`App::offscreen`] and [`App::update`] never reload, so recordings stay
243//! the same, and builds without `dev` hold none of the reload.
244//!
245//! # The debug UI
246//!
247//! With the `dev` feature, a game adds windows of its own to a debug UI
248//! with `App::add_debug_window`, each shown and hidden by a key, and fills
249//! them each frame with the widgets of `nadir::debug`, the `nadir-debug`
250//! crate: labels, buttons, checkboxes, sliders, text fields, lists, trees,
251//! plots. They are drawn over the game's UI in the engine's own pixel
252//! font; they drag, collapse, resize and scroll; while one has the
253//! pointer, or one of their text fields the keys, the game's actions do not
254//! see them; and [`App::run`] keeps their places in `debug_ui.jsonc` in the
255//! game's settings folder. The resource `WindowSize` is the window's size.
256//! The engine's own windows are the stats overlay (F1), the inspector (F2),
257//! the profiler (F3), the debug drawing (F4), whose overlays draw into the
258//! world, and the console (the backtick), which runs the engine's commands
259//! and those a game adds with `App::add_console_command`. F5 pauses the
260//! game's time and runs it again, F6 steps it a tick, and F7 and Shift+F7
261//! scale it, a label at the top-right saying so.
262//!
263//! ```
264//! # #[cfg(feature = "dev")]
265//! # {
266//! use nadir::prelude::*;
267//!
268//! /// A note the developer types in.
269//! #[derive(Default)]
270//! struct Note(String);
271//!
272//! let app = App::new(Config::default())
273//!     .insert_resource(Note::default())
274//!     .add_debug_window(
275//!         Key::F8,
276//!         "Notes",
277//!         Rect::new(Vec2::new(16.0, 16.0), Vec2::new(216.0, 116.0)),
278//!         |world, ui| {
279//!             ui.text_input("Note", &mut world.resource_mut::<Note>().0);
280//!             let ticks = world.resource::<TickStats>().ticks;
281//!             ui.label(format_args!("{ticks} ticks this frame"));
282//!         },
283//!     );
284//! # let _ = app;
285//! # }
286//! ```
287//!
288//! # Replays and determinism
289//!
290//! [`App::play_replay`] plays a recording of the game's actions, made with
291//! an [`InputRecorder`](input::InputRecorder), in place of the live input,
292//! and the resource [`Replay`] says how far it got. [`world_hash`] and
293//! [`App::world_hash`] hash the reflected components, so that a test can
294//! check that a replay reaches the same world, tick after tick.
295//!
296//! # The modules
297//!
298//! | Module | Crate | What it holds |
299//! | :- | :- | :- |
300//! | [`assets`] | `nadir-assets` | Handles, the asset server, sources and scopes |
301//! | [`audio`] | `nadir-audio` | Sounds, music, the mixer, its buses and voices |
302//! | [`collision`] | `nadir-collision` | Shapes, layers, the tile grid, move-and-slide, triggers, queries |
303//! | [`ecs`] | `nadir-ecs` | The world, components, resources, events, commands, the schedule |
304//! | [`input`] | `nadir-input` | Actions, bindings, their state, replays |
305//! | [`render`] | `nadir-render` | The frame to draw, sprites, tiles, the camera, textures, atlases |
306//! | [`scene`] | `nadir-scene` | Reflection: the macros that define reflected types, and the type registry |
307//! | [`log`] | `nadir-core` | The log macros, `error!` to `trace!` |
308//! | [`cli`] | `nadir-core` | A small parser of command lines |
309//!
310//! [`Vec2`](prelude::Vec2), [`IVec2`](prelude::IVec2), [`UVec2`](prelude::UVec2),
311//! [`Rect`](prelude::Rect), [`Color`](prelude::Color), [`Key`](prelude::Key),
312//! [`MouseButton`](prelude::MouseButton), [`Pcg32`](prelude::Pcg32) and the
313//! time types [`Tick`](prelude::Tick), [`Frame`](prelude::Frame) and
314//! [`Stopwatch`](prelude::Stopwatch) are in the [`prelude`]; the rest of
315//! `nadir-core`, such as its matrices and linear colours, is a dependency
316//! of its own. The OS
317//! layer, the GPU layer and the codecs are the engine's own, and a game
318//! does not use them, except for the window's [`Event`]s, which
319//! [`App::update`] takes.
320//!
321//! # Examples
322//!
323//! A frame of one tick moves an entity by its velocity, with no window:
324//!
325//! ```
326//! use std::time::Duration;
327//!
328//! use nadir::prelude::*;
329//!
330//! let mut app = App::new(Config::default());
331//! let ball = app
332//!     .world_mut()
333//!     .spawn()
334//!     .with(Transform::at(Vec2::ZERO))
335//!     .with(Velocity(Vec2::new(60.0, 0.0)))
336//!     .id();
337//! // 1/60 of a second, rounded up to the nanosecond: one tick.
338//! app.update(Duration::from_nanos(16_666_667), &[]);
339//! let at = app.world().read::<Transform>().get(ball).map(|it| it.position);
340//! assert_eq!(at, Some(Vec2::new(1.0, 0.0)));
341//! ```
342//!
343//! A trigger counts who steps on it, in a tick system after the engine's
344//! `nadir::triggers`:
345//!
346//! ```
347//! use std::time::Duration;
348//!
349//! use nadir::prelude::*;
350//!
351//! /// How many times something stepped on the plate.
352//! #[derive(Default)]
353//! struct Steps(usize);
354//!
355//! fn count_steps(world: &World, _tick: &Tick) {
356//!     let entered = world.resource::<Events<TriggerEnter>>().tick_events().len();
357//!     world.resource_mut::<Steps>().0 += entered;
358//! }
359//!
360//! let mut app = App::new(Config::default())
361//!     .insert_resource(Steps::default())
362//!     .add_fixed_system(FixedStage::PostMovement, "count_steps", count_steps);
363//! let world = app.world_mut();
364//! // A plate 8 pixels across at x = 20.
365//! world
366//!     .spawn()
367//!     .with(Transform::at(Vec2::new(20.0, 0.0)))
368//!     .with(Collider::trigger(Shape::Aabb { half: Vec2::splat(4.0) }));
369//! // Someone who walks right across it, at 2 pixels a tick.
370//! world
371//!     .spawn()
372//!     .with(Transform::at(Vec2::ZERO))
373//!     .with(Velocity(Vec2::new(120.0, 0.0)))
374//!     .with(Collider::solid(Shape::Aabb { half: Vec2::splat(2.0) }));
375//! for _ in 0..30 {
376//!     app.update(Duration::from_nanos(16_666_667), &[]);
377//! }
378//! assert_eq!(app.world().resource::<Steps>().0, 1);
379//! ```
380//!
381//! An animator shows the frame of its clip that the simulated time has
382//! reached. The texture need not have loaded: the clip writes its regions
383//! into the sprite all the same.
384//!
385//! ```
386//! use std::time::Duration;
387//!
388//! use nadir::prelude::*;
389//!
390//! let mut app = App::new(Config::default());
391//! let world = app.world_mut();
392//! let sheet = world.resource_mut::<AssetServer>().load::<Texture>("hero.qoi");
393//! // The sheet's left and right halves, 100 ms each, over and over.
394//! let half = |x: f32| {
395//!     let uv = Rect::new(Vec2::new(x, 0.0), Vec2::new(x + 0.5, 1.0));
396//!     ClipFrame::new(sheet, uv, Duration::from_millis(100))
397//! };
398//! let clip = Clip::new(vec![half(0.0), half(0.5)], Playback::Loop);
399//! let walk = world.resource_mut::<Clips>().add(clip);
400//! let hero = world
401//!     .spawn()
402//!     .with(Transform::at(Vec2::ZERO))
403//!     .with(Sprite::new(sheet, Vec2::new(16.0, 16.0)))
404//!     .with(Animator::new(walk))
405//!     .id();
406//! // 9 ticks, 150 ms: the second frame shows.
407//! for _ in 0..9 {
408//!     app.update(Duration::from_nanos(16_666_667), &[]);
409//! }
410//! let uv = app.world().read::<Sprite>().get(hero).map(|it| it.uv.min.x);
411//! assert_eq!(uv, Some(0.5));
412//! ```
413//!
414//! # Using it well
415//!
416//! - **Threads.** The world, the systems, the window and the GPU all live
417//!   on the thread that runs the app, and systems run one at a time. The
418//!   asset server reads and decodes files on 1 to 4 worker threads of its
419//!   own, and the mixer runs on the audio output's thread, which
420//!   [`Audio`](audio::Audio)'s commands reach through a queue. Call
421//!   [`App::run`] on the main thread: macOS opens windows only there.
422//! - **Borrows.** Storages and resources are borrowed at run time. A system
423//!   that borrows one mutably while it is borrowed panics, with the
424//!   system's name and the type.
425//! - **Determinism.** Ticks have a fixed length, and the clock counts
426//!   frames' lengths exactly, so the same frames give the same ticks. Keep
427//!   gameplay in tick systems. What frames set, such as an
428//!   [`Animator`]'s time, whether an asset has loaded, and the pointer and
429//!   the wheel differ from run to run: [`world_hash`] gives the conditions
430//!   under which a replay reproduces the world.
431//! - **Assets.** Loads finish only in drawn frames, so [`App::update`]
432//!   finishes none, and a tick system must not depend on whether an asset
433//!   has loaded. Before the window opens there is no GPU device, so only
434//!   assets that need none, such as an [`Atlas`](render::Atlas), can be
435//!   made then, with [`AssetServer::load_now`](assets::AssetServer::load_now).
436//! - **Allocation.** The engine's own systems and drawing do not allocate in
437//!   a steady frame: its tests count a frame of 10,000 animated sprites and
438//!   a tile layer with the `dev` feature's counter. Systems are function
439//!   pointers; keep their buffers in resources and reuse them.
440//! - **Errors and logs.** [`App::run`] logs an [`Error`] and shows it to the
441//!   player before it returns it: on standard error on Linux, and in a
442//!   message box on Windows or an alert on macOS. The [`log`] macros write to standard
443//!   error, and [`App::run`] also writes the log to `nadir.log` in the
444//!   game's logs folder, named by [`Config::studio`] and [`Config::game`].
445//! - **Platforms.** On Linux the engine needs X11, or XWayland, and OpenGL
446//!   3.3, which it loads at run time, and plays sound through ALSA's
447//!   `libasound.so.2`, loaded at run time too: without it the game is
448//!   silent. On Windows and macOS it has no OpenGL context yet:
449//!   [`App::run`] logs that and runs the game without drawing, and so
450//!   without reloading, and [`App::offscreen`] fails; nor has it audio
451//!   output, so the game is silent there.
452//!
453//! # Features
454//!
455//! - `dev`: development builds. The assets are the loose files of
456//!   [`Config::assets`], not the cook's pack there, which builds without
457//!   `dev` read when it is there (ADR-0041). A texture that failed to load
458//!   shows a placeholder rather than nothing, and the global allocator counts
459//!   allocations: the resource `FrameAllocs` holds the last frame's, and
460//!   `thread_alloc_counts` and `process_alloc_counts` give the counts so
461//!   far, as `AllocCounts`. No other crate in the program may then declare
462//!   a `#[global_allocator]`. [`App::run`] reloads what changes while it
463//!   runs ("Hot reload", above), and the game's debug windows show ("The
464//!   debug UI", above), with `nadir::debug`, `App::add_debug_window`,
465//!   `DebugWindow` and `WindowSize`. Turn it on from a feature of the game,
466//!   never from a normal dependency, so that release builds leave it out.
467
468// The README's examples are compiled as doc tests too.
469#[cfg(doctest)]
470#[doc = include_str!("../README.md")]
471struct ReadmeDoctests;
472
473mod animation;
474mod app;
475mod collisions;
476mod components;
477#[cfg(feature = "dev")]
478mod debug_ui;
479mod error;
480#[cfg(feature = "dev")]
481mod frame_allocs;
482mod glue;
483#[cfg(feature = "dev")]
484mod hot_reload;
485mod level;
486mod limiter;
487mod log_file;
488mod pack;
489mod reflected;
490mod replay;
491mod sound;
492mod tick_stats;
493#[cfg(feature = "dev")]
494mod window_size;
495
496pub use nadir_core::{cli, log};
497#[cfg(feature = "dev")]
498pub use nadir_debug as debug;
499pub use nadir_platform::Event;
500#[cfg(feature = "dev")]
501pub use nadir_platform::{AllocCounts, process_alloc_counts, thread_alloc_counts};
502pub use {
503    nadir_assets as assets, nadir_audio as audio, nadir_collision as collision, nadir_ecs as ecs,
504    nadir_input as input, nadir_render as render, nadir_scene as scene,
505};
506
507pub use animation::{
508    AnimationFinished, Animator, Clip, ClipError, ClipFrame, Clips, Placement, Playback,
509};
510pub use app::{App, Config, Offscreen, TICK_HZ, Volumes};
511pub use collisions::{Collisions, TriggerEnter, TriggerExit};
512pub use components::{
513    AudioEmitter, AudioListener, Collider, Facing, MusicArea, Parent, Player, PrevTransform,
514    SaveId, Sprite, Transform, Velocity,
515};
516#[cfg(feature = "dev")]
517pub use debug_ui::{ConsoleCommand, DebugWindow};
518pub use error::Error;
519#[cfg(feature = "dev")]
520pub use frame_allocs::FrameAllocs;
521pub use level::{CurrentLevel, LevelError, load_level, unload_level};
522pub use reflected::{CollisionLayers, loading_context, reflect_context};
523pub use replay::{Replay, world_hash};
524pub use sound::AudioState;
525pub use tick_stats::TickStats;
526#[cfg(feature = "dev")]
527pub use window_size::WindowSize;
528
529/// What most games use, for one `use nadir::prelude::*`.
530pub mod prelude {
531    pub use nadir_assets::{AssetServer, FinalizeCtx, Handle, LoadState};
532    pub use nadir_audio::{Audio, Bus, Music, PlayParams, Sound, VoiceChange, VoiceId};
533    pub use nadir_collision::{LayerMask, Shape, TileGrid};
534    pub use nadir_core::time::{Frame, Stopwatch, Tick};
535    pub use nadir_core::{Color, IVec2, Key, MouseButton, Pcg32, Rect, UVec2, Vec2};
536    pub use nadir_ecs::{
537        Commands, Component, Entity, Events, FixedStage, FrameStage, Res, ResMut, World,
538    };
539    pub use nadir_input::{ActionKind, ActionMap, ActionSet, ActionState, Binding, Input};
540    pub use nadir_render::{
541        Atlas, AtlasClip, AtlasClipFrame, AtlasFrame, AtlasPage, AtlasSprite, Camera2D, Flip,
542        FrameStats, RenderFrame, SortMode, SpriteDraw, Texture, Tile, TileLayer, TileLayerDraw,
543        TileLayers, TileSet,
544    };
545
546    pub use crate::{
547        AnimationFinished, Animator, App, AudioEmitter, AudioListener, AudioState, Clip, ClipError,
548        ClipFrame, Clips, Collider, Collisions, Config, Facing, MusicArea, Parent, Placement,
549        Playback, Player, PrevTransform, SaveId, Sprite, TickStats, Transform, TriggerEnter,
550        TriggerExit, Velocity, Volumes,
551    };
552}