Skip to content

Commit

Permalink
chore: Fix remaining EntropyComponent references
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluefinger committed Dec 15, 2024
1 parent 0c4f973 commit b4aaabe
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions bevy_prng/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub use wyrand::WyRand;
pub use xoshiro::*;

/// A marker trait to define the required trait bounds for a seedable PRNG to
/// integrate into `EntropyComponent` or `GlobalEntropy`. This is a sealed trait.
/// integrate into `Entropy` or `GlobalEntropy`. This is a sealed trait.
#[cfg(feature = "serialize")]
pub trait EntropySource:
RngCore
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<
}

/// A marker trait to define the required trait bounds for a seedable PRNG to
/// integrate into `EntropyComponent` or `GlobalEntropy`. This is a sealed trait.
/// integrate into `Entropy` or `GlobalEntropy`. This is a sealed trait.
#[cfg(not(feature = "serialize"))]
pub trait EntropySource:
RngCore
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod resource;
pub mod seed;
#[cfg(feature = "thread_local_entropy")]
mod thread_local_entropy;
/// Traits for enabling utility methods for [`crate::component::EntropyComponent`] and [`crate::resource::GlobalEntropy`].
/// Traits for enabling utility methods for [`crate::component::Entropy`] and [`crate::resource::GlobalEntropy`].
pub mod traits;
#[cfg(doc)]
pub mod tutorial;
6 changes: 3 additions & 3 deletions src/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use rand_core::SeedableRng;

use crate::{component::Entropy, traits::SeedSource};

/// The initial seed/state for an [`EntropyComponent`]. Adding this component to an `Entity` will cause
/// an `EntropyComponent` to be initialised as well. To force a reseed, just insert this component to an
/// `Entity` to overwrite the old value, and the `EntropyComponent` will be overwritten with the new seed
/// The initial seed/state for an [`Entropy`]. Adding this component to an `Entity` will cause
/// an `Entropy` to be initialised as well. To force a reseed, just insert this component to an
/// `Entity` to overwrite the old value, and the `Entropy` will be overwritten with the new seed
/// in turn.
#[derive(Debug, Reflect)]
pub struct RngSeed<R: EntropySource> {
Expand Down
14 changes: 7 additions & 7 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy_prng::EntropySource;
use rand_core::{RngCore, SeedableRng};

/// Trait for implementing Forking behaviour for [`crate::component::EntropyComponent`] and [`crate::resource::GlobalEntropy`].
/// Trait for implementing Forking behaviour for [`crate::component::Entropy`] and [`crate::resource::GlobalEntropy`].
/// Forking creates a new RNG instance using a generated seed from the original source. If the original is seeded with a known
/// seed, this process is deterministic.
pub trait ForkableRng: EcsEntropy {
Expand Down Expand Up @@ -31,7 +31,7 @@ pub trait ForkableRng: EcsEntropy {
}
}

/// Trait for implementing Forking behaviour for [`crate::component::EntropyComponent`] and [`crate::resource::GlobalEntropy`].
/// Trait for implementing Forking behaviour for [`crate::component::Entropy`] and [`crate::resource::GlobalEntropy`].
/// Forking creates a new RNG instance using a generated seed from the original source. If the original is seeded with a known
/// seed, this process is deterministic. This trait enables forking between different PRNG algorithm types.
pub trait ForkableAsRng: EcsEntropy {
Expand Down Expand Up @@ -63,7 +63,7 @@ pub trait ForkableAsRng: EcsEntropy {
}
}

/// Trait for implementing Forking behaviour for [`crate::component::EntropyComponent`] and [`crate::resource::GlobalEntropy`].
/// Trait for implementing Forking behaviour for [`crate::component::Entropy`] and [`crate::resource::GlobalEntropy`].
/// Forking creates a new RNG instance using a generated seed from the original source. If the original is seeded with a known
/// seed, this process is deterministic. This trait enables forking the inner PRNG instance of the source component/resource.
pub trait ForkableInnerRng: EcsEntropy {
Expand Down Expand Up @@ -96,7 +96,7 @@ pub trait ForkableInnerRng: EcsEntropy {
}
}

/// Trait for implementing forking behaviour for [`crate::component::EntropyComponent`] and [`crate::resource::GlobalEntropy`].
/// Trait for implementing forking behaviour for [`crate::component::Entropy`] and [`crate::resource::GlobalEntropy`].
/// Forking creates a new RNG instance using a generated seed from the original source. If the original is seeded with a known
/// seed, this process is deterministic. This trait enables forking from an entropy source to a seed component.
pub trait ForkableSeed<S: EntropySource>: EcsEntropy
Expand Down Expand Up @@ -133,7 +133,7 @@ where
}
}

/// Trait for implementing Forking behaviour for [`crate::component::EntropyComponent`] and [`crate::resource::GlobalEntropy`].
/// Trait for implementing Forking behaviour for [`crate::component::Entropy`] and [`crate::resource::GlobalEntropy`].
/// Forking creates a new RNG instance using a generated seed from the original source. If the original is seeded with a known
/// seed, this process is deterministic. This trait enables forking from an entropy source to a seed component of a different
/// PRNG algorithm.
Expand Down Expand Up @@ -174,7 +174,7 @@ pub trait ForkableAsSeed<S: EntropySource>: EcsEntropy {
}
}

/// Trait for implementing forking behaviour for [`crate::component::EntropyComponent`] and [`crate::resource::GlobalEntropy`].
/// Trait for implementing forking behaviour for [`crate::component::Entropy`] and [`crate::resource::GlobalEntropy`].
/// Forking creates a new RNG instance using a generated seed from the original source. If the original is seeded with a known
/// seed, this process is deterministic. This trait enables forking from an entropy source to the RNG's seed type.
pub trait ForkableInnerSeed<S: EntropySource>: EcsEntropy
Expand Down Expand Up @@ -251,7 +251,7 @@ where
}
}

/// A marker trait for [`crate::component::EntropyComponent`] and [`crate::resource::GlobalEntropy`].
/// A marker trait for [`crate::component::Entropy`] and [`crate::resource::GlobalEntropy`].
/// This is a sealed trait and cannot be consumed by downstream.
pub trait EcsEntropy: RngCore + SeedableRng + private::SealedSource {}

Expand Down
2 changes: 1 addition & 1 deletion tutorial/01-choosing-prng.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use bevy_rand::prelude::*;
use bevy_prng::{ChaCha8Rng, WyRand};
```

When you've selected and imported the PRNG algorithm you want to use, you then need to enable it by adding the `EntropyPlugin` to your app. This then makes it available for use with `GlobalEntropy` and `EntropyComponent`, as well as registering the types for reflection.
When you've selected and imported the PRNG algorithm you want to use, you then need to enable it by adding the `EntropyPlugin` to your app. This then makes it available for use with `GlobalEntropy` and `Entropy`, as well as registering the types for reflection.

```rust
use bevy_ecs::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion tutorial/02-basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ fn randomise_npc_stat(mut rng: ResMut<GlobalEntropy<WyRand>>, mut q_npc: Query<&
}
```

But how can we achieve determinism in cases of where we want to randomise values within a query iteration? Well, by not using `GlobalEntropy` but `EntropyComponent` instead, moving the RNG source to the entities themselves. The next section will cover their usage.
But how can we achieve determinism in cases of where we want to randomise values within a query iteration? Well, by not using `GlobalEntropy` but `Entropy` instead, moving the RNG source to the entities themselves. The next section will cover their usage.
4 changes: 2 additions & 2 deletions tutorial/04-observer-driven-reseeding.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# EXPERIMENTAL - Observer-driven Reseeding

The following feature is _experimental_ so to enable it, you'll need to edit your Cargo.toml file and change the dependency declaration for `bevy_rand` to have `features=["experimental"]` applied. Once done, you'll get access to some utils that will enable easy setup of observer driven reseeding utilities for managing when entities with `EntropyComponent`s obtain new seeds from which sources. Keep in mind, this feature is not *stable* and will be subject to further work and iteration, so if problems and issues are encountered, please do create issues outlining the use-cases and difficulties.
The following feature is _experimental_ so to enable it, you'll need to edit your Cargo.toml file and change the dependency declaration for `bevy_rand` to have `features=["experimental"]` applied. Once done, you'll get access to some utils that will enable easy setup of observer driven reseeding utilities for managing when entities with `Entropy`s obtain new seeds from which sources. Keep in mind, this feature is not *stable* and will be subject to further work and iteration, so if problems and issues are encountered, please do create issues outlining the use-cases and difficulties.

```toml
bevy_rand = { version = "0.8", features = ["rand_chacha", "wyrand", "experimental"] }
Expand Down Expand Up @@ -42,7 +42,7 @@ fn reseed_target_entities_from_set_seed(mut commands: Commands, mut q_targets: Q
}
```

With these observers, you can initialise entropy components on all targetted entities simply by triggering a reseed event on them. As long as your entities have been spawned with a component you can target them with, they will automatically be given an `RngSeed` component (which stores the initial seed value) and an `EntropyComponent`.
With these observers, you can initialise entropy components on all targetted entities simply by triggering a reseed event on them. As long as your entities have been spawned with a component you can target them with, they will automatically be given an `RngSeed` component (which stores the initial seed value) and an `Entropy`.

Additionally, you can link entities to draw their seeds from other source entities instead of the global resources. So one `Source` entity can then seed many `Target` entities, and whenever the `Source` entity is updated with a new seed value, it then automatically pushes new seeds to its linked targets. Note: this is NOT a `bevy_hierarchy` relationship, and while the `Source` will have "child" entities, removing/despawning the source entity will *not* despawn the children entities. They will simply no longer have a valid "link". A new link can be established by triggering another "link" event.

Expand Down

0 comments on commit b4aaabe

Please sign in to comment.