diff --git a/all-is-cubes-render/src/raytracer/mod.rs b/all-is-cubes-render/src/raytracer/mod.rs index f09aa526f..81bff11ef 100644 --- a/all-is-cubes-render/src/raytracer/mod.rs +++ b/all-is-cubes-render/src/raytracer/mod.rs @@ -1,12 +1,9 @@ //! CPU raytracer for All is Cubes content. //! -//! ## Why? -//! -//! The original reason this exists is that I thought “we have [`all_is_cubes::raycast`], -//! and that's nearly all the work, so why not?” Secondarily, it was written before -//! the mesh-based renderer, and was useful as a cross-check since -//! it is much simpler. It continues to serve as a “reference implementation”, and is used -//! by the terminal UI and in unit tests via [`print_space`]. +//! While not fast enough for serious interactive use, +//! this raytracer serves as the reference implementation of rendering. +//! Some of its components are also used in areas like computing derived properties of blocks. +//! It may also be used for visual output in tests via [`print_space()`]. // As a workaround for , // we list some items explicitly even though they should be redundant with @@ -14,7 +11,9 @@ #[cfg(feature = "std")] pub use all_is_cubes::raytracer::print_space; -pub use all_is_cubes::raytracer::{Accumulate, SpaceRaytracer, UpdatingSpaceRaytracer, *}; +pub use all_is_cubes::raytracer::{ + Accumulate, CharacterBuf, RtBlockData, SpaceRaytracer, UpdatingSpaceRaytracer, *, +}; mod renderer; pub use renderer::{RtRenderer, RtScene}; diff --git a/all-is-cubes-render/src/raytracer/renderer.rs b/all-is-cubes-render/src/raytracer/renderer.rs index 96e910070..f78db4392 100644 --- a/all-is-cubes-render/src/raytracer/renderer.rs +++ b/all-is-cubes-render/src/raytracer/renderer.rs @@ -310,11 +310,14 @@ impl HeadlessRenderer for RtRenderer<()> { } } -/// Bundle of references to the current scene data in a [`RtRenderer`], -/// used to implement tracing individual rays independent of how they -/// are assembled into an image. Differs from [`SpaceRaytracer::trace_ray()`] -/// in that it includes the cameras (thus accepting screen-space coordinates -/// rather than a ray) and [`Layers`] rather than one space. +/// Scene to be raytraced. +/// +/// This may be obtained from [`RtRenderer::scene()`] and used to trace individual rays, +/// rather than an entire image. +/// +/// Differs from [`SpaceRaytracer`] +/// in that it includes the [`Camera`]s (thus accepting screen-space coordinates +/// rather than a world-space ray) and [`Layers`] rather than one space. /// /// Obtain this by calling [`RtRenderer::scene()`]. pub struct RtScene<'a, P: Accumulate> { diff --git a/all-is-cubes/src/block.rs b/all-is-cubes/src/block.rs index eb0c63fc8..3fdcb52e1 100644 --- a/all-is-cubes/src/block.rs +++ b/all-is-cubes/src/block.rs @@ -1110,6 +1110,7 @@ impl BlockChange { } /// Construct a set of [`Primitive::Recur`] blocks that form a miniature of the given `space`. +/// /// The returned [`Space`] contains each of the blocks; its coordinates will correspond to /// those of the input, scaled down by `resolution`. /// diff --git a/all-is-cubes/src/camera.rs b/all-is-cubes/src/camera.rs index e303dfb8b..aac1e6a76 100644 --- a/all-is-cubes/src/camera.rs +++ b/all-is-cubes/src/camera.rs @@ -446,11 +446,13 @@ pub enum NominalPixel {} #[derive(Debug, Eq, PartialEq)] pub enum ImagePixel {} -/// Unit-of-measure type for points/vectors in “normalized device coordinates”: -/// screen-space *x* and *y* have the range -1 to 1; +/// Unit-of-measure type for points/vectors in “normalized device coordinates”. +/// +/// In this coordinate system, +/// screen-space x and y have the range -1 to 1; /// zero is the center of the screen; -/// and *z* has the range 0 (nearest) to 1 (farthest) and is image depth rather than an equivalent -/// third spatial axis. +/// and z has the range 0 (nearest) to 1 (farthest), +/// and is image depth rather than an equivalent third spatial axis. #[allow(clippy::exhaustive_enums)] #[derive(Debug, Eq, PartialEq)] pub enum Ndc {} diff --git a/all-is-cubes/src/content/palette.rs b/all-is-cubes/src/content/palette.rs index efff421ca..32b54e548 100644 --- a/all-is-cubes/src/content/palette.rs +++ b/all-is-cubes/src/content/palette.rs @@ -14,6 +14,9 @@ // // 0xBB is the sRGB value approximating linear value 0.5. +#![allow(unknown_lints)] // TODO: remove after Rust 1.81 is released +#![allow(clippy::too_long_first_doc_paragraph)] // false positive on SVG + use crate::math::{rgb_const, Rgb}; /// Define a color constant and preview it in the documentation. diff --git a/all-is-cubes/src/drawing.rs b/all-is-cubes/src/drawing.rs index ee6272246..2f46e6996 100644 --- a/all-is-cubes/src/drawing.rs +++ b/all-is-cubes/src/drawing.rs @@ -72,6 +72,9 @@ pub fn rectangle_to_aab(rectangle: Rectangle, transform: Gridgid, max_brush: Gri // way, since it is precisely about identifying the volume occupied by drawing a // 2D-pixel. + #![allow(unknown_lints)] // TODO: remove after Rust 1.81 is released + #![allow(clippy::too_long_first_doc_paragraph)] // TODO: find better phrasing + // TODO: propagate numeric overflow cases #![allow(clippy::cast_possible_wrap)] diff --git a/all-is-cubes/src/lib.rs b/all-is-cubes/src/lib.rs index a0b1ab451..dda99ce26 100644 --- a/all-is-cubes/src/lib.rs +++ b/all-is-cubes/src/lib.rs @@ -114,6 +114,7 @@ //! `all_is_cubes` depends on and re-exports the following crates as part of its public //! API: //! +//! * [`arcstr`] for string data (as `all_is_cubes::arcstr`). //! * [`euclid`] for vector math (as `all_is_cubes::euclid`). //! * [`ordered_float`] (as `all_is_cubes::math::NotNan`). //! * [`embedded_graphics`] (as `all_is_cubes::drawing::embedded_graphics`). diff --git a/all-is-cubes/src/linking.rs b/all-is-cubes/src/linking.rs index 0304e7bf9..1c04bb27f 100644 --- a/all-is-cubes/src/linking.rs +++ b/all-is-cubes/src/linking.rs @@ -311,9 +311,15 @@ crate::util::cfg_should_impl_error! { impl ErrorIfStd for ProviderError {} } -/// An error resulting from “world generation”: failure to calculate/create/place objects -/// (due to bad parameters or unforeseen edge cases), failure to successfully store them -/// in or retrieve them from a [`Universe`], et cetera. +/// An error resulting from “world generation”. +/// +/// May be failure to calculate/create/place objects +/// (due to bad parameters or unforeseen edge cases), +/// failure to successfully store them in or retrieve them from a [`Universe`], +/// et cetera. +/// +/// A [`GenError`] contains an [`InGenError`] and additionally specifies which universe +/// member was to be generated but failed. #[derive(Debug)] pub struct GenError { #[cfg_attr(not(feature = "std"), allow(dead_code))] diff --git a/all-is-cubes/src/listen.rs b/all-is-cubes/src/listen.rs index 579af405b..e9be2b17f 100644 --- a/all-is-cubes/src/listen.rs +++ b/all-is-cubes/src/listen.rs @@ -57,15 +57,17 @@ impl Listen for Arc { } } -/// Mechanism for observing changes to objects. A [`Notifier`] delivers messages -/// of type `M` to a set of listeners, each of which usually holds a weak reference -/// to allow it to be removed when the actual recipient is gone or uninterested. +/// Message broadcaster, usually used for change notifications. /// -/// TODO: Currently, each message is [`Clone`]d for each recipient. This is fine for -/// most cases, but in some cases it would be cheaper to pass a reference. We could -/// make Notifier and Listener always take `&M`, but it's not clear how to use -/// references *some* of the time — making `M` be a reference type can't have a -/// satisfactory lifetime. +/// A `Notifier` delivers messages of type `M` to a dynamic set of [`Listener`]s. +/// +/// The `Notifier` is usually owned by some entity which emits messages when it changes, +/// such as a [`ListenableCell`]. +/// Each `Listener` usually holds a weak reference to allow it to be removed when the +/// actual recipient is gone or uninterested. +/// +/// [`Listener`]s may be added using the [`Listen`] implementation, and are removed when +/// they report themselves as dead. pub struct Notifier { listeners: RwLock>>, } diff --git a/all-is-cubes/src/listen/listeners.rs b/all-is-cubes/src/listen/listeners.rs index a417e28e4..4153f0e30 100644 --- a/all-is-cubes/src/listen/listeners.rs +++ b/all-is-cubes/src/listen/listeners.rs @@ -10,8 +10,9 @@ use manyfmt::Refmt as _; use crate::listen::{Listen, Listener}; use crate::util::maybe_sync::{RwLock, SendSyncIfStd}; -/// A [`Listener`] which discards all messages and is suitable for filling -/// listener parameters when no listener is needed. +/// A [`Listener`] which discards all messages. +/// +/// Use this when a [`Listener`] is demanded, but there is nothing it should do. #[allow(clippy::exhaustive_structs)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct NullListener; diff --git a/all-is-cubes/src/listen/util.rs b/all-is-cubes/src/listen/util.rs index 1883e146b..1bf9e2281 100644 --- a/all-is-cubes/src/listen/util.rs +++ b/all-is-cubes/src/listen/util.rs @@ -53,10 +53,11 @@ where } } -/// Controls a [`Listener`] chain by discarding messages when this gate is dropped. +/// Breaks a [`Listener`] connection when dropped. /// -/// Construct this using [`Listener::gate`], or if a placeholder instance with no -/// effect is required, [`Gate::default`]. +/// Construct this using [`Listener::gate()`], or if a placeholder instance with no +/// effect is required, [`Gate::default()`]. Then, drop the [`Gate`] when no more messages +/// should be delivered. #[derive(Clone, Default)] pub struct Gate { /// By owning this we keep its [`Weak`] peers alive, and thus the [`GateListener`] active. @@ -83,8 +84,10 @@ impl Gate { } } -/// [`Listener`] implementation which discards messages when the corresponding [`Gate`] -/// is dropped. Construct this using [`Listener::gate()`]. +/// A [`Listener`] which forwards messages to another, +/// until the corresponding [`Gate`] is dropped. +/// +/// Construct this using [`Listener::gate()`]. #[derive(Clone, Debug)] pub struct GateListener { weak: Weak<()>, diff --git a/all-is-cubes/src/physics/body.rs b/all-is-cubes/src/physics/body.rs index b71c472f8..21b6abcd3 100644 --- a/all-is-cubes/src/physics/body.rs +++ b/all-is-cubes/src/physics/body.rs @@ -600,7 +600,9 @@ impl Body { } } -/// Diagnostic data returned by `Body::step()`. The exact contents of this structure +/// Diagnostic data returned by `Body::step()`. +/// +/// The exact contents of this structure /// are unstable; use only [`Debug`] formatting to examine its contents unless you have /// a specific need for one of the values. /// diff --git a/all-is-cubes/src/raytracer/text.rs b/all-is-cubes/src/raytracer/text.rs index 4c4d29206..276442eac 100644 --- a/all-is-cubes/src/raytracer/text.rs +++ b/all-is-cubes/src/raytracer/text.rs @@ -14,9 +14,11 @@ use crate::math::FreeVector; use crate::raytracer::{Accumulate, RtBlockData, RtOptionsRef, SpaceRaytracer}; use crate::space::{Space, SpaceBlockData}; -/// TODO: better name, docs +/// If you are using [`CharacterBuf`], use this [`RtBlockData`] implementation. +// TODO: better name #[derive(Clone, Debug, Eq, PartialEq)] #[allow(clippy::exhaustive_structs)] +// TODO: field would ideally be private pub struct CharacterRtData(pub Substr); impl RtBlockData for CharacterRtData { diff --git a/all-is-cubes/src/space.rs b/all-is-cubes/src/space.rs index 870319369..1228521ef 100644 --- a/all-is-cubes/src/space.rs +++ b/all-is-cubes/src/space.rs @@ -1258,7 +1258,9 @@ pub struct SpaceFluff { pub fluff: Fluff, } -/// Performance data returned by [`Space::step`]. The exact contents of this structure +/// Performance data returned by [`Space::step`]. +/// +/// The exact contents of this structure /// are unstable; use only `Debug` formatting to examine its contents unless you have /// a specific need for one of the values. #[derive(Clone, Debug, Default, PartialEq)] diff --git a/all-is-cubes/src/transaction.rs b/all-is-cubes/src/transaction.rs index 29ba627bf..a37e27de6 100644 --- a/all-is-cubes/src/transaction.rs +++ b/all-is-cubes/src/transaction.rs @@ -16,15 +16,18 @@ mod tester; #[cfg(test)] pub use tester::*; +/// A mutation that is to be performed atomically. +/// /// A `Transaction` is a description of a mutation to an object or collection thereof that /// should occur in a logically atomic fashion (all or nothing), with a set of -/// preconditions for it to happen at all. +/// preconditions for it to happen at all. (Here we mean [“atomic” in the database sense][atomic], +/// not in the CPU instruction sense.) /// /// Transactions are used: /// /// * to enable game objects to have effects on their containers in a way compatible /// with Rust's ownership rules, -/// * to avoid “item duplication” type bugs by checking all preconditions before making +/// * to avoid bugs of the “item duplication” sort, by checking all preconditions before making /// any changes, and /// * to avoid update-order-dependent game mechanics by applying effects in batches. /// @@ -33,6 +36,8 @@ pub use tester::*; /// /// If a transaction implements [`Default`], then the default value should be a /// transaction which has no effects and always succeeds, and is cheap to create. +/// +/// [atomic]: https://en.wikipedia.org/wiki/Atomicity_(database_systems) #[must_use] pub trait Transaction: Merge { /// Type of the transaction’s target (what it can be used to mutate). @@ -133,8 +138,14 @@ pub trait Transaction: Merge { } } -/// Merging two transactions (or, in principle, other values) to produce one result “with -/// the effect of both”. Merging is a commutative, fallible operation. +/// Merging two transactions (or other values) to produce one result “with +/// the effect of both”. +/// +/// Merging is a commutative, fallible operation. +/// The exact conditions under which it fails are up to the specific type, but generally, +/// it will fail whenever there is no outcome which reasonably corresponds to +/// the pair of transactions being executed “simultaneously”, and it will succeed when +/// the pair of transactions modify independent parts of their target. /// /// This is a separate trait from [`Transaction`] because some components of transactions /// are mergeable but not executable in isolation. diff --git a/all-is-cubes/src/universe.rs b/all-is-cubes/src/universe.rs index 4032a5699..e5012fca9 100644 --- a/all-is-cubes/src/universe.rs +++ b/all-is-cubes/src/universe.rs @@ -832,7 +832,9 @@ pub(crate) struct DeserializeHandlesError { to: Name, } -/// Performance data returned by [`Universe::step`]. The exact contents of this structure +/// Performance data returned by [`Universe::step`]. +/// +/// The exact contents of this structure /// are unstable; use only `Debug` formatting to examine its contents unless you have /// a specific need for one of the values. #[derive(Clone, Debug, Default, PartialEq)] diff --git a/all-is-cubes/src/util/status_text.rs b/all-is-cubes/src/util/status_text.rs index 129e40d53..6e4517af1 100644 --- a/all-is-cubes/src/util/status_text.rs +++ b/all-is-cubes/src/util/status_text.rs @@ -6,6 +6,7 @@ use all_is_cubes_base::util::ConciseDebug; /// Format type for [`manyfmt::Fmt`] which provides an highly condensed, ideally constant-width /// or constant-height, user-facing format for live-updating textual status messages. +/// /// This format does not follow Rust [`fmt::Debug`] syntax, and when implemented /// for standard Rust types may have quirks. Values may have multiple lines. #[allow(clippy::exhaustive_structs)]