Skip to content

Commit

Permalink
feat: Workspace refactor and tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluefinger committed Feb 19, 2024
1 parent 965313b commit c0fadc2
Show file tree
Hide file tree
Showing 21 changed files with 739 additions and 426 deletions.
55 changes: 37 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,48 +1,67 @@
[package]
name = "bevy_rand"
version = "0.4.0"
edition = "2021"
[workspace]
members = ["bevy_prng"]
resolver = "2"

[workspace.package]
authors = ["Gonçalo Rica Pais da Silva <[email protected]>"]
description = "A plugin to integrate rand for ECS optimised RNG for the Bevy game engine."
edition = "2021"
repository = "https://github.com/Bluefinger/bevy_rand"
license = "MIT OR Apache-2.0"
version = "0.5.0"
rust-version = "1.76.0"

[workspace.dependencies]
bevy = { version = "0.13", default-features = false }
serde = "1"
serde_derive = "1"
rand_core = { version = "0.6", features = ["std"] }
rand_chacha = "0.3"
wyrand = "0.1"
rand_pcg = "0.3"
rand_xoshiro = "0.6"

[package]
name = "bevy_rand"
version = { workspace = true }
edition = { workspace = true }
authors = { workspace = true }
description = "A plugin to integrate rand for ECS optimised RNG for the Bevy game engine."
repository = { workspace = true }
license = { workspace = true }
keywords = ["game", "bevy", "rand", "rng"]
categories = ["game-engines", "algorithms"]
exclude = ["/.*"]
resolver = "2"
rust-version = "1.70.0"
rust-version = { workspace = true }

[features]
default = ["serialize", "thread_local_entropy"]
thread_local_entropy = ["dep:rand_chacha"]
serialize = ["dep:serde", "rand_core/serde1"]
serialize = ["dep:serde", "dep:serde_derive", "rand_core/serde1"]
rand_chacha = ["bevy_prng/rand_chacha"]
rand_pcg = ["bevy_prng/rand_pcg"]
rand_xoshiro = ["bevy_prng/rand_xoshiro"]
wyrand = ["bevy_prng/wyrand"]

[workspace]
members = ["bevy_prng"]

[dependencies]
# bevy
bevy = { version = "0.12.0", default-features = false }
bevy_prng = { path = "bevy_prng", version = "0.2" }
bevy.workspace = true
bevy_prng = { path = "bevy_prng", version = "0.5" }

# others
serde = { version = "1.0", features = ["derive"], optional = true }
rand_core = { version = "0.6", features = ["std"] }
rand_chacha = { version = "0.3", optional = true }
rand_core.workspace = true
rand_chacha = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }

# This cfg cannot be enabled, but it forces Cargo to keep bevy_prng's
# version in lockstep with bevy_rand, so that even minor versions
# cannot be out of step with bevy_rand due to dependencies on traits
# and implementations between the two crates.
[target.'cfg(any())'.dependencies]
bevy_prng = { path = "bevy_prng", version = "=0.2" }
bevy_prng = { path = "bevy_prng", version = "=0.5" }

[dev-dependencies]
bevy_prng = { path = "bevy_prng", version = "0.2", features = ["rand_chacha", "wyrand"] }
bevy_prng = { path = "bevy_prng", version = "0.5", features = ["rand_chacha", "wyrand"] }
rand = "0.8"
ron = { version = "0.8.0", features = ["integer128"] }

Expand Down
110 changes: 20 additions & 90 deletions README.md

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions bevy_prng/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[package]
name = "bevy_prng"
version = "0.2.0"
edition = "2021"
authors = ["Gonçalo Rica Pais da Silva <[email protected]>"]
version = { workspace = true }
edition = { workspace = true }
authors = { workspace = true }
description = "A crate providing newtyped RNGs for integration into Bevy."
repository = "https://github.com/Bluefinger/bevy_rand"
license = "MIT OR Apache-2.0"
repository = { workspace = true }
license = { workspace = true }
keywords = ["game", "bevy", "rand", "rng"]
categories = ["game-engines", "algorithms"]
exclude = ["/.*"]
resolver = "2"
rust-version = "1.70.0"
rust-version = { workspace = true }

[features]
default = ["serialize"]
serialize = [
"dep:serde",
"dep:serde_derive",
"rand_core/serde1",
"rand_chacha?/serde1",
"rand_pcg?/serde1",
Expand All @@ -24,13 +24,14 @@ serialize = [
]

[dependencies]
bevy = { version = "0.12.0", default-features = false }
rand_core = { version = "0.6", features = ["std"] }
serde = { version = "1.0", features = ["derive"], optional = true }
rand_chacha = { version = "0.3", optional = true }
wyrand = { version = "0.1", optional = true }
rand_pcg = { version = "0.3", optional = true }
rand_xoshiro = { version = "0.6", optional = true }
bevy.workspace = true
rand_core.workspace = true
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
rand_chacha = { workspace = true, optional = true }
wyrand = { workspace = true, optional = true }
rand_pcg = { workspace = true, optional = true }
rand_xoshiro = { workspace = true, optional = true }

[package.metadata.docs.rs]
all-features = true
Expand Down
7 changes: 7 additions & 0 deletions bevy_prng/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ All the below crates implement the necessary traits to be compatible with `bevy_

| `bevy` | `bevy_prng` |
| ------ | ----------- |
| v0.13 | v0.5 |
| v0.12 | v0.2 |
| v0.11 | v0.1 |

The versions of `rand_core`/`rand` that `bevy_prng` is compatible with is as follows:

| `bevy_prng` | `rand_core` | `rand` |
| ------------ | ----------- | ------ |
| v0.1 -> v0.5 | v0.6 | v0.8 |

## License

Licensed under either of
Expand Down
31 changes: 31 additions & 0 deletions bevy_prng/src/chacha.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::{newtype::newtype_prng, SeedableEntropySource};

use bevy::prelude::{Reflect, ReflectFromReflect};
use rand_core::{RngCore, SeedableRng};

#[cfg(feature = "serialize")]
use bevy::prelude::{ReflectDeserialize, ReflectSerialize};

newtype_prng!(
ChaCha8Rng,
::rand_chacha::ChaCha8Rng,
[u8; 32],
"A newtyped [`rand_chacha::ChaCha8Rng`] RNG",
"rand_chacha"
);

newtype_prng!(
ChaCha12Rng,
::rand_chacha::ChaCha12Rng,
[u8; 32],
"A newtyped [`rand_chacha::ChaCha12Rng`] RNG",
"rand_chacha"
);

newtype_prng!(
ChaCha20Rng,
::rand_chacha::ChaCha20Rng,
[u8; 32],
"A newtyped [`rand_chacha::ChaCha20Rng`] RNG",
"rand_chacha"
);
Loading

0 comments on commit c0fadc2

Please sign in to comment.