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