Skip to content

Commit

Permalink
Bump Bevy to 0.15.0-rc.3. (#27)
Browse files Browse the repository at this point in the history
* Bump Bevy to 0.15.0-rc.3.

* Move the `Typed` trait bound to `SeedableEntropySource`.

This trait already holds the majority of trait requirements, so we might as well add it there as well.

* Remove Xoshiro512 variants and Seed512.

Seed512 doesn't impl `Typed` so reflection is broken here because of it.
  • Loading branch information
andriyDev authored Nov 11, 2024
1 parent c4769ad commit 57806e7
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version = "0.8.0"
rust-version = "1.76.0"

[workspace.dependencies]
bevy = { version = "0.14", default-features = false }
bevy = { version = "0.15.0-rc.3", default-features = false }
serde = "1"
serde_derive = "1"
rand_core = { version = "0.6", features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn setup_npc_from_source(
- **`serialize`** - Enables `Serialize` and `Deserialize` derives. Enabled by default.
- **`rand_chacha`** - This enables the exporting of newtyped `ChaCha*Rng` structs, for those that want/need to use a CSPRNG level source.
- **`rand_pcg`** - This enables the exporting of newtyped `Pcg*` structs from `rand_pcg`.
- **`rand_xoshiro`** - This enables the exporting of newtyped `Xoshiro*` structs from `rand_xoshiro`. It also reexports `Seed512` so to allow setting up `Xoshiro512StarStar` and so forth without the need to pull in `rand_xoshiro` explicitly.
- **`rand_xoshiro`** - This enables the exporting of newtyped `Xoshiro*` structs from `rand_xoshiro`.
- **`wyrand`** - This enables the exporting of newtyped `WyRand` from `wyrand`, the same algorithm in use within `fastrand`/`turborand`.

## Supported Versions & MSRV
Expand Down
2 changes: 1 addition & 1 deletion bevy_prng/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ By default, `bevy_prng` won't export anything _unless_ the feature/algorithm you

- **`rand_chacha`** - This enables the exporting of newtyped `ChaCha*Rng` structs, for those that want/need to use a CSPRNG level source.
- **`rand_pcg`** - This enables the exporting of newtyped `Pcg*` structs from `rand_pcg`.
- **`rand_xoshiro`** - This enables the exporting of newtyped `Xoshiro*` structs from `rand_xoshiro`. It also reexports `Seed512` so to allow setting up `Xoshiro512StarStar` and so forth without the need to pull in `rand_xoshiro` explicitly.
- **`rand_xoshiro`** - This enables the exporting of newtyped `Xoshiro*` structs from `rand_xoshiro`.
- **`wyrand`** - This enables the exporting of newtyped `WyRand` from `wyrand`, the same algorithm in use within `fastrand`/`turborand`.

In addition to these feature flags to enable various supported algorithms, there's also **`serialize`** flag to provide `serde` support for `Serialize`/`Deserialize`, which is enabled by default.
Expand Down
11 changes: 5 additions & 6 deletions bevy_prng/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::fmt::Debug;

use bevy::{
prelude::{FromReflect, Reflect},
reflect::{GetTypeRegistration, TypePath},
reflect::{GetTypeRegistration, TypePath, Typed},
};
use rand_core::{RngCore, SeedableRng};
#[cfg(feature = "serialize")]
Expand All @@ -33,9 +33,6 @@ use serde::{Deserialize, Serialize};
pub use chacha::*;
#[cfg(feature = "rand_pcg")]
pub use pcg::*;
#[cfg(feature = "rand_xoshiro")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand_xoshiro")))]
pub use rand_xoshiro::Seed512;
#[cfg(feature = "wyrand")]
pub use wyrand::WyRand;
#[cfg(feature = "rand_xoshiro")]
Expand All @@ -46,7 +43,7 @@ pub use xoshiro::*;
#[cfg(feature = "serialize")]
pub trait SeedableEntropySource:
RngCore
+ SeedableRng
+ SeedableRng<Seed: Typed>
+ Clone
+ Debug
+ PartialEq
Expand All @@ -56,6 +53,7 @@ pub trait SeedableEntropySource:
+ TypePath
+ FromReflect
+ GetTypeRegistration
+ Typed
+ Serialize
+ for<'a> Deserialize<'a>
+ private::SealedSeedable
Expand Down Expand Up @@ -106,7 +104,7 @@ impl<
#[cfg(not(feature = "serialize"))]
pub trait SeedableEntropySource:
RngCore
+ SeedableRng
+ SeedableRng<Seed: Typed>
+ Clone
+ Debug
+ PartialEq
Expand All @@ -115,6 +113,7 @@ pub trait SeedableEntropySource:
+ TypePath
+ FromReflect
+ GetTypeRegistration
+ Typed
+ Sync
+ Send
+ private::SealedSeedable
Expand Down
4 changes: 2 additions & 2 deletions bevy_prng/src/newtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ macro_rules! newtype_prng {
)]
#[cfg_attr(
all(feature = "serialize"),
reflect_value(Debug, PartialEq, FromReflect, Serialize, Deserialize)
reflect(opaque, Debug, PartialEq, FromReflect, Serialize, Deserialize)
)]
#[cfg_attr(
all(not(feature = "serialize")),
reflect_value(Debug, PartialEq, FromReflect)
reflect(opaque, Debug, PartialEq, FromReflect)
)]
#[cfg_attr(docsrs, doc(cfg(feature = $feature)))]
#[type_path = "bevy_prng"]
Expand Down
21 changes: 0 additions & 21 deletions bevy_prng/src/xoshiro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,6 @@ use rand_core::{RngCore, SeedableRng};
#[cfg(feature = "serialize")]
use bevy::prelude::{ReflectDeserialize, ReflectSerialize};

newtype_prng!(
Xoshiro512StarStar,
::rand_xoshiro::Xoshiro512StarStar,
"A newtyped [`rand_xoshiro::Xoshiro512StarStar`] RNG",
"rand_xoshiro"
);

newtype_prng!(
Xoshiro512PlusPlus,
::rand_xoshiro::Xoshiro512PlusPlus,
"A newtyped [`rand_xoshiro::Xoshiro512PlusPlus`] RNG",
"rand_xoshiro"
);

newtype_prng!(
Xoshiro512Plus,
::rand_xoshiro::Xoshiro512Plus,
"A newtyped [`rand_xoshiro::Xoshiro512Plus`] RNG",
"rand_xoshiro"
);

newtype_prng!(
Xoshiro256StarStar,
::rand_xoshiro::Xoshiro256StarStar,
Expand Down
8 changes: 4 additions & 4 deletions src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ mod tests {
fn rng_untyped_serialization() {
use bevy::reflect::{
serde::{ReflectDeserializer, ReflectSerializer},
TypeRegistry,
FromReflect, TypeRegistry,
};
use ron::to_string;
use serde::de::DeserializeSeed;
Expand Down Expand Up @@ -323,7 +323,7 @@ mod tests {

let value = de.deserialize(&mut deserializer).unwrap();

let mut dynamic = value.take::<EntropyComponent<ChaCha8Rng>>().unwrap();
let mut dynamic = EntropyComponent::<ChaCha8Rng>::take_from_reflect(value).unwrap();

// The two instances should be the same
assert_eq!(
Expand All @@ -343,7 +343,7 @@ mod tests {
fn rng_typed_serialization() {
use bevy::reflect::{
serde::{TypedReflectDeserializer, TypedReflectSerializer},
GetTypeRegistration, TypeRegistry,
FromReflect, GetTypeRegistration, TypeRegistry,
};
use ron::ser::to_string;
use serde::de::DeserializeSeed;
Expand Down Expand Up @@ -373,7 +373,7 @@ mod tests {

let value = de.deserialize(&mut deserializer).unwrap();

let mut dynamic = value.take::<EntropyComponent<ChaCha8Rng>>().unwrap();
let mut dynamic = EntropyComponent::<ChaCha8Rng>::take_from_reflect(value).unwrap();

// The two instances should be the same
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ pub use bevy_prng::{Pcg32, Pcg64, Pcg64Mcg};
pub use bevy_prng::{
Xoroshiro128Plus, Xoroshiro128PlusPlus, Xoroshiro128StarStar, Xoroshiro64Star,
Xoroshiro64StarStar, Xoshiro128Plus, Xoshiro128PlusPlus, Xoshiro128StarStar, Xoshiro256Plus,
Xoshiro256PlusPlus, Xoshiro256StarStar, Xoshiro512Plus, Xoshiro512PlusPlus, Xoshiro512StarStar,
Xoshiro256PlusPlus, Xoshiro256StarStar,
};
8 changes: 4 additions & 4 deletions src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ mod tests {
fn rng_untyped_serialization() {
use bevy::reflect::{
serde::{ReflectDeserializer, ReflectSerializer},
TypeRegistry,
FromReflect, TypeRegistry,
};
use ron::ser::to_string;
use serde::de::DeserializeSeed;
Expand Down Expand Up @@ -301,7 +301,7 @@ mod tests {

let value = de.deserialize(&mut deserializer).unwrap();

let mut dynamic = value.take::<GlobalEntropy<ChaCha8Rng>>().unwrap();
let mut dynamic = GlobalEntropy::<ChaCha8Rng>::take_from_reflect(value).unwrap();

// The two instances should be the same
assert_eq!(
Expand All @@ -321,7 +321,7 @@ mod tests {
fn rng_typed_serialization() {
use bevy::reflect::{
serde::{TypedReflectDeserializer, TypedReflectSerializer},
GetTypeRegistration, TypeRegistry,
FromReflect, GetTypeRegistration, TypeRegistry,
};
use ron::to_string;
use serde::de::DeserializeSeed;
Expand Down Expand Up @@ -351,7 +351,7 @@ mod tests {

let value = de.deserialize(&mut deserializer).unwrap();

let mut dynamic = value.take::<GlobalEntropy<ChaCha8Rng>>().unwrap();
let mut dynamic = GlobalEntropy::<ChaCha8Rng>::take_from_reflect(value).unwrap();

// The two instances should be the same
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions src/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ mod tests {

assert!(value.is_dynamic());
assert!(value.represents::<RngSeed<WyRand>>());
assert!(!value.is::<RngSeed<WyRand>>());
assert!(!value.try_downcast_ref::<RngSeed<WyRand>>().is_some());

let recreated = RngSeed::<WyRand>::from_reflect(value.as_reflect()).unwrap();
let recreated = RngSeed::<WyRand>::from_reflect(value.as_ref()).unwrap();

assert_eq!(val.clone_seed(), recreated.clone_seed());
}
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn observer_global_reseeding() {
.zip(seeds.map(u64::from_ne_bytes))
.for_each(|(expected, actual)| assert_ne!(expected, actual));
})
.observe(reseed);
.add_observer(reseed);

app.run();
}
Expand Down Expand Up @@ -278,7 +278,7 @@ fn observer_children_reseeding() {

let mut source = commands.spawn(seed);

source.add(|mut entity: EntityWorldMut| {
source.queue(|mut entity: EntityWorldMut| {
// FORK! Quicker than allocating a new Vec of components to spawn.
let mut rng = entity
.get_mut::<EntropyComponent<WyRand>>()
Expand Down Expand Up @@ -361,8 +361,8 @@ fn observer_children_reseeding() {
assert_eq!(children.iter().size_hint().0, 5);
},
)
.observe(reseed)
.observe(reseed_children);
.add_observer(reseed)
.add_observer(reseed_children);

app.run();
}
2 changes: 1 addition & 1 deletion tutorial/01-choosing-prng.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn main() {
The current set of PRNG algorithms that are supported out of the box in `bevy_prng` are as follows:

- `wyrand`: This provides newtyped `WyRand` from `wyrand`, the same algorithm in use within `fastrand`/`turborand`.
- `rand_xoshiro`: This provides newtyped `Xoshiro*` structs from `rand_xoshiro`. It also reexports `Seed512` so to allow setting up `Xoshiro512StarStar` and so forth without the need to pull in `rand_xoshiro` explicitly.
- `rand_xoshiro`: This provides newtyped `Xoshiro*` structs from `rand_xoshiro`.
- `rand_pcg`: This provides newtyped `Pcg*` structs from `rand_pcg`.
- `rand_chacha`: This provides newtyped `ChaCha*Rng` structs, for those that want/need to use a CSPRNG level source.

Expand Down

0 comments on commit 57806e7

Please sign in to comment.