Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_rng"
version = "0.3.0"
version = "0.3.1"
authors = ["Jean Mertz <[email protected]>"]
edition = "2018"
repository = "https://github.com/rustic-games/bevy_rng"
Expand All @@ -12,8 +12,8 @@ rand = { version = "0.8", default-features = false, features = ["getrandom"] }
rand_seeder = "0.2"
rand_xoshiro = "0.6"

bevy-stable = { package = "bevy", version = "0.4", default-features = false, optional = true }
bevy-nightly = { package = "bevy", version = "0.4", git = "https://github.com/bevyengine/bevy", rev = "c2a427f1a38db6b1d9798e631a7da7a8507fe18c", default-features = false, optional = true }
bevy-stable = { package = "bevy", version = "0.5", default-features = false, optional = true }
bevy-nightly = { package = "bevy", version = "0.5", git = "https://github.com/bevyengine/bevy", rev = "4f341430469acef478a709aff00bde375743f946", default-features = false, optional = true }

[features]
default = ["bevy-stable"]
default = ["bevy-stable"]
13 changes: 9 additions & 4 deletions examples/rng.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#[cfg(all(feature = "bevy-nightly", not(feature = "bevy-stable")))]
use bevy_nightly as bevy;
#[cfg(all(feature = "bevy-stable", not(feature = "bevy-nightly")))]
use bevy_stable as bevy;

use bevy::app::ScheduleRunnerSettings;
use bevy::prelude::*;
use bevy_rng::*;
Expand All @@ -6,15 +11,15 @@ use std::time::Duration;
fn main() {
// Don't register the plugin (non-deterministic)...
App::build()
.add_resource(ScheduleRunnerSettings::run_once())
.insert_resource(ScheduleRunnerSettings::run_once())
.add_plugins(MinimalPlugins)
.add_system(random_number_1.system())
.add_system(random_number_2.system())
.run();

// ...don't provide a seed (same as above)...
App::build()
.add_resource(ScheduleRunnerSettings::run_once())
.insert_resource(ScheduleRunnerSettings::run_once())
.add_plugins(MinimalPlugins)
.add_plugin(RngPlugin::default())
.add_system(random_number_1.system())
Expand All @@ -23,7 +28,7 @@ fn main() {

// ...seed from u64 (deterministic)...
App::build()
.add_resource(ScheduleRunnerSettings::run_once())
.insert_resource(ScheduleRunnerSettings::run_once())
.add_plugins(MinimalPlugins)
.add_plugin(RngPlugin::from(42))
.add_system(random_number_1.system())
Expand All @@ -32,7 +37,7 @@ fn main() {

// ...or from a string (same as above).
App::build()
.add_resource(ScheduleRunnerSettings::run_loop(Duration::from_millis(100)))
.insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_millis(100)))
.add_plugins(MinimalPlugins)
.add_plugin(RngPlugin::from("your seed here"))
.add_system(random_number_1.system())
Expand Down
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use bevy_stable as bevy;

use bevy::prelude::*;


pub use rand::Rng as _;

/// `RngPlugin` allows you to inject a (optionally seeded) random number
Expand Down Expand Up @@ -69,10 +70,7 @@ impl Plugin for RngPlugin {
None => Xoshiro256StarStar::from_entropy(),
};

#[cfg(all(feature = "bevy-nightly", not(feature = "bevy-stable")))]
app.insert_resource(RootRng { rng });
#[cfg(all(feature = "bevy-stable", not(feature = "bevy-nightly")))]
app.add_resource(RootRng { rng });
}
}

Expand Down Expand Up @@ -105,10 +103,10 @@ impl DerefMut for Rng {
}
}

impl FromResources for Rng {
fn from_resources(resources: &Resources) -> Self {
let inner = match resources.get_mut::<RootRng>() {
Some(mut rng) => Xoshiro256StarStar::from_rng(&mut rng.deref_mut().rng)
impl FromWorld for Rng {
fn from_world(world: &mut World) -> Self {
let inner = match world.get_resource::<RootRng>() {
Some(rng) => Xoshiro256StarStar::from_rng(rng.rng.clone())
.expect("failed to create rng"),
None => Xoshiro256StarStar::from_entropy(),
};
Expand Down