all_is_cubes/lib.rs
1//! All is Cubes is a game/engine for worlds made of cubical blocks, where the blocks
2//! are themselves made of “smaller” blocks (voxels) that define their appearance and
3//! behavior.
4//!
5//! This crate, `all_is_cubes`, defines the data model and simulation rules.
6//! (User interface components, rendering, platform glue, and game content are kept in other
7//! crates.)
8//! This crate is designed to be a reusable library for simulating and rendering voxel
9//! world/scenes, but is not yet mature; many pieces of functionality are only sketched out
10//! or missing entirely.
11//!
12//! ## Capabilities
13//!
14//! Here is a brief summary of the concepts and capabilities (actual or planned) of
15//! All is Cubes, so that you may evaluate whether it suits your needs. Many of these
16//! details are subject to change; this is currently a one-author project with a rather
17//! chaotic vision.
18//!
19//! ### Data model
20//!
21//! Note that there is not currently any networking/multiplayer, or any save files.
22//! Both of these are planned, but may result in substantal revisions to the data model.
23//!
24//! * [`Universe`] manages a graph of interrelated game objects. It is intended to
25//! be the run-time form of what a player might call “a save file” or “a world”.
26//! Time advances at a uniform rate throughout a `Universe`.
27//! * A [`Space`] is a 3D array of [`Block`]s forming the physical space/scene which
28//! player characters can move through and interact with.
29//! * `Space`s currently have fixed boundaries (no infinite procedural generation),
30//! can have dimensions in the range of an [`i32`], and are kept in memory
31//! uncompressed at 6 bytes per cube. They can contain at most 65536 distinct
32//! blocks (subject to change).
33//! * The light falling on surfaces within a `Space` is computed using a global
34//! illumination algorithm (optionally).
35//! * In addition to their [`Block`] contents, `Space`s have global physical
36//! properties such as gravity and illumination. They also can have [`Behavior`]s
37//! attached for miscellaneous “scripting” purposes, though this feature is
38//! to be redesigned.
39//! * There can be arbitrarily many spaces per [`Universe`]. Eventually there will
40//! be ways to teleport between spaces; for now, this mainly assists [`Block`]s.
41//! * A [`Block`] is a cubical object which can be placed in a [`Space`] or carried in
42//! a [`Character`]'s inventory.
43//! * Blocks' shape and appearance (their [`Primitive`]) is either a cube of a single
44//! color, or recursively defined by a [`Space`] of smaller blocks (at a reduced
45//! size of [between 1/2 and 1/128][block::Resolution] of a full cube).
46//! Each of these voxels can be transparent.
47//! * The player will be able to enter these [`Space`]s and interactively edit
48//! blocks. This is not currently implemented but that is a lack in the user
49//! interface rather than core data structures.
50//! * In the future, there may be ways for blocks to be fully procedurally defined
51//! rather than working through [`Space`]s, such as for the purposes of
52//! animation or deriving variations from a single template or formula.
53//! * Blocks can have [`Modifier`]s applied to them which change the basic shape and
54//! behavior in a particular instance, such as being rotated into different
55//! orientations.
56//! * Blocks have various forms of active behavior and responses to their environment,
57//! such as [periodically taking an action][block::BlockAttributes::tick_action]
58//! and [playing sound][block::BlockAttributes::ambient_sound].
59//! * A [`Character`] can move around a [`Space`], acting as the player's viewpoint, and
60//! carry [`Tool`]s (items) with which to affect the space.
61//! * There can be multiple characters, but not yet any multiplayer, NPC AI, or even
62//! being able to see another character. Some of these this may be in the future.
63//! * A character's ability to modify the [`Space`] depends entirely on the provided
64//! tools, so that there can be entirely free editing or only actions following
65//! gameplay rules.
66//!
67//! ### Coordinate system
68//!
69//! Currently, there are some assumptions of a specific coordinate system.
70//! All of these might be generalized in the future.
71//!
72//! * [`Space`] and [`Block`] use 3-dimensional integer coordinates with no assumptions
73//! about axes. However, the default [`SpacePhysics`] configuration currently has a
74//! gravity vector in the −Y direction.
75//! * [`Character`] and [`Body`] have a look direction and corresponding transformation
76//! matrix which assumes OpenGL-style coordinates: +X right, +Y up, +Z towards viewer —
77//! a “right-handed” coordinate system.
78//! Jumping is also hardcoded to work in the +Y direction.
79//! Future versions may support arbitrary character orientation.
80//!
81//! ## Package features
82//!
83//! This package, `all-is-cubes`, defines the following feature flags:
84//!
85//! * `"save"`:
86//! Enable [`serde`] serialization of [`Universe`]s and some other types.
87//! * `"auto-threads"`:
88//! Enable use of threads for parallel and background processing, including via
89//! [`rayon`]’s global thread pool.
90//! This feature does not affect the public API (except via enabling other features),
91//! only performance and dependencies.
92//! * `"arbitrary"`: Adds implementations of the [`arbitrary::Arbitrary`] trait for
93//! fuzzing / property testing on types defined by this crate.
94//! * `"std"` (enabled by default):
95//! If disabled, the library becomes `no_std` compatible, at this cost:
96//! * Some trait implementations for [`std`] types are removed.
97//! * Floating-point functions are provided by [`libm`] instead of [`std`].
98//! * Spinlocks may be used in cases where that is a poor choice, reducing
99//! multithreaded performance.
100//! * Certain data calculations are not memoized.
101//!
102//! ## Platform compatibility
103//!
104//! * Compatible with web `wasm32-unknown-unknown`, whether or not the `std` feature is active.
105//! That is, the parts of `std` it uses are the thread-safety and floating-point parts,
106//! not IO (and not creating threads, unless requested).
107//! However, you must enable the `"web"` feature of [`bevy_platform`].
108//!
109//! * `usize` must be at least 32 bits (that is, not 16).
110//!
111//! ## Dependencies and global state
112//!
113//! `all_is_cubes` avoids having any global state, for the most part. However, it does write
114//! log messages using the [`log`] crate and is therefore subject to that global
115//! configuration.
116//!
117//! `all_is_cubes` depends on and re-exports the following crates as part of its public
118//! API:
119//!
120//! * [`arcstr`] for string data (as `all_is_cubes::arcstr`).
121//! * [`euclid`] for vector math (as `all_is_cubes::euclid`).
122//! * [`ordered_float`] (only the type [`all_is_cubes::math::NotNan`][crate::math::NotNan]).
123//! * [`embedded_graphics`] (as `all_is_cubes::drawing::embedded_graphics`).
124//!
125//! [`Behavior`]: crate::behavior::Behavior
126//! [`Block`]: crate::block::Block
127//! [`Body`]: crate::physics::Body
128//! [`Character`]: crate::character::Character
129//! [`Modifier`]: crate::block::Modifier
130//! [`Primitive`]: crate::block::Primitive
131//! [`Space`]: crate::space::Space
132//! [`SpacePhysics`]: crate::space::SpacePhysics
133//! [`Tool`]: crate::inv::Tool
134//! [`Universe`]: crate::universe::Universe
135#![cfg_attr(
136 not(feature = "arbitrary"),
137 doc = "[`arbitrary::Arbitrary`]: https://docs.rs/arbitrary/1.0.2/arbitrary/trait.Arbitrary.html"
138)]
139#![cfg_attr(
140 not(feature = "auto-threads"),
141 doc = "[`rayon`]: https://docs.rs/rayon/"
142)]
143#![no_std]
144// Crate-specific lint settings. (General settings can be found in the workspace manifest.)
145// * This crate contains some unsafe code and therefore does not `forbid(unsafe_code)`.
146// All of it is located in the `universe` module and pertains to ECS extensions.
147#![cfg_attr(
148 not(any(test, feature = "arbitrary")),
149 warn(clippy::std_instead_of_core, clippy::std_instead_of_alloc)
150)]
151#![cfg_attr(not(feature = "std"), allow(clippy::arc_with_non_send_sync))]
152#![cfg_attr(feature = "_special_testing", allow(private_interfaces))]
153
154#[cfg(any(feature = "std", test))]
155#[cfg_attr(test, macro_use)]
156extern crate std;
157#[macro_use]
158extern crate alloc;
159
160pub mod behavior;
161pub mod block;
162#[doc(hidden)] // Exported only for use by all_is_cubes_render
163pub mod camera;
164pub mod character;
165pub mod chunking;
166#[doc(hidden)] // Exported only for use by all_is_cubes_content
167pub mod content;
168pub mod drawing;
169pub mod fluff;
170pub mod inv;
171pub mod linking;
172pub mod listen;
173pub mod math;
174pub mod op;
175pub mod physics;
176pub mod raycast;
177#[doc(hidden)] // Exported only for use by all_is_cubes_render
178pub mod raytracer;
179#[doc(hidden)]
180#[cfg_attr(not(feature = "rerun"), path = "rerun_glue_disabled.rs")]
181pub mod rerun_glue;
182pub mod save;
183pub mod sound;
184pub mod space;
185pub mod tag;
186pub mod time;
187pub mod transaction;
188pub mod universe;
189pub mod util;
190
191/// Re-export the version of the `arcstr` string type library we're using.
192pub use arcstr;
193/// Re-export the version of the `euclid` vector math library we're using.
194pub use euclid;