doryen_extra/
lib.rs

1/* BSD 3-Clause License
2 *
3 * Copyright © 2019, Alexander Krivács Schrøder <alexschrod@gmail.com>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 *    this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 *    this list of conditions and the following disclaimer in the documentation
14 *    and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 *    contributors may be used to endorse or promote products derived from
18 *    this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33// NOTE: Make sure to keep this documentation in sync with the README.
34
35//! # Doryen-extra
36//!
37//! Doryen-extra aims to be a loose re-implementation of the utility features from the popular roguelike
38//! library named [`libtcod`], which is also known as the Doryen Library. The [`doryen-rs`] crate fulfills
39//! the re-implementation of the game engine part of the library, but is otherwise (at the time of writing)
40//! missing a lot of the features that were present in [`libtcod`].
41//!
42//! After finding myself frustrated with the various limitations and hassles that are involved when
43//! wrapping a C library in rust, which is what the [`tcod`] crate has done, I decided to just go
44//! all-in and re-code the library in Rust.
45//!
46//! While I could've just copied and pasted the code as it was, and turned it into Rust with minimal modifications,
47//! I wanted to make it a proper Rust library, so it has been coded with retaining functionality in mind,
48//! but not with retaining form. By that, I mean that all the functionality you're used to from [`libtcod`] should
49//! be present, but how it's accessed or used may vary greatly from the original.
50//!
51//! # Features
52//!
53//! ## `doryen`
54//!
55//! While this library is called doryen-extra, I didn't actually want to force it to be tied to the
56//! [`doryen-rs`] library, so functionality that pertains to it is behind the feature `doryen`. If
57//! you want to use this library without bringing in [`doryen-rs`] as a dependency, just put
58//! ```toml
59//! [dependencies]
60//! doryen-extra = { version = "...", default-features = false }
61//! ```
62//! in your `Cargo.toml` file, which removes the default `doryen` feature.
63//!
64//! ## `libtcod-compat`
65//!
66//! This feature restores (on a best-effort basis) the functionality of the original
67//! `libtcod` library, where it has been modified. At the time of writing, the only change that
68//! will happen is to the float generation of the `ComplementaryMultiplyWithCarry` RNG algorithm.
69//!
70//! ## `rng_support`
71//!
72//! With this feature enabled, the [`Random`] struct implements [`rand_core::RngCore`] and
73//! [`rand_core::SeedableRng`], which lets it be used in any place that accepts the `rand` crate RNGs.
74//!
75//! ## `serialization`
76//!
77//! With this feature enabled, all types for which it makes sense to serialize will implement
78//! [`serde::ser::Serialize`] and [`serde::de::Deserialize`]. NOTE: More types may get implementations
79//! for this in the future.
80//!
81//! # Missing Features / Toolkits
82//!
83//! The following toolkits from [`libtcod`] have not yet been converted, with possible reason given in parenthesis:
84//! * `bsp` toolkit: 2D Binary Space Partition
85//! * `fov` toolkit: Easily calculate the potential visible set of map cells from the player position
86//! * `image` toolkit: Some image manipulation utilities (undecided on whether to convert this one; other crates may already serve this purpose)
87//! * `list` toolkit: A fast, lightweight and generic container, that provides array, list and stack paradigms (use `Vec` instead)
88//! * `namegen` toolkit: Allows one to generate random names out of custom made syllable sets (parts requires `parse` toolkit)
89//! * `parse` toolkit: An easy way to parse complex text configuration files
90//!
91//! [`libtcod`]: https://github.com/libtcod/libtcod
92//! [`doryen-rs`]: https://crates.io/crates/doryen-rs
93//! [`tcod`]: https://crates.io/crates/tcod
94//!
95//! [`Random`]: ./random/struct.Random.html
96//! [`rand_core::RngCore`]: ../rand_core/trait.RngCore.html
97//! [`rand_core::SeedableRng`]: ../rand_core/trait.SeedableRng.html
98//! [`serde::ser::Serialize`]: ../serde/ser/trait.Serialize.html
99//! [`serde::de::Deserialize`]: ../serde/de/trait.Deserialize.html
100
101// Coding conventions
102//
103// Deny (don't do this)
104#![deny(anonymous_parameters)]
105#![deny(bare_trait_objects)]
106#![deny(elided_lifetimes_in_paths)]
107#![deny(ellipsis_inclusive_range_patterns)]
108#![deny(non_camel_case_types)]
109#![deny(non_snake_case)]
110#![deny(non_upper_case_globals)]
111#![deny(trivial_numeric_casts)]
112#![deny(unreachable_pub)]
113#![deny(unsafe_code)]
114#![deny(unused_import_braces)]
115#![deny(unused_mut)]
116#![deny(unused_qualifications)]
117//
118// Warn (try not to do this)
119#![warn(missing_copy_implementations)]
120#![warn(missing_debug_implementations)]
121#![warn(missing_docs)]
122#![warn(rust_2018_idioms)]
123#![warn(variant_size_differences)]
124//#![warn(unused_results)]
125//
126// Clippy conventions
127//
128// Deny (don't do this)
129#![deny(clippy::cast_lossless)]
130#![deny(clippy::default_trait_access)]
131#![deny(clippy::empty_enum)]
132#![deny(clippy::enum_glob_use)]
133#![deny(clippy::expl_impl_clone_on_copy)]
134#![deny(clippy::explicit_into_iter_loop)]
135#![deny(clippy::explicit_iter_loop)]
136#![deny(clippy::filter_map)]
137#![deny(clippy::filter_map_next)]
138#![deny(clippy::find_map)]
139#![deny(clippy::if_not_else)]
140#![deny(clippy::invalid_upcast_comparisons)]
141#![deny(clippy::items_after_statements)]
142#![deny(clippy::large_digit_groups)]
143#![deny(clippy::map_flatten)]
144#![deny(clippy::match_same_arms)]
145#![deny(clippy::mut_mut)]
146#![deny(clippy::needless_continue)]
147#![deny(clippy::needless_pass_by_value)]
148#![deny(clippy::map_unwrap_or)]
149#![deny(clippy::redundant_closure_for_method_calls)]
150#![deny(clippy::single_match_else)]
151#![deny(clippy::string_add_assign)]
152#![deny(clippy::type_repetition_in_bounds)]
153#![deny(clippy::unseparated_literal_suffix)]
154#![deny(clippy::unused_self)]
155#![deny(clippy::use_self)] // Sometimes gives false positives; feel free to disable.
156#![deny(clippy::used_underscore_binding)]
157//
158// Warn (try not to do this)
159//#![warn(clippy::must_use_candidate)]
160#![deny(clippy::new_without_default)]
161#![warn(clippy::pub_enum_variant_names)]
162#![warn(clippy::shadow_unrelated)]
163#![warn(clippy::similar_names)]
164#![warn(clippy::too_many_lines)]
165
166#[macro_use]
167mod util;
168
169mod base;
170pub use base::*;
171
172#[cfg(feature = "doryen")]
173pub mod extenders;
174#[cfg(feature = "doryen")]
175pub mod extensions;
176
177pub mod bresenham;
178pub mod color;
179
180pub mod heightmap;
181pub mod noise;
182pub mod random;